Implement AutomationBotFactory and UI for Bot selection.
This commit is contained in:
@@ -7,6 +7,8 @@ namespace VAR.ScreenAutomation.Bots
|
|||||||
{
|
{
|
||||||
private int frameCount = 0;
|
private int frameCount = 0;
|
||||||
|
|
||||||
|
public string Name => "Dummy";
|
||||||
|
|
||||||
public void Init(IOutputHandler output)
|
public void Init(IOutputHandler output)
|
||||||
{
|
{
|
||||||
frameCount = 0;
|
frameCount = 0;
|
||||||
|
|||||||
63
VAR.ScreenAutomation/Code/AutomationBotFactory.cs
Normal file
63
VAR.ScreenAutomation/Code/AutomationBotFactory.cs
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using VAR.ScreenAutomation.Bots;
|
||||||
|
using VAR.ScreenAutomation.Interfaces;
|
||||||
|
|
||||||
|
namespace VAR.ScreenAutomation.Code
|
||||||
|
{
|
||||||
|
public class AutomationBotFactory
|
||||||
|
{
|
||||||
|
private static Dictionary<string, Type> _dictAutomationBots = null;
|
||||||
|
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
return _dictAutomationBots;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static object[] GetAllAutomationBots()
|
||||||
|
{
|
||||||
|
Dictionary<string, Type> dict = GetDict();
|
||||||
|
string[] allAutomationBots = dict.Select(p => p.Key).ToArray();
|
||||||
|
return allAutomationBots;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(string.Format("Can't create IAutomationBot with this name: {0}", name));
|
||||||
|
}
|
||||||
|
Type proxyCmdExecutorType = dict[name];
|
||||||
|
|
||||||
|
IAutomationBot automationBot = Activator.CreateInstance(proxyCmdExecutorType) as IAutomationBot;
|
||||||
|
|
||||||
|
return automationBot;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
44
VAR.ScreenAutomation/FrmScreenAutomation.Designer.cs
generated
44
VAR.ScreenAutomation/FrmScreenAutomation.Designer.cs
generated
@@ -31,8 +31,9 @@
|
|||||||
this.picCapturer = new System.Windows.Forms.PictureBox();
|
this.picCapturer = new System.Windows.Forms.PictureBox();
|
||||||
this.splitMain = new System.Windows.Forms.SplitContainer();
|
this.splitMain = new System.Windows.Forms.SplitContainer();
|
||||||
this.splitOutput = new System.Windows.Forms.SplitContainer();
|
this.splitOutput = new System.Windows.Forms.SplitContainer();
|
||||||
this.picPreview = new VAR.ScreenAutomation.Controls.CtrImageViewer();
|
this.ddlAutomationBot = new System.Windows.Forms.ComboBox();
|
||||||
this.btnStartEnd = new System.Windows.Forms.Button();
|
this.btnStartEnd = new System.Windows.Forms.Button();
|
||||||
|
this.picPreview = new VAR.ScreenAutomation.Controls.CtrImageViewer();
|
||||||
this.ctrOutput = new VAR.ScreenAutomation.Controls.CtrOutput();
|
this.ctrOutput = new VAR.ScreenAutomation.Controls.CtrOutput();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.picCapturer)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.picCapturer)).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.splitMain)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.splitMain)).BeginInit();
|
||||||
@@ -91,12 +92,37 @@
|
|||||||
//
|
//
|
||||||
// splitOutput.Panel2
|
// splitOutput.Panel2
|
||||||
//
|
//
|
||||||
|
this.splitOutput.Panel2.Controls.Add(this.ddlAutomationBot);
|
||||||
this.splitOutput.Panel2.Controls.Add(this.btnStartEnd);
|
this.splitOutput.Panel2.Controls.Add(this.btnStartEnd);
|
||||||
this.splitOutput.Panel2.Controls.Add(this.ctrOutput);
|
this.splitOutput.Panel2.Controls.Add(this.ctrOutput);
|
||||||
this.splitOutput.Size = new System.Drawing.Size(309, 816);
|
this.splitOutput.Size = new System.Drawing.Size(309, 816);
|
||||||
this.splitOutput.SplitterDistance = 371;
|
this.splitOutput.SplitterDistance = 371;
|
||||||
this.splitOutput.TabIndex = 4;
|
this.splitOutput.TabIndex = 4;
|
||||||
//
|
//
|
||||||
|
// ddlAutomationBot
|
||||||
|
//
|
||||||
|
this.ddlAutomationBot.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.ddlAutomationBot.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||||
|
this.ddlAutomationBot.FormattingEnabled = true;
|
||||||
|
this.ddlAutomationBot.Location = new System.Drawing.Point(13, 4);
|
||||||
|
this.ddlAutomationBot.Name = "ddlAutomationBot";
|
||||||
|
this.ddlAutomationBot.Size = new System.Drawing.Size(293, 24);
|
||||||
|
this.ddlAutomationBot.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// btnStartEnd
|
||||||
|
//
|
||||||
|
this.btnStartEnd.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.btnStartEnd.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.btnStartEnd.Location = new System.Drawing.Point(15, 34);
|
||||||
|
this.btnStartEnd.Name = "btnStartEnd";
|
||||||
|
this.btnStartEnd.Size = new System.Drawing.Size(294, 39);
|
||||||
|
this.btnStartEnd.TabIndex = 3;
|
||||||
|
this.btnStartEnd.Text = "Start";
|
||||||
|
this.btnStartEnd.UseVisualStyleBackColor = true;
|
||||||
|
this.btnStartEnd.Click += new System.EventHandler(this.BtnStartEnd_Click);
|
||||||
|
//
|
||||||
// picPreview
|
// picPreview
|
||||||
//
|
//
|
||||||
this.picPreview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.picPreview.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
@@ -110,25 +136,14 @@
|
|||||||
this.picPreview.TabIndex = 1;
|
this.picPreview.TabIndex = 1;
|
||||||
this.picPreview.TabStop = false;
|
this.picPreview.TabStop = false;
|
||||||
//
|
//
|
||||||
// btnStartEnd
|
|
||||||
//
|
|
||||||
this.btnStartEnd.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
|
||||||
this.btnStartEnd.Location = new System.Drawing.Point(12, 3);
|
|
||||||
this.btnStartEnd.Name = "btnStartEnd";
|
|
||||||
this.btnStartEnd.Size = new System.Drawing.Size(294, 39);
|
|
||||||
this.btnStartEnd.TabIndex = 3;
|
|
||||||
this.btnStartEnd.Text = "Start";
|
|
||||||
this.btnStartEnd.UseVisualStyleBackColor = true;
|
|
||||||
this.btnStartEnd.Click += new System.EventHandler(this.BtnStartEnd_Click);
|
|
||||||
//
|
|
||||||
// ctrOutput
|
// ctrOutput
|
||||||
//
|
//
|
||||||
this.ctrOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
this.ctrOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
| System.Windows.Forms.AnchorStyles.Left)
|
| System.Windows.Forms.AnchorStyles.Left)
|
||||||
| System.Windows.Forms.AnchorStyles.Right)));
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.ctrOutput.Location = new System.Drawing.Point(12, 48);
|
this.ctrOutput.Location = new System.Drawing.Point(12, 79);
|
||||||
this.ctrOutput.Name = "ctrOutput";
|
this.ctrOutput.Name = "ctrOutput";
|
||||||
this.ctrOutput.Size = new System.Drawing.Size(294, 380);
|
this.ctrOutput.Size = new System.Drawing.Size(294, 349);
|
||||||
this.ctrOutput.TabIndex = 2;
|
this.ctrOutput.TabIndex = 2;
|
||||||
this.ctrOutput.Text = "ctrOutput1";
|
this.ctrOutput.Text = "ctrOutput1";
|
||||||
//
|
//
|
||||||
@@ -164,6 +179,7 @@
|
|||||||
private System.Windows.Forms.SplitContainer splitMain;
|
private System.Windows.Forms.SplitContainer splitMain;
|
||||||
private System.Windows.Forms.SplitContainer splitOutput;
|
private System.Windows.Forms.SplitContainer splitOutput;
|
||||||
private System.Windows.Forms.Button btnStartEnd;
|
private System.Windows.Forms.Button btnStartEnd;
|
||||||
|
private System.Windows.Forms.ComboBox ddlAutomationBot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using VAR.ScreenAutomation.Bots;
|
|
||||||
using VAR.ScreenAutomation.Code;
|
using VAR.ScreenAutomation.Code;
|
||||||
using VAR.ScreenAutomation.Interfaces;
|
using VAR.ScreenAutomation.Interfaces;
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ namespace VAR.ScreenAutomation
|
|||||||
public partial class FrmScreenAutomation : Form
|
public partial class FrmScreenAutomation : Form
|
||||||
{
|
{
|
||||||
private bool _running = false;
|
private bool _running = false;
|
||||||
private IAutomationBot _automationBot = new DummyBot();
|
private IAutomationBot _automationBot = null;
|
||||||
|
|
||||||
private Timer timTicker;
|
private Timer timTicker;
|
||||||
private Bitmap bmpScreen = null;
|
private Bitmap bmpScreen = null;
|
||||||
@@ -31,6 +30,11 @@ namespace VAR.ScreenAutomation
|
|||||||
TransparencyKey = Color.LimeGreen;
|
TransparencyKey = Color.LimeGreen;
|
||||||
picCapturer.BackColor = Color.LimeGreen;
|
picCapturer.BackColor = Color.LimeGreen;
|
||||||
|
|
||||||
|
|
||||||
|
ddlAutomationBot.Items.AddRange(AutomationBotFactory.GetAllAutomationBots());
|
||||||
|
ddlAutomationBot.SelectedIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
if (components == null) { components = new Container(); }
|
if (components == null) { components = new Container(); }
|
||||||
timTicker = new Timer(components)
|
timTicker = new Timer(components)
|
||||||
{
|
{
|
||||||
@@ -80,6 +84,7 @@ namespace VAR.ScreenAutomation
|
|||||||
if (_running) { return; }
|
if (_running) { return; }
|
||||||
_running = true;
|
_running = true;
|
||||||
btnStartEnd.Text = "End";
|
btnStartEnd.Text = "End";
|
||||||
|
_automationBot = AutomationBotFactory.CreateFromName((string)ddlAutomationBot.SelectedItem);
|
||||||
_automationBot?.Init(ctrOutput);
|
_automationBot?.Init(ctrOutput);
|
||||||
Point pointCapturerCenter = picCapturer.PointToScreen(new Point(picCapturer.Width / 2, picCapturer.Height / 2));
|
Point pointCapturerCenter = picCapturer.PointToScreen(new Point(picCapturer.Width / 2, picCapturer.Height / 2));
|
||||||
Mouse.SetPosition((uint)pointCapturerCenter.X, (uint)pointCapturerCenter.Y);
|
Mouse.SetPosition((uint)pointCapturerCenter.X, (uint)pointCapturerCenter.Y);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace VAR.ScreenAutomation.Interfaces
|
|||||||
{
|
{
|
||||||
public interface IAutomationBot
|
public interface IAutomationBot
|
||||||
{
|
{
|
||||||
|
string Name { get; }
|
||||||
void Init(IOutputHandler output);
|
void Init(IOutputHandler output);
|
||||||
Bitmap Process(Bitmap bmpInput, IOutputHandler output);
|
Bitmap Process(Bitmap bmpInput, IOutputHandler output);
|
||||||
string ResponseKeys();
|
string ResponseKeys();
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Bots\DummyBot.cs" />
|
<Compile Include="Bots\DummyBot.cs" />
|
||||||
|
<Compile Include="Code\AutomationBotFactory.cs" />
|
||||||
<Compile Include="Code\Mouse.cs" />
|
<Compile Include="Code\Mouse.cs" />
|
||||||
<Compile Include="Code\Screenshoter.cs" />
|
<Compile Include="Code\Screenshoter.cs" />
|
||||||
<Compile Include="Code\WindowHandling.cs" />
|
<Compile Include="Code\WindowHandling.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user