Skip to content

Commit

Permalink
Added Modify Variable to handle case changes and base64 conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Apr 23, 2019
1 parent 9c9ca65 commit 1752b88
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 2 deletions.
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 + "']";
}
}
}
1 change: 1 addition & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace taskt.Core.Automation.Commands
[XmlInclude(typeof(RemoteDesktopCommand))]
[XmlInclude(typeof(EnvironmentVariableCommand))]
[XmlInclude(typeof(OSVariableCommand))]
[XmlInclude(typeof(ModifyVariableCommand))]
public abstract class ScriptCommand
{
[XmlAttribute]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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" CommandID="07a12233-0373-4f6f-b0fa-efdef3ec4b08" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="1" PauseBeforeExeucution="false" v_Comment="Sample shows how to modify case or convert to/from base64 format" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="VariableCommand" CommandID="4f603ead-69be-4be3-bb28-9813870095fe" CommandName="VariableCommand" IsCommented="false" SelectionName="Set Variable" DefaultPause="0" LineNumber="2" PauseBeforeExeucution="false" CommandEnabled="true" v_userVariableName="vVar" v_Input="hello world!" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="61478b82-3a4c-4dc5-b954-0bf000b2efa8" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="3" PauseBeforeExeucution="false" v_Comment="Show Starting Value" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="8ae6b1bb-23e0-44a9-836c-42884b00fba1" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="4" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="Starting With: {vVar}" v_AutoCloseAfter="0" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="e33fc4e6-7931-465b-ab08-78ecf17c3a80" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="5" PauseBeforeExeucution="false" v_Comment="Show Upper Case Conversion" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="ModifyVariableCommand" CommandID="61dd23d0-0313-4afc-82e0-ddc7ffebdd69" CommandName="StringCaseCommand" IsCommented="false" SelectionName="Modify Variable" DefaultPause="0" LineNumber="6" PauseBeforeExeucution="false" CommandEnabled="true" v_userVariableName="vVar" v_ConvertType="To Upper Case" v_applyToVariableName="vVar" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="1ad28387-2160-469f-b3ae-828b3018d583" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="7" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="To Upper Case: {vVar}" v_AutoCloseAfter="0" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="18c6a368-f213-4f03-9c2a-8e21d9b9b837" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="8" PauseBeforeExeucution="false" v_Comment="Show Lower Case Conversion" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="ModifyVariableCommand" CommandID="45554a6f-d9ec-419f-a075-36f69e4b76c7" CommandName="StringCaseCommand" IsCommented="false" SelectionName="Modify Variable" DefaultPause="0" LineNumber="9" PauseBeforeExeucution="false" CommandEnabled="true" v_userVariableName="vVar" v_ConvertType="To Lower Case" v_applyToVariableName="vVar" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="a285fa22-42b3-4538-85a0-d1fabf45c2d4" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="10" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="To Lower Case: {vVar}" v_AutoCloseAfter="0" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="62012f06-0422-436a-b550-64b378afbc2a" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="11" PauseBeforeExeucution="false" v_Comment="Show To Base64 Conversion" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="ModifyVariableCommand" CommandID="2a88bb4e-edcf-4950-88a2-6c21e3cd2e41" CommandName="StringCaseCommand" IsCommented="false" SelectionName="Modify Variable" DefaultPause="0" LineNumber="12" PauseBeforeExeucution="false" CommandEnabled="true" v_userVariableName="vVar" v_ConvertType="To Base64 String" v_applyToVariableName="vVar" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="d595a259-fa0f-478a-89bd-e9086a48aeed" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="13" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="To Base 64: {vVar}" v_AutoCloseAfter="0" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="28ca5eef-7ca1-42b7-875e-a1e881efbdd8" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="14" PauseBeforeExeucution="false" v_Comment="Show From Base64 Conversion" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="ModifyVariableCommand" CommandID="c2aacdcc-acba-440b-9148-3f1d83c7a8b9" CommandName="StringCaseCommand" IsCommented="false" SelectionName="Modify Variable" DefaultPause="0" LineNumber="15" PauseBeforeExeucution="false" CommandEnabled="true" v_userVariableName="vVar" v_ConvertType="From Base64 String" v_applyToVariableName="vVar" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="291c0dc3-3e49-46f2-8705-415718d5c471" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="16" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="From Base 64: {vVar}" v_AutoCloseAfter="0" />
</ScriptAction>
</Commands>
<Variables>
<ScriptVariable>
<VariableName>vVar</VariableName>
<VariableValue xsi:type="xsd:string"></VariableValue>
</ScriptVariable>
</Variables>
</Script>
3 changes: 1 addition & 2 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,9 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("StopProcessCommand", taskt.Properties.Resources.command_stop_process);
uiImages.Add("StartProcessCommand", taskt.Properties.Resources.command_start_process);
uiImages.Add("VariableCommand", taskt.Properties.Resources.command_function);
uiImages.Add("EnvironmentVariableCommand", taskt.Properties.Resources.command_function);
uiImages.Add("OSVariableCommand", taskt.Properties.Resources.command_function);
uiImages.Add("AddVariableCommand", taskt.Properties.Resources.command_function);
uiImages.Add("FormatDataCommand", taskt.Properties.Resources.command_function);
uiImages.Add("ModifyVariableCommand", taskt.Properties.Resources.command_function);
uiImages.Add("DateCalculationCommand", taskt.Properties.Resources.command_function);
uiImages.Add("RegExExtractorCommand", taskt.Properties.Resources.command_function);
uiImages.Add("TextExtractorCommand", taskt.Properties.Resources.command_function);
Expand Down
1 change: 1 addition & 0 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
<Compile Include="Core\Automation\Commands\StartProcessCommand.cs" />
<Compile Include="Core\Automation\Commands\RemoteDesktopCommand.cs" />
<Compile Include="Core\Automation\Commands\EnvironmentVariableCommand.cs" />
<Compile Include="Core\Automation\Commands\ModifyVariableCommand.cs" />
<Compile Include="Core\Automation\Commands\SystemActionCommand.cs" />
<Compile Include="Core\Automation\Commands\StopwatchCommand.cs" />
<Compile Include="Core\Automation\Commands\StopProcessCommand.cs" />
Expand Down

0 comments on commit 1752b88

Please sign in to comment.