Changes recommended by Rider/Resharper
This commit is contained in:
13
.idea/.idea.VAR.ScreenAutomation/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.VAR.ScreenAutomation/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/projectSettingsUpdater.xml
|
||||
/.idea.VAR.ScreenAutomation.iml
|
||||
/contentModel.xml
|
||||
/modules.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
4
.idea/.idea.VAR.ScreenAutomation/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.VAR.ScreenAutomation/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
.idea/.idea.VAR.ScreenAutomation/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.VAR.ScreenAutomation/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/.idea.VAR.ScreenAutomation/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.VAR.ScreenAutomation/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
60
VAR.ScreenAutomation.sln.DotSettings
Normal file
60
VAR.ScreenAutomation.sln.DotSettings
Normal file
@@ -0,0 +1,60 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_IFELSE/@EntryValue">NotRequired</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/TRAILING_COMMA_IN_MULTILINE_LISTS/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/TRAILING_COMMA_IN_SINGLELINE_LISTS/@EntryValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EMPTY_BLOCK_STYLE/@EntryValue">TOGETHER_SAME_LINE</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_EMBEDDED_BLOCK_ARRANGEMENT/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_BLOCK_ON_SAME_LINE/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/ALLOW_FAR_ALIGNMENT/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/NormalizeTagNames/@EntryValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/ProcessingInstructionAttributeIndenting/@EntryValue">OneStep</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/TagAttributeIndenting/@EntryValue">OneStep</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/TagSpaceBeforeHeaderEnd1/@EntryValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseVarWhenEvident</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AES/@EntryIndexedValue">AES</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AM/@EntryIndexedValue">AM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AUX/@EntryIndexedValue">AUX</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BPP/@EntryIndexedValue">BPP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=CYC/@EntryIndexedValue">CYC</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DC/@EntryIndexedValue">DC</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DES/@EntryIndexedValue">DES</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EPM/@EntryIndexedValue">EPM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GDI/@EntryIndexedValue">GDI</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RECT/@EntryIndexedValue">RECT</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RGB/@EntryIndexedValue">RGB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SCART/@EntryIndexedValue">SCART</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SPDIF/@EntryIndexedValue">SPDIF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQL/@EntryIndexedValue">SQL</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SRCCOPY/@EntryIndexedValue">SRCCOPY</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TCP/@EntryIndexedValue">TCP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=URL/@EntryIndexedValue">URL</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=USB/@EntryIndexedValue">USB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=VAR/@EntryIndexedValue">VAR</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WMIC/@EntryIndexedValue">WMIC</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=YRYBY/@EntryIndexedValue">YRYBY</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=EnumMember/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb"><ExtraRule Prefix="T" Suffix="" Style="AaBb_AaBb" /></Policy></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Interfaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=LocalConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Locals/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Method/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Parameters/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Property/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PublicFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -17,12 +17,12 @@ namespace VAR.ScreenAutomation.Bots
|
||||
private TetrisGrid _workGrid1;
|
||||
private double[] _columnEvaluation;
|
||||
|
||||
private bool _shapeFound = false;
|
||||
private bool _shapeFound;
|
||||
private int _shapeX;
|
||||
private int _shapeY;
|
||||
private double _bestEvaluation = double.MinValue;
|
||||
private int _bestXOffset = 0;
|
||||
private int _bestRotation = 0;
|
||||
private int _bestXOffset;
|
||||
private int _bestRotation;
|
||||
|
||||
public string Name => "Tetris";
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
new TetrisShape(),
|
||||
};
|
||||
output.Clean();
|
||||
output.AddLine(string.Format("TetrisBot: Starting {0}", DateTime.UtcNow.ToString("s")));
|
||||
output.AddLine($"TetrisBot: Starting {DateTime.UtcNow:s}");
|
||||
}
|
||||
|
||||
public Bitmap Process(Bitmap bmpInput, IOutputHandler output)
|
||||
@@ -74,6 +74,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
_currentShape[_bestRotation].Drop(_workGrid0, _shapeX + _bestXOffset, _shapeY, TetrisGrid.CellShapeA);
|
||||
_currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.CellShapeB);
|
||||
}
|
||||
|
||||
_workGrid0.Draw(bmpInput, 0.75f);
|
||||
_workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
_workGrid0.RemoveGround();
|
||||
@@ -91,7 +92,8 @@ namespace VAR.ScreenAutomation.Bots
|
||||
{
|
||||
for (int x = 0; x < _grid.Width; x++)
|
||||
{
|
||||
TetrisShape matchedShape = TetrisShape.DefaultShapes.FirstOrDefault(s => s.MatchOnGrid(_workGrid0, x, y));
|
||||
TetrisShape matchedShape =
|
||||
TetrisShape.DefaultShapes.FirstOrDefault(s => s.MatchOnGrid(_workGrid0, x, y));
|
||||
if (matchedShape != null)
|
||||
{
|
||||
_workGrid1.SampleOther(_workGrid0, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
@@ -102,14 +104,16 @@ namespace VAR.ScreenAutomation.Bots
|
||||
_currentShape[0].Copy(matchedShape);
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
_currentShape[i].RotateCW(_currentShape[i - 1]);
|
||||
_currentShape[i].RotateClockWise(_currentShape[i - 1]);
|
||||
}
|
||||
|
||||
_shapeX = x;
|
||||
_shapeY = y;
|
||||
_shapeFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_shapeFound) { break; }
|
||||
}
|
||||
}
|
||||
@@ -147,9 +151,11 @@ namespace VAR.ScreenAutomation.Bots
|
||||
// Search valid X range
|
||||
int minX = _shapeX;
|
||||
while (minX >= 0 && _columnEvaluation[minX] > double.MinValue) { minX--; }
|
||||
|
||||
minX++;
|
||||
int maxX = _shapeX;
|
||||
while (maxX < _grid.Width && _columnEvaluation[maxX] > double.MinValue) { maxX++; }
|
||||
|
||||
maxX--;
|
||||
|
||||
// Apply best value inside valid X range
|
||||
@@ -165,8 +171,8 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
|
||||
private int _shotCooldownFrames = 0;
|
||||
private int _shotCooldown = 0;
|
||||
private int _shotCooldownFrames;
|
||||
private int _shotCooldown;
|
||||
|
||||
public string ResponseKeys()
|
||||
{
|
||||
@@ -189,9 +195,13 @@ namespace VAR.ScreenAutomation.Bots
|
||||
_shotCooldown = _shotCooldownFrames;
|
||||
|
||||
if (_bestRotation != 0 && _bestXOffset < 0) { return "{UP}{LEFT}"; }
|
||||
|
||||
if (_bestRotation != 0 && _bestXOffset > 0) { return "{UP}{RIGHT}"; }
|
||||
|
||||
if (_bestRotation != 0) { return "{UP}"; }
|
||||
|
||||
if (_bestXOffset < 0) { return "{LEFT}"; }
|
||||
|
||||
if (_bestXOffset > 0) { return "{RIGHT}"; }
|
||||
|
||||
return string.Empty;
|
||||
@@ -200,11 +210,11 @@ namespace VAR.ScreenAutomation.Bots
|
||||
|
||||
public class TetrisShape
|
||||
{
|
||||
public const int ShapeSize = 4;
|
||||
private const int ShapeSize = 4;
|
||||
|
||||
private byte[][] _cells = null;
|
||||
private readonly byte[][] _cells;
|
||||
|
||||
private int _count = 0;
|
||||
private int _count;
|
||||
|
||||
public TetrisShape(byte[][] cells = null)
|
||||
{
|
||||
@@ -220,9 +230,11 @@ namespace VAR.ScreenAutomation.Bots
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
if (j >= cells.Length) { break; }
|
||||
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (i >= cells[j].Length) { break; }
|
||||
|
||||
_cells[j][i] = cells[j][i];
|
||||
if (_cells[j][i] != 0) { _count++; }
|
||||
}
|
||||
@@ -235,124 +247,140 @@ namespace VAR.ScreenAutomation.Bots
|
||||
return _count;
|
||||
}
|
||||
|
||||
private static List<TetrisShape> _defaultShapes = null;
|
||||
private static List<TetrisShape> _defaultShapes;
|
||||
|
||||
public static List<TetrisShape> DefaultShapes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_defaultShapes == null)
|
||||
{
|
||||
_defaultShapes = new List<TetrisShape>
|
||||
return _defaultShapes ?? (_defaultShapes = new List<TetrisShape>
|
||||
{
|
||||
// I
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
|
||||
// J
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, 1, },
|
||||
new byte[]{ 0, 0, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, },
|
||||
new byte[] { 0, 0, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 0, 1, },
|
||||
new byte[]{ 0, 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
}),
|
||||
|
||||
// L
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 0, 0, 1, },
|
||||
new byte[]{ 1, 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 0, 1, },
|
||||
new byte[] { 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, 1, },
|
||||
new byte[]{ 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 0, 1, },
|
||||
new byte[]{ 0, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
|
||||
// S
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 0, 1, 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 0, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
|
||||
// T
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 0, 1, },
|
||||
new byte[]{ 1, 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, 1, },
|
||||
new byte[]{ 0, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 0, 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 0, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
|
||||
// Z
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 0, 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 0, 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
|
||||
// O
|
||||
new TetrisShape(new byte[][]{
|
||||
new byte[]{ 1, 1, },
|
||||
new byte[]{ 1, 1, },
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
})
|
||||
};
|
||||
}
|
||||
return _defaultShapes;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
if (_count != 4) { return false; }
|
||||
bool matchesAnyDefault = DefaultShapes.Any(ts => CompareShape(ts));
|
||||
|
||||
bool matchesAnyDefault = DefaultShapes.Any(CompareShape);
|
||||
return matchesAnyDefault;
|
||||
}
|
||||
|
||||
@@ -368,7 +396,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
|
||||
public bool CompareShape(TetrisShape shape)
|
||||
private bool CompareShape(TetrisShape shape)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
@@ -380,6 +408,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -410,6 +439,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (_cells[j][i] == 0) { continue; }
|
||||
|
||||
grid.Set(x + i, y + j, value);
|
||||
}
|
||||
}
|
||||
@@ -422,27 +452,31 @@ namespace VAR.ScreenAutomation.Bots
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (_cells[j][i] == 0) { continue; }
|
||||
|
||||
if (grid.Get(x + i, y + j) != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Drop(TetrisGrid grid, int x, int y, byte value)
|
||||
{
|
||||
if (CheckIntersection(grid, x, y)) { return false; }
|
||||
|
||||
while (CheckIntersection(grid, x, y + 1) == false)
|
||||
{
|
||||
y++;
|
||||
}
|
||||
|
||||
PutOnGrid(grid, x, y, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SearchFirstCell(byte value, out int x, out int y)
|
||||
private bool SearchFirstCell(byte value, out int x, out int y)
|
||||
{
|
||||
x = -1;
|
||||
y = -1;
|
||||
@@ -456,7 +490,9 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (y == -1) { return false; }
|
||||
|
||||
for (int i = 0; i < ShapeSize && x == -1; i++)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize && x == -1; j++)
|
||||
@@ -467,11 +503,13 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x == -1) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Offset(int x, int y)
|
||||
private void Offset(int x, int y)
|
||||
{
|
||||
_count = 0;
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
@@ -494,7 +532,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
|
||||
public void RotateCW(TetrisShape shape)
|
||||
public void RotateClockWise(TetrisShape shape)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
@@ -503,6 +541,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
_cells[i][ShapeSize - (j + 1)] = shape._cells[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
_count = shape._count;
|
||||
|
||||
if (SearchFirstCell(1, out int offsetX, out int offsetY))
|
||||
@@ -518,15 +557,9 @@ namespace VAR.ScreenAutomation.Bots
|
||||
StringBuilder sbLine = new StringBuilder();
|
||||
for (int x = 0; x < ShapeSize; x++)
|
||||
{
|
||||
if (_cells[y][x] == 0)
|
||||
{
|
||||
sbLine.Append("..");
|
||||
}
|
||||
else
|
||||
{
|
||||
sbLine.Append("[]");
|
||||
}
|
||||
sbLine.Append(_cells[y][x] == 0 ? ".." : "[]");
|
||||
}
|
||||
|
||||
output.AddLine(sbLine.ToString());
|
||||
}
|
||||
}
|
||||
@@ -554,6 +587,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -565,15 +599,15 @@ namespace VAR.ScreenAutomation.Bots
|
||||
public const byte CellShapeA = 2;
|
||||
public const byte CellShapeB = 3;
|
||||
|
||||
private int _gridWidth;
|
||||
private int _gridHeight;
|
||||
private readonly int _gridWidth;
|
||||
private readonly int _gridHeight;
|
||||
|
||||
public int Width { get { return _gridWidth; } }
|
||||
public int Height { get { return _gridHeight; } }
|
||||
public int Width => _gridWidth;
|
||||
public int Height => _gridHeight;
|
||||
|
||||
private byte[][] _grid = null;
|
||||
private readonly byte[][] _grid;
|
||||
|
||||
private int[] _heights = null;
|
||||
private readonly int[] _heights;
|
||||
|
||||
public TetrisGrid(int gridWidth, int gridHeight)
|
||||
{
|
||||
@@ -584,27 +618,32 @@ namespace VAR.ScreenAutomation.Bots
|
||||
{
|
||||
_grid[y] = new byte[_gridWidth];
|
||||
}
|
||||
|
||||
_heights = new int[_gridWidth];
|
||||
}
|
||||
|
||||
public byte Get(int x, int y)
|
||||
{
|
||||
if (x >= _gridWidth || x < 0) { return 0xFF; }
|
||||
|
||||
if (y >= _gridHeight || y < 0) { return 0xFF; }
|
||||
|
||||
return _grid[y][x];
|
||||
}
|
||||
|
||||
public void Set(int x, int y, byte value)
|
||||
{
|
||||
if (x >= _gridWidth || x < 0) { return; }
|
||||
|
||||
if (y >= _gridHeight || y < 0) { return; }
|
||||
|
||||
_grid[y][x] = value;
|
||||
}
|
||||
|
||||
public void SampleFromBitmap(Bitmap bmp)
|
||||
{
|
||||
float xStep = bmp.Width / _gridWidth;
|
||||
float yStep = bmp.Height / _gridHeight;
|
||||
float xStep = bmp.Width / (float)_gridWidth;
|
||||
float yStep = bmp.Height / (float)_gridHeight;
|
||||
float xOff0 = xStep / 2;
|
||||
float xOff1 = xOff0 / 2;
|
||||
float xOff2 = xOff0 + xOff1;
|
||||
@@ -665,11 +704,14 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
|
||||
public void FloodFill(int x, int y, byte expectedValue, byte fillValue)
|
||||
private void FloodFill(int x, int y, byte expectedValue, byte fillValue)
|
||||
{
|
||||
if (x >= _gridWidth || x < 0) { return; }
|
||||
|
||||
if (y >= _gridHeight || y < 0) { return; }
|
||||
|
||||
if (_grid[y][x] != expectedValue) { return; }
|
||||
|
||||
_grid[y][x] = fillValue;
|
||||
FloodFill(x - 1, y - 1, expectedValue, fillValue);
|
||||
FloodFill(x - 1, y + 0, expectedValue, fillValue);
|
||||
@@ -681,7 +723,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
FloodFill(x + 1, y + 1, expectedValue, fillValue);
|
||||
}
|
||||
|
||||
public void SampleOther(TetrisGrid grid, byte value, byte setValue = 1)
|
||||
public void SampleOther(TetrisGrid grid, byte value, byte setValue)
|
||||
{
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
@@ -713,7 +755,9 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (y == -1) { return false; }
|
||||
|
||||
for (int i = 0; i < _gridWidth && x == -1; i++)
|
||||
{
|
||||
for (int j = 0; j < _gridHeight && x == -1; j++)
|
||||
@@ -724,11 +768,13 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x == -1) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsCompleteLine(int y)
|
||||
private bool IsCompleteLine(int y)
|
||||
{
|
||||
bool complete = true;
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
@@ -739,6 +785,7 @@ namespace VAR.ScreenAutomation.Bots
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return complete;
|
||||
}
|
||||
|
||||
@@ -748,14 +795,16 @@ namespace VAR.ScreenAutomation.Bots
|
||||
double holesWeight = -0.35663,
|
||||
double bumpinessWeight = -0.184483)
|
||||
{
|
||||
// Calculte aggregate height
|
||||
// Calculate aggregate height
|
||||
for (int i = 0; i < _gridWidth; i++)
|
||||
{
|
||||
int j = 0;
|
||||
while (j < _gridHeight && _grid[j][i] == CellEmpty) { j++; }
|
||||
|
||||
_heights[i] = _gridHeight - j;
|
||||
}
|
||||
double agregateHeight = _heights.Sum();
|
||||
|
||||
double aggregateHeight = _heights.Sum();
|
||||
|
||||
// Calculate complete lines
|
||||
int completeLines = 0;
|
||||
@@ -783,18 +832,18 @@ namespace VAR.ScreenAutomation.Bots
|
||||
}
|
||||
|
||||
// Calculate bumpiness
|
||||
int bumpines = 0;
|
||||
int bumpiness = 0;
|
||||
for (int i = 1; i < _gridWidth; i++)
|
||||
{
|
||||
bumpines += Math.Abs(_heights[i] - _heights[i - 1]);
|
||||
bumpiness += Math.Abs(_heights[i] - _heights[i - 1]);
|
||||
}
|
||||
|
||||
// Evaluate formula
|
||||
double evaluationValue =
|
||||
aggregateHeightWeight * agregateHeight +
|
||||
aggregateHeightWeight * aggregateHeight +
|
||||
completeLinesWeight * completeLines +
|
||||
holesWeight * holes +
|
||||
bumpinessWeight * bumpines +
|
||||
bumpinessWeight * bumpiness +
|
||||
0;
|
||||
return evaluationValue;
|
||||
}
|
||||
@@ -832,9 +881,11 @@ namespace VAR.ScreenAutomation.Bots
|
||||
{
|
||||
br = Brushes.Green;
|
||||
}
|
||||
|
||||
if (br == null) { continue; }
|
||||
|
||||
g.DrawRectangle(borderPen, (xStep * x) + offX - 1, (yStep * y) + offY - 1, halfXStep + 2, halfYStep + 2);
|
||||
g.DrawRectangle(borderPen, (xStep * x) + offX - 1, (yStep * y) + offY - 1, halfXStep + 2,
|
||||
halfYStep + 2);
|
||||
g.FillRectangle(br, (xStep * x) + offX, (yStep * y) + offY, halfXStep, halfYStep);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ using VAR.ScreenAutomation.Interfaces;
|
||||
|
||||
namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
public class AutomationBotFactory
|
||||
public static class AutomationBotFactory
|
||||
{
|
||||
private static Dictionary<string, Type> _dictAutomationBots = null;
|
||||
private static Dictionary<string, Type> _dictAutomationBots;
|
||||
|
||||
private static Dictionary<string, Type> GetDict()
|
||||
{
|
||||
@@ -28,8 +28,9 @@ namespace VAR.ScreenAutomation.Code
|
||||
true);
|
||||
_dictAutomationBots = automationBotTypes.ToDictionary(t =>
|
||||
{
|
||||
IAutomationBot automationBot = System.Runtime.Serialization.FormatterServices.GetUninitializedObject(t) as IAutomationBot;
|
||||
return automationBot.Name;
|
||||
IAutomationBot automationBot =
|
||||
System.Runtime.Serialization.FormatterServices.GetUninitializedObject(t) as IAutomationBot;
|
||||
return automationBot?.Name ?? t.Name;
|
||||
});
|
||||
|
||||
return _dictAutomationBots;
|
||||
@@ -39,7 +40,7 @@ namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
Dictionary<string, Type> dict = GetDict();
|
||||
string[] allAutomationBots = dict.Select(p => p.Key).ToArray();
|
||||
return allAutomationBots;
|
||||
return allAutomationBots.ToArray<object>();
|
||||
}
|
||||
|
||||
public static IAutomationBot CreateFromName(string name)
|
||||
@@ -49,10 +50,12 @@ namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
return new DummyBot();
|
||||
}
|
||||
|
||||
if (dict.ContainsKey(name) == false)
|
||||
{
|
||||
throw new NotImplementedException(string.Format("Can't create IAutomationBot with this name: {0}", name));
|
||||
throw new NotImplementedException($"Can't create IAutomationBot with this name: {name}");
|
||||
}
|
||||
|
||||
Type proxyCmdExecutorType = dict[name];
|
||||
|
||||
IAutomationBot automationBot = Activator.CreateInstance(proxyCmdExecutorType) as IAutomationBot;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
@@ -7,9 +8,9 @@ namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
public class FileBackedConfiguration : IConfiguration
|
||||
{
|
||||
private MemoryBackedConfiguration _config = new MemoryBackedConfiguration();
|
||||
private readonly MemoryBackedConfiguration _config = new MemoryBackedConfiguration();
|
||||
|
||||
private string _name = null;
|
||||
private readonly string _name;
|
||||
|
||||
public FileBackedConfiguration(string name = null)
|
||||
{
|
||||
@@ -18,33 +19,22 @@ namespace VAR.ScreenAutomation.Code
|
||||
|
||||
private static string GetConfigFileName(string name = null)
|
||||
{
|
||||
string location = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
string location = System.Reflection.Assembly.GetEntryAssembly()?.Location;
|
||||
string path = Path.GetDirectoryName(location);
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(location);
|
||||
string configFile;
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
configFile = string.Format("{0}/{1}.cfg", path, filenameWithoutExtension);
|
||||
}
|
||||
else
|
||||
{
|
||||
configFile = string.Format("{0}/{1}_{2}.cfg", path, filenameWithoutExtension, name);
|
||||
}
|
||||
string configFile = string.IsNullOrEmpty(name)
|
||||
? $"{path}/{filenameWithoutExtension}.cfg"
|
||||
: $"{path}/{filenameWithoutExtension}_{name}.cfg";
|
||||
return configFile;
|
||||
}
|
||||
|
||||
private static string[] GetConfigurationLines(string name = null)
|
||||
{
|
||||
string configFile = GetConfigFileName(name);
|
||||
string[] config;
|
||||
if (File.Exists(configFile) == false)
|
||||
{
|
||||
config = new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
config = File.ReadAllLines(configFile);
|
||||
}
|
||||
string[] config = File.Exists(configFile) == false
|
||||
? Array.Empty<string>()
|
||||
: File.ReadAllLines(configFile);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -58,11 +48,13 @@ namespace VAR.ScreenAutomation.Code
|
||||
_config.Set(key, other.Get(key, null));
|
||||
}
|
||||
}
|
||||
|
||||
string[] configLines = GetConfigurationLines(_name);
|
||||
foreach (string configLine in configLines)
|
||||
{
|
||||
int idxSplit = configLine.IndexOf('|');
|
||||
if (idxSplit < 0) { continue; }
|
||||
|
||||
string configName = configLine.Substring(0, idxSplit);
|
||||
string configData = configLine.Substring(idxSplit + 1);
|
||||
|
||||
@@ -77,6 +69,7 @@ namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
sbConfig.AppendFormat("{0}|{1}\n", key, _config.Get(key, string.Empty));
|
||||
}
|
||||
|
||||
string configFileName = GetConfigFileName(_name);
|
||||
File.WriteAllText(configFileName, sbConfig.ToString());
|
||||
}
|
||||
@@ -120,6 +113,5 @@ namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
_config.Set(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,13 @@ namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
public class MemoryBackedConfiguration : IConfiguration
|
||||
{
|
||||
private Dictionary<string, string> _configItems = new Dictionary<string, string>();
|
||||
private readonly Dictionary<string, string> _configItems = new Dictionary<string, string>();
|
||||
|
||||
public IEnumerable<string> GetKeys()
|
||||
{
|
||||
if (_configItems == null) { return new List<string>(); }
|
||||
return _configItems.Select(p => p.Key);
|
||||
return _configItems == null
|
||||
? new List<string>()
|
||||
: _configItems.Select(p => p.Key);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
@@ -23,41 +24,44 @@ namespace VAR.ScreenAutomation.Code
|
||||
public string Get(string key, string defaultValue)
|
||||
{
|
||||
if (_configItems == null) { return defaultValue; }
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
return _configItems[key];
|
||||
}
|
||||
return defaultValue;
|
||||
|
||||
return _configItems.ContainsKey(key) ? _configItems[key] : defaultValue;
|
||||
}
|
||||
|
||||
public int Get(string key, int defaultValue)
|
||||
{
|
||||
if (_configItems == null) { return defaultValue; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
if (int.TryParse(_configItems[key], out int value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public bool Get(string key, bool defaultValue)
|
||||
{
|
||||
if (_configItems == null) { return defaultValue; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
string value = _configItems[key];
|
||||
return (value == "true");
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
if (_configItems == null) { return; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
_configItems[key] = value;
|
||||
@@ -71,6 +75,7 @@ namespace VAR.ScreenAutomation.Code
|
||||
public void Set(string key, int value)
|
||||
{
|
||||
if (_configItems == null) { return; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
_configItems[key] = Convert.ToString(value);
|
||||
@@ -84,6 +89,7 @@ namespace VAR.ScreenAutomation.Code
|
||||
public void Set(string key, bool value)
|
||||
{
|
||||
if (_configItems == null) { return; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
_configItems[key] = value ? "true" : "false";
|
||||
@@ -93,6 +99,5 @@ namespace VAR.ScreenAutomation.Code
|
||||
_configItems.Add(key, value ? "true" : "false");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
public class Mouse
|
||||
public static class Mouse
|
||||
{
|
||||
public enum MouseButtons
|
||||
{
|
||||
@@ -24,14 +26,17 @@ namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
input.Data.Mouse.Flags = down ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP;
|
||||
}
|
||||
|
||||
if (button == MouseButtons.Middle)
|
||||
{
|
||||
input.Data.Mouse.Flags = down ? MOUSEEVENTF_MIDDLEDOWN : MOUSEEVENTF_MIDDLEUP;
|
||||
}
|
||||
|
||||
if (button == MouseButtons.Right)
|
||||
{
|
||||
input.Data.Mouse.Flags = down ? MOUSEEVENTF_RIGHTDOWN : MOUSEEVENTF_RIGHTUP;
|
||||
}
|
||||
|
||||
INPUT[] inputs = new INPUT[] { input };
|
||||
if (SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT))) == 0)
|
||||
throw new Exception();
|
||||
@@ -73,14 +78,11 @@ namespace VAR.ScreenAutomation.Code
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct MOUSEKEYBDHARDWAREINPUT
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public HARDWAREINPUT Hardware;
|
||||
[FieldOffset(0)] public HARDWAREINPUT Hardware;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public KEYBDINPUT Keyboard;
|
||||
[FieldOffset(0)] public KEYBDINPUT Keyboard;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public MOUSEINPUT Mouse;
|
||||
[FieldOffset(0)] public MOUSEINPUT Mouse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -144,7 +146,6 @@ namespace VAR.ScreenAutomation.Code
|
||||
public static extern int SendInput(int nInputs, INPUT[] pInputs, int cbSize);
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Struct representing a point.
|
||||
/// </summary>
|
||||
@@ -163,7 +164,6 @@ namespace VAR.ScreenAutomation.Code
|
||||
public static extern bool GetCursorPos(out POINT lpPoint);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
public static extern Boolean SetCursorPos(UInt32 X, UInt32 Y);
|
||||
|
||||
public static extern Boolean SetCursorPos(UInt32 x, UInt32 y);
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,19 @@ using System.Windows.Forms;
|
||||
|
||||
namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
public class Screenshoter
|
||||
public static class Screenshoter
|
||||
{
|
||||
public static Bitmap CaptureControl(Control ctrl, Bitmap bmp = null)
|
||||
{
|
||||
if (ctrl == null) { return bmp; }
|
||||
|
||||
Point picCapturerOrigin = ctrl.PointToScreen(new Point(0, 0));
|
||||
bmp = CaptureScreen(bmp, picCapturerOrigin.X, picCapturerOrigin.Y, ctrl.Width, ctrl.Height);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public static Bitmap CaptureScreen(Bitmap bmp = null, int? left = null, int? top = null, int? width = null, int? height = null)
|
||||
private static Bitmap CaptureScreen(Bitmap bmp = null, int? left = null, int? top = null, int? width = null,
|
||||
int? height = null)
|
||||
{
|
||||
if (width <= 0 || height <= 0) { return bmp; }
|
||||
|
||||
@@ -25,9 +27,9 @@ namespace VAR.ScreenAutomation.Code
|
||||
height = height ?? SystemInformation.VirtualScreen.Height;
|
||||
|
||||
// Create a bitmap of the appropriate size to receive the screenshot.
|
||||
if (bmp == null || bmp?.Width != width || bmp?.Height != height)
|
||||
if (bmp == null || bmp.Width != width || bmp.Height != height)
|
||||
{
|
||||
bmp = new Bitmap(width ?? 0, height ?? 0);
|
||||
bmp = new Bitmap((int)width, (int)height);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -35,10 +37,14 @@ namespace VAR.ScreenAutomation.Code
|
||||
// Draw the screenshot into our bitmap.
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
g.CopyFromScreen(left ?? 0, top ?? 0, 0, 0, bmp.Size);
|
||||
g.CopyFromScreen((int)left, (int)top, 0, 0, bmp.Size);
|
||||
}
|
||||
}
|
||||
catch (Exception) { /* Nom Nom Nom */}
|
||||
catch (Exception)
|
||||
{
|
||||
/* Nom Nom Nom */
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows.Forms;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace VAR.ScreenAutomation.Code
|
||||
{
|
||||
public class WindowHandling
|
||||
public static class WindowHandling
|
||||
{
|
||||
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
||||
private static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
|
||||
@@ -15,18 +17,15 @@ namespace VAR.ScreenAutomation.Code
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
|
||||
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy,
|
||||
uint uFlags);
|
||||
|
||||
public static void WindowSetTopLevel(Form form, bool top = true)
|
||||
{
|
||||
if (top)
|
||||
{
|
||||
SetWindowPos(form.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowPos(form.Handle, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
|
||||
}
|
||||
SetWindowPos(form.Handle, top
|
||||
? HWND_TOPMOST
|
||||
: HWND_NOTOPMOST,
|
||||
0, 0, 0, 0, TOPMOST_FLAGS);
|
||||
}
|
||||
|
||||
public static bool ApplicationIsActivated()
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private Image _imageShow = null;
|
||||
private Image _imageShow;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -16,7 +16,8 @@ namespace VAR.ScreenAutomation.Controls
|
||||
|
||||
public Image ImageShow
|
||||
{
|
||||
get { return _imageShow; }
|
||||
// ReSharper disable once InconsistentlySynchronizedField
|
||||
get => _imageShow;
|
||||
set
|
||||
{
|
||||
lock (this)
|
||||
@@ -32,6 +33,11 @@ namespace VAR.ScreenAutomation.Controls
|
||||
#region Control life cycle
|
||||
|
||||
public CtrImageViewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
BackColor = Color.Black;
|
||||
}
|
||||
@@ -59,6 +65,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_imageShow)
|
||||
{
|
||||
if (graph == null)
|
||||
@@ -71,7 +78,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
int imgDrawHeight;
|
||||
float imgDrawX = 0;
|
||||
float imgDrawY = 0;
|
||||
float relation = (float)_imageShow.Width / (float)_imageShow.Height;
|
||||
float relation = _imageShow.Width / (float)_imageShow.Height;
|
||||
if (relation > 0)
|
||||
{
|
||||
// Imagen mas ancha que alta
|
||||
@@ -110,6 +117,5 @@ namespace VAR.ScreenAutomation.Controls
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace VAR.ScreenAutomation.Controls
|
||||
{
|
||||
public class CtrOutput : Control, IOutputHandler
|
||||
@@ -18,6 +20,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public object Data { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Text;
|
||||
@@ -37,7 +40,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
FormattingEnabled = true,
|
||||
Font = new System.Drawing.Font("Consolas", 9),
|
||||
Font = new Font("Consolas", 9),
|
||||
BackColor = Color.Black,
|
||||
ForeColor = Color.Gray,
|
||||
SelectionMode = SelectionMode.MultiExtended,
|
||||
@@ -69,6 +72,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
CopyToClipboard();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.ProcessCmdKey(ref msg, keyData);
|
||||
}
|
||||
|
||||
@@ -87,6 +91,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
{
|
||||
sbText.AppendLine(item.Text);
|
||||
}
|
||||
|
||||
if (sbText.Length > 0)
|
||||
{
|
||||
Clipboard.SetText(sbText.ToString());
|
||||
@@ -106,7 +111,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private bool _updated = false;
|
||||
private bool _updated;
|
||||
private readonly List<OutputItem> _pendingOutput = new List<OutputItem>();
|
||||
|
||||
private void UpdatePosition()
|
||||
@@ -119,6 +124,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
{
|
||||
_listBox.Items.Add(item);
|
||||
}
|
||||
|
||||
_pendingOutput.Clear();
|
||||
_listBox.ResumeLayout();
|
||||
|
||||
@@ -131,7 +137,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
|
||||
private static extern IntPtr SendMessage(HandleRef hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
|
||||
private static extern IntPtr SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
private static void EnableRepaint(HandleRef handle, bool enable)
|
||||
{
|
||||
@@ -168,6 +174,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
public string GetCurrentText()
|
||||
{
|
||||
if (_listBox.SelectedItems.Count == 0) { return null; }
|
||||
|
||||
OutputItem item = (OutputItem)_listBox.SelectedItems[0];
|
||||
return item?.Text;
|
||||
}
|
||||
@@ -175,6 +182,7 @@ namespace VAR.ScreenAutomation.Controls
|
||||
public object GetCurrentData()
|
||||
{
|
||||
if (_listBox.SelectedItems.Count == 0) { return null; }
|
||||
|
||||
OutputItem item = (OutputItem)_listBox.SelectedItems[0];
|
||||
return item?.Data;
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ namespace VAR.ScreenAutomation
|
||||
{
|
||||
public partial class FrmAutomationBotParams : Form
|
||||
{
|
||||
private FileBackedConfiguration _config = null;
|
||||
private readonly FileBackedConfiguration _config;
|
||||
|
||||
private BindingList<Pair> pairs = null;
|
||||
private BindingList<Pair> _pairs;
|
||||
|
||||
private DataGridView dgvParams = null;
|
||||
private DataGridView _dgvParams;
|
||||
|
||||
public FrmAutomationBotParams(FileBackedConfiguration config)
|
||||
{
|
||||
@@ -24,32 +24,34 @@ namespace VAR.ScreenAutomation
|
||||
|
||||
private void FrmAutomationBotParams_Load(object sender, EventArgs e)
|
||||
{
|
||||
pairs = new BindingList<Pair>();
|
||||
_pairs = new BindingList<Pair>();
|
||||
foreach (string key in _config.GetKeys())
|
||||
{
|
||||
pairs.Add(new Pair { Key = key, Value = _config.Get(key, string.Empty), });
|
||||
_pairs.Add(new Pair { Key = key, Value = _config.Get(key, string.Empty), });
|
||||
}
|
||||
pairs.AddingNew += (s, a) =>
|
||||
|
||||
_pairs.AddingNew += (s, a) =>
|
||||
{
|
||||
a.NewObject = new Pair { Parent = pairs };
|
||||
a.NewObject = new Pair { Parent = _pairs };
|
||||
};
|
||||
dgvParams = new DataGridView
|
||||
_dgvParams = new DataGridView
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
DataSource = pairs
|
||||
DataSource = _pairs
|
||||
};
|
||||
|
||||
Controls.Add(dgvParams);
|
||||
Controls.Add(_dgvParams);
|
||||
}
|
||||
|
||||
private void FrmAutomationBotParams_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
var parms = new Dictionary<string, string>();
|
||||
foreach (Pair pair in pairs)
|
||||
foreach (Pair pair in _pairs)
|
||||
{
|
||||
if (string.IsNullOrEmpty(pair.Key)) { continue; }
|
||||
|
||||
_config.Set(pair.Key, pair.Value);
|
||||
}
|
||||
|
||||
_config.Save();
|
||||
}
|
||||
|
||||
@@ -59,10 +61,7 @@ namespace VAR.ScreenAutomation
|
||||
public string Key { get; set; }
|
||||
public string Value { get; set; }
|
||||
|
||||
string IDataErrorInfo.Error
|
||||
{
|
||||
get { return string.Empty; }
|
||||
}
|
||||
string IDataErrorInfo.Error => string.Empty;
|
||||
|
||||
string IDataErrorInfo.this[string columnName]
|
||||
{
|
||||
@@ -73,6 +72,7 @@ namespace VAR.ScreenAutomation
|
||||
{
|
||||
return "duplicate key";
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,46 +59,47 @@
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
<xsd:attribute name="name" use="required" type="xsd:string"/>
|
||||
<xsd:attribute name="type" type="xsd:string"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string"/>
|
||||
<xsd:attribute ref="xml:space"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="alias" type="xsd:string"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
|
||||
<xsd:attribute ref="xml:space"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
@@ -112,9 +113,13 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -5,23 +5,31 @@ using System.Windows.Forms;
|
||||
using VAR.ScreenAutomation.Code;
|
||||
using VAR.ScreenAutomation.Interfaces;
|
||||
|
||||
// ReSharper disable LocalizableElement
|
||||
|
||||
namespace VAR.ScreenAutomation
|
||||
{
|
||||
public partial class FrmScreenAutomation : Form
|
||||
{
|
||||
private bool _running = false;
|
||||
private IAutomationBot _automationBot = null;
|
||||
private bool _running;
|
||||
private IAutomationBot _automationBot;
|
||||
|
||||
private Timer timTicker;
|
||||
private Bitmap bmpScreen = null;
|
||||
private Timer _timTicker;
|
||||
private Bitmap _bmpScreen;
|
||||
|
||||
public FrmScreenAutomation()
|
||||
{
|
||||
AutoScaleMode = AutoScaleMode.None;
|
||||
Font = new Font(Font.Name, 8.25f * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont);
|
||||
PreInitializeComponent();
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void PreInitializeComponent()
|
||||
{
|
||||
AutoScaleMode = AutoScaleMode.None;
|
||||
Font = new Font(Font.Name, 8.25f * 96f / CreateGraphics().DpiX, Font.Style, Font.Unit, Font.GdiCharSet,
|
||||
Font.GdiVerticalFont);
|
||||
}
|
||||
|
||||
private void FrmScreenAutomation_Load(object sender, EventArgs e)
|
||||
{
|
||||
var configuration = new FileBackedConfiguration();
|
||||
@@ -31,7 +39,8 @@ namespace VAR.ScreenAutomation
|
||||
Width = configuration.Get("Width", Width);
|
||||
Height = configuration.Get("Height", Height);
|
||||
splitMain.SplitterDistance = configuration.Get("splitMain.SplitterDistance", splitMain.SplitterDistance);
|
||||
splitOutput.SplitterDistance = configuration.Get("splitOutput.SplitterDistance", splitOutput.SplitterDistance);
|
||||
splitOutput.SplitterDistance =
|
||||
configuration.Get("splitOutput.SplitterDistance", splitOutput.SplitterDistance);
|
||||
|
||||
SetStyle(ControlStyles.UserPaint, true);
|
||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
@@ -40,7 +49,8 @@ namespace VAR.ScreenAutomation
|
||||
picCapturer.BackColor = Color.LimeGreen;
|
||||
|
||||
ddlAutomationBot.Items.AddRange(AutomationBotFactory.GetAllAutomationBots());
|
||||
ddlAutomationBot.SelectedItem = configuration.Get("ddlAutomationBot", (string)ddlAutomationBot.SelectedItem);
|
||||
ddlAutomationBot.SelectedItem =
|
||||
configuration.Get("ddlAutomationBot", (string)ddlAutomationBot.SelectedItem);
|
||||
if (ddlAutomationBot.SelectedIndex < 0)
|
||||
{
|
||||
ddlAutomationBot.SelectedIndex = 0;
|
||||
@@ -52,14 +62,14 @@ namespace VAR.ScreenAutomation
|
||||
chkClick.Checked = configuration.Get("chkClick", chkClick.Checked);
|
||||
|
||||
if (components == null) { components = new Container(); }
|
||||
timTicker = new Timer(components)
|
||||
|
||||
_timTicker = new Timer(components)
|
||||
{
|
||||
Interval = Convert.ToInt32(1000 / numFPS.Value),
|
||||
};
|
||||
timTicker.Tick += TimTicker_Tick;
|
||||
timTicker.Enabled = true;
|
||||
timTicker.Start();
|
||||
|
||||
_timTicker.Tick += TimTicker_Tick;
|
||||
_timTicker.Enabled = true;
|
||||
_timTicker.Start();
|
||||
}
|
||||
|
||||
private void FrmScreenAutomation_FormClosing(object sender, FormClosingEventArgs e)
|
||||
@@ -80,14 +90,14 @@ namespace VAR.ScreenAutomation
|
||||
|
||||
private void TimTicker_Tick(object sender, EventArgs e)
|
||||
{
|
||||
timTicker.Enabled = false;
|
||||
timTicker.Stop();
|
||||
_timTicker.Enabled = false;
|
||||
_timTicker.Stop();
|
||||
|
||||
bmpScreen = Screenshoter.CaptureControl(picCapturer, bmpScreen);
|
||||
_bmpScreen = Screenshoter.CaptureControl(picCapturer, _bmpScreen);
|
||||
|
||||
if (_automationBot != null)
|
||||
{
|
||||
bmpScreen = _automationBot.Process(bmpScreen, ctrOutput);
|
||||
_bmpScreen = _automationBot.Process(_bmpScreen, ctrOutput);
|
||||
if (_running)
|
||||
{
|
||||
string responseKeys = _automationBot.ResponseKeys();
|
||||
@@ -97,11 +107,12 @@ namespace VAR.ScreenAutomation
|
||||
}
|
||||
}
|
||||
}
|
||||
picPreview.ImageShow = bmpScreen;
|
||||
|
||||
timTicker.Interval = Convert.ToInt32(1000 / numFPS.Value);
|
||||
timTicker.Enabled = true;
|
||||
timTicker.Start();
|
||||
picPreview.ImageShow = _bmpScreen;
|
||||
|
||||
_timTicker.Interval = Convert.ToInt32(1000 / numFPS.Value);
|
||||
_timTicker.Enabled = true;
|
||||
_timTicker.Start();
|
||||
}
|
||||
|
||||
private void BtnStartEnd_Click(object sender, EventArgs e)
|
||||
@@ -124,6 +135,7 @@ namespace VAR.ScreenAutomation
|
||||
private void BtnAutomationBotConfig_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_automationBot == null) { return; }
|
||||
|
||||
IConfiguration defaultConfig = _automationBot.GetDefaultConfiguration();
|
||||
var config = new FileBackedConfiguration(_automationBot.Name);
|
||||
config.Load(defaultConfig);
|
||||
@@ -135,6 +147,7 @@ namespace VAR.ScreenAutomation
|
||||
{
|
||||
WindowHandling.WindowSetTopLevel(this, false);
|
||||
}
|
||||
|
||||
frmAutomationBotParameters.ShowDialog();
|
||||
InitBot(_automationBot.Name);
|
||||
if (_isToplevel)
|
||||
@@ -146,20 +159,22 @@ namespace VAR.ScreenAutomation
|
||||
private void Start()
|
||||
{
|
||||
if (_running) { return; }
|
||||
|
||||
_running = true;
|
||||
btnStartEnd.Text = "End";
|
||||
InitBot((string)ddlAutomationBot.SelectedItem);
|
||||
if (chkClick.Checked)
|
||||
{
|
||||
Point pointCapturerCenter = picCapturer.PointToScreen(new Point(picCapturer.Width / 2, picCapturer.Height / 2));
|
||||
if (!chkClick.Checked) { return; }
|
||||
|
||||
Point pointCapturerCenter =
|
||||
picCapturer.PointToScreen(new Point(picCapturer.Width / 2, picCapturer.Height / 2));
|
||||
Mouse.SetPosition((uint)pointCapturerCenter.X, (uint)pointCapturerCenter.Y);
|
||||
Mouse.Click(Mouse.MouseButtons.Left);
|
||||
}
|
||||
}
|
||||
|
||||
private void End()
|
||||
{
|
||||
if (_running == false) { return; }
|
||||
|
||||
_running = false;
|
||||
btnStartEnd.Text = "Start";
|
||||
}
|
||||
@@ -177,19 +192,21 @@ namespace VAR.ScreenAutomation
|
||||
WindowSetTopLevel(chkKeepToplevel.Checked);
|
||||
}
|
||||
|
||||
private bool _isToplevel = false;
|
||||
private bool _isToplevel;
|
||||
|
||||
private void WindowSetTopLevel(bool toplevel)
|
||||
{
|
||||
if (toplevel)
|
||||
{
|
||||
if (_isToplevel) { return; }
|
||||
|
||||
WindowHandling.WindowSetTopLevel(this);
|
||||
_isToplevel = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isToplevel == false) { return; }
|
||||
|
||||
WindowHandling.WindowSetTopLevel(this, false);
|
||||
_isToplevel = false;
|
||||
}
|
||||
|
||||
@@ -59,46 +59,47 @@
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
<xsd:attribute name="name" use="required" type="xsd:string"/>
|
||||
<xsd:attribute name="type" type="xsd:string"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string"/>
|
||||
<xsd:attribute ref="xml:space"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="alias" type="xsd:string"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
|
||||
<xsd:attribute ref="xml:space"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
@@ -112,9 +113,13 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
|
||||
@@ -59,43 +59,44 @@
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
<xsd:attribute name="type" type="xsd:string"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="alias" type="xsd:string"/>
|
||||
<xsd:attribute name="name" type="xsd:string"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1"/>
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="name" type="xsd:string" use="required"/>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
@@ -109,9 +110,13 @@
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
|
||||
PublicKeyToken=b77a5c561934e089
|
||||
</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
<Profile Name="(Default)"/>
|
||||
</Profiles>
|
||||
<Settings />
|
||||
<Settings/>
|
||||
</SettingsFile>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -36,34 +36,34 @@
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System"/>
|
||||
<Reference Include="System.Core"/>
|
||||
<Reference Include="System.Xml.Linq"/>
|
||||
<Reference Include="System.Data.DataSetExtensions"/>
|
||||
<Reference Include="Microsoft.CSharp"/>
|
||||
<Reference Include="System.Data"/>
|
||||
<Reference Include="System.Deployment"/>
|
||||
<Reference Include="System.Drawing"/>
|
||||
<Reference Include="System.Net.Http"/>
|
||||
<Reference Include="System.Windows.Forms"/>
|
||||
<Reference Include="System.Xml"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Bots\DummyBot.cs" />
|
||||
<Compile Include="Bots\TetrisBot.cs" />
|
||||
<Compile Include="Code\AutomationBotFactory.cs" />
|
||||
<Compile Include="Code\FileBackedConfiguration.cs" />
|
||||
<Compile Include="Code\MemoryBackedConfiguration.cs" />
|
||||
<Compile Include="Bots\DummyBot.cs"/>
|
||||
<Compile Include="Bots\TetrisBot.cs"/>
|
||||
<Compile Include="Code\AutomationBotFactory.cs"/>
|
||||
<Compile Include="Code\FileBackedConfiguration.cs"/>
|
||||
<Compile Include="Code\MemoryBackedConfiguration.cs"/>
|
||||
<Compile Include="FrmAutomationBotParams.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmAutomationBotParams.Designer.cs">
|
||||
<DependentUpon>FrmAutomationBotParams.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Interfaces\IConfiguration.cs" />
|
||||
<Compile Include="Code\Mouse.cs" />
|
||||
<Compile Include="Code\Screenshoter.cs" />
|
||||
<Compile Include="Code\WindowHandling.cs" />
|
||||
<Compile Include="Interfaces\IConfiguration.cs"/>
|
||||
<Compile Include="Code\Mouse.cs"/>
|
||||
<Compile Include="Code\Screenshoter.cs"/>
|
||||
<Compile Include="Code\WindowHandling.cs"/>
|
||||
<Compile Include="Controls\CtrImageViewer.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
@@ -76,10 +76,10 @@
|
||||
<Compile Include="FrmScreenAutomation.Designer.cs">
|
||||
<DependentUpon>FrmScreenAutomation.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Interfaces\IAutomationBot.cs" />
|
||||
<Compile Include="Interfaces\IOutputHandler.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Interfaces\IAutomationBot.cs"/>
|
||||
<Compile Include="Interfaces\IOutputHandler.cs"/>
|
||||
<Compile Include="Program.cs"/>
|
||||
<Compile Include="Properties\AssemblyInfo.cs"/>
|
||||
<EmbeddedResource Include="FrmAutomationBotParams.resx">
|
||||
<DependentUpon>FrmAutomationBotParams.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
@@ -95,7 +95,7 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<None Include="app.manifest" />
|
||||
<None Include="app.manifest"/>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
@@ -107,7 +107,7 @@
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="App.config"/>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
|
||||
</Project>
|
||||
@@ -16,7 +16,7 @@
|
||||
Remove this element if your application requires this virtualization for backwards
|
||||
compatibility.
|
||||
-->
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
|
||||
Reference in New Issue
Block a user