Skip to content

Commit

Permalink
Merge pull request saucepleez#45 from saucepleez/development-branch
Browse files Browse the repository at this point in the history
Development branch
  • Loading branch information
saucepleez authored Oct 7, 2018
2 parents 5c3eb7d + 538bcaf commit 0636df4
Show file tree
Hide file tree
Showing 29 changed files with 4,992 additions and 477 deletions.
2 changes: 2 additions & 0 deletions taskt/Core/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ public class ClientSettings
{
public bool AntiIdleWhileOpen { get; set; }
public string RootFolder { get; set; }
public bool InsertCommandsInline { get; set; }
public ClientSettings()
{
AntiIdleWhileOpen = false;
InsertCommandsInline = false;
RootFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "taskt");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public enum UIAdditionalHelperType
ShowVariableHelper,
ShowFileSelectionHelper,
ShowImageRecogitionHelper,
ShowCodeBuilder
ShowCodeBuilder,
ShowMouseCaptureHelper,
ShowElementRecorder
}
}
[System.AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
Expand Down
570 changes: 545 additions & 25 deletions taskt/Core/AutomationCommands.cs

Large diffs are not rendered by default.

32 changes: 26 additions & 6 deletions taskt/Core/AutomationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public class AutomationEngineInstance
public List<Core.Script.ScriptVariable> VariableList { get; set; }
public Dictionary<string, object> AppInstances { get; set; }
public Core.AutomationCommands.ErrorHandlingCommand ErrorHandler;
public List<ScriptError> ErrorsOccured { get; set; }
public bool IsCancellationPending { get; set; }
public bool CurrentLoopCancelled { get; set; }
private bool IsScriptPaused { get; set; }
public UI.Forms.frmScriptEngine tasktEngineUI { get; set; }
private System.Diagnostics.Stopwatch sw { get; set; }
Expand All @@ -33,6 +35,9 @@ public AutomationEngineInstance()
engineLogger = new Logging().CreateLogger("Engine", Serilog.RollingInterval.Day);
engineLogger.Information("Engine Class has been initialized");

//initialize error tracking list
ErrorsOccured = new List<ScriptError>();

//set to initialized
CurrentStatus = EngineStatus.Loaded;

Expand Down Expand Up @@ -86,9 +91,10 @@ public void ExecuteScript(string filePath)
ReportProgress("Creating Variable List");
VariableList = automationScript.Variables;
ReportProgress("Creating App Instance Tracking List");
AppInstances = new Dictionary<string, object>();


//create app instances and merge in global instances
AppInstances = GlobalAppInstances.GetInstances();

//execute commands
foreach (var executionCommand in automationScript.Commands)
{
Expand Down Expand Up @@ -168,7 +174,7 @@ public void ExecuteCommand(Core.Script.ScriptAction command)
//bypass comments
if (parentCommand is Core.AutomationCommands.CommentCommand || parentCommand.IsCommented)
{
ReportProgress("Skipping Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue());
ReportProgress("Skipping Line " + parentCommand.LineNumber + ": " + parentCommand.GetDisplayValue().ConvertToUserVariable(this));
return;
}

Expand All @@ -180,7 +186,7 @@ public void ExecuteCommand(Core.Script.ScriptAction command)
try
{
//determine type of command
if ((parentCommand is Core.AutomationCommands.BeginNumberOfTimesLoopCommand) || (parentCommand is Core.AutomationCommands.BeginListLoopCommand) || (parentCommand is Core.AutomationCommands.BeginIfCommand) || parentCommand is Core.AutomationCommands.BeginExcelDatasetLoopCommand)
if ((parentCommand is Core.AutomationCommands.BeginNumberOfTimesLoopCommand) || (parentCommand is Core.AutomationCommands.BeginContinousLoopCommand) || (parentCommand is Core.AutomationCommands.BeginListLoopCommand) || (parentCommand is Core.AutomationCommands.BeginIfCommand) || parentCommand is Core.AutomationCommands.BeginExcelDatasetLoopCommand)
{
//run the command and pass bgw/command as this command will recursively call this method for sub commands
parentCommand.RunCommand(this, command);
Expand All @@ -191,9 +197,13 @@ public void ExecuteCommand(Core.Script.ScriptAction command)
}
else if (parentCommand is Core.AutomationCommands.StopTaskCommand)
{
// bgw.CancelAsync();
IsCancellationPending = true;
return;
}
else if (parentCommand is Core.AutomationCommands.ExitLoopCommand)
{
CurrentLoopCancelled = true;
}
else
{
//run the command
Expand All @@ -202,7 +212,8 @@ public void ExecuteCommand(Core.Script.ScriptAction command)
}
catch (Exception ex)
{

ErrorsOccured.Add(new ScriptError() { LineNumber = parentCommand.LineNumber, ErrorMessage = ex.Message, StackTrace = ex.ToString() });

//error occuured so decide what user selected
if (ErrorHandler != null)
{
Expand Down Expand Up @@ -320,4 +331,13 @@ public class LineNumberChangedEventArgs : EventArgs
{
public int CurrentLineNumber { get; set; }
}

public class ScriptError
{
public int LineNumber { get; set; }
public string StackTrace { get; set; }
public string ErrorMessage { get; set; }
}


}
23 changes: 23 additions & 0 deletions taskt/Core/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -115,6 +116,9 @@ private static bool CommandEnabled(Type cmd)
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Folder.ScriptPath", VariableValue = Core.Folders.GetFolder(Folders.FolderType.ScriptsFolder) });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "DateTime.Now", VariableValue = DateTime.Now.ToString() });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "DateTime.Now.FileSafe", VariableValue = DateTime.Now.ToString("MM-dd-yy hh.mm.ss") });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Error.Message", VariableValue = "An Error Occured!" });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Error.Line", VariableValue = "1" });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Error.StackTrace", VariableValue = "An Error Occured + StackTrace" });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "PC.MachineName", VariableValue = Environment.MachineName });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "PC.UserName", VariableValue = Environment.UserName });
systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "PC.DomainName", VariableValue = Environment.UserDomainName });
Expand Down Expand Up @@ -142,5 +146,24 @@ public static Image Base64ToImage(string base64String)
return image;
}

public static List<string> GetAvailableWindowNames()
{
List<string> windowList = new List<string>();
//get all running processes
Process[] processlist = Process.GetProcesses();
//pull the main window title for each
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
//add to the control list of available windows
windowList.Add(process.MainWindowTitle);
}
}
windowList.Sort();

return windowList;
}

}
}
36 changes: 36 additions & 0 deletions taskt/Core/GlobalAppInstances.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace taskt.Core
{
public static class GlobalAppInstances
{
private static Dictionary<string, object> AppInstances { get; set; } = new Dictionary<string, object>();

public static void AddInstance(string instanceName, object instanceObject)
{
//remove if already exists
if (AppInstances.ContainsKey(instanceName))
{
AppInstances.Remove(instanceName);
}

//add to instance tracking
AppInstances.Add(instanceName, instanceObject);
}

public static Dictionary<string, object> GetInstances()
{
return AppInstances;
}


}




}
2 changes: 1 addition & 1 deletion taskt/Core/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static Script SerializeScript(ListView.ListViewItemCollection scriptComma
var command = (Core.AutomationCommands.ScriptCommand)commandItem.Tag;
command.LineNumber = lineNumber;

if ((command is Core.AutomationCommands.BeginNumberOfTimesLoopCommand) || (command is Core.AutomationCommands.BeginListLoopCommand) || (command is Core.AutomationCommands.BeginIfCommand) || (command is Core.AutomationCommands.BeginExcelDatasetLoopCommand))
if ((command is Core.AutomationCommands.BeginNumberOfTimesLoopCommand) || (command is Core.AutomationCommands.BeginContinousLoopCommand) || (command is Core.AutomationCommands.BeginListLoopCommand) || (command is Core.AutomationCommands.BeginIfCommand) || (command is Core.AutomationCommands.BeginExcelDatasetLoopCommand))
{
if (subCommands.Count == 0) //if this is the first loop
{
Expand Down
97 changes: 96 additions & 1 deletion taskt/Core/Win32Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static IntPtr FindWindow(string windowName)
return hWnd;
}

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.dll", EntryPoint = "SetForegroundWindow")]
private static extern IntPtr SetForegroundWindowNative(IntPtr hWnd);
public static void SetForegroundWindow(IntPtr hWnd)
Expand Down Expand Up @@ -274,6 +277,12 @@ public static string GetClipboardText()
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern IntPtr GetDesktopWindow();

private delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam);

[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);

public static Bitmap CaptureWindow(string windowName)
{
IntPtr hWnd;
Expand Down Expand Up @@ -311,6 +320,7 @@ public class GlobalHook
private const int WM_KEYDOWN = 0x0100;
private static readonly LowLevelKeyboardProc _kbProc = KeyboardHookEvent;
private static readonly LowLevelMouseProc _mouseProc = MouseHookEvent;
private static readonly LowLevelMouseProc _mouseLeftUpProc = MouseHookForLeftClickUpEvent;
private static IntPtr _keyboardHookID = IntPtr.Zero;
private static IntPtr _mouseHookID = IntPtr.Zero;
private static Stopwatch sw;
Expand All @@ -335,8 +345,12 @@ public static void StartEngineCancellationHook()
//set hook for engine cancellation
_keyboardHookID = SetKeyboardHook(_kbProc);
}
public static void StartElementCaptureHook()
{
//set hook for engine cancellation
_mouseHookID = SetMouseHook(_mouseLeftUpProc);
}


public static void StartScreenRecordingHook(bool captureClick, bool captureMouse, bool groupMouseMoves, bool captureKeyboard, bool captureWindow, bool activateTopLeft, bool trackActivatedWindowSize, bool trackWindowsOpenLocation, int eventResolution)
{
//create new list for commands generated
Expand Down Expand Up @@ -412,6 +426,30 @@ private static IntPtr KeyboardHookEvent(int nCode, IntPtr wParam, IntPtr lParam)
return CallNextHookEx(_keyboardHookID, nCode, wParam, lParam);

}
public static event EventHandler<MouseCoordinateEventArgs> MouseEvent;
private static IntPtr MouseHookForLeftClickUpEvent(int nCode, IntPtr wParam, IntPtr lParam)

{

if (nCode >= 0)
{
var message = (MouseMessages)wParam;

if (message == MouseMessages.WM_LBUTTONDOWN)
{
UnhookWindowsHookEx(_mouseHookID);

MSLLHOOKSTRUCT hookStruct = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
System.Windows.Point point = new System.Windows.Point(hookStruct.pt.x, hookStruct.pt.y);
MouseEvent?.Invoke(null, new MouseCoordinateEventArgs() { MouseCoordinates = point });
}

}

return CallNextHookEx(_mouseHookID, nCode, wParam, lParam);

}

private static IntPtr MouseHookEvent(int nCode, IntPtr wParam, IntPtr lParam)

{
Expand Down Expand Up @@ -856,6 +894,9 @@ private static IntPtr SetMouseHook(LowLevelMouseProc proc)
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(POINT Point);

[DllImport("user32.dll")]
static extern IntPtr ChildWindowFromPoint(IntPtr hWndParent, POINT Point);

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int ToUnicode(uint virtualKeyCode,uint scanCode, byte[] keyboardState, StringBuilder receivingBuffer, int bufferSize, uint flags);

Expand Down Expand Up @@ -954,4 +995,58 @@ enum SystemEvents


}
public class WindowHandleInfo
{
private delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam);

[DllImport("user32")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);

private IntPtr _MainHandle;

public WindowHandleInfo(IntPtr handle)
{
this._MainHandle = handle;
}

public List<IntPtr> GetAllChildHandles()
{
List<IntPtr> childHandles = new List<IntPtr>();

GCHandle gcChildhandlesList = GCHandle.Alloc(childHandles);
IntPtr pointerChildHandlesList = GCHandle.ToIntPtr(gcChildhandlesList);

try
{
EnumWindowProc childProc = new EnumWindowProc(EnumWindow);
EnumChildWindows(this._MainHandle, childProc, pointerChildHandlesList);
}
finally
{
gcChildhandlesList.Free();
}

return childHandles;
}

private bool EnumWindow(IntPtr hWnd, IntPtr lParam)
{
GCHandle gcChildhandlesList = GCHandle.FromIntPtr(lParam);

if (gcChildhandlesList == null || gcChildhandlesList.Target == null)
{
return false;
}

List<IntPtr> childHandles = gcChildhandlesList.Target as List<IntPtr>;
childHandles.Add(hWnd);

return true;
}
}
public class MouseCoordinateEventArgs : EventArgs
{
public System.Windows.Point MouseCoordinates { get; set; }
}
}
2 changes: 1 addition & 1 deletion taskt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.0.*")]
[assembly: AssemblyFileVersion("1.8.2.0")]
[assembly: AssemblyFileVersion("1.9.0.0")]
//[assembly: AssemblyVersion("0.0.0.2")]
//[assembly: AssemblyFileVersion("0.0.0.2")]
10 changes: 10 additions & 0 deletions taskt/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions taskt/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,7 @@
<data name="robot source" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\robot source.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="command_exitloop" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\command-exitloop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added taskt/Resources/command-exitloop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0636df4

Please sign in to comment.