Skip to content

Commit fb9ee07

Browse files
author
WS2\Carlos
committed
New repo commit
0 parents  commit fb9ee07

File tree

155 files changed

+60196
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+60196
-0
lines changed

Core/AsyncDispatcher.cs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Timers;
5+
using System.Text;
6+
7+
using BAFactory.Moira.Core.Elements;
8+
using BAFactory.Moira.Core.Log;
9+
using System.Threading.Tasks;
10+
11+
namespace BAFactory.Moira.Core
12+
{
13+
public class AsyncDispatcher : Dispatcher
14+
{
15+
public override bool IsEnabled
16+
{
17+
get { return MainTimer.Enabled; }
18+
}
19+
public AsyncDispatcher()
20+
{
21+
InitializeComponents();
22+
}
23+
private void InitializeComponents()
24+
{
25+
MainTimer = new System.Timers.Timer();
26+
MainTimer.Interval = 1000;
27+
}
28+
protected override async void RunOnStartup()
29+
{
30+
await Configuration.LogWriter.LogMessageAsync(LogLevel.Debug, "Running tasks on Startup");
31+
foreach (Timetable.Entry entry in Configuration.TasksLists)
32+
{
33+
if (!entry.Task.Enabled || !entry.Task.RunOnStartUp || entry.IsExecuting)
34+
{
35+
continue;
36+
}
37+
38+
Dispatch(entry);
39+
}
40+
}
41+
protected override async void AttendTimer(object sender, ElapsedEventArgs e)
42+
{
43+
await Configuration.LogWriter.LogMessageAsync(LogLevel.Info, "Running tasks on schedule");
44+
foreach (Timetable.Entry entry in Configuration.TasksLists)
45+
{
46+
bool isOnTime = await CheckIsOnTime(entry);
47+
if (isOnTime)
48+
{
49+
Dispatch(entry);
50+
}
51+
}
52+
}
53+
private async Task<bool> CheckIsOnTime(Timetable.Entry e)
54+
{
55+
bool isOnTime = (ulong)DateTime.Now.Ticks >= e.NextRun;
56+
await Configuration.LogWriter.LogMessageAsync(LogLevel.Debug, string.Format("Task {0} is {1}on time", e.Task.Id, isOnTime ? "NOT " : string.Empty));
57+
await Configuration.LogWriter.LogMessageAsync(LogLevel.Debug, string.Format("Task {0} is {1}running", e.Task.Id, !e.IsExecuting ? "NOT " : string.Empty));
58+
await Configuration.LogWriter.LogMessageAsync(LogLevel.Debug, string.Format("Task {0} will {1}run now", e.Task.Id, (!(e.IsExecuting && isOnTime)) ? "NOT " : string.Empty));
59+
60+
61+
return (!e.IsExecuting && (ulong)DateTime.Now.Ticks >= e.NextRun);
62+
}
63+
private async void Dispatch(Timetable.Entry e)
64+
{
65+
await Configuration.LogWriter.LogMessageAsync(LogLevel.Debug, string.Concat("Spawning execution of task with Id: ", e.Task.Id));
66+
67+
if (e == null)
68+
{
69+
return;
70+
}
71+
72+
UpdateTimeTable(e, true);
73+
74+
try
75+
{
76+
bool success = false;
77+
78+
success = await e.Task.ExecuteAsync();
79+
80+
if (!success && !string.IsNullOrEmpty(e.Task.Error))
81+
{
82+
await Configuration.LogWriter.LogMessageAsync(LogLevel.Error, e.Task.Error);
83+
e.Task.Revert();
84+
}
85+
}
86+
finally
87+
{
88+
UpdateTimeTable(e, false);
89+
}
90+
}
91+
private static void UpdateTimeTable(Timetable.Entry e, bool executing)
92+
{
93+
ulong currentTicks = 0;
94+
e.IsExecuting = executing;
95+
96+
currentTicks = (ulong)DateTime.Now.Ticks;
97+
98+
if (executing)
99+
e.NextRun = currentTicks + e.Task.Interval;
100+
}
101+
private void CalculateTimeTable()
102+
{ }
103+
private void ResetTimeTable()
104+
{ }
105+
}
106+
}

Core/Config Files/FilesDispatcher.xml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Configuration
3+
xmlns="http://BAFactory.net/schemas/FilesDispatcher"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://BAFactory.net/schemas/ FilesDispatcher.xsd">
6+
<Assemblies>
7+
<Steps>
8+
<Step Type="Copy" Class="BAFactory.Moira.Steps.Copy" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
9+
<Step Type="Move" Class="BAFactory.Moira.Steps.Move" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
10+
<Step Type="CreateFolder" Class="BAFactory.Moira.Steps.CreateFolder" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
11+
</Steps>
12+
<FileAnalyzers>
13+
<FileAnalyzer Type="ExifTags" Class="BAFactory.Moira.FileAnalyzers.ExifTagFileAnalyzer" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
14+
<FileAnalyzer Type="FileAttribute" Class="BAFactory.Moira.FileAnalyzers.AttributesFileAnalyzer" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
15+
<FileAnalyzer Type="WpFileName" Class="BAFactory.Moira.FileAnalyzers.WpVideoNameAnalyzer" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
16+
</FileAnalyzers>
17+
<LogProvider Type="TextFileLog" Class="BAFactory.Moira.Core.Log.TextFileLogProvider" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
18+
<Dispatcher Type="AsyncDispatcher" Class="BAFactory.Moira.Core.AsyncDispatcher" Assembly="BAFactory.Moira.Core" PublicKeyToken="null" Culture="neutral" Version="1.0.0.0" />
19+
</Assemblies>
20+
21+
<Tasks>
22+
<Task id="OrderPictures" enabled="true" runonstartup="true">
23+
<BaseDirectory>
24+
<Path><![CDATA[d:\temp]]></Path>
25+
<Pattern isRegEx="false"><![CDATA[*.mov]]></Pattern>
26+
<Interval>10</Interval>
27+
</BaseDirectory>
28+
<StepsGroups>
29+
<StepsGroup id="ByDateAquired" enabled="true" breakcondition="OnSuccess">
30+
<Step Type="CreateFolder" id="CreateFolderByDateAquired" breakcondition="OnError">
31+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
32+
<Parameters>
33+
<Parameter name="FullDirectoryName" analyzer="ExifTags" attributeName="DateTime" attributeType="System.DateTime" ><![CDATA[d:\temp\{yyyy - MM - dd}]]></Parameter>
34+
</Parameters>
35+
</Step >
36+
<Step Type="Move" id="MoveFileByDateTaken">
37+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
38+
<Parameters>
39+
<Parameter name="DestinationPath" fromLastResult="true"></Parameter>
40+
</Parameters>
41+
</Step >
42+
</StepsGroup>
43+
<StepsGroup id="ByDateTaken" enabled="true" breakcondition="OnSuccess">
44+
<Step Type="CreateFolder" id="CreateFolderByDateTaken" breakcondition="OnError">
45+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
46+
<Parameters>
47+
<Parameter name="FullDirectoryName" analyzer="ExifTags" attributeName="DateTimeOriginal" attributeType="System.DateTime" ><![CDATA[d:\temp\{yyyy - MM - dd}]]></Parameter>
48+
</Parameters>
49+
</Step >
50+
<Step Type="Move" id="MoveFileByDateTaken">
51+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
52+
<Parameters>
53+
<Parameter name="DestinationPath" fromLastResult="true"></Parameter>
54+
</Parameters>
55+
</Step >
56+
</StepsGroup>
57+
<StepsGroup id="ByDateModified" enabled="true" breakcondition="OnSuccess">
58+
<Step Type="CreateFolder" id="CreateFolderByDateModified" breakcondition="OnError">
59+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
60+
<Parameters>
61+
<Parameter name="FullDirectoryName" analyzer="FileAttribute" attributeName="LastWriteTime" attributeType="System.DateTime" ><![CDATA[d:\temp\{yyyy - MM - dd}]]></Parameter>
62+
</Parameters>
63+
</Step >
64+
<Step Type="Move" id="MoveFileByDateModified">
65+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
66+
<Parameters>
67+
<Parameter name="DestinationPath" fromLastResult="true"></Parameter>
68+
</Parameters>
69+
</Step >
70+
</StepsGroup >
71+
<StepsGroup id="ByWpFileName" enabled="true" breakcondition="OnSuccess">
72+
<Step Type="CreateFolder" id="CreateFolderByDateModified" breakcondition="OnError">
73+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
74+
<Parameters>
75+
<Parameter name="FullDirectoryName" analyzer="WpFileName" attributeName="Name" attributeType="System.DateTime" ><![CDATA[d:\temp\{yyyy - MM - dd}]]></Parameter>
76+
</Parameters>
77+
</Step >
78+
<Step Type="Move" id="MoveFileByWpFileName">
79+
<Pattern isRegEx="false"><![CDATA[*.*]]></Pattern>
80+
<Parameters>
81+
<Parameter name="DestinationPath" fromLastResult="true"></Parameter>
82+
</Parameters>
83+
</Step >
84+
</StepsGroup >
85+
</StepsGroups>
86+
</Task>
87+
</Tasks>
88+
</Configuration>

Core/Config Files/FilesDispatcher.xsd

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema id="FilesDispatcherConfiguration"
3+
elementFormDefault="unqualified"
4+
attributeFormDefault="unqualified"
5+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
6+
xmlns="http://BAFactory.net/schemas/FilesDispatcher/"
7+
targetNamespace="http://BAFactory.net/schemas/FilesDispatcher/"
8+
>
9+
10+
<xs:complexType name="AssemblyInfoElement">
11+
<xs:attribute name="Type" type="xs:string" use="required" />
12+
<xs:attribute name="Class" type="xs:string" use="required"/>
13+
<xs:attribute name="Assembly" type="xs:string" use="required"/>
14+
<xs:attribute name="PublicKeyToken" type="xs:string" />
15+
<xs:attribute name="Culture" type="xs:string" />
16+
<xs:attribute name="Version" type="xs:string" />
17+
</xs:complexType>
18+
19+
<xs:complexType name="PatternElement">
20+
<xs:simpleContent>
21+
<xs:extension base="xs:string">
22+
<xs:attribute name="IsRegEx" type="xs:boolean" use="required"/>
23+
</xs:extension>
24+
</xs:simpleContent>
25+
</xs:complexType>
26+
27+
<xs:complexType name ="ParameterElement">
28+
<xs:simpleContent>
29+
<xs:extension base="xs:string">
30+
<xs:attribute name="Name" />
31+
<xs:attribute name="Analyzer" />
32+
<xs:attribute name="AttributeName" />
33+
<xs:attribute name="AttributeType" />
34+
</xs:extension>
35+
</xs:simpleContent>
36+
</xs:complexType>
37+
38+
<xs:element name="Configuration">
39+
<xs:complexType>
40+
<xs:sequence>
41+
<xs:element name="Assemblies" minOccurs="1">
42+
<xs:complexType>
43+
<xs:sequence>
44+
<xs:element name="Steps">
45+
<xs:complexType>
46+
<xs:all>
47+
<xs:element name="Step" type="AssemblyInfoElement" />
48+
</xs:all>
49+
</xs:complexType>
50+
</xs:element>
51+
<xs:element name="FileAnalyzers">
52+
<xs:complexType>
53+
<xs:all>
54+
<xs:element name="Step"/>
55+
</xs:all>
56+
</xs:complexType>
57+
</xs:element>
58+
<xs:element name="LogProvider" type="AssemblyInfoElement" />
59+
</xs:sequence>
60+
</xs:complexType>
61+
</xs:element>
62+
<xs:element name="Tasks" minOccurs="1" >
63+
<xs:complexType>
64+
<xs:sequence>
65+
<xs:element name="BaseDirectory" minOccurs="1" maxOccurs="1">
66+
<xs:complexType>
67+
<xs:sequence>
68+
<xs:element name="Path" type="xs:string" minOccurs="1" maxOccurs="1" />
69+
<xs:element name="Pattern" type="PatternElement" minOccurs="1" maxOccurs="1" />
70+
<xs:element name="Interval" type="xs:unsignedLong" minOccurs="1" maxOccurs="1" />
71+
</xs:sequence>
72+
</xs:complexType>
73+
</xs:element>
74+
<xs:element name="StepsGroups" minOccurs="1" maxOccurs="1">
75+
<xs:complexType>
76+
<xs:all>
77+
<xs:element name="StepsGroup">
78+
<xs:complexType>
79+
<xs:all>
80+
<xs:element name="Step" minOccurs="1">
81+
<xs:complexType>
82+
<xs:sequence>
83+
<xs:element name="Pattern" type="PatternElement" minOccurs="1" maxOccurs="1"/>
84+
<xs:element name="Parameters" minOccurs="1" maxOccurs="1">
85+
<xs:complexType>
86+
<xs:all>
87+
<xs:element name="Parameter" type="ParameterElement" />
88+
</xs:all>
89+
</xs:complexType>
90+
</xs:element>
91+
</xs:sequence>
92+
</xs:complexType>
93+
</xs:element>
94+
</xs:all>
95+
</xs:complexType>
96+
</xs:element>
97+
</xs:all>
98+
</xs:complexType>
99+
</xs:element>
100+
</xs:sequence>
101+
<xs:attribute name="Id" type="xs:string" use="required" />
102+
<xs:attribute name="Enabled" type="xs:boolean" use="required"/>
103+
<xs:attribute name="RunOnStartUp" type="xs:boolean" use="required"/>
104+
</xs:complexType>
105+
</xs:element>
106+
107+
</xs:sequence>
108+
</xs:complexType>
109+
</xs:element>
110+
111+
</xs:schema>

Core/Config Files/TextLogProvider.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
3+
<TextLogProvider
4+
xmlns="http://BAFactory.net/schemas/TextLogProvider"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://BAFactory.net/schemas/ TextLogProvider.xsd">
7+
8+
<Level>Info</Level>
9+
<FilePath>./log/FilesDispatcherLog.txt</FilePath>
10+
<RotateOption>OnSizeInBytes</RotateOption>
11+
<RotateLimit>1048576</RotateLimit>
12+
<MaxFiles>5</MaxFiles>
13+
</TextLogProvider>

Core/Config Files/TextLogProvider.xsd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema id="FilesDispatcherConfiguration"
3+
elementFormDefault="unqualified"
4+
attributeFormDefault="unqualified"
5+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
6+
xmlns="http://BAFactory.net/schemas/TextLogProvider/"
7+
targetNamespace="http://BAFactory.net/schemas/TextLogProvider/"
8+
>
9+
<xs:simpleType name="RotateOptions">
10+
<xs:restriction base="xs:string">
11+
<xs:enumeration value="OnTimeSpanInMinutes"/>
12+
<xs:enumeration value="OnSizeInBytes"/>
13+
</xs:restriction>
14+
</xs:simpleType>
15+
16+
<xs:simpleType name="LogLevels">
17+
<xs:restriction base="xs:string">
18+
<xs:enumeration value="Error"/>
19+
<xs:enumeration value="Warning"/>
20+
<xs:enumeration value="Info"/>
21+
<xs:enumeration value="Debug"/>
22+
</xs:restriction>
23+
</xs:simpleType>
24+
25+
<xs:element name="Log">
26+
<xs:complexType>
27+
<xs:sequence>
28+
<xs:element name="Level" type="LogLevels" minOccurs="1" maxOccurs="1" />
29+
<xs:element name="FilePath" type="xs:string" minOccurs="1" maxOccurs="1" />
30+
<xs:element name="RotateOption" type="RotateOptions" minOccurs="1" maxOccurs="1" />
31+
<xs:element name="MaxFiles" type="xs:short" minOccurs="1" maxOccurs="1" />
32+
<xs:element name="MaxFiles" type="xs:short" minOccurs="1" maxOccurs="1" />
33+
</xs:sequence>
34+
</xs:complexType>
35+
</xs:element>
36+
</xs:schema>

0 commit comments

Comments
 (0)