Replace AutomationBotFactory with one using BaseFactory<>
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using VAR.ScreenAutomation.Bots;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
|
||||
namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
public static class AutomationBotFactory
|
||||
{
|
||||
private static Dictionary<string, Type> _dictAutomationBots;
|
||||
|
||||
private static Dictionary<string, Type> GetDict()
|
||||
{
|
||||
if (_dictAutomationBots != null)
|
||||
{
|
||||
return _dictAutomationBots;
|
||||
}
|
||||
|
||||
Type iAutomationBot = typeof(IAutomationBot);
|
||||
IEnumerable<Type> automationBotTypes = AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.SelectMany(x => x.GetTypes())
|
||||
.Where(x =>
|
||||
x.IsAbstract == false &&
|
||||
x.IsInterface == false &&
|
||||
iAutomationBot.IsAssignableFrom(x) &&
|
||||
true);
|
||||
_dictAutomationBots = automationBotTypes.ToDictionary(t =>
|
||||
{
|
||||
IAutomationBot automationBot =
|
||||
System.Runtime.Serialization.FormatterServices.GetUninitializedObject(t) as IAutomationBot;
|
||||
return automationBot?.Name ?? t.Name;
|
||||
});
|
||||
|
||||
return _dictAutomationBots;
|
||||
}
|
||||
|
||||
public static object[] GetAllAutomationBots()
|
||||
{
|
||||
Dictionary<string, Type> dict = GetDict();
|
||||
string[] allAutomationBots = dict.Select(p => p.Key).ToArray();
|
||||
return allAutomationBots.ToArray<object>();
|
||||
}
|
||||
|
||||
public static IAutomationBot CreateFromName(string name)
|
||||
{
|
||||
Dictionary<string, Type> dict = GetDict();
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
return new DummyBot();
|
||||
}
|
||||
|
||||
if (dict.ContainsKey(name) == false)
|
||||
{
|
||||
throw new NotImplementedException($"Can't create IAutomationBot with this name: {name}");
|
||||
}
|
||||
|
||||
Type proxyCmdExecutorType = dict[name];
|
||||
|
||||
IAutomationBot automationBot = Activator.CreateInstance(proxyCmdExecutorType) as IAutomationBot;
|
||||
|
||||
return automationBot;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
VAR.Toolbox/Code/Bots/AutomationBotFactory.cs
Normal file
8
VAR.Toolbox/Code/Bots/AutomationBotFactory.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using VAR.Toolbox.Code.Bots;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class AutomationBotFactory: BaseFactory<IAutomationBot>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Drawing;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
|
||||
namespace VAR.ScreenAutomation.Bots
|
||||
namespace VAR.Toolbox.Code.Bots
|
||||
{
|
||||
public class DummyBot : IAutomationBot
|
||||
{
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System.Drawing;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
|
||||
namespace VAR.ScreenAutomation.Interfaces
|
||||
namespace VAR.Toolbox.Code.Bots
|
||||
{
|
||||
public interface IAutomationBot
|
||||
public interface IAutomationBot: INamed
|
||||
{
|
||||
string Name { get; }
|
||||
IConfiguration GetDefaultConfiguration();
|
||||
void Init(VAR.Toolbox.Code.IOutputHandler output, IConfiguration config);
|
||||
Bitmap Process(Bitmap bmpInput, VAR.Toolbox.Code.IOutputHandler output);
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Text;
|
||||
using VAR.ScreenAutomation.Code;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
|
||||
namespace VAR.ScreenAutomation.Bots
|
||||
namespace VAR.Toolbox.Code.Bots
|
||||
{
|
||||
public class TetrisBot : IAutomationBot
|
||||
{
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using VAR.ScreenAutomation.Code;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
using VAR.Toolbox.Code;
|
||||
using VAR.Toolbox.Code.Bots;
|
||||
using Mouse = VAR.ScreenAutomation.Code.Mouse;
|
||||
using Screenshoter = VAR.ScreenAutomation.Code.Screenshoter;
|
||||
|
||||
// ReSharper disable LocalizableElement
|
||||
|
||||
@@ -52,7 +57,7 @@ namespace VAR.ScreenAutomation
|
||||
TransparencyKey = Color.LimeGreen;
|
||||
picCapturer.BackColor = Color.LimeGreen;
|
||||
|
||||
ddlAutomationBot.Items.AddRange(AutomationBotFactory.GetAllAutomationBots());
|
||||
ddlAutomationBot.Items.AddRange(AutomationBotFactory.GetNames().ToArray<object>());
|
||||
ddlAutomationBot.SelectedItem =
|
||||
configuration.Get("ddlAutomationBot", (string)ddlAutomationBot.SelectedItem);
|
||||
if (ddlAutomationBot.SelectedIndex < 0)
|
||||
|
||||
@@ -74,8 +74,8 @@
|
||||
<Compile Include="..\VAR.Json\VAR.Json\ParserContext.cs">
|
||||
<Link>Code\Json\ParserContext.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Code\AutomationBotFactory.cs" />
|
||||
<Compile Include="Code\BaseFactory.cs" />
|
||||
<Compile Include="Code\Bots\AutomationBotFactory.cs" />
|
||||
<Compile Include="Code\Bots\DummyBot.cs" />
|
||||
<Compile Include="Code\Bots\IAutomationBot.cs" />
|
||||
<Compile Include="Code\Bots\Mouse.cs" />
|
||||
|
||||
Reference in New Issue
Block a user