diff --git a/taskt/Core/Automation/Attributes/Attributes.cs b/taskt/Core/Automation/Attributes/Attributes.cs index 0d1989d88..9f1494b3b 100644 --- a/taskt/Core/Automation/Attributes/Attributes.cs +++ b/taskt/Core/Automation/Attributes/Attributes.cs @@ -116,7 +116,8 @@ public enum UIAdditionalHelperType ShowDLLExplorer, AddInputParameter, ShowHTMLBuilder, - ShowIfBuilder + ShowIfBuilder, + ShowLoopBuilder } } [System.AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] diff --git a/taskt/Core/Automation/Commands/BeginListLoopCommand.cs b/taskt/Core/Automation/Commands/BeginListLoopCommand.cs index 05129ad1c..6fe853f98 100644 --- a/taskt/Core/Automation/Commands/BeginListLoopCommand.cs +++ b/taskt/Core/Automation/Commands/BeginListLoopCommand.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using taskt.UI.Forms; using taskt.UI.CustomControls; +using Microsoft.Office.Interop.Outlook; namespace taskt.Core.Automation.Commands { @@ -59,7 +60,7 @@ public override void RunCommand(object sender, Core.Script.ScriptAction parentCo //if still null then throw exception if (complexVariable == null) { - throw new Exception("Complex Variable '" + v_LoopParameter + "' or '" + v_LoopParameter.ApplyVariableFormatting() + "' not found. Ensure the variable exists before attempting to modify it."); + throw new System.Exception("Complex Variable '" + v_LoopParameter + "' or '" + v_LoopParameter.ApplyVariableFormatting() + "' not found. Ensure the variable exists before attempting to modify it."); } dynamic listToLoop; @@ -75,6 +76,10 @@ public override void RunCommand(object sender, Core.Script.ScriptAction parentCo { listToLoop = ((DataTable)complexVariable.VariableValue).Rows; } + else if (complexVariable.VariableValue is List) + { + listToLoop = (List)complexVariable.VariableValue; + } else if ((complexVariable.VariableValue.ToString().StartsWith("[")) && (complexVariable.VariableValue.ToString().EndsWith("]")) && (complexVariable.VariableValue.ToString().Contains(","))) { //automatically handle if user has given a json array @@ -92,7 +97,7 @@ public override void RunCommand(object sender, Core.Script.ScriptAction parentCo } else { - throw new Exception("Complex Variable List Type Not Supported"); + throw new System.Exception("Complex Variable List Type Not Supported"); } diff --git a/taskt/Core/Automation/Commands/BeginLoopCommand.cs b/taskt/Core/Automation/Commands/BeginLoopCommand.cs new file mode 100644 index 000000000..8ee154e06 --- /dev/null +++ b/taskt/Core/Automation/Commands/BeginLoopCommand.cs @@ -0,0 +1,957 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using taskt.Core.Automation.User32; +using System.Collections.Generic; +using System.Windows.Forms; +using taskt.UI.Forms; +using taskt.UI.CustomControls; +using System.Drawing; +using System.Text; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Loop Commands")] + [Attributes.ClassAttributes.Description("This command allows you to evaluate a logical statement to determine if the statement is true. The following actions will repeat continuously until that statement becomes false")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to check if a statement is 'true' or 'false' and subsequently loop actions based on either condition. Any 'BeginLoop' command must have a following 'EndLoop' command.")] + [Attributes.ClassAttributes.ImplementationDescription("This command evaluates supplied arguments and if evaluated to true runs sub elements")] + public class BeginLoopCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please select type of Loop Command")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Value")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Date Compare")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Variable Compare")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Variable Has Value")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Variable Is Numeric")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Window Name Exists")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Active Window Name Is")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("File Exists")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Folder Exists")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Web Element Exists")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("GUI Element Exists")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Error Occured")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Error Did Not Occur")] + [Attributes.PropertyAttributes.InputSpecification("Select the necessary comparison type.")] + [Attributes.PropertyAttributes.SampleUsage("Select **Value**, **Window Name Exists**, **Active Window Name Is**, **File Exists**, **Folder Exists**, **Web Element Exists**, **Error Occured**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_LoopActionType { get; set; } + + [XmlElement] + [Attributes.PropertyAttributes.PropertyDescription("Additional Parameters")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Select the required comparison parameters.")] + [Attributes.PropertyAttributes.SampleUsage("n/a")] + [Attributes.PropertyAttributes.Remarks("")] + public DataTable v_LoopActionParameterTable { get; set; } + + [XmlIgnore] + [NonSerialized] + private DataGridView LoopGridViewHelper; + + [XmlIgnore] + [NonSerialized] + private ComboBox ActionDropdown; + + [XmlIgnore] + [NonSerialized] + private List ParameterControls; + + [XmlIgnore] + [NonSerialized] + CommandItemControl RecorderControl; + + public BeginLoopCommand() + { + this.CommandName = "BeginLoopCommand"; + this.SelectionName = "Begin Loop"; + this.CommandEnabled = true; + this.CustomRendering = true; + + //define parameter table + this.v_LoopActionParameterTable = new System.Data.DataTable + { + TableName = DateTime.Now.ToString("LoopActionParamTable" + DateTime.Now.ToString("MMddyy.hhmmss")) + }; + this.v_LoopActionParameterTable.Columns.Add("Parameter Name"); + this.v_LoopActionParameterTable.Columns.Add("Parameter Value"); + + LoopGridViewHelper = new DataGridView(); + LoopGridViewHelper.AllowUserToAddRows = true; + LoopGridViewHelper.AllowUserToDeleteRows = true; + LoopGridViewHelper.Size = new Size(400, 250); + LoopGridViewHelper.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + LoopGridViewHelper.DataBindings.Add("DataSource", this, "v_LoopActionParameterTable", false, DataSourceUpdateMode.OnPropertyChanged); + LoopGridViewHelper.AllowUserToAddRows = false; + LoopGridViewHelper.AllowUserToDeleteRows = false; + LoopGridViewHelper.MouseEnter += LoopGridViewHelper_MouseEnter; + + RecorderControl = new taskt.UI.CustomControls.CommandItemControl(); + RecorderControl.Padding = new System.Windows.Forms.Padding(10, 0, 0, 0); + RecorderControl.ForeColor = Color.AliceBlue; + RecorderControl.Name = "guirecorder_helper"; + RecorderControl.CommandImage = UI.Images.GetUIImage("ClipboardGetTextCommand"); + RecorderControl.CommandDisplay = "Element Recorder"; + RecorderControl.Click += ShowLoopElementRecorder; + RecorderControl.Hide(); + } + private void LoopGridViewHelper_MouseEnter(object sender, EventArgs e) + { + loopAction_SelectionChangeCommitted(null, null); + } + public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var loopResult = DetermineStatementTruth(sender); + engine.ReportProgress("Starting Loop"); + + while (loopResult) + { + foreach (var cmd in parentCommand.AdditionalScriptCommands) + { + if (engine.IsCancellationPending) + return; + + engine.ExecuteCommand(cmd); + + if (engine.CurrentLoopCancelled) + { + engine.ReportProgress("Exiting Loop"); + engine.CurrentLoopCancelled = false; + return; + } + + if (engine.CurrentLoopContinuing) + { + engine.ReportProgress("Continuing Next Loop"); + engine.CurrentLoopContinuing = false; + break; + } + } + loopResult = DetermineStatementTruth(sender); + } + } + + public bool DetermineStatementTruth(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + bool loopResult = false; + + if (v_LoopActionType == "Value") + { + string value1 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value1" + select rw.Field("Parameter Value")).FirstOrDefault()); + string operand = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Operand" + select rw.Field("Parameter Value")).FirstOrDefault()); + string value2 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value2" + select rw.Field("Parameter Value")).FirstOrDefault()); + + value1 = value1.ConvertToUserVariable(sender); + value2 = value2.ConvertToUserVariable(sender); + + + + decimal cdecValue1, cdecValue2; + + switch (operand) + { + case "is equal to": + loopResult = (value1 == value2); + break; + + case "is not equal to": + loopResult = (value1 != value2); + break; + + case "is greater than": + cdecValue1 = Convert.ToDecimal(value1); + cdecValue2 = Convert.ToDecimal(value2); + loopResult = (cdecValue1 > cdecValue2); + break; + + case "is greater than or equal to": + cdecValue1 = Convert.ToDecimal(value1); + cdecValue2 = Convert.ToDecimal(value2); + loopResult = (cdecValue1 >= cdecValue2); + break; + + case "is less than": + cdecValue1 = Convert.ToDecimal(value1); + cdecValue2 = Convert.ToDecimal(value2); + loopResult = (cdecValue1 < cdecValue2); + break; + + case "is less than or equal to": + cdecValue1 = Convert.ToDecimal(value1); + cdecValue2 = Convert.ToDecimal(value2); + loopResult = (cdecValue1 <= cdecValue2); + break; + } + } + else if (v_LoopActionType == "Date Compare") + { + string value1 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value1" + select rw.Field("Parameter Value")).FirstOrDefault()); + string operand = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Operand" + select rw.Field("Parameter Value")).FirstOrDefault()); + string value2 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value2" + select rw.Field("Parameter Value")).FirstOrDefault()); + + value1 = value1.ConvertToUserVariable(sender); + value2 = value2.ConvertToUserVariable(sender); + + + + DateTime dt1, dt2; + dt1 = DateTime.Parse(value1); + dt2 = DateTime.Parse(value2); + switch (operand) + { + case "is equal to": + loopResult = (dt1 == dt2); + break; + + case "is not equal to": + loopResult = (dt1 != dt2); + break; + + case "is greater than": + loopResult = (dt1 > dt2); + break; + + case "is greater than or equal to": + loopResult = (dt1 >= dt2); + break; + + case "is less than": + loopResult = (dt1 < dt2); + break; + + case "is less than or equal to": + loopResult = (dt1 <= dt2); + break; + } + } + else if (v_LoopActionType == "Variable Compare") + { + string value1 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value1" + select rw.Field("Parameter Value")).FirstOrDefault()); + string operand = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Operand" + select rw.Field("Parameter Value")).FirstOrDefault()); + string value2 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value2" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string caseSensitive = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Case Sensitive" + select rw.Field("Parameter Value")).FirstOrDefault()); + + value1 = value1.ConvertToUserVariable(sender); + value2 = value2.ConvertToUserVariable(sender); + + if (caseSensitive == "No") + { + value1 = value1.ToUpper(); + value2 = value2.ToUpper(); + } + + + + switch (operand) + { + case "contains": + loopResult = (value1.Contains(value2)); + break; + + case "does not contain": + loopResult = (!value1.Contains(value2)); + break; + + case "is equal to": + loopResult = (value1 == value2); + break; + + case "is not equal to": + loopResult = (value1 != value2); + break; + } + } + else if (v_LoopActionType == "Variable Has Value") + { + string variableName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Variable Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + var actualVariable = variableName.ConvertToUserVariable(sender).Trim(); + + if (!string.IsNullOrEmpty(actualVariable)) + { + loopResult = true; + } + else + { + loopResult = false; + } + + } + else if (v_LoopActionType == "Variable Is Numeric") + { + string variableName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Variable Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + var actualVariable = variableName.ConvertToUserVariable(sender).Trim(); + + var numericTest = decimal.TryParse(actualVariable, out decimal parsedResult); + + if (numericTest) + { + loopResult = true; + } + else + { + loopResult = false; + } + + } + else if (v_LoopActionType == "Error Occured") + { + //get line number + string userLineNumber = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Line Number" + select rw.Field("Parameter Value")).FirstOrDefault()); + + //convert to variable + string variableLineNumber = userLineNumber.ConvertToUserVariable(sender); + + //convert to int + int lineNumber = int.Parse(variableLineNumber); + + //determine if error happened + if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() > 0) + { + + var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault(); + error.ErrorMessage.StoreInUserVariable(sender, "Error.Message"); + error.LineNumber.ToString().StoreInUserVariable(sender, "Error.Line"); + error.StackTrace.StoreInUserVariable(sender, "Error.StackTrace"); + + loopResult = true; + } + else + { + loopResult = false; + } + + } + else if (v_LoopActionType == "Error Did Not Occur") + { + //get line number + string userLineNumber = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Line Number" + select rw.Field("Parameter Value")).FirstOrDefault()); + + //convert to variable + string variableLineNumber = userLineNumber.ConvertToUserVariable(sender); + + //convert to int + int lineNumber = int.Parse(variableLineNumber); + + //determine if error happened + if (engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).Count() == 0) + { + loopResult = true; + } + else + { + var error = engine.ErrorsOccured.Where(f => f.LineNumber == lineNumber).FirstOrDefault(); + error.ErrorMessage.StoreInUserVariable(sender, "Error.Message"); + error.LineNumber.ToString().StoreInUserVariable(sender, "Error.Line"); + error.StackTrace.StoreInUserVariable(sender, "Error.StackTrace"); + + loopResult = false; + } + + } + else if (v_LoopActionType == "Window Name Exists") + { + //get user supplied name + string windowName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Window Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + //variable translation + string variablizedWindowName = windowName.ConvertToUserVariable(sender); + + //search for window + IntPtr windowPtr = User32Functions.FindWindow(variablizedWindowName); + + //conditional + if (windowPtr != IntPtr.Zero) + { + loopResult = true; + } + + + + } + else if (v_LoopActionType == "Active Window Name Is") + { + string windowName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Window Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string variablizedWindowName = windowName.ConvertToUserVariable(sender); + + var currentWindowTitle = User32Functions.GetActiveWindowTitle(); + + if (currentWindowTitle == variablizedWindowName) + { + loopResult = true; + } + + } + else if (v_LoopActionType == "File Exists") + { + + string fileName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "File Path" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string trueWhenFileExists = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "True When" + select rw.Field("Parameter Value")).FirstOrDefault()); + + var userFileSelected = fileName.ConvertToUserVariable(sender); + + bool existCheck = false; + if (trueWhenFileExists == "It Does Exist") + { + existCheck = true; + } + + + if (System.IO.File.Exists(userFileSelected) == existCheck) + { + loopResult = true; + } + + + } + else if (v_LoopActionType == "Folder Exists") + { + string folderName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Folder Path" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string trueWhenFileExists = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "True When" + select rw.Field("Parameter Value")).FirstOrDefault()); + + var userFolderSelected = folderName.ConvertToUserVariable(sender); + + bool existCheck = false; + if (trueWhenFileExists == "It Does Exist") + { + existCheck = true; + } + + + if (System.IO.Directory.Exists(folderName) == existCheck) + { + loopResult = true; + } + + } + else if (v_LoopActionType == "Web Element Exists") + { + string instanceName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Selenium Instance Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string parameterName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Element Search Parameter" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string searchMethod = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Element Search Method" + select rw.Field("Parameter Value")).FirstOrDefault()); + + + SeleniumBrowserElementActionCommand newElementActionCommand = new SeleniumBrowserElementActionCommand(); + newElementActionCommand.v_SeleniumSearchType = searchMethod; + newElementActionCommand.v_InstanceName = instanceName.ConvertToUserVariable(sender); + bool elementExists = newElementActionCommand.ElementExists(sender, searchMethod, parameterName); + loopResult = elementExists; + + } + else if (v_LoopActionType == "GUI Element Exists") + { + string windowName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Window Name" + select rw.Field("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender)); + + string elementSearchParam = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Element Search Parameter" + select rw.Field("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender)); + + string elementSearchMethod = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Element Search Method" + select rw.Field("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender)); + + + UIAutomationCommand newUIACommand = new UIAutomationCommand(); + newUIACommand.v_WindowName = windowName; + newUIACommand.v_UIASearchParameters.Rows.Add(true, elementSearchMethod, elementSearchParam); + var handle = newUIACommand.SearchForGUIElement(sender, windowName); + + if (handle is null) + { + loopResult = false; + } + else + { + loopResult = true; + } + + + } + else + { + throw new Exception("Loop type not recognized!"); + } + + return loopResult; + } + + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + ActionDropdown = (ComboBox)CommandControls.CreateDropdownFor("v_LoopActionType", this); + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_LoopActionType", this)); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_LoopActionType", this, new Control[] { ActionDropdown }, editor)); + ActionDropdown.SelectionChangeCommitted += loopAction_SelectionChangeCommitted; + + RenderedControls.Add(ActionDropdown); + + ParameterControls = new List(); + ParameterControls.Add(CommandControls.CreateDefaultLabelFor("v_LoopActionParameterTable", this)); + ParameterControls.Add(RecorderControl); + ParameterControls.AddRange(CommandControls.CreateUIHelpersFor("v_LoopActionParameterTable", this, new Control[] { LoopGridViewHelper }, editor)); + ParameterControls.Add(LoopGridViewHelper); + + RenderedControls.AddRange(ParameterControls); + + return RenderedControls; + } + + private void loopAction_SelectionChangeCommitted(object sender, EventArgs e) + { + ComboBox loopAction = (ComboBox)ActionDropdown; + DataGridView loopActionParameterBox = (DataGridView)LoopGridViewHelper; + + Core.Automation.Commands.BeginLoopCommand cmd = (Core.Automation.Commands.BeginLoopCommand)this; + DataTable actionParameters = cmd.v_LoopActionParameterTable; + + //sender is null when command is updating + if (sender != null) + actionParameters.Rows.Clear(); + + DataGridViewComboBoxCell comparisonComboBox = new DataGridViewComboBoxCell(); + + //recorder control + Control recorderControl = (Control)RecorderControl; + + //remove if exists + if (RecorderControl.Visible) + { + RecorderControl.Hide(); + } + + + switch (loopAction.SelectedItem) + { + case "Value": + case "Date Compare": + + loopActionParameterBox.Visible = true; + + if (sender != null) + { + actionParameters.Rows.Add("Value1", ""); + actionParameters.Rows.Add("Operand", ""); + actionParameters.Rows.Add("Value2", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + //combobox cell for Variable Name + comparisonComboBox = new DataGridViewComboBoxCell(); + comparisonComboBox.Items.Add("is equal to"); + comparisonComboBox.Items.Add("is greater than"); + comparisonComboBox.Items.Add("is greater than or equal to"); + comparisonComboBox.Items.Add("is less than"); + comparisonComboBox.Items.Add("is less than or equal to"); + comparisonComboBox.Items.Add("is not equal to"); + + //assign cell as a combobox + loopActionParameterBox.Rows[1].Cells[1] = comparisonComboBox; + + break; + case "Variable Compare": + + loopActionParameterBox.Visible = true; + + if (sender != null) + { + actionParameters.Rows.Add("Value1", ""); + actionParameters.Rows.Add("Operand", ""); + actionParameters.Rows.Add("Value2", ""); + actionParameters.Rows.Add("Case Sensitive", "No"); + loopActionParameterBox.DataSource = actionParameters; + } + + //combobox cell for Variable Name + comparisonComboBox = new DataGridViewComboBoxCell(); + comparisonComboBox.Items.Add("contains"); + comparisonComboBox.Items.Add("does not contain"); + comparisonComboBox.Items.Add("is equal to"); + comparisonComboBox.Items.Add("is not equal to"); + + //assign cell as a combobox + loopActionParameterBox.Rows[1].Cells[1] = comparisonComboBox; + + comparisonComboBox = new DataGridViewComboBoxCell(); + comparisonComboBox.Items.Add("Yes"); + comparisonComboBox.Items.Add("No"); + + //assign cell as a combobox + loopActionParameterBox.Rows[3].Cells[1] = comparisonComboBox; + + break; + + case "Variable Has Value": + + loopActionParameterBox.Visible = true; + if (sender != null) + { + actionParameters.Rows.Add("Variable Name", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + break; + case "Variable Is Numeric": + + loopActionParameterBox.Visible = true; + if (sender != null) + { + actionParameters.Rows.Add("Variable Name", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + break; + case "Error Occured": + + loopActionParameterBox.Visible = true; + if (sender != null) + { + actionParameters.Rows.Add("Line Number", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + break; + case "Error Did Not Occur": + + loopActionParameterBox.Visible = true; + + if (sender != null) + { + actionParameters.Rows.Add("Line Number", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + break; + case "Window Name Exists": + case "Active Window Name Is": + + loopActionParameterBox.Visible = true; + if (sender != null) + { + actionParameters.Rows.Add("Window Name", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + break; + case "File Exists": + + loopActionParameterBox.Visible = true; + if (sender != null) + { + actionParameters.Rows.Add("File Path", ""); + actionParameters.Rows.Add("True When", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + + //combobox cell for Variable Name + comparisonComboBox = new DataGridViewComboBoxCell(); + comparisonComboBox.Items.Add("It Does Exist"); + comparisonComboBox.Items.Add("It Does Not Exist"); + + //assign cell as a combobox + loopActionParameterBox.Rows[1].Cells[1] = comparisonComboBox; + + break; + case "Folder Exists": + + loopActionParameterBox.Visible = true; + + + if (sender != null) + { + actionParameters.Rows.Add("Folder Path", ""); + actionParameters.Rows.Add("True When", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + //combobox cell for Variable Name + comparisonComboBox = new DataGridViewComboBoxCell(); + comparisonComboBox.Items.Add("It Does Exist"); + comparisonComboBox.Items.Add("It Does Not Exist"); + + //assign cell as a combobox + loopActionParameterBox.Rows[1].Cells[1] = comparisonComboBox; + break; + case "Web Element Exists": + + loopActionParameterBox.Visible = true; + + if (sender != null) + { + actionParameters.Rows.Add("Selenium Instance Name", "default"); + actionParameters.Rows.Add("Element Search Method", ""); + actionParameters.Rows.Add("Element Search Parameter", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + + + comparisonComboBox = new DataGridViewComboBoxCell(); + comparisonComboBox.Items.Add("Find Element By XPath"); + comparisonComboBox.Items.Add("Find Element By ID"); + comparisonComboBox.Items.Add("Find Element By Name"); + comparisonComboBox.Items.Add("Find Element By Tag Name"); + comparisonComboBox.Items.Add("Find Element By Class Name"); + comparisonComboBox.Items.Add("Find Element By CSS Selector"); + + //assign cell as a combobox + loopActionParameterBox.Rows[1].Cells[1] = comparisonComboBox; + + break; + case "GUI Element Exists": + + + loopActionParameterBox.Visible = true; + if (sender != null) + { + actionParameters.Rows.Add("Window Name", "Current Window"); + actionParameters.Rows.Add("Element Search Method", ""); + actionParameters.Rows.Add("Element Search Parameter", ""); + loopActionParameterBox.DataSource = actionParameters; + } + + + + var parameterName = new DataGridViewComboBoxCell(); + parameterName.Items.Add("AcceleratorKey"); + parameterName.Items.Add("AccessKey"); + parameterName.Items.Add("AutomationId"); + parameterName.Items.Add("ClassName"); + parameterName.Items.Add("FrameworkId"); + parameterName.Items.Add("HasKeyboardFocus"); + parameterName.Items.Add("HelpText"); + parameterName.Items.Add("IsContentElement"); + parameterName.Items.Add("IsControlElement"); + parameterName.Items.Add("IsEnabled"); + parameterName.Items.Add("IsKeyboardFocusable"); + parameterName.Items.Add("IsOffscreen"); + parameterName.Items.Add("IsPassword"); + parameterName.Items.Add("IsRequiredForForm"); + parameterName.Items.Add("ItemStatus"); + parameterName.Items.Add("ItemType"); + parameterName.Items.Add("LocalizedControlType"); + parameterName.Items.Add("Name"); + parameterName.Items.Add("NativeWindowHandle"); + parameterName.Items.Add("ProcessID"); + + //assign cell as a combobox + loopActionParameterBox.Rows[1].Cells[1] = parameterName; + + RecorderControl.Show(); + + break; + + default: + break; + } + } + + private void ShowLoopElementRecorder(object sender, EventArgs e) + { + //get command reference + Core.Automation.Commands.UIAutomationCommand cmd = new Core.Automation.Commands.UIAutomationCommand(); + + //create recorder + UI.Forms.Supplemental.frmThickAppElementRecorder newElementRecorder = new UI.Forms.Supplemental.frmThickAppElementRecorder(); + newElementRecorder.searchParameters = cmd.v_UIASearchParameters; + + //show form + newElementRecorder.ShowDialog(); + + var sb = new StringBuilder(); + sb.AppendLine("Element Properties Found!"); + sb.AppendLine(Environment.NewLine); + sb.AppendLine("Element Search Method - Element Search Parameter"); + foreach (DataRow rw in cmd.v_UIASearchParameters.Rows) + { + if (rw.ItemArray[2].ToString().Trim() == string.Empty) + continue; + + sb.AppendLine(rw.ItemArray[1].ToString() + " - " + rw.ItemArray[2].ToString()); + } + + DataGridView loopActionBox = LoopGridViewHelper; + loopActionBox.Rows[0].Cells[1].Value = newElementRecorder.cboWindowTitle.Text; + + MessageBox.Show(sb.ToString()); + } + + public override string GetDisplayValue() + { + switch (v_LoopActionType) + { + case "Value": + case "Date Compare": + case "Variable Compare": + string value1 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value1" + select rw.Field("Parameter Value")).FirstOrDefault()); + string operand = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Operand" + select rw.Field("Parameter Value")).FirstOrDefault()); + string value2 = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Value2" + select rw.Field("Parameter Value")).FirstOrDefault()); + + return "Loop While (" + value1 + " " + operand + " " + value2 + ")"; + + case "Variable Has Value": + string variableName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Variable Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + return "Loop While (Variable " + variableName + " Has Value)"; + case "Variable Is Numeric": + string varName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Variable Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + return "Loop While (Variable " + varName + " Is Numeric)"; + + case "Error Occured": + + string lineNumber = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Line Number" + select rw.Field("Parameter Value")).FirstOrDefault()); + + return "Loop While (Error Occured on Line Number " + lineNumber + ")"; + case "Error Did Not Occur": + + string lineNum = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Line Number" + select rw.Field("Parameter Value")).FirstOrDefault()); + + return "Loop While (Error Did Not Occur on Line Number " + lineNum + ")"; + case "Window Name Exists": + case "Active Window Name Is": + + string windowName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Window Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + return "Loop While " + v_LoopActionType + " [Name: " + windowName + "]"; + case "File Exists": + + string filePath = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "File Path" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string fileCompareType = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "True When" + select rw.Field("Parameter Value")).FirstOrDefault()); + + + return "Loop While " + v_LoopActionType + " [File: " + filePath + "]"; + + case "Folder Exists": + + string folderPath = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Folder Path" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string folderCompareType = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "True When" + select rw.Field("Parameter Value")).FirstOrDefault()); + + + return "Loop While " + v_LoopActionType + " [Folder: " + folderPath + "]"; + + case "Web Element Exists": + + + string parameterName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Element Search Parameter" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string searchMethod = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Element Search Method" + select rw.Field("Parameter Value")).FirstOrDefault()); + + + return "Loop While Web Element Exists [" + searchMethod + ": " + parameterName + "]"; + + case "GUI Element Exists": + + + string guiWindowName = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Window Name" + select rw.Field("Parameter Value")).FirstOrDefault()); + + string guiSearch = ((from rw in v_LoopActionParameterTable.AsEnumerable() + where rw.Field("Parameter Name") == "Element Search Parameter" + select rw.Field("Parameter Value")).FirstOrDefault()); + + + + + return "Loop While GUI Element Exists [Find " + guiSearch + " Element In " + guiWindowName + "]"; + + + default: + + return "Loop While .... "; + } + + } + } +} diff --git a/taskt/Core/Automation/Commands/BeginMultiLoopCommand.cs b/taskt/Core/Automation/Commands/BeginMultiLoopCommand.cs new file mode 100644 index 000000000..942ed82b4 --- /dev/null +++ b/taskt/Core/Automation/Commands/BeginMultiLoopCommand.cs @@ -0,0 +1,237 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using taskt.Core.Automation.User32; +using System.Collections.Generic; +using System.Windows.Forms; +using taskt.UI.Forms; +using taskt.UI.CustomControls; +using System.Drawing; +using System.Text; + +namespace taskt.Core.Automation.Commands +{ + + + + + [Serializable] + [Attributes.ClassAttributes.Group("Loop Commands")] + [Attributes.ClassAttributes.Description("This command allows you to evaluate a logical statement to determine if the statement is true. The following actions will repeat continuously until that statement becomes false")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to check if a statement is 'true' or 'false' and subsequently loop actions based on either condition. Any 'BeginLoop' command must have a following 'EndLoop' command.")] + [Attributes.ClassAttributes.ImplementationDescription("This command evaluates supplied arguments and if evaluated to true runs sub elements")] + public class BeginMultiLoopCommand : ScriptCommand + { + + [XmlElement] + [Attributes.PropertyAttributes.PropertyDescription("Multiple Loop Conditions - All Must Be True")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowLoopBuilder)] + [Attributes.PropertyAttributes.InputSpecification("")] + [Attributes.PropertyAttributes.SampleUsage("n/a")] + [Attributes.PropertyAttributes.Remarks("")] + public DataTable v_LoopConditionsTable { get; set; } + + [XmlIgnore] + [NonSerialized] + private DataGridView LoopConditionHelper; + + [XmlIgnore] + private List ScriptVariables { get; set; } + + public BeginMultiLoopCommand() + { + this.CommandName = "BeginMultiLoopCommand"; + this.SelectionName = "Begin Multi Loop"; + this.CommandEnabled = true; + this.CustomRendering = true; + + v_LoopConditionsTable = new DataTable(); + v_LoopConditionsTable.TableName = DateTime.Now.ToString("MultiLoopConditionTable" + DateTime.Now.ToString("MMddyy.hhmmss")); + v_LoopConditionsTable.Columns.Add("Statement"); + v_LoopConditionsTable.Columns.Add("CommandData"); + + } + + + public override void RunCommand(object sender, Core.Script.ScriptAction parentCommand) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + + bool isTrueStatement = DetermineMultiStatementTruth(sender); + + engine.ReportProgress("Starting Loop"); + + while (isTrueStatement) + { + foreach (var cmd in parentCommand.AdditionalScriptCommands) + { + if (engine.IsCancellationPending) + return; + + engine.ExecuteCommand(cmd); + + if (engine.CurrentLoopCancelled) + { + engine.ReportProgress("Exiting Loop"); + engine.CurrentLoopCancelled = false; + return; + } + + if (engine.CurrentLoopContinuing) + { + engine.ReportProgress("Continuing Next Loop"); + engine.CurrentLoopContinuing = false; + break; + } + } + isTrueStatement = DetermineMultiStatementTruth(sender); + } + + } + + + private bool DetermineMultiStatementTruth(object sender) + { + bool isTrueStatement = true; + foreach (DataRow rw in v_LoopConditionsTable.Rows) + { + var commandData = rw["CommandData"].ToString(); + var loopCommand = Newtonsoft.Json.JsonConvert.DeserializeObject(commandData); + + var statementResult = loopCommand.DetermineStatementTruth(sender); + + if (!statementResult) + { + isTrueStatement = false; + break; + } + } + return isTrueStatement; + } + + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //get script variables for feeding into loop builder form + ScriptVariables = editor.scriptVariables; + + //create controls + var controls = CommandControls.CreateDataGridViewGroupFor("v_LoopConditionsTable", this, editor); + LoopConditionHelper = controls[2] as DataGridView; + + //handle helper click + var helper = controls[1] as taskt.UI.CustomControls.CommandItemControl; + helper.Click += (sender, e) => CreateLoopCondition(sender, e); + + //add for rendering + RenderedControls.AddRange(controls); + + //define if condition helper + LoopConditionHelper.Width = 450; + LoopConditionHelper.Height = 200; + LoopConditionHelper.AutoGenerateColumns = false; + LoopConditionHelper.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; + LoopConditionHelper.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "Condition", DataPropertyName = "Statement", ReadOnly = true, AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill }); + LoopConditionHelper.Columns.Add(new DataGridViewTextBoxColumn() { HeaderText = "CommandData", DataPropertyName = "CommandData", ReadOnly = true, Visible = false }); + LoopConditionHelper.Columns.Add(new DataGridViewButtonColumn() { HeaderText = "Edit", UseColumnTextForButtonValue = true, Text = "Edit", Width = 45 }); + LoopConditionHelper.Columns.Add(new DataGridViewButtonColumn() { HeaderText = "Delete", UseColumnTextForButtonValue = true, Text = "Delete", Width = 45 }); + LoopConditionHelper.AllowUserToAddRows = false; + LoopConditionHelper.AllowUserToDeleteRows = true; + LoopConditionHelper.CellContentClick += LoopConditionHelper_CellContentClick; + + + return RenderedControls; + } + + private void LoopConditionHelper_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + var senderGrid = (DataGridView)sender; + + if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) + { + var buttonSelected = senderGrid.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell; + var selectedRow = v_LoopConditionsTable.Rows[e.RowIndex]; + + if (buttonSelected.Value.ToString() == "Edit") + { + //launch editor + var statement = selectedRow["Statement"]; + var commandData = selectedRow["CommandData"].ToString(); + + var loopCommand = Newtonsoft.Json.JsonConvert.DeserializeObject(commandData); + + var automationCommands = taskt.UI.CustomControls.CommandControls.GenerateCommandsandControls().Where(f => f.Command is BeginLoopCommand).ToList(); + frmCommandEditor editor = new frmCommandEditor(automationCommands, null); + editor.selectedCommand = loopCommand; + editor.editingCommand = loopCommand; + editor.originalCommand = loopCommand; + editor.creationMode = frmCommandEditor.CreationMode.Edit; + editor.scriptVariables = ScriptVariables; + + if (editor.ShowDialog() == DialogResult.OK) + { + var editedCommand = editor.editingCommand as BeginLoopCommand; + var displayText = editedCommand.GetDisplayValue(); + var serializedData = Newtonsoft.Json.JsonConvert.SerializeObject(editedCommand); + + selectedRow["Statement"] = displayText; + selectedRow["CommandData"] = serializedData; + } + + + } + else if (buttonSelected.Value.ToString() == "Delete") + { + //delete + v_LoopConditionsTable.Rows.Remove(selectedRow); + } + else + { + throw new NotImplementedException("Requested Action is not implemented."); + } + + } + + } + + private void CreateLoopCondition(object sender, EventArgs e) + { + + var automationCommands = taskt.UI.CustomControls.CommandControls.GenerateCommandsandControls().Where(f => f.Command is BeginLoopCommand).ToList(); + + frmCommandEditor editor = new frmCommandEditor(automationCommands, null); + editor.selectedCommand = new BeginLoopCommand(); + var res = editor.ShowDialog(); + + if (res == DialogResult.OK) + { + //get data + var configuredCommand = editor.selectedCommand as BeginLoopCommand; + var displayText = configuredCommand.GetDisplayValue(); + var serializedData = Newtonsoft.Json.JsonConvert.SerializeObject(configuredCommand); + + //add to list + v_LoopConditionsTable.Rows.Add(displayText, serializedData); + + } + + } + + public override string GetDisplayValue() + { + + if (v_LoopConditionsTable.Rows.Count == 0) + { + return "Loop "; + } + else + { + var statements = v_LoopConditionsTable.AsEnumerable().Select(f => f.Field("Statement")).ToList(); + return string.Join(" && ", statements); + } + + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/ExcelActivateSheetCommand.cs b/taskt/Core/Automation/Commands/ExcelActivateSheetCommand.cs index 684ada0b9..8249343d8 100644 --- a/taskt/Core/Automation/Commands/ExcelActivateSheetCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelActivateSheetCommand.cs @@ -17,7 +17,7 @@ public class ExcelActivateSheetCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelAddWorkbookCommand.cs b/taskt/Core/Automation/Commands/ExcelAddWorkbookCommand.cs index c293c265d..d2a060c27 100644 --- a/taskt/Core/Automation/Commands/ExcelAddWorkbookCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelAddWorkbookCommand.cs @@ -17,7 +17,7 @@ public class ExcelAddWorkbookCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelAppendCellCommand.cs b/taskt/Core/Automation/Commands/ExcelAppendCellCommand.cs index 92b0d0d7d..3d5fa01c6 100644 --- a/taskt/Core/Automation/Commands/ExcelAppendCellCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelAppendCellCommand.cs @@ -18,7 +18,7 @@ public class ExcelAppendCellCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelAppendRowCommand.cs b/taskt/Core/Automation/Commands/ExcelAppendRowCommand.cs index 8c2be8888..bff26510e 100644 --- a/taskt/Core/Automation/Commands/ExcelAppendRowCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelAppendRowCommand.cs @@ -18,12 +18,12 @@ public class ExcelAppendRowCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } [XmlAttribute] - [Attributes.PropertyAttributes.PropertyDescription("Please Enter text to set")] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Row to set")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter the text value that will be set (This could be a DataRow).")] [Attributes.PropertyAttributes.SampleUsage("Hello,world or [vText]")] @@ -47,10 +47,19 @@ public override void RunCommand(object sender) Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject; Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet; - var lastUsedRow = excelSheet.Cells.Find("*", System.Reflection.Missing.Value, + int lastUsedRow; + try + { + lastUsedRow = excelSheet.Cells.Find("*", System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlPrevious, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value).Row; + } + catch(Exception ex) + { + lastUsedRow = 0; + } + var targetText = v_TextToSet.ConvertToUserVariable(sender); splittext = targetText.Split(','); @@ -82,7 +91,7 @@ public override List Render(frmCommandEditor editor) } public override string GetDisplayValue() { - return base.GetDisplayValue() + " [Append Row '" +v_TextToSet+ " to last row" + "of workboook with Instance Name: '" + v_InstanceName + "']"; + return base.GetDisplayValue() + " [Append Row '" +v_TextToSet+ " to last row of workboook with Instance Name: '" + v_InstanceName + "']"; } } } \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/ExcelCloseApplicationCommand.cs b/taskt/Core/Automation/Commands/ExcelCloseApplicationCommand.cs index 918ec38a8..aca962bd1 100644 --- a/taskt/Core/Automation/Commands/ExcelCloseApplicationCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelCloseApplicationCommand.cs @@ -17,7 +17,7 @@ public class ExcelCloseApplicationCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelDeleteCellCommand.cs b/taskt/Core/Automation/Commands/ExcelDeleteCellCommand.cs index 91e78cc9e..347a08926 100644 --- a/taskt/Core/Automation/Commands/ExcelDeleteCellCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelDeleteCellCommand.cs @@ -17,7 +17,7 @@ public class ExcelDeleteCellCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelDeleteRowCommand.cs b/taskt/Core/Automation/Commands/ExcelDeleteRowCommand.cs index 59596a13c..d67b190f0 100644 --- a/taskt/Core/Automation/Commands/ExcelDeleteRowCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelDeleteRowCommand.cs @@ -17,7 +17,7 @@ public class ExcelDeleteRowCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelGetCellCommand.cs b/taskt/Core/Automation/Commands/ExcelGetCellCommand.cs index 5720ad5b0..37d09773a 100644 --- a/taskt/Core/Automation/Commands/ExcelGetCellCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelGetCellCommand.cs @@ -17,7 +17,7 @@ public class ExcelGetCellCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelGetLastRowCommand.cs b/taskt/Core/Automation/Commands/ExcelGetLastRowCommand.cs index c56859115..2d9115b3f 100644 --- a/taskt/Core/Automation/Commands/ExcelGetLastRowCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelGetLastRowCommand.cs @@ -17,7 +17,7 @@ public class ExcelGetLastRowCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelGetRangeCommand .cs b/taskt/Core/Automation/Commands/ExcelGetRangeCommand .cs index 6383042d3..d9d15e5a3 100644 --- a/taskt/Core/Automation/Commands/ExcelGetRangeCommand .cs +++ b/taskt/Core/Automation/Commands/ExcelGetRangeCommand .cs @@ -17,7 +17,7 @@ public class ExcelGetRangeCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } @@ -60,7 +60,14 @@ public override void RunCommand(object sender) Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject; Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet; - var cellValue = excelSheet.Range[targetAddress1, targetAddress2]; + Microsoft.Office.Interop.Excel.Range cellValue; + if (targetAddress2 != "") + cellValue = excelSheet.Range[targetAddress1, targetAddress2]; + else + { + Microsoft.Office.Interop.Excel.Range last = excelSheet.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing); + cellValue = excelSheet.Range[targetAddress1, last]; + } List lst = new List(); int rw = cellValue.Rows.Count; @@ -85,7 +92,6 @@ public override void RunCommand(object sender) } string output = String.Join(",", lst); - v_ExcelCellAddress1 = output; //Store Strings of comma seperated values into user variable output.StoreInUserVariable(sender, v_userVariableName); diff --git a/taskt/Core/Automation/Commands/ExcelGetRangeCommandASDT.cs b/taskt/Core/Automation/Commands/ExcelGetRangeCommandASDT.cs index c7fdad781..c19914777 100644 --- a/taskt/Core/Automation/Commands/ExcelGetRangeCommandASDT.cs +++ b/taskt/Core/Automation/Commands/ExcelGetRangeCommandASDT.cs @@ -6,6 +6,7 @@ using taskt.UI.Forms; using System.Data; using System.Text; +using System.Linq; namespace taskt.Core.Automation.Commands { @@ -19,7 +20,7 @@ public class ExcelGetRangeCommandAsDT : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } @@ -39,12 +40,22 @@ public class ExcelGetRangeCommandAsDT : ScriptCommand [Attributes.PropertyAttributes.Remarks("")] public string v_Output { get; set; } [XmlAttribute] - [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Second Cell Location (ex. A1 or B2)")] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Second Cell Location (ex. A1 or B2, Leave Blank for All)")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter the actual location of the cell.")] [Attributes.PropertyAttributes.SampleUsage("A1, B10, [vAddress]")] [Attributes.PropertyAttributes.Remarks("")] public string v_ExcelCellAddress2 { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Add Headers")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("No")] + [Attributes.PropertyAttributes.InputSpecification("When selected, the column headers from the specified spreadsheet range are also extracted.")] + [Attributes.PropertyAttributes.SampleUsage("Select from **Yes** or **No**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_AddHeaders { get; set; } + [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] [Attributes.PropertyAttributes.InputSpecification("Select or provide a variable from the variable list")] @@ -58,13 +69,14 @@ public ExcelGetRangeCommandAsDT() this.SelectionName = "Get Range As Datatable"; this.CommandEnabled = true; this.CustomRendering = true; + this.v_AddHeaders = "Yes"; } public override void RunCommand(object sender) { - var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; var vInstance = v_InstanceName.ConvertToUserVariable(engine); var excelObject = engine.GetAppInstance(vInstance); var targetAddress1 = v_ExcelCellAddress1.ConvertToUserVariable(sender); @@ -72,7 +84,16 @@ public override void RunCommand(object sender) Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject; Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet; - var cellValue = excelSheet.Range[targetAddress1, targetAddress2]; + Microsoft.Office.Interop.Excel.Range cellValue; + if (targetAddress2 != "") + cellValue = excelSheet.Range[targetAddress1, targetAddress2]; + else + { + Microsoft.Office.Interop.Excel.Range last = excelSheet.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing); + cellValue = excelSheet.Range[targetAddress1, last]; + } + + if (v_Output == "Datatable") { @@ -81,9 +102,10 @@ public override void RunCommand(object sender) int cl = cellValue.Columns.Count; int rCnt; int cCnt; - string str; + string cName; DataTable DT = new DataTable(); - for (rCnt = 1; rCnt <= rw; rCnt++) + + for (rCnt = 2; rCnt <= rw; rCnt++) { DataRow newRow = DT.NewRow(); @@ -103,12 +125,29 @@ public override void RunCommand(object sender) } DT.Rows.Add(newRow); } + + if (v_AddHeaders == "Yes") + { + //Set column names + for (cCnt = 1; cCnt <= cl; cCnt++) + { + cName = ((cellValue.Cells[1, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2).ToString(); + DT.Columns[cCnt - 1].ColumnName = cName; + } + } + Script.ScriptVariable newDataset = new Script.ScriptVariable { VariableName = v_userVariableName, VariableValue = DT }; + //Overwrites variable if it already exists + if (engine.VariableList.Exists(x => x.VariableName == newDataset.VariableName)) + { + Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newDataset.VariableName).FirstOrDefault(); + engine.VariableList.Remove(temp); + } engine.VariableList.Add(newDataset); } if(v_Output == "Delimited String") @@ -136,7 +175,6 @@ public override void RunCommand(object sender) } string output = String.Join(",", lst); - v_ExcelCellAddress1 = output; //Store Strings of comma seperated values into user variable output.StoreInUserVariable(sender, v_userVariableName); @@ -157,7 +195,7 @@ public override List Render(frmCommandEditor editor) RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_userVariableName", this, new Control[] { VariableNameControl }, editor)); RenderedControls.Add(VariableNameControl); RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_Output", this, editor)); - + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_AddHeaders", this, editor)); return RenderedControls; @@ -165,7 +203,7 @@ public override List Render(frmCommandEditor editor) public override string GetDisplayValue() { - return base.GetDisplayValue() + " [Get Value Between '" + v_ExcelCellAddress1 + "And " + v_ExcelCellAddress2 + "' and apply to variable '" + v_userVariableName + "'from, Instance Name: '" + v_InstanceName + "']"; + return base.GetDisplayValue() + " [Get Values Between '" + v_ExcelCellAddress1 + "' and '" + v_ExcelCellAddress2 + "' and apply to variable '" + v_userVariableName + "', Instance Name: '" + v_InstanceName + "']"; } } } \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/ExcelGoToCellCommand.cs b/taskt/Core/Automation/Commands/ExcelGoToCellCommand.cs index 5af5950da..a2aa07d3a 100644 --- a/taskt/Core/Automation/Commands/ExcelGoToCellCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelGoToCellCommand.cs @@ -17,7 +17,7 @@ public class ExcelGoToCellCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelOpenWorkbookCommand.cs b/taskt/Core/Automation/Commands/ExcelOpenWorkbookCommand.cs index d3e0eba7d..b5897ae69 100644 --- a/taskt/Core/Automation/Commands/ExcelOpenWorkbookCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelOpenWorkbookCommand.cs @@ -17,7 +17,7 @@ public class ExcelOpenWorkbookCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelRunMacroCommand.cs b/taskt/Core/Automation/Commands/ExcelRunMacroCommand.cs index 5ddfa23d6..e4ef3ae62 100644 --- a/taskt/Core/Automation/Commands/ExcelRunMacroCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelRunMacroCommand.cs @@ -17,7 +17,7 @@ public class ExcelRunMacroCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelSaveAsCommand.cs b/taskt/Core/Automation/Commands/ExcelSaveAsCommand.cs index 9acc5bbad..cf66d0b47 100644 --- a/taskt/Core/Automation/Commands/ExcelSaveAsCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelSaveAsCommand.cs @@ -17,7 +17,7 @@ public class ExcelSaveAsCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelSaveCommand.cs b/taskt/Core/Automation/Commands/ExcelSaveCommand.cs index 425b48647..1778b4544 100644 --- a/taskt/Core/Automation/Commands/ExcelSaveCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelSaveCommand.cs @@ -17,7 +17,7 @@ public class ExcelSaveCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelSetCellCommand.cs b/taskt/Core/Automation/Commands/ExcelSetCellCommand.cs index 031249f42..3fe5bbc69 100644 --- a/taskt/Core/Automation/Commands/ExcelSetCellCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelSetCellCommand.cs @@ -17,7 +17,7 @@ public class ExcelSetCellCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/ExcelSplitRangeByColumnCommand.cs b/taskt/Core/Automation/Commands/ExcelSplitRangeByColumnCommand.cs new file mode 100644 index 000000000..89cdf9aca --- /dev/null +++ b/taskt/Core/Automation/Commands/ExcelSplitRangeByColumnCommand.cs @@ -0,0 +1,248 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using System.Data; +using System.Text; +using System.Linq; +using System.IO; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Excel Commands")] + [Attributes.ClassAttributes.Description("This command gets text from a specified Excel Range and splits it into separate ranges by column.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to split a range into separate ranges.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements 'Excel Interop' to achieve automation.")] + public class ExcelSplitRangeByColumnCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the First Cell Location (ex. A1 or B2)")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter the actual location of the cell.")] + [Attributes.PropertyAttributes.SampleUsage("A1, B10, [vAddress]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ExcelCellAddress1 { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Second Cell Location (ex. A1 or B2, Leave Blank for All)")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter the actual location of the cell.")] + [Attributes.PropertyAttributes.SampleUsage("A1, B10, [vAddress]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ExcelCellAddress2 { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Column Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter the name of the column you wish to split by.")] + [Attributes.PropertyAttributes.SampleUsage("ColA, [vColumn]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ColumnName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the output directory")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter or Select the new directory for the split Excel Files.")] + [Attributes.PropertyAttributes.SampleUsage("C:\\temp\\new path\\ or [vTextFolderPath]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_OutputDirectory { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Indicate the File Type to save as")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("xlsx")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("csv")] + [Attributes.PropertyAttributes.InputSpecification("Specify the file format type for the split ranges")] + [Attributes.PropertyAttributes.SampleUsage("Select either **xlsx* or **csv**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_FileType { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign DataTable List to Variable")] + [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_userVariableName { get; set; } + + public ExcelSplitRangeByColumnCommand() + { + this.CommandName = "ExcelSplitRangeByColumnCommand"; + this.SelectionName = "Split Range By Column"; + this.CommandEnabled = true; + this.CustomRendering = true; + v_FileType = "xlsx"; + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var vExcelObject = engine.GetAppInstance(vInstance); + var vTargetAddress1 = v_ExcelCellAddress1.ConvertToUserVariable(sender); + var vTargetAddress2 = v_ExcelCellAddress2.ConvertToUserVariable(sender); + var vColumnName = v_ColumnName.ConvertToUserVariable(sender); + var vOutputDirectory = v_OutputDirectory.ConvertToUserVariable(sender); + + Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)vExcelObject; + excelInstance.Visible = false; + excelInstance.DisplayAlerts = false; + Microsoft.Office.Interop.Excel.Worksheet excelSheet = excelInstance.ActiveSheet; + + Microsoft.Office.Interop.Excel.Range cellValue; + if (vTargetAddress2 != "") + cellValue = excelSheet.Range[vTargetAddress1, vTargetAddress2]; + else + { + Microsoft.Office.Interop.Excel.Range last = excelSheet.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing); + cellValue = excelSheet.Range[vTargetAddress1, last]; + } + + //Convert Range to DataTable + List lst = new List(); + int rw = cellValue.Rows.Count; + int cl = cellValue.Columns.Count; + int rCnt; + int cCnt; + string cName; + DataTable DT = new DataTable(); + + //start from row 2 + for (rCnt = 2; rCnt <= rw; rCnt++) + { + DataRow newRow = DT.NewRow(); + for (cCnt = 1; cCnt <= cl; cCnt++) + { + if (((cellValue.Cells[rCnt, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2) != null) + { + if (!DT.Columns.Contains(cCnt.ToString())) + { + DT.Columns.Add(cCnt.ToString()); + } + newRow[cCnt.ToString()] = ((cellValue.Cells[rCnt, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2).ToString(); + } + else if (((cellValue.Cells[rCnt, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2) == null && ((cellValue.Cells[1, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2) != null) + { + if (!DT.Columns.Contains(cCnt.ToString())) + { + DT.Columns.Add(cCnt.ToString()); + } + newRow[cCnt.ToString()] = string.Empty; + } + + } + DT.Rows.Add(newRow); + } + + //Set column names + for (cCnt = 1; cCnt <= cl; cCnt++) + { + cName = ((cellValue.Cells[1, cCnt] as Microsoft.Office.Interop.Excel.Range).Value2).ToString(); + DT.Columns[cCnt-1].ColumnName = cName; + } + + //split table by column + List result = DT.AsEnumerable() + .GroupBy(row => row.Field(vColumnName)) + .Select(g => g.CopyToDataTable()) + .ToList(); + + //add list of datatables to output variable + Script.ScriptVariable splitDataset = new Script.ScriptVariable + { + VariableName = v_userVariableName, + VariableValue = result + }; + engine.VariableList.Add(splitDataset); + + //save split datatables in individual workbooks labeled by selected column data + if (Directory.Exists(vOutputDirectory)) + { + string newName; + foreach (DataTable newDT in result) + { + try + { + newName = newDT.Rows[0].Field(vColumnName).ToString(); + } + catch (Exception ex) + { + continue; + } + + Console.WriteLine(newName); + Microsoft.Office.Interop.Excel.Workbook newWorkBook = excelInstance.Workbooks.Add(Type.Missing); + Microsoft.Office.Interop.Excel.Worksheet newSheet = newWorkBook.ActiveSheet; + for (int i = 1; i < newDT.Columns.Count + 1; i++) + { + newSheet.Cells[1, i] = newDT.Columns[i - 1].ColumnName; + } + + for (int j = 0; j < newDT.Rows.Count; j++) + { + for (int k = 0; k < newDT.Columns.Count; k++) + { + newSheet.Cells[j + 2, k + 1] = newDT.Rows[j].ItemArray[k].ToString(); + } + } + + if (newName.Contains(".")) + { + newName = newName.Replace(".", string.Empty); + } + + if (v_FileType == "csv" && !newName.Equals(string.Empty)) + { + newWorkBook.SaveAs(Path.Combine(vOutputDirectory, newName), Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV, Type.Missing, Type.Missing, + Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, + Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); + } + else if (!newName.Equals(string.Empty)) + { + newWorkBook.SaveAs(Path.Combine(vOutputDirectory, newName + ".xlsx")); + } + + } + } + } + + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ExcelCellAddress1", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ExcelCellAddress2", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ColumnName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_OutputDirectory", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_FileType", this, editor)); + //create control for variable name + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_userVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_userVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_userVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + //RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_Output", this, editor)); + + + return RenderedControls; + + } + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Get Value Between '" + v_ExcelCellAddress1 + " and " + v_ExcelCellAddress2 + "' and apply to variable '" + v_userVariableName + "'from, Instance Name: '" + v_InstanceName + "', Split By Column: '" + v_ColumnName + "']"; + } + } +} diff --git a/taskt/Core/Automation/Commands/ExcelWriteRangeCommand.cs b/taskt/Core/Automation/Commands/ExcelWriteRangeCommand.cs index 68a381ed6..e9fe9051b 100644 --- a/taskt/Core/Automation/Commands/ExcelWriteRangeCommand.cs +++ b/taskt/Core/Automation/Commands/ExcelWriteRangeCommand.cs @@ -20,7 +20,7 @@ public class ExcelWriteRangeCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } @@ -30,7 +30,7 @@ public class ExcelWriteRangeCommand : ScriptCommand [Attributes.PropertyAttributes.InputSpecification("Enter the text value that will be set.")] [Attributes.PropertyAttributes.SampleUsage("Hello World or [vText]")] [Attributes.PropertyAttributes.Remarks("")] - public string v_TextToSet { get; set; } + public string v_DataTableToSet { get; set; } [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Cell Location to start from (ex. A1 or B2)")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] @@ -38,18 +38,28 @@ public class ExcelWriteRangeCommand : ScriptCommand [Attributes.PropertyAttributes.SampleUsage("A1, B10, [vAddress]")] [Attributes.PropertyAttributes.Remarks("")] public string v_ExcelCellAddress { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Add Headers")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("No")] + [Attributes.PropertyAttributes.InputSpecification("When selected, the column headers from the specified spreadsheet range are also written.")] + [Attributes.PropertyAttributes.SampleUsage("Select from **Yes** or **No**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_AddHeaders { get; set; } public ExcelWriteRangeCommand() { this.CommandName = "ExcelWriteRangeCommand"; this.SelectionName = "Write Range"; this.CommandEnabled = true; this.CustomRendering = true; + this.v_AddHeaders = "Yes"; } public override void RunCommand(object sender) { var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; var vInstance = v_InstanceName.ConvertToUserVariable(engine); - var dataSetVariable = engine.VariableList.Where(f => f.VariableName == v_TextToSet).FirstOrDefault(); + var dataSetVariable = LookupVariable(engine); var targetAddress = v_ExcelCellAddress.ConvertToUserVariable(sender); var excelObject = engine.GetAppInstance(vInstance); @@ -71,34 +81,80 @@ public override void RunCommand(object sender) sum += (targetAddress[i] - 'A' + 1); } - for (int i = 0; i < Dt.Rows.Count; i++) + if (v_AddHeaders == "Yes") { + //Write column names + string columnName; for (int j = 0; j < Dt.Columns.Count; j++) { - if (Dt.Rows[i][j].ToString() == "null") + if (Dt.Columns[j].ColumnName == "null") + columnName = string.Empty; + + else + columnName = Dt.Columns[j].ColumnName; + + excelSheet.Cells[Int32.Parse(numberOfRow), j + sum] = columnName; + } + + for (int i = 0; i < Dt.Rows.Count; i++) + { + for (int j = 0; j < Dt.Columns.Count; j++) + { + if (Dt.Rows[i][j].ToString() == "null") + { + Dt.Rows[i][j] = string.Empty; + } + excelSheet.Cells[i + Int32.Parse(numberOfRow) + 1, j + sum] = Dt.Rows[i][j].ToString(); + } + } + } + else { + for (int i = 0; i < Dt.Rows.Count; i++) + { + for (int j = 0; j < Dt.Columns.Count; j++) { - Dt.Rows[i][j] = string.Empty; + if (Dt.Rows[i][j].ToString() == "null") + { + Dt.Rows[i][j] = string.Empty; + } + excelSheet.Cells[i + Int32.Parse(numberOfRow), j + sum] = Dt.Rows[i][j].ToString(); } - excelSheet.Cells[i + Int32.Parse(numberOfRow), j + sum] = Dt.Rows[i][j].ToString(); } } } + + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataTableToSet).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataTableToSet.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataTableToSet.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataTableToSet.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } public override List Render(frmCommandEditor editor) { base.Render(editor); //create standard group controls RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); - RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_TextToSet", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableToSet", this, editor)); RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ExcelCellAddress", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_AddHeaders", this, editor)); return RenderedControls; } public override string GetDisplayValue() { - return base.GetDisplayValue() + " [Writing Cells starting form '" + v_ExcelCellAddress + "' to " + "', Instance Name: '" + v_InstanceName + "']"; + return base.GetDisplayValue() + " [Writing Cells starting from '" + v_ExcelCellAddress + "', Instance Name: '" + v_InstanceName + "']"; } } } \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/ExcelWriteRowCommand.cs b/taskt/Core/Automation/Commands/ExcelWriteRowCommand.cs new file mode 100644 index 000000000..331137780 --- /dev/null +++ b/taskt/Core/Automation/Commands/ExcelWriteRowCommand.cs @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using System.Data; +using System.Linq; +using System.Text.RegularExpressions; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Excel Commands")] + [Attributes.ClassAttributes.Description("This command writes a DataRow to an excel sheet starting from the given cell address.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to set a value to a specific cell.")] + [Attributes.ClassAttributes.ImplementationDescription("This command implements Excel Interop to achieve automation.")] + public class ExcelWriteRowCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] + [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Excel** command")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **excelInstance**")] + [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Excel** command will cause an error")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + public string v_InstanceName { get; set; } + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Row to Set")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter the text value that will be set (This could be a DataRow).")] + [Attributes.PropertyAttributes.SampleUsage("Hello,World or [vText]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataRowToSet { get; set; } + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Cell Location to start from (ex. A1 or B2)")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter the actual location of the cell.")] + [Attributes.PropertyAttributes.SampleUsage("A1, B10, [vAddress]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ExcelCellAddress { get; set; } + + public ExcelWriteRowCommand() + { + this.CommandName = "ExcelWriteRowCommand"; + this.SelectionName = "Write Row"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vInstance = v_InstanceName.ConvertToUserVariable(engine); + var dataRowVariable = LookupVariable(engine); + var variableList = engine.VariableList; + DataRow row; + + var targetAddress = v_ExcelCellAddress.ConvertToUserVariable(sender); + var excelObject = engine.GetAppInstance(vInstance); + + Microsoft.Office.Interop.Excel.Application excelInstance = (Microsoft.Office.Interop.Excel.Application)excelObject; + var excelSheet = (Microsoft.Office.Interop.Excel.Worksheet)excelInstance.ActiveSheet; + + //check in case of looping through datatable using BeginListLoopCommand + if (dataRowVariable.VariableValue is DataTable && engine.VariableList.Exists(x => x.VariableName == "Loop.CurrentIndex")) + { + var loopIndexVariable = engine.VariableList.Where(x => x.VariableName == "Loop.CurrentIndex").FirstOrDefault(); + int loopIndex = int.Parse(loopIndexVariable.VariableValue.ToString()); + row = ((DataTable)dataRowVariable.VariableValue).Rows[loopIndex - 1]; + } + + else row = (DataRow)dataRowVariable.VariableValue; + + + if (string.IsNullOrEmpty(targetAddress)) throw new ArgumentNullException("columnName"); + + var numberOfRow = Regex.Match(targetAddress, @"\d+").Value; + targetAddress = Regex.Replace(targetAddress, @"[\d-]", string.Empty); + targetAddress = targetAddress.ToUpperInvariant(); + + int sum = 0; + + for (int i = 0; i < targetAddress.Length; i++) + { + sum *= 26; + sum += (targetAddress[i] - 'A' + 1); + } + + + //Write row + string cellValue; + for (int j = 0; j < row.ItemArray.Length; j++) + { + if (row.ItemArray[j] == null) + cellValue = string.Empty; + + else + cellValue = row.ItemArray[j].ToString(); + + excelSheet.Cells[Int32.Parse(numberOfRow), j + sum] = cellValue; + } + } + + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataRowToSet).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataRowToSet.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataRowToSet.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataRowToSet.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + //create standard group controls + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_InstanceName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataRowToSet", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ExcelCellAddress", this, editor)); + + return RenderedControls; + + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [Writing Cells starting from '" + v_ExcelCellAddress + "', Instance Name: '" + v_InstanceName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/FilterDataTableCommand.cs b/taskt/Core/Automation/Commands/FilterDataTableCommand.cs index 3213b5287..9aaad0f0d 100644 --- a/taskt/Core/Automation/Commands/FilterDataTableCommand.cs +++ b/taskt/Core/Automation/Commands/FilterDataTableCommand.cs @@ -105,6 +105,13 @@ public override void RunCommand(object sender) VariableValue = outputDT }; + //Overwrites variable if it already exists + if (engine.VariableList.Exists(y => y.VariableName == newDatatable.VariableName)) + { + Script.ScriptVariable temp = engine.VariableList.Where(y => y.VariableName == newDatatable.VariableName).FirstOrDefault(); + engine.VariableList.Remove(temp); + } + engine.VariableList.Add(newDatatable); dataSetVariable.VariableValue = Dt; diff --git a/taskt/Core/Automation/Commands/GetDataRowCommand.cs b/taskt/Core/Automation/Commands/GetDataRowCommand.cs new file mode 100644 index 000000000..6a9af04cd --- /dev/null +++ b/taskt/Core/Automation/Commands/GetDataRowCommand.cs @@ -0,0 +1,113 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using System.Windows.Forms; +using System.Collections.Generic; +using taskt.UI.Forms; +using taskt.UI.CustomControls; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("DataTable Commands")] + [Attributes.ClassAttributes.Description("This command allows you to get a DataRow from a DataTable")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to add a datarow to a DataTable.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetDataRowCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the DataTable Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a existing DataTable to fet rows from.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataTableName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please enter the index of the DataRow")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a valid DataRow index value")] + [Attributes.PropertyAttributes.SampleUsage("0 or [vIndex]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataRowIndex { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetDataRowCommand() + { + this.CommandName = "GetDataRowCommand"; + this.SelectionName = "Get DataRow"; + this.CommandEnabled = true; + this.CustomRendering = true; + + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var dataSetVariable = LookupVariable(engine); + DataTable dataTable = (DataTable)dataSetVariable.VariableValue; + + var rowIndex = v_DataRowIndex.ConvertToUserVariable(sender); + int index = int.Parse(rowIndex); + + DataRow row = dataTable.Rows[index]; + + Script.ScriptVariable newDataRow = new Script.ScriptVariable + { + VariableName = v_UserVariableName, + VariableValue = row + }; + + //Overwrites variable if it already exists + if (engine.VariableList.Exists(x => x.VariableName == newDataRow.VariableName)) + { + Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newDataRow.VariableName).FirstOrDefault(); + engine.VariableList.Remove(temp); + } + engine.VariableList.Add(newDataRow); + + } + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataTableName).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataTableName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataTableName.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataTableName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataRowIndex", this, editor)); + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + + + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + $" [Get DataRow '{v_DataRowIndex}' from '{v_DataTableName}', Store In: '{v_UserVariableName}']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetDataRowCountCommand.cs b/taskt/Core/Automation/Commands/GetDataRowCountCommand.cs new file mode 100644 index 000000000..44f82b84f --- /dev/null +++ b/taskt/Core/Automation/Commands/GetDataRowCountCommand.cs @@ -0,0 +1,89 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using System.Windows.Forms; +using System.Collections.Generic; +using taskt.UI.Forms; +using taskt.UI.CustomControls; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("DataTable Commands")] + [Attributes.ClassAttributes.Description("This command allows you to get the datarow count of a DataTable")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to get the datarow count of a DataTable.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetDataRowCountCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the DataTable Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a existing DataTable.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataTableName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetDataRowCountCommand() + { + this.CommandName = "GetDataRowCountCommand"; + this.SelectionName = "Get DataRow Count"; + this.CommandEnabled = true; + this.CustomRendering = true; + + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var dataSetVariable = LookupVariable(engine); + DataTable dataTable = (DataTable)dataSetVariable.VariableValue; + + var count = dataTable.Rows.Count.ToString(); + + count.StoreInUserVariable(sender, v_UserVariableName); + + } + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataTableName).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataTableName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataTableName.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataTableName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataTableName", this, editor)); + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + + + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + $" [From '{v_DataTableName}', Store In: '{v_UserVariableName}']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetDataRowValueCommand.cs b/taskt/Core/Automation/Commands/GetDataRowValueCommand.cs new file mode 100644 index 000000000..bf9dcd7aa --- /dev/null +++ b/taskt/Core/Automation/Commands/GetDataRowValueCommand.cs @@ -0,0 +1,131 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using System.Windows.Forms; +using System.Collections.Generic; +using taskt.UI.Forms; +using taskt.UI.CustomControls; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("DataTable Commands")] + [Attributes.ClassAttributes.Description("This command allows you to get a DataRow Value from a DataTable")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to add a datarow to a DataTable.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetDataRowValueCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the DataRow Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a existing DataRow to get Values from.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataRowName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Select value by Index or Column Name")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Index")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Column Name")] + [Attributes.PropertyAttributes.InputSpecification("Select whether the DataRow value should be found by index or column name")] + [Attributes.PropertyAttributes.SampleUsage("Select from **Index** or **Column Name**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_Option { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please enter the index of the DataRow Value")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a valid DataRow index value")] + [Attributes.PropertyAttributes.SampleUsage("0 or [vIndex]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataValueIndex { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetDataRowValueCommand() + { + this.CommandName = "GetDataRowValueCommand"; + this.SelectionName = "Get DataRow Value"; + this.CommandEnabled = true; + this.CustomRendering = true; + v_Option = "Index"; + + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var dataRowVariable = LookupVariable(engine); + var variableList = engine.VariableList; + DataRow dataRow; + //check if currently looping through datatable using BeginListLoopCommand + if (dataRowVariable.VariableValue is DataTable && engine.VariableList.Exists(x => x.VariableName == "Loop.CurrentIndex")) + { + var loopIndexVariable = engine.VariableList.Where(x => x.VariableName == "Loop.CurrentIndex").FirstOrDefault(); + int loopIndex = int.Parse(loopIndexVariable.VariableValue.ToString()); + dataRow = ((DataTable)dataRowVariable.VariableValue).Rows[loopIndex-1]; + } + + else dataRow = (DataRow)dataRowVariable.VariableValue; + + var valueIndex = v_DataValueIndex.ConvertToUserVariable(sender); + string value = ""; + if (v_Option == "Index") + { + int index = int.Parse(valueIndex); + value = dataRow[index].ToString(); + + } + else if (v_Option == "Column Name") + { + string index = valueIndex; + value = dataRow.Field(index); + } + + value.StoreInUserVariable(sender, v_UserVariableName); + + } + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataRowName).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataRowName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataRowName.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataRowName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataRowName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_Option", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataValueIndex", this, editor)); + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + + + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + $" [Get Value '{v_DataValueIndex}' from '{v_DataRowName}', Store In: '{v_UserVariableName}']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetDictionaryValueCommand.cs b/taskt/Core/Automation/Commands/GetDictionaryValueCommand.cs index fc111e6e2..b61210247 100644 --- a/taskt/Core/Automation/Commands/GetDictionaryValueCommand.cs +++ b/taskt/Core/Automation/Commands/GetDictionaryValueCommand.cs @@ -53,6 +53,7 @@ public override void RunCommand(object sender) { //Retrieve Dictionary by name var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var vKey = v_Key.ConvertToUserVariable(sender); var dataSetVariable = LookupVariable(engine); //Declare local dictionary and assign output @@ -60,8 +61,15 @@ public override void RunCommand(object sender) Script.ScriptVariable Output = new Script.ScriptVariable { VariableName = v_OutputVariable, - VariableValue = dict[v_Key] + VariableValue = dict[vKey] }; + + //Overwrites variable if it already exists + if (engine.VariableList.Exists(x => x.VariableName == Output.VariableName)) + { + Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == Output.VariableName).FirstOrDefault(); + engine.VariableList.Remove(temp); + } //Add to variable list engine.VariableList.Add(Output); } @@ -95,7 +103,7 @@ public override List Render(frmCommandEditor editor) public override string GetDisplayValue() { - return base.GetDisplayValue(); + return base.GetDisplayValue() + $" [From: {v_InputData}, Get: {v_Key}, Store In: {v_OutputVariable}]"; } } } \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetFilesCommand.cs b/taskt/Core/Automation/Commands/GetFilesCommand.cs new file mode 100644 index 000000000..d0ef0528c --- /dev/null +++ b/taskt/Core/Automation/Commands/GetFilesCommand.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using System.Linq; + +namespace taskt.Core.Automation.Commands +{ + + [Serializable] + [Attributes.ClassAttributes.Group("File Operation Commands")] + [Attributes.ClassAttributes.Description("This command returns a list of file paths from a specified location")] + [Attributes.ClassAttributes.UsesDescription("Use this command to return a list of file paths from a specific location.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetFilesCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the source folder")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the folder.")] + [Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_SourceFolderPath { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetFilesCommand() + { + this.CommandName = "GetFilesCommand"; + this.SelectionName = "Get Files"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + //apply variable logic + var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender); + + //delete folder + //System.IO.Directory.Delete(sourceFolder, true); + var filesList = System.IO.Directory.GetFiles(sourceFolder).ToList(); + + Script.ScriptVariable newFilesList = new Script.ScriptVariable + { + VariableName = v_UserVariableName, + VariableValue = filesList + }; + //Overwrites variable if it already exists + if (engine.VariableList.Exists(x => x.VariableName == newFilesList.VariableName)) + { + Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newFilesList.VariableName).FirstOrDefault(); + engine.VariableList.Remove(temp); + } + engine.VariableList.Add(newFilesList); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor)); + + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [From: '" + v_SourceFolderPath + "', Store In: '" + v_UserVariableName + "']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetFoldersCommand.cs b/taskt/Core/Automation/Commands/GetFoldersCommand.cs new file mode 100644 index 000000000..cc3570c1d --- /dev/null +++ b/taskt/Core/Automation/Commands/GetFoldersCommand.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using System.Xml.Serialization; +using taskt.UI.CustomControls; +using taskt.UI.Forms; +using System.Linq; + +namespace taskt.Core.Automation.Commands +{ + + [Serializable] + [Attributes.ClassAttributes.Group("Folder Operation Commands")] + [Attributes.ClassAttributes.Description("This command returns a list of folder directories from a specified location")] + [Attributes.ClassAttributes.UsesDescription("Use this command to return a list of folder directories from a specific location.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetFoldersCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the source folder")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the folder.")] + [Attributes.PropertyAttributes.SampleUsage("C:\\temp\\myfolder or [vTextFolderPath]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_SourceFolderPath { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetFoldersCommand() + { + this.CommandName = "GetFoldersCommand"; + this.SelectionName = "Get Folders"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + //apply variable logic + var sourceFolder = v_SourceFolderPath.ConvertToUserVariable(sender); + + //delete folder + //System.IO.Directory.Delete(sourceFolder, true); + var directoriesList = System.IO.Directory.GetDirectories(sourceFolder).ToList(); + + Script.ScriptVariable newDirectoriesList = new Script.ScriptVariable + { + VariableName = v_UserVariableName, + VariableValue = directoriesList + }; + //Overwrites variable if it already exists + if (engine.VariableList.Exists(x => x.VariableName == newDirectoriesList.VariableName)) + { + Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newDirectoriesList.VariableName).FirstOrDefault(); + engine.VariableList.Remove(temp); + } + engine.VariableList.Add(newDirectoriesList); + + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_SourceFolderPath", this, editor)); + + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + public override string GetDisplayValue() + { + return base.GetDisplayValue() + " [From: '" + v_SourceFolderPath + "', Store In: '"+ v_UserVariableName +"']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetListCountCommand.cs b/taskt/Core/Automation/Commands/GetListCountCommand.cs new file mode 100644 index 000000000..6a11a3de3 --- /dev/null +++ b/taskt/Core/Automation/Commands/GetListCountCommand.cs @@ -0,0 +1,124 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using System.Windows.Forms; +using System.Collections.Generic; +using taskt.UI.Forms; +using taskt.UI.CustomControls; +using Microsoft.Office.Interop.Outlook; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Data Commands")] + [Attributes.ClassAttributes.Description("This command allows you to get the item count of a List")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to get the item count of a List.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetListCountCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the List Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a existing List.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ListName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetListCountCommand() + { + this.CommandName = "GetListCountCommand"; + this.SelectionName = "Get List Count"; + this.CommandEnabled = true; + this.CustomRendering = true; + + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + //get variable by regular name + Script.ScriptVariable listVariable = engine.VariableList.Where(x => x.VariableName == v_ListName).FirstOrDefault(); + + + + + //user may potentially include brackets [] + if (listVariable == null) + { + listVariable = engine.VariableList.Where(x => x.VariableName.ApplyVariableFormatting() == v_ListName).FirstOrDefault(); + } + + //if still null then throw exception + if (listVariable == null) + { + throw new System.Exception("Complex Variable '" + v_ListName + "' or '" + v_ListName.ApplyVariableFormatting() + "' not found. Ensure the variable exists before attempting to modify it."); + } + + dynamic listToCount; + if (listVariable.VariableValue is List) + { + listToCount = (List)listVariable.VariableValue; + } + else if (listVariable.VariableValue is List) + { + listToCount = (List)listVariable.VariableValue; + } + else if (listVariable.VariableValue is List) + { + listToCount = (List)listVariable.VariableValue; + } + else if ((listVariable.VariableValue.ToString().StartsWith("[")) && (listVariable.VariableValue.ToString().EndsWith("]")) && (listVariable.VariableValue.ToString().Contains(","))) + { + //automatically handle if user has given a json array + Newtonsoft.Json.Linq.JArray jsonArray = Newtonsoft.Json.JsonConvert.DeserializeObject(listVariable.VariableValue.ToString()) as Newtonsoft.Json.Linq.JArray; + + var itemList = new List(); + foreach (var item in jsonArray) + { + var value = (Newtonsoft.Json.Linq.JValue)item; + itemList.Add(value.ToString()); + } + + listVariable.VariableValue = itemList; + listToCount = itemList; + } + else + { + throw new System.Exception("Complex Variable List Type Not Supported"); + } + + string count = listToCount.Count.ToString(); + + count.StoreInUserVariable(sender, v_UserVariableName); + + } + + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ListName", this, editor)); + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + + + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + $" [From '{v_ListName}', Store In: '{v_UserVariableName}']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/GetListItemCommand.cs b/taskt/Core/Automation/Commands/GetListItemCommand.cs new file mode 100644 index 000000000..8e4bd1b23 --- /dev/null +++ b/taskt/Core/Automation/Commands/GetListItemCommand.cs @@ -0,0 +1,144 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using System.Windows.Forms; +using System.Collections.Generic; +using taskt.UI.Forms; +using taskt.UI.CustomControls; +using Microsoft.Office.Interop.Outlook; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Data Commands")] + [Attributes.ClassAttributes.Description("This command allows you to get an item from a List")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to get an item from a List.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class GetListItemCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the List Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a existing List.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ListName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please enter the index of the List item")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a valid List index value")] + [Attributes.PropertyAttributes.SampleUsage("0 or [vIndex]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_ItemIndex { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Assign to Variable")] + [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_UserVariableName { get; set; } + + public GetListItemCommand() + { + this.CommandName = "GetListItemCommand"; + this.SelectionName = "Get List Item"; + this.CommandEnabled = true; + this.CustomRendering = true; + + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var itemIndex = v_ItemIndex.ConvertToUserVariable(sender); + int index = int.Parse(itemIndex); + //get variable by regular name + Script.ScriptVariable listVariable = engine.VariableList.Where(x => x.VariableName == v_ListName).FirstOrDefault(); + + //user may potentially include brackets [] + if (listVariable == null) + { + listVariable = engine.VariableList.Where(x => x.VariableName.ApplyVariableFormatting() == v_ListName).FirstOrDefault(); + } + + //if still null then throw exception + if (listVariable == null) + { + throw new System.Exception("Complex Variable '" + v_ListName + "' or '" + v_ListName.ApplyVariableFormatting() + "' not found. Ensure the variable exists before attempting to modify it."); + } + + dynamic listToIndex; + if (listVariable.VariableValue is List) + { + listToIndex = (List)listVariable.VariableValue; + } + else if (listVariable.VariableValue is List) + { + listToIndex = (List)listVariable.VariableValue; + } + else if (listVariable.VariableValue is List) + { + listToIndex = (List)listVariable.VariableValue; + } + else if ((listVariable.VariableValue.ToString().StartsWith("[")) && (listVariable.VariableValue.ToString().EndsWith("]")) && (listVariable.VariableValue.ToString().Contains(","))) + { + //automatically handle if user has given a json array + Newtonsoft.Json.Linq.JArray jsonArray = Newtonsoft.Json.JsonConvert.DeserializeObject(listVariable.VariableValue.ToString()) as Newtonsoft.Json.Linq.JArray; + + var itemList = new List(); + foreach (var jsonItem in jsonArray) + { + var value = (Newtonsoft.Json.Linq.JValue)jsonItem; + itemList.Add(value.ToString()); + } + + listVariable.VariableValue = itemList; + listToIndex = itemList; + } + else + { + throw new System.Exception("Complex Variable List Type Not Supported"); + } + + var item = listToIndex[index]; + + Script.ScriptVariable newListItem = new Script.ScriptVariable + { + VariableName = v_UserVariableName, + VariableValue = item + }; + + //Overwrites variable if it already exists + if (engine.VariableList.Exists(x => x.VariableName == newListItem.VariableName)) + { + Script.ScriptVariable temp = engine.VariableList.Where(x => x.VariableName == newListItem.VariableName).FirstOrDefault(); + engine.VariableList.Remove(temp); + } + engine.VariableList.Add(newListItem); + + } + + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ListName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ItemIndex", this, editor)); + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_UserVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_UserVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_UserVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + + return RenderedControls; + } + + + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + $" [From '{v_ListName}', Store In: '{v_UserVariableName}']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/LoadDictionaryCommand.cs b/taskt/Core/Automation/Commands/LoadDictionaryCommand.cs index 214a411dc..757c0c7bb 100644 --- a/taskt/Core/Automation/Commands/LoadDictionaryCommand.cs +++ b/taskt/Core/Automation/Commands/LoadDictionaryCommand.cs @@ -18,6 +18,7 @@ public class LoadDictionaryCommand : ScriptCommand { [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the Dictionary Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter a name for a Dictionary.")] [Attributes.PropertyAttributes.SampleUsage("**myDictionary**")] [Attributes.PropertyAttributes.Remarks("")] @@ -25,6 +26,7 @@ public class LoadDictionaryCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please indicate the workbook file path")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter or Select the path to the applicable file that should be loaded into the Dictionary.")] [Attributes.PropertyAttributes.SampleUsage(@"C:\temp\myfile.xlsx or [vFilePath]")] @@ -33,7 +35,7 @@ public class LoadDictionaryCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please indicate the Sheet Name")] - [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter the sheet name of the workbook to be read.")] [Attributes.PropertyAttributes.SampleUsage("Sheet1")] [Attributes.PropertyAttributes.Remarks("")] @@ -41,7 +43,7 @@ public class LoadDictionaryCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please indicate the Key column")] - [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter the key column name to create a Dictionary off of.")] [Attributes.PropertyAttributes.SampleUsage("keyColumn")] [Attributes.PropertyAttributes.Remarks("")] @@ -49,7 +51,7 @@ public class LoadDictionaryCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please indicate the Value Column")] - [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter a value column name to create a Dictionary off of.")] [Attributes.PropertyAttributes.SampleUsage("valueColumn")] [Attributes.PropertyAttributes.Remarks("")] @@ -67,6 +69,12 @@ public override void RunCommand(object sender) var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; var vInstance = DateTime.Now.ToString(); var vFilePath = v_FilePath.ConvertToUserVariable(sender); + var vDictionaryName = v_DictionaryName; + var vDictionary = LookupVariable(engine); + if (vDictionary != null) + { + vDictionaryName = vDictionary.VariableName; + } var newExcelSession = new Microsoft.Office.Interop.Excel.Application { @@ -81,7 +89,7 @@ public override void RunCommand(object sender) //Query required from workbook using OLEDB DatasetCommands dataSetCommand = new DatasetCommands(); - DataTable requiredData = dataSetCommand.CreateDataTable(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + v_FilePath + @";Extended Properties=""Excel 12.0;HDR=YES;IMEX=1""", "Select " + v_KeyColumn + "," + v_ValueColumn + " From [" + v_SheetName + "$]"); + DataTable requiredData = dataSetCommand.CreateDataTable(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + vFilePath + @";Extended Properties=""Excel 12.0;HDR=YES;IMEX=1""", "Select " + v_KeyColumn + "," + v_ValueColumn + " From [" + v_SheetName + "$]"); var dictlist = requiredData.AsEnumerable().Select(x => new { @@ -97,7 +105,7 @@ public override void RunCommand(object sender) Script.ScriptVariable newDictionary = new Script.ScriptVariable { - VariableName = v_DictionaryName, + VariableName = vDictionaryName, VariableValue = outputDictionary }; //close excel @@ -106,8 +114,30 @@ public override void RunCommand(object sender) //remove instance engine.RemoveAppInstance(vInstance); + //Overwrites variable if it already exists + if (engine.VariableList.Exists(x => x.VariableName == newDictionary.VariableName)) + { + Script.ScriptVariable tempDictionary = engine.VariableList.Where(x => x.VariableName == newDictionary.VariableName).FirstOrDefault(); + engine.VariableList.Remove(tempDictionary); + } engine.VariableList.Add(newDictionary); } + + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DictionaryName).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DictionaryName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DictionaryName.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DictionaryName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } public override List Render(frmCommandEditor editor) { base.Render(editor); diff --git a/taskt/Core/Automation/Commands/OutlookGetEmailsCommand.cs b/taskt/Core/Automation/Commands/OutlookGetEmailsCommand.cs index 6e4647757..8987027bf 100644 --- a/taskt/Core/Automation/Commands/OutlookGetEmailsCommand.cs +++ b/taskt/Core/Automation/Commands/OutlookGetEmailsCommand.cs @@ -44,6 +44,15 @@ public class OutlookGetEmailsCommand : ScriptCommand [Attributes.PropertyAttributes.Remarks("")] public string v_GetUnreadOnly { get; set; } + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Mark emails as read")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("No")] + [Attributes.PropertyAttributes.InputSpecification("Specify whether to retrieve unread email messages only")] + [Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_MarkAsRead { get; set; } + [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please indicate the output directory for the messages")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] @@ -54,13 +63,20 @@ public class OutlookGetEmailsCommand : ScriptCommand public string v_MessageDirectory { get; set; } [XmlAttribute] - [Attributes.PropertyAttributes.PropertyDescription("Save attachments")] + [Attributes.PropertyAttributes.PropertyDescription("Assign MailItem List to variable")] + [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_userVariableName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Save messages and attachments")] [Attributes.PropertyAttributes.PropertyUISelectionOption("Yes")] [Attributes.PropertyAttributes.PropertyUISelectionOption("No")] [Attributes.PropertyAttributes.InputSpecification("Specify whether to save the email attachments to a local directory")] [Attributes.PropertyAttributes.SampleUsage("Select **Yes** or **No**")] [Attributes.PropertyAttributes.Remarks("")] - public string v_SaveAttachments { get; set; } + public string v_SaveMessagesAndAttachments { get; set; } [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please indicate the output directory for the attachments")] @@ -71,8 +87,6 @@ public class OutlookGetEmailsCommand : ScriptCommand [Attributes.PropertyAttributes.Remarks("")] public string v_AttachmentDirectory { get; set; } - - public OutlookGetEmailsCommand() { this.CommandName = "OutlookGetEmailsCommand"; @@ -108,6 +122,8 @@ public override void RunCommand(object sender) filteredItems = userFolder.Items; } + List outMail = new List(); + foreach (object _obj in filteredItems) { if (_obj is MailItem) @@ -118,24 +134,41 @@ public override void RunCommand(object sender) if (tempMail.UnRead == true) { ProcessEmail(tempMail, vMessageDirectory, vAttachmentDirectory); + outMail.Add(tempMail); } } else { ProcessEmail(tempMail, vMessageDirectory, vAttachmentDirectory); + outMail.Add(tempMail); } } } + //add list of datatables to output variable + Script.ScriptVariable mailItemList = new Script.ScriptVariable + { + VariableName = v_userVariableName, + VariableValue = outMail + }; + engine.VariableList.Add(mailItemList); } } private void ProcessEmail(MailItem mail, string msgDirectory, string attDirectory) { - mail.SaveAs(System.IO.Path.Combine(msgDirectory, mail.Subject + ".msg")); - if (v_SaveAttachments == "Yes") + if (v_MarkAsRead == "Yes") + { + mail.UnRead = false; + } + if (v_SaveMessagesAndAttachments == "Yes") { - foreach (Attachment attachment in mail.Attachments) + if (System.IO.Directory.Exists(msgDirectory)) + mail.SaveAs(System.IO.Path.Combine(msgDirectory, mail.Subject + ".msg")); + if (System.IO.Directory.Exists(attDirectory)) { - attachment.SaveAsFile(System.IO.Path.Combine(attDirectory, attachment.FileName)); - } + foreach (Attachment attachment in mail.Attachments) + { + attachment.SaveAsFile(System.IO.Path.Combine(attDirectory, attachment.FileName)); + } + } } } @@ -145,10 +178,16 @@ public override List Render(frmCommandEditor editor) RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Folder", this, editor)); RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Filter", this, editor)); RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_GetUnreadOnly", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_MarkAsRead", this, editor)); + //create control for variable name + RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_userVariableName", this)); + var VariableNameControl = CommandControls.CreateStandardComboboxFor("v_userVariableName", this).AddVariableNames(editor); + RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_userVariableName", this, new Control[] { VariableNameControl }, editor)); + RenderedControls.Add(VariableNameControl); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_SaveMessagesAndAttachments", this, editor)); RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_MessageDirectory", this, editor)); - RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_SaveAttachments", this, editor)); RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_AttachmentDirectory", this, editor)); - + return RenderedControls; } diff --git a/taskt/Core/Automation/Commands/RunTaskCommand.cs b/taskt/Core/Automation/Commands/RunTaskCommand.cs index 8854e1796..a0cf91a6a 100644 --- a/taskt/Core/Automation/Commands/RunTaskCommand.cs +++ b/taskt/Core/Automation/Commands/RunTaskCommand.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Drawing; +using System.Linq; using System.Windows.Forms; using System.Xml.Serialization; using taskt.UI.Forms; @@ -18,7 +19,8 @@ public class RunTaskCommand : ScriptCommand { [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Select a Task to run")] - [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] [Attributes.PropertyAttributes.InputSpecification("Enter or Select the valid path to the file.")] [Attributes.PropertyAttributes.SampleUsage("c:\\temp\\mytask.xml or [vScriptPath]")] [Attributes.PropertyAttributes.Remarks("")] @@ -55,8 +57,9 @@ public RunTaskCommand() this.CustomRendering = true; v_VariableAssignments = new DataTable(); - v_VariableAssignments.Columns.Add("VariableName"); + v_VariableAssignments.Columns.Add("VariableName"); v_VariableAssignments.Columns.Add("VariableValue"); + v_VariableAssignments.Columns.Add("VariableReturn"); v_VariableAssignments.TableName = "RunTaskCommandInputParameters" + DateTime.Now.ToString("MMddyyhhmmss"); AssignmentsGridViewHelper = new DataGridView(); @@ -70,27 +73,87 @@ public RunTaskCommand() public override void RunCommand(object sender) { + Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance)sender; var startFile = v_taskPath.ConvertToUserVariable(sender); //create variable list var variableList = new List(); + var variableReturnList = new List(); + foreach (DataRow rw in v_VariableAssignments.Rows) { - var variableName = (string)rw.ItemArray[0]; - var variableValue = ((string)rw.ItemArray[1]).ConvertToUserVariable(sender); + var variableName = (string)rw.ItemArray[0]; + object variableValue; + try + { + variableValue = LookupVariable(currentScriptEngine, (string)rw.ItemArray[1]).VariableValue; + } + catch(Exception ex) + { + variableValue = ((string)rw.ItemArray[1]).ConvertToUserVariable(sender); + } + var variableReturn = (string)rw.ItemArray[2]; variableList.Add(new Script.ScriptVariable { VariableName = variableName, VariableValue = variableValue }); + if (variableReturn == "Yes") + { + variableReturnList.Add(new Script.ScriptVariable + { + VariableName = variableName, + VariableValue = variableValue + }); + } + } UI.Forms.frmScriptEngine newEngine = new UI.Forms.frmScriptEngine(startFile, null, variableList, true); - Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance) sender; + + //Core.Automation.Engine.AutomationEngineInstance currentScriptEngine = (Core.Automation.Engine.AutomationEngineInstance) sender; currentScriptEngine.tasktEngineUI.Invoke((Action)delegate () { currentScriptEngine.tasktEngineUI.TopMost = false; }); Application.Run(newEngine); + + //get new variable list from the new task engine after it finishes running + var newVariableList = newEngine.engineInstance.VariableList; + foreach (var variable in variableReturnList) + { + //check if the variables we wish to return are in the new variable list + if (newVariableList.Exists(x => x.VariableName == variable.VariableName)) + { + //if yes, get that variable from the new list + Script.ScriptVariable newTemp = newVariableList.Where(x => x.VariableName == variable.VariableName).FirstOrDefault(); + //check if that variable previously existed in the current engine + if (currentScriptEngine.VariableList.Exists(x => x.VariableName == newTemp.VariableName)) + { + //if yes, overwrite it + Script.ScriptVariable currentTemp = currentScriptEngine.VariableList.Where(x => x.VariableName == newTemp.VariableName).FirstOrDefault(); + currentScriptEngine.VariableList.Remove(currentTemp); + } + //Add to current engine variable list + currentScriptEngine.VariableList.Add(newTemp); + } + } + //currentScriptEngine.tasktEngineUI.TopMost = false; currentScriptEngine.tasktEngineUI.Invoke((Action)delegate () { currentScriptEngine.tasktEngineUI.TopMost = true; }); + } + + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance, string lookupVariable ) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == lookupVariable).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (lookupVariable.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (lookupVariable.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = lookupVariable.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; } public override List Render(frmCommandEditor editor) @@ -118,9 +181,6 @@ public override List Render(frmCommandEditor editor) RenderedControls.Add(AssignmentsGridViewHelper); - - - return RenderedControls; } @@ -131,26 +191,39 @@ private void TaskPathControl_TextChanged(object sender, EventArgs e) private void PassParametersCheckbox_CheckedChanged(object sender, EventArgs e) { + Engine.AutomationEngineInstance currentScriptEngine = new Engine.AutomationEngineInstance(); + var startFile = v_taskPath.ConvertToUserVariable(currentScriptEngine); + var Sender = (CheckBox)sender; + AssignmentsGridViewHelper.Visible = Sender.Checked; //load variables if selected and file exists - if ((Sender.Checked) && (System.IO.File.Exists(v_taskPath))) + if ((Sender.Checked) && (System.IO.File.Exists(startFile))) { - Script.Script deserializedScript = Core.Script.Script.DeserializeFile(v_taskPath); - + Script.Script deserializedScript = Core.Script.Script.DeserializeFile(startFile); + foreach (var variable in deserializedScript.Variables) { DataRow[] foundVariables = v_VariableAssignments.Select("VariableName = '" + variable.VariableName + "'"); if (foundVariables.Length == 0) { v_VariableAssignments.Rows.Add(variable.VariableName, variable.VariableValue); + } } - AssignmentsGridViewHelper.DataSource = v_VariableAssignments; + + + for (int i = 0; i("Parameter Name") == "Timeout (Seconds)" switch (v_SeleniumElementAction) { case "Invoke Click": + int seleniumWindowHeightY = seleniumInstance.Manage().Window.Size.Height; + int elementPositionY = element.Location.Y; + if (elementPositionY > seleniumWindowHeightY) + { + String scroll = String.Format("window.scroll(0, {0})", elementPositionY); + IJavaScriptExecutor js = browserObject as IJavaScriptExecutor; + js.ExecuteScript(scroll); + } element.Click(); break; diff --git a/taskt/Core/Automation/Commands/ThrowExceptionCommand.cs b/taskt/Core/Automation/Commands/ThrowExceptionCommand.cs new file mode 100644 index 000000000..9c42007ae --- /dev/null +++ b/taskt/Core/Automation/Commands/ThrowExceptionCommand.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using taskt.UI.CustomControls; +using taskt.UI.Forms; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("Error Handling Commands")] + [Attributes.ClassAttributes.Description("This command allows you to throw an exception error.")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to throw an exception error")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class ThrowExceptionCommand : ScriptCommand + { + public string ErrorMessage { get; set; } + public string StackTrace { get; set; } + + public ThrowExceptionCommand() + { + this.CommandName = "ThrowExceptionCommand"; + this.SelectionName = "Throw Exception"; + this.CommandEnabled = true; + this.CustomRendering = true; + } + public override void RunCommand(object sender) + { + throw new System.Exception(); + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_Comment", this, editor)); + return RenderedControls; + } + public override string GetDisplayValue() + { + return base.GetDisplayValue(); + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WordAddDocumentCommand.cs b/taskt/Core/Automation/Commands/WordAddDocumentCommand.cs index eafbe6abf..186b20292 100644 --- a/taskt/Core/Automation/Commands/WordAddDocumentCommand.cs +++ b/taskt/Core/Automation/Commands/WordAddDocumentCommand.cs @@ -17,7 +17,7 @@ public class WordAddDocumentCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs b/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs index 67ba98dee..fbe41f341 100644 --- a/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs +++ b/taskt/Core/Automation/Commands/WordAppendDataTableCommand.cs @@ -21,7 +21,7 @@ public class WordAppendDataTableCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordAppendImageCommand.cs b/taskt/Core/Automation/Commands/WordAppendImageCommand.cs index 81a76273c..fdf8bcb39 100644 --- a/taskt/Core/Automation/Commands/WordAppendImageCommand.cs +++ b/taskt/Core/Automation/Commands/WordAppendImageCommand.cs @@ -21,7 +21,7 @@ public class WordAppendImageCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordAppendTextCommand.cs b/taskt/Core/Automation/Commands/WordAppendTextCommand.cs index 584dc78fb..12618cc71 100644 --- a/taskt/Core/Automation/Commands/WordAppendTextCommand.cs +++ b/taskt/Core/Automation/Commands/WordAppendTextCommand.cs @@ -21,7 +21,7 @@ public class WordAppendTextCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs b/taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs index 74989ab08..cbec7c18a 100644 --- a/taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs +++ b/taskt/Core/Automation/Commands/WordCloseApplicationCommand.cs @@ -17,7 +17,7 @@ public class WordCloseApplicationCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs index bf010c41a..f6afdd427 100644 --- a/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs +++ b/taskt/Core/Automation/Commands/WordExportToPDFCommand.cs @@ -18,7 +18,7 @@ public class WordExportToPDFCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs b/taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs index 6e0f29b43..bd05744e7 100644 --- a/taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs +++ b/taskt/Core/Automation/Commands/WordOpenDocumentCommand.cs @@ -17,7 +17,7 @@ public class WordOpenDocumentCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs b/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs index 5658192ab..e000aba19 100644 --- a/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs +++ b/taskt/Core/Automation/Commands/WordReadDocumentCommand.cs @@ -18,7 +18,7 @@ public class WordReadDocumentCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs b/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs index 3efaa5f41..082cc9cbb 100644 --- a/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs +++ b/taskt/Core/Automation/Commands/WordReplaceTextCommand.cs @@ -18,7 +18,7 @@ public class WordReplaceTextCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordSaveAsCommand.cs b/taskt/Core/Automation/Commands/WordSaveAsCommand.cs index d33716dfb..8d964b00f 100644 --- a/taskt/Core/Automation/Commands/WordSaveAsCommand.cs +++ b/taskt/Core/Automation/Commands/WordSaveAsCommand.cs @@ -18,7 +18,7 @@ public class WordSaveAsCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WordSaveCommand.cs b/taskt/Core/Automation/Commands/WordSaveCommand.cs index f0f5950cc..a66b0de92 100644 --- a/taskt/Core/Automation/Commands/WordSaveCommand.cs +++ b/taskt/Core/Automation/Commands/WordSaveCommand.cs @@ -17,7 +17,7 @@ public class WordSaveCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please Enter the instance name")] [Attributes.PropertyAttributes.InputSpecification("Enter the unique instance name that was specified in the **Create Word** command")] - [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **seleniumInstance**")] + [Attributes.PropertyAttributes.SampleUsage("**myInstance** or **wordInstance**")] [Attributes.PropertyAttributes.Remarks("Failure to enter the correct instance name or failure to first call **Create Word** command will cause an error")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] public string v_InstanceName { get; set; } diff --git a/taskt/Core/Automation/Commands/WriteDataRowValueCommand.cs b/taskt/Core/Automation/Commands/WriteDataRowValueCommand.cs new file mode 100644 index 000000000..f69ccb0f0 --- /dev/null +++ b/taskt/Core/Automation/Commands/WriteDataRowValueCommand.cs @@ -0,0 +1,131 @@ +using System; +using System.Linq; +using System.Xml.Serialization; +using System.Data; +using System.Windows.Forms; +using System.Collections.Generic; +using taskt.UI.Forms; +using taskt.UI.CustomControls; + +namespace taskt.Core.Automation.Commands +{ + [Serializable] + [Attributes.ClassAttributes.Group("DataTable Commands")] + [Attributes.ClassAttributes.Description("This command allows you to write a Value to a DataRow")] + [Attributes.ClassAttributes.UsesDescription("Use this command when you want to write a Value to a DataRow.")] + [Attributes.ClassAttributes.ImplementationDescription("")] + public class WriteDataRowValueCommand : ScriptCommand + { + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please indicate the DataRow Name")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a existing DataTable to add rows to.")] + [Attributes.PropertyAttributes.SampleUsage("**myData**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataRowName { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Select value by Index or Column Name")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Index")] + [Attributes.PropertyAttributes.PropertyUISelectionOption("Column Name")] + [Attributes.PropertyAttributes.InputSpecification("Select whether the DataRow value should be found by index or column name")] + [Attributes.PropertyAttributes.SampleUsage("Select from **Index** or **Column Name**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_Option { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please enter the index of the DataRow Value")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter a valid DataRow index value")] + [Attributes.PropertyAttributes.SampleUsage("0 or [vIndex]")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataValueIndex { get; set; } + + [XmlAttribute] + [Attributes.PropertyAttributes.PropertyDescription("Please enter the Value")] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.InputSpecification("Enter the value to write to the DataRow cell")] + [Attributes.PropertyAttributes.SampleUsage("**vSomeVariable**")] + [Attributes.PropertyAttributes.Remarks("")] + public string v_DataRowValue { get; set; } + + public WriteDataRowValueCommand() + { + this.CommandName = "WriteDataRowValueCommand"; + this.SelectionName = "Write DataRow Value"; + this.CommandEnabled = true; + this.CustomRendering = true; + v_Option = "Index"; + + } + + public override void RunCommand(object sender) + { + var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; + var dataRowValue = v_DataRowValue.ConvertToUserVariable(sender); + + var dataRowVariable = LookupVariable(engine); + var variableList = engine.VariableList; + DataRow dataRow; + + //check in case of looping through datatable using BeginListLoopCommand + if (dataRowVariable.VariableValue is DataTable && engine.VariableList.Exists(x => x.VariableName == "Loop.CurrentIndex")) + { + var loopIndexVariable = engine.VariableList.Where(x => x.VariableName == "Loop.CurrentIndex").FirstOrDefault(); + int loopIndex = int.Parse(loopIndexVariable.VariableValue.ToString()); + dataRow = ((DataTable)dataRowVariable.VariableValue).Rows[loopIndex - 1]; + } + + else dataRow = (DataRow)dataRowVariable.VariableValue; + + var valueIndex = v_DataValueIndex.ConvertToUserVariable(sender); + + if (v_Option == "Index") + { + int index = int.Parse(valueIndex); + dataRow[index] = dataRowValue; + + } + else if (v_Option == "Column Name") + { + string index = valueIndex; + dataRow.SetField(index, dataRowValue); + } + + } + private Script.ScriptVariable LookupVariable(Core.Automation.Engine.AutomationEngineInstance sendingInstance) + { + //search for the variable + var requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == v_DataRowName).FirstOrDefault(); + + //if variable was not found but it starts with variable naming pattern + if ((requiredVariable == null) && (v_DataRowName.StartsWith(sendingInstance.engineSettings.VariableStartMarker)) && (v_DataRowName.EndsWith(sendingInstance.engineSettings.VariableEndMarker))) + { + //reformat and attempt + var reformattedVariable = v_DataRowName.Replace(sendingInstance.engineSettings.VariableStartMarker, "").Replace(sendingInstance.engineSettings.VariableEndMarker, ""); + requiredVariable = sendingInstance.VariableList.Where(var => var.VariableName == reformattedVariable).FirstOrDefault(); + } + + return requiredVariable; + } + public override List Render(frmCommandEditor editor) + { + base.Render(editor); + + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataRowName", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultDropdownGroupFor("v_Option", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataValueIndex", this, editor)); + RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_DataRowValue", this, editor)); + + + return RenderedControls; + } + + + + public override string GetDisplayValue() + { + return base.GetDisplayValue() + $" [Write Value '{v_DataRowValue}' to '{v_DataValueIndex}' in '{v_DataRowName}']"; + } + } +} \ No newline at end of file diff --git a/taskt/Core/Automation/Commands/WriteTextFileCommand.cs b/taskt/Core/Automation/Commands/WriteTextFileCommand.cs index ab0532f43..b7c497e0f 100644 --- a/taskt/Core/Automation/Commands/WriteTextFileCommand.cs +++ b/taskt/Core/Automation/Commands/WriteTextFileCommand.cs @@ -30,6 +30,7 @@ public class WriteTextFileCommand : ScriptCommand [XmlAttribute] [Attributes.PropertyAttributes.PropertyDescription("Please indicate the text to be written. [crLF] inserts a newline.")] [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] + [Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFolderSelectionHelper)] [Attributes.PropertyAttributes.InputSpecification("Indicate the text should be written to files.")] [Attributes.PropertyAttributes.SampleUsage("**[vText]** or **Hello World!**")] [Attributes.PropertyAttributes.Remarks("")] diff --git a/taskt/Core/Automation/Engine/AutomationEngineInstance.cs b/taskt/Core/Automation/Engine/AutomationEngineInstance.cs index 9bb3a2b06..8537c47df 100644 --- a/taskt/Core/Automation/Engine/AutomationEngineInstance.cs +++ b/taskt/Core/Automation/Engine/AutomationEngineInstance.cs @@ -273,7 +273,7 @@ public void ExecuteCommand(Core.Script.ScriptAction command) try { //determine type of command - if ((parentCommand is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (parentCommand is Core.Automation.Commands.BeginContinousLoopCommand) || (parentCommand is Core.Automation.Commands.BeginListLoopCommand) || (parentCommand is Core.Automation.Commands.BeginIfCommand) || (parentCommand is Core.Automation.Commands.BeginMultiIfCommand) || (parentCommand is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (parentCommand is Commands.TryCommand)) + if ((parentCommand is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (parentCommand is Core.Automation.Commands.BeginContinousLoopCommand) || (parentCommand is Core.Automation.Commands.BeginListLoopCommand) || (parentCommand is Core.Automation.Commands.BeginIfCommand) || (parentCommand is Core.Automation.Commands.BeginMultiIfCommand) || (parentCommand is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (parentCommand is Commands.TryCommand) || (parentCommand is Core.Automation.Commands.BeginLoopCommand) || (parentCommand is Core.Automation.Commands.BeginMultiLoopCommand)) { //run the command and pass bgw/command as this command will recursively call this method for sub commands parentCommand.RunCommand(this, command); diff --git a/taskt/Core/Common.cs b/taskt/Core/Common.cs index b11ab8aeb..b3dc1c247 100644 --- a/taskt/Core/Common.cs +++ b/taskt/Core/Common.cs @@ -152,6 +152,8 @@ private static bool CommandEnabled(Type cmd) systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Folder.Documents", VariableValue = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }); systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Folder.AppData", VariableValue = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) }); systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Folder.ScriptPath", VariableValue = Core.IO.Folders.GetFolder(Folders.FolderType.ScriptsFolder) }); + systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Folder.RootPath", VariableValue = Core.IO.Folders.GetFolder(Folders.FolderType.RootFolder)}); + systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "Folder.AttendedTasksPath", VariableValue = Core.IO.Folders.GetFolder(Folders.FolderType.AttendedTasksFolder) }); systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "DateTime.Now", VariableValue = DateTime.Now.ToString() }); systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "DateTime.Now.Month", VariableValue = DateTime.Now.ToString("MM")}); systemVariableList.Add(new Core.Script.ScriptVariable { VariableName = "DateTime.Now.Day", VariableValue = DateTime.Now.ToString("dd") }); diff --git a/taskt/Core/IO/Folders.cs b/taskt/Core/IO/Folders.cs index 31b10c309..1340dac1d 100644 --- a/taskt/Core/IO/Folders.cs +++ b/taskt/Core/IO/Folders.cs @@ -10,13 +10,19 @@ public static class Folders { public static string GetFolder(FolderType folderType) { + switch (folderType) { case FolderType.RootFolder: - //return folder from settings - var settings = new Core.ApplicationSettings().GetOrCreateApplicationSettings(); - var rootFolder = settings.ClientSettings.RootFolder; + //return root folder from settings + var rootSettings = new Core.ApplicationSettings().GetOrCreateApplicationSettings(); + var rootFolder = rootSettings.ClientSettings.RootFolder; return rootFolder; + case FolderType.AttendedTasksFolder: + //return attended tasks folder from settings + var attendedSettings = new Core.ApplicationSettings().GetOrCreateApplicationSettings(); + var attentedTasksFolder = attendedSettings.ClientSettings.AttendedTasksFolder; + return attentedTasksFolder; case FolderType.SettingsFolder: //return app data taskt folder return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\taskt\\"; @@ -43,7 +49,8 @@ public enum FolderType SettingsFolder, ScriptsFolder, LogFolder, - TempFolder + TempFolder, + AttendedTasksFolder } } } diff --git a/taskt/Core/Script.cs b/taskt/Core/Script.cs index a9db7fa26..5b0d226cd 100644 --- a/taskt/Core/Script.cs +++ b/taskt/Core/Script.cs @@ -74,7 +74,7 @@ public static Script SerializeScript(ListView.ListViewItemCollection scriptComma var command = (Core.Automation.Commands.ScriptCommand)commandItem.Tag; command.LineNumber = lineNumber; - if ((command is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (command is Core.Automation.Commands.BeginContinousLoopCommand) || (command is Core.Automation.Commands.BeginListLoopCommand) || (command is Core.Automation.Commands.BeginIfCommand) || (command is Core.Automation.Commands.BeginMultiIfCommand) || (command is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (command is Core.Automation.Commands.TryCommand)) + if ((command is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (command is Core.Automation.Commands.BeginContinousLoopCommand) || (command is Core.Automation.Commands.BeginListLoopCommand) || (command is Core.Automation.Commands.BeginIfCommand) || (command is Core.Automation.Commands.BeginMultiIfCommand) || (command is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (command is Core.Automation.Commands.TryCommand) || (command is Core.Automation.Commands.BeginLoopCommand) || (command is Core.Automation.Commands.BeginMultiLoopCommand)) { if (subCommands.Count == 0) //if this is the first loop { diff --git a/taskt/Sample Scripts/DataTable Sample.xml b/taskt/Sample Scripts/DataTable Sample.xml new file mode 100644 index 000000000..a1158bdfa --- /dev/null +++ b/taskt/Sample Scripts/DataTable Sample.xml @@ -0,0 +1,213 @@ + + \ No newline at end of file diff --git a/taskt/Sample Scripts/Excel Split Range By Column Sample.xml b/taskt/Sample Scripts/Excel Split Range By Column Sample.xml new file mode 100644 index 000000000..8ec9e78d0 --- /dev/null +++ b/taskt/Sample Scripts/Excel Split Range By Column Sample.xml @@ -0,0 +1,18 @@ + + \ No newline at end of file diff --git a/taskt/Sample Scripts/Folder File and List Sample.xml b/taskt/Sample Scripts/Folder File and List Sample.xml new file mode 100644 index 000000000..cfa68ae06 --- /dev/null +++ b/taskt/Sample Scripts/Folder File and List Sample.xml @@ -0,0 +1,112 @@ + + \ No newline at end of file diff --git a/taskt/Sample Scripts/Multi Loop Sample.xml b/taskt/Sample Scripts/Multi Loop Sample.xml new file mode 100644 index 000000000..8ff133ffb --- /dev/null +++ b/taskt/Sample Scripts/Multi Loop Sample.xml @@ -0,0 +1,105 @@ + + \ No newline at end of file diff --git a/taskt/Sample Scripts/Outlook Sample.xml b/taskt/Sample Scripts/Outlook Sample.xml index 95492cce8..cc90c594a 100644 --- a/taskt/Sample Scripts/Outlook Sample.xml +++ b/taskt/Sample Scripts/Outlook Sample.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/taskt/UI/CustomControls/CommandControls.cs b/taskt/UI/CustomControls/CommandControls.cs index 0bd2e9d2e..4023cdd21 100644 --- a/taskt/UI/CustomControls/CommandControls.cs +++ b/taskt/UI/CustomControls/CommandControls.cs @@ -253,6 +253,11 @@ public static List CreateUIHelpersFor(string parameterName, Core.Automa helperControl.CommandImage = UI.Images.GetUIImage("VariableCommand"); helperControl.CommandDisplay = "Add New If Statement"; break; + case Core.Automation.Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowLoopBuilder: + //show variable selector + helperControl.CommandImage = UI.Images.GetUIImage("VariableCommand"); + helperControl.CommandDisplay = "Add New Loop Statement"; + break; //default: // MessageBox.Show("Command Helper does not exist for: " + attrib.additionalHelper.ToString()); diff --git a/taskt/UI/CustomControls/CustomControls.cs b/taskt/UI/CustomControls/CustomControls.cs index 6e3ac3fe6..b31de33bd 100644 --- a/taskt/UI/CustomControls/CustomControls.cs +++ b/taskt/UI/CustomControls/CustomControls.cs @@ -451,6 +451,8 @@ public static Dictionary UIImageDictionary() uiImages.Add("PDFTextExtractionCommand", taskt.Properties.Resources.command_function); uiImages.Add("GetWordLengthCommand", taskt.Properties.Resources.command_function); uiImages.Add("GetWordCountCommand", taskt.Properties.Resources.command_function); + uiImages.Add("GetListCountCommand", taskt.Properties.Resources.command_function); + uiImages.Add("GetListItemCommand", 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); @@ -497,7 +499,12 @@ public static Dictionary UIImageDictionary() uiImages.Add("WordAppendTextCommand", taskt.Properties.Resources.command_files); uiImages.Add("WordAppendImageCommand", taskt.Properties.Resources.command_files); uiImages.Add("WordAppendDataTableCommand", taskt.Properties.Resources.command_files); + uiImages.Add("ExcelSplitRangeByColumnCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("AddDataRowCommand", taskt.Properties.Resources.command_spreadsheet); + uiImages.Add("GetDataRowCommand", taskt.Properties.Resources.command_spreadsheet); + uiImages.Add("GetDataRowValueCommand", taskt.Properties.Resources.command_spreadsheet); + uiImages.Add("WriteDataRowValueCommand", taskt.Properties.Resources.command_spreadsheet); + uiImages.Add("GetDataRowCountCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("CreateDataTableCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("FilterDataTableCommand", taskt.Properties.Resources.command_spreadsheet); uiImages.Add("RemoveDataRowCommand", taskt.Properties.Resources.command_spreadsheet); @@ -524,6 +531,7 @@ public static Dictionary UIImageDictionary() uiImages.Add("CatchExceptionCommand", taskt.Properties.Resources.command_try); uiImages.Add("FinallyCommand", taskt.Properties.Resources.command_try); uiImages.Add("EndTryCommand", taskt.Properties.Resources.command_try); + uiImages.Add("ThrowExceptionCommand", taskt.Properties.Resources.command_try); uiImages.Add("StringSubstringCommand", taskt.Properties.Resources.command_string); uiImages.Add("StringSplitCommand", taskt.Properties.Resources.command_string); uiImages.Add("StringReplaceCommand", taskt.Properties.Resources.command_string); @@ -541,6 +549,8 @@ public static Dictionary UIImageDictionary() uiImages.Add("BeginContinousLoopCommand", taskt.Properties.Resources.command_startloop); uiImages.Add("BeginExcelDatasetLoopCommand", taskt.Properties.Resources.command_startloop); uiImages.Add("BeginNumberOfTimesLoopCommand", taskt.Properties.Resources.command_startloop); + uiImages.Add("BeginLoopCommand", taskt.Properties.Resources.command_startloop); + uiImages.Add("BeginMultiLoopCommand", taskt.Properties.Resources.command_startloop); uiImages.Add("ExitLoopCommand", taskt.Properties.Resources.command_exitloop); uiImages.Add("SequenceCommand", taskt.Properties.Resources.command_sequence); uiImages.Add("ReadTextFileCommand", taskt.Properties.Resources.command_files); @@ -549,6 +559,8 @@ public static Dictionary UIImageDictionary() uiImages.Add("DeleteFileCommand", taskt.Properties.Resources.command_files); uiImages.Add("RenameFileCommand", taskt.Properties.Resources.command_files); uiImages.Add("WaitForFileToExistCommand", taskt.Properties.Resources.command_files); + uiImages.Add("GetFilesCommand", taskt.Properties.Resources.command_files); + uiImages.Add("GetFoldersCommand", taskt.Properties.Resources.command_files); uiImages.Add("CreateFolderCommand", taskt.Properties.Resources.command_files); uiImages.Add("DeleteFolderCommand", taskt.Properties.Resources.command_files); uiImages.Add("MoveFolderCommand", taskt.Properties.Resources.command_files); diff --git a/taskt/UI/Forms/frmScriptBuilder.cs b/taskt/UI/Forms/frmScriptBuilder.cs index f9ba48d35..570563c8c 100644 --- a/taskt/UI/Forms/frmScriptBuilder.cs +++ b/taskt/UI/Forms/frmScriptBuilder.cs @@ -892,7 +892,7 @@ public void AddCommandToListView(Core.Automation.Commands.ScriptCommand selected lstScriptActions.Items.Insert(insertionIndex, command); //special types also get a following command and comment - if ((selectedCommand is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginListLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginContinousLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginNumberOfTimesLoopCommand)) + if ((selectedCommand is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginListLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginContinousLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginLoopCommand) || (selectedCommand is Core.Automation.Commands.BeginMultiLoopCommand)) { lstScriptActions.Items.Insert(insertionIndex + 1, CreateScriptCommandListViewItem(new Core.Automation.Commands.CommentCommand() { v_Comment = "Items in this section will run within the loop" })); lstScriptActions.Items.Insert(insertionIndex + 2, CreateScriptCommandListViewItem(new Core.Automation.Commands.EndLoopCommand())); @@ -933,7 +933,7 @@ private void IndentListViewItems() continue; } - if ((rowItem.Tag is Core.Automation.Commands.BeginIfCommand) || (rowItem.Tag is Core.Automation.Commands.BeginMultiIfCommand) || (rowItem.Tag is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (rowItem.Tag is Core.Automation.Commands.BeginListLoopCommand) || (rowItem.Tag is Core.Automation.Commands.BeginContinousLoopCommand) || (rowItem.Tag is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (rowItem.Tag is Core.Automation.Commands.TryCommand)) + if ((rowItem.Tag is Core.Automation.Commands.BeginIfCommand) || (rowItem.Tag is Core.Automation.Commands.BeginMultiIfCommand) || (rowItem.Tag is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (rowItem.Tag is Core.Automation.Commands.BeginListLoopCommand) || (rowItem.Tag is Core.Automation.Commands.BeginContinousLoopCommand) || (rowItem.Tag is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (rowItem.Tag is Core.Automation.Commands.TryCommand) || (rowItem.Tag is Core.Automation.Commands.BeginLoopCommand) || (rowItem.Tag is Core.Automation.Commands.BeginMultiLoopCommand)) { indent += 2; rowItem.IndentCount = indent; @@ -1491,7 +1491,7 @@ private void SaveToFile(bool saveAs) int tryCatchValidationCount = 0; foreach (ListViewItem item in lstScriptActions.Items) { - if ((item.Tag is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (item.Tag is Core.Automation.Commands.BeginListLoopCommand) || (item.Tag is Core.Automation.Commands.BeginContinousLoopCommand) ||(item.Tag is Core.Automation.Commands.BeginNumberOfTimesLoopCommand)) + if ((item.Tag is Core.Automation.Commands.BeginExcelDatasetLoopCommand) || (item.Tag is Core.Automation.Commands.BeginListLoopCommand) || (item.Tag is Core.Automation.Commands.BeginContinousLoopCommand) ||(item.Tag is Core.Automation.Commands.BeginNumberOfTimesLoopCommand) || (item.Tag is Core.Automation.Commands.BeginLoopCommand) || (item.Tag is Core.Automation.Commands.BeginMultiLoopCommand)) { beginLoopValidationCount++; } diff --git a/taskt/taskt.csproj b/taskt/taskt.csproj index b95ea5e4c..a4e12e1a2 100644 --- a/taskt/taskt.csproj +++ b/taskt/taskt.csproj @@ -169,11 +169,22 @@ + + + + + + + + + + + @@ -217,6 +228,7 @@ + @@ -334,6 +346,7 @@ +