Skip to content

Commit

Permalink
Bug fixes for dictionary commands. Started Powershell command
Browse files Browse the repository at this point in the history
  • Loading branch information
openbots-ff committed Mar 17, 2020
1 parent a126fed commit a606b49
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 2 deletions.
7 changes: 7 additions & 0 deletions taskt/Core/Automation/Commands/GetDictionaryValueCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ public override void RunCommand(object sender)
VariableName = v_OutputVariable,
VariableValue = dict[v_Key]
};

//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);
}
Expand Down
11 changes: 9 additions & 2 deletions taskt/Core/Automation/Commands/LoadDictionaryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ 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.ConvertToUserVariable(sender);

var newExcelSession = new Microsoft.Office.Interop.Excel.Application
{
Expand All @@ -81,7 +82,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
{
Expand All @@ -97,7 +98,7 @@ public override void RunCommand(object sender)

Script.ScriptVariable newDictionary = new Script.ScriptVariable
{
VariableName = v_DictionaryName,
VariableName = vDictionaryName,
VariableValue = outputDictionary
};
//close excel
Expand All @@ -106,6 +107,12 @@ 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);
}
public override List<Control> Render(frmCommandEditor editor)
Expand Down
83 changes: 83 additions & 0 deletions taskt/Core/Automation/Commands/RunPowerShellScriptCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Windows.Forms;
using System.Xml.Serialization;
using taskt.UI.CustomControls;
using taskt.UI.Forms;

namespace taskt.Core.Automation.Commands
{
[Serializable]
[Attributes.ClassAttributes.Group("Programs/Process Commands")]
[Attributes.ClassAttributes.Description("This command allows you to run a script or program and wait for it to exit before proceeding.")]
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to run a script (such as vbScript, javascript, or executable) but wait for it to close before taskt continues executing.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements 'Process.Start' and waits for the script/program to exit before proceeding.")]
public class RunPowerShellScriptCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Enter the path to the PowerShell script")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
[Attributes.PropertyAttributes.InputSpecification("Enter a fully qualified path to the script, including the script extension.")]
[Attributes.PropertyAttributes.SampleUsage("**C:\\temp\\myscript.ps1**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_ScriptPath { get; set; }

public RunPowerShellScriptCommand()
{
this.CommandName = "RunPowerShellScriptCommand";
this.SelectionName = "Run PowerShell Script";
this.CommandEnabled = true;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{
{
var scriptPath = v_ScriptPath.ConvertToUserVariable(sender);

RunScript(scriptPath);

}
}

public static ICollection<PSObject> RunScript(string scriptFullPath, ICollection<CommandParameter> parameters = null)
{
var runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
var pipeline = runspace.CreatePipeline();
var cmd = new Command(scriptFullPath);
if (parameters != null)
{
foreach (var p in parameters)
{
cmd.Parameters.Add(p);
}
}
pipeline.Commands.Add(cmd);
var results = pipeline.Invoke();
pipeline.Dispose();
runspace.Dispose();
return results;

}

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

RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ScriptPath", this, editor));



return RenderedControls;
}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [Script Path: " + v_ScriptPath + "]";
}
}
}
1 change: 1 addition & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace taskt.Core.Automation.Commands
[XmlInclude(typeof(AddVariableCommand))]
[XmlInclude(typeof(VariableCommand))]
[XmlInclude(typeof(RunScriptCommand))]
[XmlInclude(typeof(RunPowerShellScriptCommand))]
[XmlInclude(typeof(CloseWindowCommand))]
[XmlInclude(typeof(SetWindowStateCommand))]
[XmlInclude(typeof(BeginExcelDatasetLoopCommand))]
Expand Down
1 change: 1 addition & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ public static class Images
uiImages.Add("GetWordLengthCommand", taskt.Properties.Resources.command_function);
uiImages.Add("GetWordCountCommand", taskt.Properties.Resources.command_function);
uiImages.Add("RunScriptCommand", taskt.Properties.Resources.command_script);
uiImages.Add("RunPowerShellScriptCommand", taskt.Properties.Resources.command_script);
uiImages.Add("RunCustomCodeCommand", taskt.Properties.Resources.command_script);
uiImages.Add("RunTaskCommand", taskt.Properties.Resources.command_start_process);
uiImages.Add("StopTaskCommand", taskt.Properties.Resources.command_stop_process);
Expand Down
1 change: 1 addition & 0 deletions taskt/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
<package id="JetBrains.Annotations" version="11.0.0" targetFramework="net452" />
<package id="Microsoft.Office.Interop.Excel" version="14.0.0.1" targetFramework="net452" />
<package id="Microsoft.Office.Interop.Outlook" version="15.0.4797.1003" targetFramework="net48" />
<package id="Microsoft.PowerShell.5.ReferenceAssemblies" version="1.1.0" targetFramework="net48" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="OneNoteOCR" version="1.0.0.0" targetFramework="net452" />
<package id="RestSharp" version="106.6.9" targetFramework="net452" />
Expand Down
4 changes: 4 additions & 0 deletions taskt/taskt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security" />
<Reference Include="System.Web" />
Expand Down Expand Up @@ -202,6 +205,7 @@
<Compile Include="Core\Automation\Commands\RemoteTaskCommand.cs" />
<Compile Include="Core\Automation\Commands\FilterDataTableCommand.cs" />
<Compile Include="Core\Automation\Commands\RemoveDataRowCommand.cs" />
<Compile Include="Core\Automation\Commands\RunPowerShellScriptCommand.cs" />
<Compile Include="Core\Automation\Commands\SeleniumBrowserSwitchFrameCommand.cs" />
<Compile Include="Core\Automation\Commands\SetEnginePreferenceCommand.cs" />
<Compile Include="Core\Automation\Commands\TryCommand.cs" />
Expand Down

0 comments on commit a606b49

Please sign in to comment.