Skip to content

Commit

Permalink
Merge pull request saucepleez#17 from saucepleez/development-branch
Browse files Browse the repository at this point in the history
Development branch
  • Loading branch information
saucepleez authored Sep 13, 2018
2 parents 4af5dd5 + 0349321 commit 350260f
Show file tree
Hide file tree
Showing 14 changed files with 1,334 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public enum UIAdditionalHelperType
{
ShowVariableHelper,
ShowFileSelectionHelper,
ShowImageRecogitionHelper
ShowImageRecogitionHelper,
ShowCodeBuilder
}
}
[System.AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
Expand Down
54 changes: 54 additions & 0 deletions taskt/Core/AutomationCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using System.Net;
using System.IO;
using System.Drawing;
using Microsoft.CSharp;
using System.CodeDom.Compiler;

namespace taskt.Core.AutomationCommands
{
Expand Down Expand Up @@ -102,6 +104,7 @@ namespace taskt.Core.AutomationCommands
[XmlInclude(typeof(DeleteFileCommand))]
[XmlInclude(typeof(RenameFileCommand))]
[XmlInclude(typeof(WaitForFileToExistCommand))]
[XmlInclude(typeof(RunCustomCodeCommand))]
[Serializable]
public abstract class ScriptCommand
{
Expand Down Expand Up @@ -1688,6 +1691,57 @@ public override string GetDisplayValue()
}
}
[Serializable]
[Attributes.ClassAttributes.Group("Programs/Process Commands")]
[Attributes.ClassAttributes.Description("This command allows you to run C# code from the input")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements 'Process.Start' and waits for the script/program to exit before proceeding.")]
public class RunCustomCodeCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Paste the C# code to execute")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowCodeBuilder)]
public string v_Code { get; set; }

public RunCustomCodeCommand()
{
this.CommandName = "RunCustomCodeCommand";
this.SelectionName = "Run Custom Code";
this.CommandEnabled = true;
}

public override void RunCommand(object sender)
{
//create compiler service
var compilerSvc = new Core.CompilerServices();
var customCode = v_Code.ConvertToUserVariable(sender);

//compile custom code
var result = compilerSvc.CompileInput(customCode);

//check for errors
if (result.Errors.HasErrors)
{
//throw exception
var errors = string.Join(", ", result.Errors);
throw new Exception("Errors Occured: " + errors);
}
else
{
//run code, taskt will wait for the app to exit before resuming
System.Diagnostics.Process scriptProc = new System.Diagnostics.Process();
scriptProc.StartInfo.FileName = result.PathToAssembly;
scriptProc.Start();
scriptProc.WaitForExit();
scriptProc.Close();
}


}
public override string GetDisplayValue()
{
return base.GetDisplayValue();
}
}
[Serializable]
[Attributes.ClassAttributes.Group("Variable Commands")]
[Attributes.ClassAttributes.Description("This command allows you to modify variables.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements actions against VariableList from the scripting engine.")]
Expand Down
33 changes: 33 additions & 0 deletions taskt/Core/CompilerServices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace taskt.Core
{
public class CompilerServices
{
public CompilerResults CompileInput(string codeInput)
{

//define file output
string Output = "tasktOnTheFly.exe";

//create provider
CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");

//create compile parameters
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;

//compile
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, codeInput);
return results;

}
}

}
11 changes: 11 additions & 0 deletions taskt/Core/WebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ private static void MessageReceived(object sender, WebSocket4Net.MessageReceived

public static void SendMessage(string message)
{

if (webSocket == null)
{
return;
}

//if connection isnt open don't bother sending
if ((webSocket.State != WebSocket4Net.WebSocketState.Open))
{
Expand All @@ -245,6 +251,11 @@ public static void SendMessage(string message)

public static string GetSocketState()
{
if (webSocket == null)
{
return "Unknown";
}

switch (webSocket.State)
{
case WebSocket4Net.WebSocketState.None:
Expand Down
2 changes: 1 addition & 1 deletion taskt/Core/Win32Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ private static void BuildKeyboardCommand(Keys key)


//translate key press to sendkeys identifier
if (selectedKey == "End")
if (selectedKey == "Pause")
{
StopHook();
return;
Expand Down
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.4.1.0")]
[assembly: AssemblyFileVersion("1.5.2.0")]
//[assembly: AssemblyVersion("0.0.0.2")]
//[assembly: AssemblyFileVersion("0.0.0.2")]
12 changes: 12 additions & 0 deletions taskt/Sample Scripts/Run Custom Code Sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Script xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Commands>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="250" LineNumber="1" PauseBeforeExeucution="false" v_Comment="This sample demonstrates how to run custom C# code" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="RunCustomCodeCommand" CommandName="RunCustomCodeCommand" IsCommented="false" SelectionName="Run Custom Code" DefaultPause="250" LineNumber="2" PauseBeforeExeucution="false" CommandEnabled="true" v_Code="// A Hello World! program in C#.&#xA; using System;&#xA;&#xA; namespace HelloWorld&#xA; {&#xA; class Hello &#xA; {&#xA; static void Main() &#xA; {&#xA; Console.WriteLine(&quot;Hi! This code was compiled on the fly from taskt!&quot;);&#xA;&#xA; //Keep the console window open, remove this if you do not want the exe to block&#xA; Console.WriteLine(&quot;Press any key to exit.&quot;);&#xA; Console.ReadKey();&#xA; }&#xA; }&#xA; }" />
</ScriptAction>
</Commands>
<Variables />
</Script>
1 change: 1 addition & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("StartProcessCommand", taskt.Properties.Resources.command_start_process);
uiImages.Add("VariableCommand", taskt.Properties.Resources.command_function);
uiImages.Add("RunScriptCommand", taskt.Properties.Resources.command_script);
uiImages.Add("RunCustomCodeCommand", taskt.Properties.Resources.command_script);
uiImages.Add("RunTaskCommand", taskt.Properties.Resources.command_start_process);
uiImages.Add("StopTaskCommand", taskt.Properties.Resources.command_stop_process);
uiImages.Add("CloseWindowCommand", taskt.Properties.Resources.command_window_close);
Expand Down
205 changes: 205 additions & 0 deletions taskt/UI/Forms/Supplement Forms/frmCodeBuilder.Designer.cs

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

Loading

0 comments on commit 350260f

Please sign in to comment.