Skip to content

Commit

Permalink
* Queue part II
Browse files Browse the repository at this point in the history
* Removed reference to CameraCapture.Core
* Logo
  • Loading branch information
dukus committed Nov 17, 2017
1 parent 209ecfb commit d3fb532
Show file tree
Hide file tree
Showing 18 changed files with 353 additions and 39 deletions.
1 change: 1 addition & 0 deletions Capture.Workflow.Core/Capture.Workflow.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
<Compile Include="Interface\IViewElementPlugin.cs" />
<Compile Include="Interface\IViewPlugin.cs" />
<Compile Include="Interface\IWorkflowCommand.cs" />
<Compile Include="Interface\IWorkflowQueueCommand.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Database\SQLite.cs" />
Expand Down
17 changes: 17 additions & 0 deletions Capture.Workflow.Core/Classes/QueueManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using CameraControl.Devices;
using CameraControl.Devices.Classes;
using Capture.Workflow.Core.Database;
using Capture.Workflow.Core.Interface;
using GalaSoft.MvvmLight;

namespace Capture.Workflow.Core.Classes
Expand All @@ -18,6 +20,9 @@ public class QueueManager : ViewModelBase
private object _sync = new object();
private bool _isActive;

private Dictionary<string, IWorkflowQueueCommand> _loadedCommands =
new Dictionary<string, IWorkflowQueueCommand>();

public static QueueManager Instance
{
get
Expand Down Expand Up @@ -93,6 +98,18 @@ public void Process()
Count = items.Count;
foreach (var item in items)
{
IWorkflowQueueCommand command;
if (_loadedCommands.ContainsKey(item.Action))
{
command = _loadedCommands[item.Action];
}
else
{
command = WorkflowManager.Instance.GetQueueCommandPlugin(item.Action);
_loadedCommands.Add(item.Action, command);
}

item.Done = command.ExecuteQueue(item);

if (item.Done == true)
{
Expand Down
1 change: 1 addition & 0 deletions Capture.Workflow.Core/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static Settings Instance
public string DefaultWorkflowFolder => Path.Combine(BasePath, "Workflows");
public string CacheFolder => Path.Combine(DataPath, "Cache");
public string LogFolder => Path.Combine(DataPath, "Log");
public string QueueFolder => Path.Combine(DataPath, "Queue");


public Settings()
Expand Down
7 changes: 5 additions & 2 deletions Capture.Workflow.Core/Database/DbQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ public class DbQueue
[PrimaryKey, AutoIncrement]
public int Id { get; set; }

public string Action { get; set; }
public string SourceFile { get; set; }

public string Action { get; set; }

public string ActionParam { get; set; }

public bool? Done { get; set; }

public DbQueue(string action, string param)
public DbQueue(string sourceFile,string action, string param)
{
SourceFile = sourceFile;
Action = action;
ActionParam = param;
Done = false;
Expand Down
9 changes: 9 additions & 0 deletions Capture.Workflow.Core/Interface/IWorkflowQueueCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Capture.Workflow.Core.Database;

namespace Capture.Workflow.Core.Interface
{
public interface IWorkflowQueueCommand
{
bool ExecuteQueue(DbQueue queue);
}
}
7 changes: 7 additions & 0 deletions Capture.Workflow.Core/WorkflowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public WorkflowManager()
ServiceProvider.Instance.DeviceManager.PhotoCaptured += DeviceManager_PhotoCaptured;
FileItems = new AsyncObservableCollection<FileItem>();
ConfigureDatabase();
QueueManager.Instance.Start();
}

public void ConfigureDatabase()
Expand Down Expand Up @@ -524,6 +525,12 @@ public IWorkflowCommand GetCommandPlugin(string className)
return (IWorkflowCommand)Activator.CreateInstance(Type.GetType(className, AssemblyResolver, null));
}

public IWorkflowQueueCommand GetQueueCommandPlugin(string pluginName)
{
var className = Plugins.Where(x => x.Name == pluginName).Select(x => x.Class).FirstOrDefault();
return (IWorkflowQueueCommand)Activator.CreateInstance(Type.GetType(className, AssemblyResolver, null));
}

public WorkFlow CreateWorkFlow()
{
WorkFlow resflow = new WorkFlow();
Expand Down
38 changes: 34 additions & 4 deletions Capture.Workflow.Plugins/Commands/CopyFileAction.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using Capture.Workflow.Core;
using Capture.Workflow.Core.Classes;
using Capture.Workflow.Core.Classes.Attributes;
using Capture.Workflow.Core.Database;
using Capture.Workflow.Core.Interface;
using SmartFormat;

Expand All @@ -11,7 +13,7 @@ namespace Capture.Workflow.Plugins.Commands
[Description("")]
[PluginType(PluginType.Command)]
[DisplayName("CopyFile")]
public class CopyFileAction : BaseCommand, IWorkflowCommand
public class CopyFileAction : BaseCommand, IWorkflowCommand, IWorkflowQueueCommand
{

public WorkFlowCommand CreateCommand()
Expand All @@ -28,6 +30,12 @@ public WorkFlowCommand CreateCommand()
Name = "Overwrite",
PropertyType = CustomPropertyType.Bool
});
command.Properties.Add(new CustomProperty()
{
Name = "EnqueueAction",
PropertyType = CustomPropertyType.Bool,
Description = "Will execute this command in a queue in background"
});
return command;
}

Expand All @@ -40,9 +48,31 @@ public bool Execute(WorkFlowCommand command, Context context)
var filename = command.Properties["FileNameTemplate"].ToString(context);

filename = filename + Path.GetExtension(context.FileItem.TempFile);
Utils.CreateFolder(filename);
File.Copy(context.FileItem.TempFile, filename, command.Properties["Overwrite"].ToBool(context));
context.FileItem.FileName = filename;
if (command.Properties["EnqueueAction"].ToBool(context))
{
var file = Path.Combine(Settings.Instance.QueueFolder, Path.GetRandomFileName());
Utils.CreateFolder(file);
File.Copy(context.FileItem.TempFile, file, true);
WorkflowManager.Instance.Database.Add(new DbQueue(file, "CopyFile", filename));
}
else
{
Utils.CreateFolder(filename);
File.Copy(context.FileItem.TempFile, filename, command.Properties["Overwrite"].ToBool(context));
context.FileItem.FileName = filename;
}
return true;
}

public bool ExecuteQueue(DbQueue queue)
{
if (!File.Exists(queue.SourceFile))
return true;

Utils.CreateFolder(queue.ActionParam);
File.Copy(queue.SourceFile, queue.ActionParam, true);
Utils.WaitForFile(queue.SourceFile);
File.Delete(queue.SourceFile);
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Capture.Workflow.Setup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ static void Main()
new DirFiles(@"Workflows\*.*")),
new File("Capture.Workflow.exe",
new FileShortcut("Capture.Workflow", @"%ProgramMenu%\Capture.Workflow") {WorkingDirectory = @"INSTALLDIR"},
new FileShortcut("Capture.Workflow", @"%Desktop%") {WorkingDirectory = @"INSTALLDIR"}),
new File("Capture.Workflow.exe")));
new FileShortcut("Capture.Workflow", @"%Desktop%") {WorkingDirectory = @"INSTALLDIR"})
));

project.GUID = new Guid("B83E588B-BD7B-40C9-A78E-4E18E6916EA7");
//project.SourceBaseDir = "<input dir path>";
Expand Down
22 changes: 1 addition & 21 deletions Capture.Workflow.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CameraControl.Devices", "CameraControl.Devices\CameraControl.Devices.csproj", "{E8572D8B-C987-4D20-BD88-1F8925A64A82}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CameraControl.Core", "CameraControl.Core\CameraControl.Core.csproj", "{741A8DDA-4604-4CF4-8DAA-1F98A2767896}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Capture.Workflow", "Capture.Workflow\Capture.Workflow.csproj", "{5272066F-D868-423D-AF40-7B21B00C88BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Capture.Workflow.Core", "Capture.Workflow.Core\Capture.Workflow.Core.csproj", "{4B45D58C-2685-4180-BD33-4D1F818F3C40}"
Expand Down Expand Up @@ -50,24 +48,6 @@ Global
{E8572D8B-C987-4D20-BD88-1F8925A64A82}.Release|x64.Build.0 = Release|x64
{E8572D8B-C987-4D20-BD88-1F8925A64A82}.Release|x86.ActiveCfg = Release|x86
{E8572D8B-C987-4D20-BD88-1F8925A64A82}.Release|x86.Build.0 = Release|x86
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Capture.Workflow|Any CPU.ActiveCfg = Capture.Workflow|Any CPU
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Capture.Workflow|Any CPU.Build.0 = Capture.Workflow|Any CPU
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Capture.Workflow|x64.ActiveCfg = Capture.Workflow|x64
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Capture.Workflow|x64.Build.0 = Capture.Workflow|x64
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Capture.Workflow|x86.ActiveCfg = Capture.Workflow|x86
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Capture.Workflow|x86.Build.0 = Capture.Workflow|x86
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Debug|Any CPU.Build.0 = Debug|Any CPU
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Debug|x64.ActiveCfg = Debug|x64
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Debug|x64.Build.0 = Debug|x64
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Debug|x86.ActiveCfg = Debug|x86
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Debug|x86.Build.0 = Debug|x86
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Release|Any CPU.ActiveCfg = Release|Any CPU
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Release|Any CPU.Build.0 = Release|Any CPU
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Release|x64.ActiveCfg = Release|x64
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Release|x64.Build.0 = Release|x64
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Release|x86.ActiveCfg = Release|x86
{741A8DDA-4604-4CF4-8DAA-1F98A2767896}.Release|x86.Build.0 = Release|x86
{5272066F-D868-423D-AF40-7B21B00C88BA}.Capture.Workflow|Any CPU.ActiveCfg = Capture.Workflow|Any CPU
{5272066F-D868-423D-AF40-7B21B00C88BA}.Capture.Workflow|Any CPU.Build.0 = Capture.Workflow|Any CPU
{5272066F-D868-423D-AF40-7B21B00C88BA}.Capture.Workflow|x64.ActiveCfg = Capture.Workflow|Any CPU
Expand Down
4 changes: 1 addition & 3 deletions Capture.Workflow/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dragablz="http://dragablz.net/winfx/xaml/dragablz"
xmlns:converters="clr-namespace:Capture.Workflow.Wpf.Converters"
xmlns:wpf="clr-namespace:CameraControl.Core.Wpf;assembly=CameraControl.Core"
StartupUri="MainWindow.xaml" Startup="Application_Startup">
StartupUri="MainWindow.xaml" Startup="Application_Startup" SessionEnding="Application_SessionEnding">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -46,7 +45,6 @@

<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
<converters:StringToIconConverter x:Key="StringToIconConverter"/>
<wpf:NotEqualityToVisibilityConverter x:Key="NotEqualityToVisibilityConverter"/>
</ResourceDictionary>
</Application.Resources>
</Application>
9 changes: 7 additions & 2 deletions Capture.Workflow/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public partial class App : Application

private void Application_Startup(object sender, StartupEventArgs e)
{
WorkflowManager.Instance.LoadPlugins("Capture.Workflow.Plugins.dll");
Configure(Path.Combine(Settings.Instance.LogFolder, "app.log"));
WorkflowManager.Instance.LoadPlugins("Capture.Workflow.Plugins.dll");
}

public static void Configure(string logFile)
Expand All @@ -34,9 +34,9 @@ public static void Configure(string logFile)
Log.Debug("------------------------------===========================Application starting===========================------------------------------");
try
{
Log.Debug("Application version : " + Assembly.GetEntryAssembly().GetName().Version);
ServiceProvider.Instance.DeviceManager.AddFakeCamera();
ServiceProvider.Instance.DeviceManager.ConnectToCamera();
Log.Debug("Application version : " + Assembly.GetEntryAssembly().GetName().Version);
}
catch { }
}
Expand Down Expand Up @@ -82,5 +82,10 @@ public static void Configure(string appfolder, string logFile)
}
}

private void Application_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{
QueueManager.Instance.Stop();
}

}
}
21 changes: 16 additions & 5 deletions Capture.Workflow/Capture.Workflow.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>logo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetZip, Version=1.10.1.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.10.1\lib\net20\DotNetZip.dll</HintPath>
Expand Down Expand Up @@ -183,6 +186,9 @@
<Compile Include="View\WorkflowViewView.xaml.cs">
<DependentUpon>WorkflowViewView.xaml</DependentUpon>
</Compile>
<Compile Include="Wpf\Controls\Colorpicker.xaml.cs">
<DependentUpon>Colorpicker.xaml</DependentUpon>
</Compile>
<Compile Include="Wpf\Controls\EditableTextBlock.cs" />
<Compile Include="Wpf\Controls\EditableTextBlockAdorner.cs" />
<Compile Include="Wpf\Controls\IconPicker.xaml.cs">
Expand Down Expand Up @@ -222,6 +228,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Wpf\Controls\Colorpicker.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Wpf\Controls\IconPicker.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -260,10 +270,6 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CameraControl.Core\CameraControl.Core.csproj">
<Project>{741a8dda-4604-4cf4-8daa-1f98a2767896}</Project>
<Name>CameraControl.Core</Name>
</ProjectReference>
<ProjectReference Include="..\CameraControl.Devices\CameraControl.Devices.csproj">
<Project>{e8572d8b-c987-4d20-bd88-1f8925a64a82}</Project>
<Name>CameraControl.Devices</Name>
Expand All @@ -281,7 +287,12 @@
<Name>PortableDeviceLib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Resource Include="logo.ico" />
<Content Include="sqlite3.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Magick.NET-Q8-x86.7.0.7.300\build\net40\Magick.NET-Q8-x86.targets" Condition="Exists('..\packages\Magick.NET-Q8-x86.7.0.7.300\build\net40\Magick.NET-Q8-x86.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
31 changes: 31 additions & 0 deletions Capture.Workflow/Wpf/Controls/Colorpicker.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<UserControl x:Class="CameraControl.Core.Wpf.Colorpicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:CameraControl.Core.Wpf"
x:Name="ThisColorPicker">
<UserControl.Resources>
<DataTemplate DataType="{x:Type wpf:ColorViewModel}">
<StackPanel Orientation="Horizontal" Margin="2">
<Grid>
<!-- Draw a checkboard rectangle first, in case the selected color is transparent -->
<Rectangle Fill="{Binding ElementName=ThisColorPicker, Path=CheckerBrush}" Stroke="Black" SnapsToDevicePixels="True" Width="14" Height="14"/>
<!-- The actual color -->
<Rectangle Fill="{Binding Path=Brush}" Stroke="Black" SnapsToDevicePixels="True" Width="14" Height="14"/>
</Grid>
<!-- Name of the color -->
<TextBlock Text="{Binding Path=Name}" Margin="4 0 4 0" VerticalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid>
<ComboBox Name="ColorList1"
SelectedValue="{Binding ElementName=ThisColorPicker, Path=SelectedColor}"
SnapsToDevicePixels="True">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
</Grid>
</UserControl>
Loading

0 comments on commit d3fb532

Please sign in to comment.