forked from saucepleez/taskt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95ba841
commit 20e96af
Showing
8 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Forms; | ||
using System.Xml.Serialization; | ||
using taskt.UI.CustomControls; | ||
using taskt.UI.Forms; | ||
|
||
namespace taskt.Core.Automation.Commands | ||
{ | ||
[Serializable] | ||
[Attributes.ClassAttributes.Group("Engine Commands")] | ||
[Attributes.ClassAttributes.Description("This command allows you to stop a program or a process.")] | ||
[Attributes.ClassAttributes.UsesDescription("Use this command to close an application by its name such as 'chrome'. Alternatively, you may use the Close Window or Thick App Command instead.")] | ||
[Attributes.ClassAttributes.ImplementationDescription("This command implements 'Process.CloseMainWindow'.")] | ||
public class StopwatchCommand : ScriptCommand | ||
{ | ||
[XmlAttribute] | ||
[Attributes.PropertyAttributes.PropertyDescription("Enter the instance name of the Stopwatch")] | ||
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] | ||
[Attributes.PropertyAttributes.InputSpecification("Provide a unique instance or way to refer to the stopwatch")] | ||
[Attributes.PropertyAttributes.SampleUsage("**myStopwatch**, **{vStopWatch}**")] | ||
[Attributes.PropertyAttributes.Remarks("")] | ||
public string v_StopwatchName { get; set; } | ||
|
||
[XmlAttribute] | ||
[Attributes.PropertyAttributes.PropertyDescription("Enter the Stopwatch Action")] | ||
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)] | ||
[Attributes.PropertyAttributes.InputSpecification("Provide a unique instance or way to refer to the stopwatch")] | ||
[Attributes.PropertyAttributes.SampleUsage("**myStopwatch**, **{vStopWatch}**")] | ||
[Attributes.PropertyAttributes.Remarks("")] | ||
public string v_StopwatchAction { get; set; } | ||
|
||
|
||
[XmlAttribute] | ||
[Attributes.PropertyAttributes.PropertyDescription("Apply Result 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("Optional - Specify String Format")] | ||
[Attributes.PropertyAttributes.InputSpecification("Specify if a specific string format is required.")] | ||
[Attributes.PropertyAttributes.SampleUsage("MM/dd/yy, hh:mm, etc.")] | ||
[Attributes.PropertyAttributes.Remarks("")] | ||
public string v_ToStringFormat { get; set; } | ||
|
||
[XmlIgnore] | ||
[NonSerialized] | ||
public ComboBox StopWatchComboBox; | ||
|
||
[XmlIgnore] | ||
[NonSerialized] | ||
public List<Control> MeasureControls; | ||
|
||
public StopwatchCommand() | ||
{ | ||
this.CommandName = "StopwatchCommand"; | ||
this.SelectionName = "Stopwatch"; | ||
this.CommandEnabled = true; | ||
this.CustomRendering = true; | ||
this.v_StopwatchName = "default"; | ||
this.v_StopwatchAction = "Start Stopwatch"; | ||
} | ||
|
||
public override void RunCommand(object sender) | ||
{ | ||
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender; | ||
var instanceName = v_StopwatchName.ConvertToUserVariable(sender); | ||
System.Diagnostics.Stopwatch stopwatch; | ||
|
||
var action = v_StopwatchAction.ConvertToUserVariable(sender); | ||
|
||
switch (action) | ||
{ | ||
case "Start Stopwatch": | ||
//start a new stopwatch | ||
stopwatch = new System.Diagnostics.Stopwatch(); | ||
engine.AddAppInstance(instanceName, stopwatch); | ||
stopwatch.Start(); | ||
break; | ||
case "Stop Stopwatch": | ||
//stop existing stopwatch | ||
stopwatch = (System.Diagnostics.Stopwatch)engine.AppInstances[instanceName]; | ||
stopwatch.Stop(); | ||
break; | ||
case "Restart Stopwatch": | ||
//restart which sets to 0 and automatically starts | ||
stopwatch = (System.Diagnostics.Stopwatch)engine.AppInstances[instanceName]; | ||
stopwatch.Restart(); | ||
break; | ||
case "Reset Stopwatch": | ||
//reset which sets to 0 | ||
stopwatch = (System.Diagnostics.Stopwatch)engine.AppInstances[instanceName]; | ||
stopwatch.Reset(); | ||
break; | ||
case "Measure Stopwatch": | ||
//check elapsed which gives measure | ||
stopwatch = (System.Diagnostics.Stopwatch)engine.AppInstances[instanceName]; | ||
string elapsedTime; | ||
if (string.IsNullOrEmpty(v_ToStringFormat)) | ||
{ | ||
elapsedTime = stopwatch.Elapsed.ToString(); | ||
} | ||
else | ||
{ | ||
var format = v_ToStringFormat.ConvertToUserVariable(sender); | ||
elapsedTime = stopwatch.Elapsed.ToString(format); | ||
} | ||
|
||
elapsedTime.StoreInUserVariable(sender, v_userVariableName); | ||
|
||
break; | ||
default: | ||
throw new NotImplementedException("Stopwatch Action '" + action + "' not implemented"); | ||
} | ||
|
||
|
||
|
||
} | ||
public override List<Control> Render(frmCommandEditor editor) | ||
{ | ||
base.Render(editor); | ||
|
||
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_StopwatchName", this, editor)); | ||
|
||
var StopWatchComboBoxLabel = CommandControls.CreateDefaultLabelFor("v_StopwatchAction", this); | ||
StopWatchComboBox = (ComboBox)CommandControls.CreateDropdownFor("v_StopwatchAction", this); | ||
StopWatchComboBox.DataSource = new List<string> { "Start Stopwatch", "Stop Stopwatch", "Restart Stopwatch", "Reset Stopwatch", "Measure Stopwatch" }; | ||
StopWatchComboBox.SelectedIndexChanged += StopWatchComboBox_SelectedValueChanged; | ||
RenderedControls.Add(StopWatchComboBoxLabel); | ||
RenderedControls.Add(StopWatchComboBox); | ||
|
||
//create controls for user variable | ||
MeasureControls = CommandControls.CreateDefaultDropdownGroupFor("v_userVariableName", this, editor); | ||
|
||
//load variables for selection | ||
var comboBox = (ComboBox)MeasureControls[1]; | ||
comboBox.AddVariableNames(editor); | ||
|
||
MeasureControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_ToStringFormat", this, editor)); | ||
|
||
foreach (var ctrl in MeasureControls) | ||
{ | ||
ctrl.Visible = false; | ||
} | ||
RenderedControls.AddRange(MeasureControls); | ||
|
||
return RenderedControls; | ||
} | ||
|
||
private void StopWatchComboBox_SelectedValueChanged(object sender, EventArgs e) | ||
{ | ||
|
||
if (StopWatchComboBox.SelectedValue.ToString() == "Measure Stopwatch") | ||
{ | ||
foreach (var ctrl in MeasureControls) | ||
ctrl.Visible = true; | ||
|
||
} | ||
else { | ||
foreach (var ctrl in MeasureControls) | ||
ctrl.Visible = false; | ||
} | ||
|
||
} | ||
|
||
public override string GetDisplayValue() | ||
{ | ||
return base.GetDisplayValue() + " [Action: " + v_StopwatchAction + ", Name: " + v_StopwatchName + "]"; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions
68
taskt/Sample Scripts/2.x Use Case Samples/Stopwatch Sample [2.9.0.0].xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Script xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
<Commands> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="64565e14-001e-4b0e-a585-b216e8d187d6" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="1" PauseBeforeExeucution="false" v_Comment="1) Start/Stop and show elapsed time" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="ffac2e5c-79e2-4873-8df2-898193928285" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="2" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Start Stopwatch" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="PauseCommand" CommandID="dfdfd903-cfe6-402a-901f-f299242154ce" CommandName="PauseCommand" IsCommented="false" SelectionName="Pause Script" DefaultPause="0" LineNumber="3" PauseBeforeExeucution="false" CommandEnabled="true" v_PauseLength="3000" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="1aaf0c9e-b916-4b17-aaa7-7daf9aba8250" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="4" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Stop Stopwatch" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="94a39fd2-2c8f-4cf0-abfc-b58c80ca58c9" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="5" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Measure Stopwatch" v_userVariableName="vElapsed" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="2ecd7e12-beb6-45c5-8c2a-e72460954031" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="6" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vElapsed}" v_AutoCloseAfter="0" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="8481f5d8-f61e-4a5c-888c-de37b18d4825" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="7" PauseBeforeExeucution="false" v_Comment="2) Restart/Stop and show elapsed time" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="09638194-46a7-49e8-a615-64a020e0930e" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="8" PauseBeforeExeucution="false" v_Comment="Note: Restart sets to zero and starts immediately" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="294a8213-50ba-4265-9432-6325d029dee8" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="9" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Restart Stopwatch" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="PauseCommand" CommandID="a13ff69e-04ab-42b2-b2af-758b80e594f8" CommandName="PauseCommand" IsCommented="false" SelectionName="Pause Script" DefaultPause="0" LineNumber="10" PauseBeforeExeucution="false" CommandEnabled="true" v_PauseLength="4000" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="8933f34d-b041-40ce-b173-5c8f87936ca9" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="11" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Stop Stopwatch" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="4430415c-d2ae-4d2b-b7f0-e37c1270b0aa" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="12" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Measure Stopwatch" v_userVariableName="vElapsed" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="9e56bd23-317d-4e91-a335-19ac9a1704e3" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="13" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vElapsed}" v_AutoCloseAfter="0" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="22e6aad7-3349-49f7-9735-6528ad12f33e" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="14" PauseBeforeExeucution="false" v_Comment="3) Reset Stopwatch and show zero'd time" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="CommentCommand" CommandID="f6186120-e582-4e10-918b-bece34eb47a6" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="15" PauseBeforeExeucution="false" v_Comment="Note: Reset sets to zero and does not start automatically" CommandEnabled="true" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="7adfacc6-11b1-4ec2-abf4-b54a60d3c339" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="16" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Reset Stopwatch" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="PauseCommand" CommandID="c8d3cb98-0223-4fdd-b595-a42a324b64eb" CommandName="PauseCommand" IsCommented="false" SelectionName="Pause Script" DefaultPause="0" LineNumber="17" PauseBeforeExeucution="false" CommandEnabled="true" v_PauseLength="2000" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="StopwatchCommand" CommandID="a4bb34f1-d75c-4b05-852a-c20525115680" CommandName="StopwatchCommand" IsCommented="false" SelectionName="Stopwatch" DefaultPause="0" LineNumber="18" PauseBeforeExeucution="false" CommandEnabled="true" v_StopwatchName="default" v_StopwatchAction="Measure Stopwatch" v_userVariableName="vElapsed" /> | ||
</ScriptAction> | ||
<ScriptAction> | ||
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="0aaa71ba-5e85-49b7-91c0-21e74897cae1" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="19" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="{vElapsed}" v_AutoCloseAfter="0" /> | ||
</ScriptAction> | ||
</Commands> | ||
<Variables> | ||
<ScriptVariable> | ||
<VariableName>vElapsed</VariableName> | ||
<VariableValue xsi:type="xsd:string"></VariableValue> | ||
</ScriptVariable> | ||
</Variables> | ||
</Script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters