Skip to content

Commit

Permalink
Merge pull request saucepleez#114 from saucepleez/development-branch
Browse files Browse the repository at this point in the history
Development branch
  • Loading branch information
saucepleez authored Apr 27, 2019
2 parents 484f104 + ee9e572 commit dbb0101
Show file tree
Hide file tree
Showing 39 changed files with 1,662 additions and 51 deletions.
2 changes: 2 additions & 0 deletions taskt/Core/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public class EngineSettings
public bool TrackExecutionMetrics { get; set; }
public string VariableStartMarker { get; set; }
public string VariableEndMarker { get; set; }
public System.Windows.Forms.Keys CancellationKey { get; set; }
public int DelayBetweenCommands { get; set; }
public bool OverrideExistingAppInstances { get; set; }
public bool AutoCloseMessagesOnServerExecution { get; set; }
Expand All @@ -131,6 +132,7 @@ public EngineSettings()
TrackExecutionMetrics = true;
VariableStartMarker = "[";
VariableEndMarker = "]";
CancellationKey = System.Windows.Forms.Keys.Pause;
DelayBetweenCommands = 250;
OverrideExistingAppInstances = false;
AutoCloseMessagesOnServerExecution = true;
Expand Down
119 changes: 119 additions & 0 deletions taskt/Core/Automation/Commands/EnvironmentVariableCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Management;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;

namespace taskt.Core.Automation.Commands
{
[Serializable]
[Attributes.ClassAttributes.Group("System Commands")]
[Attributes.ClassAttributes.Description("This command allows you to exclusively select a system/environment variable")]
[Attributes.ClassAttributes.UsesDescription("Use this command to exclusively retrieve a system variable")]
[Attributes.ClassAttributes.ImplementationDescription("")]
public class EnvironmentVariableCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Select the required environment variable")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.InputSpecification("Select from one of the options")]
[Attributes.PropertyAttributes.SampleUsage("")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_EnvVariableName { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please select the variable to receive output")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")]
[Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")]
[Attributes.PropertyAttributes.Remarks("If you have enabled the setting **Create Missing Variables at Runtime** then you are not required to pre-define your variables, however, it is highly recommended.")]
public string v_applyToVariableName { get; set; }


[XmlIgnore]
[NonSerialized]
public ComboBox VariableNameComboBox;

[XmlIgnore]
[NonSerialized]
public Label VariableValue;
public EnvironmentVariableCommand()
{
this.CommandName = "EnvironmentVariableCommand";
this.SelectionName = "Environment Variable";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{
var environmentVariable = (string)v_EnvVariableName.ConvertToUserVariable(sender);

var variables = Environment.GetEnvironmentVariables();
var envValue = (string)variables[environmentVariable];

envValue.StoreInUserVariable(sender, v_applyToVariableName);


}
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);

var ActionNameComboBoxLabel = CommandControls.CreateDefaultLabelFor("v_EnvVariableName", this);
VariableNameComboBox = (ComboBox)CommandControls.CreateDropdownFor("v_EnvVariableName", this);


foreach (System.Collections.DictionaryEntry env in Environment.GetEnvironmentVariables())
{
var envVariableKey = env.Key.ToString();
var envVariableValue = env.Value.ToString();
VariableNameComboBox.Items.Add(envVariableKey);
}


VariableNameComboBox.SelectedValueChanged += VariableNameComboBox_SelectedValueChanged;



RenderedControls.Add(ActionNameComboBoxLabel);
RenderedControls.Add(VariableNameComboBox);

VariableValue = new Label();
VariableValue.Font = new System.Drawing.Font("Segoe UI", 12);
VariableValue.ForeColor = System.Drawing.Color.White;

RenderedControls.Add(VariableValue);


RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_applyToVariableName", this, editor));


return RenderedControls;
}

private void VariableNameComboBox_SelectedValueChanged(object sender, EventArgs e)
{
var selectedValue = VariableNameComboBox.SelectedItem;

if (selectedValue == null)
return;


var variable = Environment.GetEnvironmentVariables();
var value = variable[selectedValue];

VariableValue.Text = "[ex. " + value + "]";


}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [Apply '" + v_EnvVariableName + "' to Variable '" + v_applyToVariableName + "']";
}
}

}
11 changes: 10 additions & 1 deletion taskt/Core/Automation/Commands/ExecuteDLLCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ public override void RunCommand(object sender)
//get type
Type t = requiredAssembly.GetType(className);

//get all methods
MethodInfo[] availableMethods = t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

//get method
MethodInfo m = t.GetMethod(methodName);
MethodInfo m = availableMethods.Where(f => f.ToString() == methodName).FirstOrDefault();


//create instance
var instance = requiredAssembly.CreateInstance(className);
Expand Down Expand Up @@ -174,6 +178,11 @@ where rws.Field<string>("Parameter Name") == paramName
{
parameters.Add(requiredParameterValue);
}
else if ((param.ParameterType.FullName == "System.DateTime"))
{
var parseResult = DateTime.Parse(requiredParameterValue);
parameters.Add(parseResult);
}
else
{
throw new NotImplementedException("Only system parameter types are supported!");
Expand Down
105 changes: 105 additions & 0 deletions taskt/Core/Automation/Commands/ModifyVariableCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;

namespace taskt.Core.Automation.Commands
{
[Serializable]
[Attributes.ClassAttributes.Group("Data Commands")]
[Attributes.ClassAttributes.Description("This command allows you to trim a string")]
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to select a subset of text or variable")]
[Attributes.ClassAttributes.ImplementationDescription("This command uses the String.Substring method to achieve automation.")]
public class ModifyVariableCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please select a variable or text to modify")]
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")]
[Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_userVariableName { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Select the case type")]
[Attributes.PropertyAttributes.InputSpecification("Indicate if only so many characters should be kept")]
[Attributes.PropertyAttributes.SampleUsage("-1 to keep remainder, 1 for 1 position after start index, etc.")]
[Attributes.PropertyAttributes.Remarks("")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("To Upper Case")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("To Lower Case")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("To Base64 String")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("From Base64 String")]
public string v_ConvertType { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please select the variable to receive the changes")]
[Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")]
[Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")]
[Attributes.PropertyAttributes.Remarks("If you have enabled the setting **Create Missing Variables at Runtime** then you are not required to pre-define your variables, however, it is highly recommended.")]
public string v_applyToVariableName { get; set; }
public ModifyVariableCommand()
{
this.CommandName = "ModifyVariableCommand";
this.SelectionName = "Modify Variable";
this.CommandEnabled = true;
this.CustomRendering = true;
;
}
public override void RunCommand(object sender)
{


var stringValue = v_userVariableName.ConvertToUserVariable(sender);

var caseType = v_ConvertType.ConvertToUserVariable(sender);

switch (caseType)
{
case "To Upper Case":
stringValue = stringValue.ToUpper();
break;
case "To Lower Case":
stringValue = stringValue.ToLower();
break;
case "To Base64 String":
byte[] textAsBytes = System.Text.Encoding.ASCII.GetBytes(stringValue);
stringValue = Convert.ToBase64String(textAsBytes);
break;
case "From Base64 String":
byte[] encodedDataAsBytes = System.Convert.FromBase64String(stringValue);
stringValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
break;
default:
throw new NotImplementedException("Conversion Type '" + caseType + "' not implemented!");
}

stringValue.StoreInUserVariable(sender, v_applyToVariableName);
}
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);

RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_userVariableName", this));
var userVariableName = CommandControls.CreateStandardComboboxFor("v_userVariableName", this).AddVariableNames(editor);
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_userVariableName", this, new Control[] { userVariableName }, editor));
RenderedControls.Add(userVariableName);

//create standard group controls
RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_ConvertType", this, editor));


RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_applyToVariableName", this));
var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_applyToVariableName", this).AddVariableNames(editor);
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_applyToVariableName", this, new Control[] { VariableNameControl }, editor));
RenderedControls.Add(VariableNameControl);

return RenderedControls;

}
public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [Convert '" + v_userVariableName + "' " + v_ConvertType + "']";
}
}
}
Loading

0 comments on commit dbb0101

Please sign in to comment.