forked from saucepleez/taskt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request saucepleez#114 from saucepleez/development-branch
Development branch
- Loading branch information
Showing
39 changed files
with
1,662 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
taskt/Core/Automation/Commands/EnvironmentVariableCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "']"; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
taskt/Core/Automation/Commands/ModifyVariableCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + "']"; | ||
} | ||
} | ||
} |
Oops, something went wrong.