Skip to content

Commit

Permalink
Updated Ping Command and Provided Sample saucepleez#215
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Jun 5, 2020
1 parent 9b5cb34 commit 83ef97e
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 18 deletions.
39 changes: 23 additions & 16 deletions taskt/Core/Automation/Commands/PingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ public class PingCommand : ScriptCommand
[Attributes.PropertyAttributes.InputSpecification("Ip address or hostname you want to ping")]
[Attributes.PropertyAttributes.SampleUsage("** 192.168.0.1 or www.google.com**")]
[Attributes.PropertyAttributes.Remarks("")]
public string v_hostname { get; set; }

public string v_HostName { 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; }
public PingCommand()
{
this.CommandName = "PingCommand";
Expand All @@ -36,31 +41,33 @@ public PingCommand()
public override List<Control> Render(frmCommandEditor editor)
{
base.Render(editor);
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_hostname", this, editor));
RenderedControls.AddRange(CommandControls.CreateDefaultInputGroupFor("v_HostName", 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 void RunCommand(object sender)
{

Ping ping = new Ping();
string hstname = v_hostname.ConvertToUserVariable(sender);
PingReply pingresult = ping.Send(hstname);
if (pingresult.Status.ToString() == "Success")
{

}
else
{
throw new Exception();
}

Ping ping = new Ping();
string hstname = v_HostName.ConvertToUserVariable(sender);

PingReply pingresult = ping.Send(hstname);
var pingReply = Common.ConvertObjectToJson(pingresult);

pingReply.StoreInUserVariable(sender, v_userVariableName);

}

public override string GetDisplayValue()
{
return "Pinging " + this.v_hostname;
return $"Ping Host '{this.v_HostName}'";
}
}
}
16 changes: 16 additions & 0 deletions taskt/Core/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,22 @@ public static List<string> GetAvailableKeys()
return keyDescriptionList;
}

public static string ConvertObjectToJson(object obj)
{

//set json settings
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.Error = (serializer, err) =>
{
err.ErrorContext.Handled = true;
};

settings.Formatting = Newtonsoft.Json.Formatting.Indented;

return JsonConvert.SerializeObject(obj, settings);

}

}
}

2 changes: 2 additions & 0 deletions taskt/Core/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ public static bool TryParseBase64(this string text, Encoding encoding, out strin
return false;
}
}


}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?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="1712aaf3-0843-4d3b-acf6-88a789234408" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="1" PauseBeforeExeucution="false" v_Comment="Ping Host and Store in variable 'vRes'" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="PingCommand" CommandID="771db3af-0776-488a-aecf-c330bc950dc2" CommandName="PingCommand" IsCommented="false" SelectionName="Ping Command" DefaultPause="0" LineNumber="2" PauseBeforeExeucution="false" CommandEnabled="true" v_HostName="www.google.com" v_userVariableName="vRes" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="2be07455-d2da-46bd-972b-714221068054" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="3" PauseBeforeExeucution="false" v_Comment="Show Raw Ping Reply" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="01a1f140-dd9f-444f-be16-9a313faa1614" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="4" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="Ping Reply: {vRes}" v_AutoCloseAfter="0" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="eaa96062-c718-4077-ad5c-2bef6401f280" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="5" PauseBeforeExeucution="false" v_Comment="Check Ping Reply Status" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="BeginIfCommand" CommandID="c5030ecd-26e4-4e37-a0dc-65e885f57666" CommandName="BeginIfCommand" IsCommented="false" SelectionName="Begin If" DefaultPause="0" LineNumber="6" PauseBeforeExeucution="false" CommandEnabled="true" v_IfActionType="Variable Compare">
<v_IfActionParameterTable>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="I6AcPionPara1Table060420.090102" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="I6AcPionPara1Table060420.090102">
<xs:complexType>
<xs:sequence>
<xs:element name="Parameter_x0020_Name" type="xs:string" minOccurs="0" />
<xs:element name="Parameter_x0020_Value" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<DocumentElement>
<I6AcPionPara1Table060420.090102 diffgr:id="I6AcPionPara1Table060420.0901021" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<Parameter_x0020_Name>Value1</Parameter_x0020_Name>
<Parameter_x0020_Value>{vRes =&gt; $.Status}</Parameter_x0020_Value>
</I6AcPionPara1Table060420.090102>
<I6AcPionPara1Table060420.090102 diffgr:id="I6AcPionPara1Table060420.0901022" msdata:rowOrder="1" diffgr:hasChanges="inserted">
<Parameter_x0020_Name>Operand</Parameter_x0020_Name>
<Parameter_x0020_Value>is equal to</Parameter_x0020_Value>
</I6AcPionPara1Table060420.090102>
<I6AcPionPara1Table060420.090102 diffgr:id="I6AcPionPara1Table060420.0901023" msdata:rowOrder="2" diffgr:hasChanges="inserted">
<Parameter_x0020_Name>Value2</Parameter_x0020_Name>
<Parameter_x0020_Value>0</Parameter_x0020_Value>
</I6AcPionPara1Table060420.090102>
<I6AcPionPara1Table060420.090102 diffgr:id="I6AcPionPara1Table060420.0901024" msdata:rowOrder="3" diffgr:hasChanges="inserted">
<Parameter_x0020_Name>Case Sensitive</Parameter_x0020_Name>
<Parameter_x0020_Value>No</Parameter_x0020_Value>
</I6AcPionPara1Table060420.090102>
</DocumentElement>
</diffgr:diffgram>
</v_IfActionParameterTable>
</ScriptCommand>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="9efc1e8d-6ac8-484b-ae23-6a2590eef601" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="7" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="The ping reply was successful!" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="ElseCommand" CommandID="8b35f960-7890-439f-b262-b9f69d212b78" CommandName="ElseCommand" IsCommented="false" SelectionName="Else" DefaultPause="0" LineNumber="8" PauseBeforeExeucution="false" CommandEnabled="true" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="284d404e-1266-474c-8ced-830c721e52fe" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="9" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="The ping reply failed!" v_AutoCloseAfter="0" />
</AdditionalScriptCommands>
<AdditionalScriptCommands>
<ScriptCommand xsi:type="EndIfCommand" CommandID="cec7c299-dba8-45a2-8a87-92b0c896da54" CommandName="EndIfCommand" IsCommented="false" SelectionName="End If" DefaultPause="0" LineNumber="10" PauseBeforeExeucution="false" CommandEnabled="true" />
</AdditionalScriptCommands>
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="565acdf5-5b0c-448a-bbca-b72b1a72ddca" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="11" PauseBeforeExeucution="false" v_Comment="Extract RoundtripTime using Json Selector" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="5bdf6b4f-3383-4bf3-8500-8cc7769307a6" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="12" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="Round Trip Time (Json Selector): '{vRes =&gt; $.RoundtripTime}'" v_AutoCloseAfter="0" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="CommentCommand" CommandID="4e4a192a-155d-407d-905e-47f41c1a8fd1" CommandName="CommentCommand" IsCommented="false" SelectionName="Add Code Comment" DefaultPause="0" LineNumber="13" PauseBeforeExeucution="false" v_Comment="Extract RoundtripTime using Parse Json Command" CommandEnabled="true" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="ParseJsonCommand" CommandID="4051a1a0-9787-4d49-9dbf-a14f5b5cf717" CommandName="ParseJsonCommand" IsCommented="false" SelectionName="Parse JSON Item" DefaultPause="0" LineNumber="14" PauseBeforeExeucution="false" CommandEnabled="true" v_InputValue="{vRes}" v_JsonExtractor="RoundtripTime" v_applyToVariableName="vRoundTripTime" />
</ScriptAction>
<ScriptAction>
<ScriptCommand xsi:type="MessageBoxCommand" CommandID="9738960d-787d-48a0-b608-a33ab59f40f1" CommandName="MessageBoxCommand" IsCommented="false" SelectionName="Show Message" DefaultPause="0" LineNumber="15" PauseBeforeExeucution="false" CommandEnabled="true" v_Message="Round Trip Time (Parse Json Item Command): {vRoundTripTime}" v_AutoCloseAfter="0" />
</ScriptAction>
</Commands>
<Variables>
<ScriptVariable>
<VariableName>vRes</VariableName>
<VariableValue xsi:type="xsd:string"></VariableValue>
</ScriptVariable>
<ScriptVariable>
<VariableName>vRoundTripTime</VariableName>
<VariableValue xsi:type="xsd:string"></VariableValue>
</ScriptVariable>
</Variables>
</Script>
4 changes: 2 additions & 2 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("AddDictionaryCommand", taskt.Properties.Resources.command_dictionary);
uiImages.Add("CreateDictionaryCommand", taskt.Properties.Resources.command_dictionary);
uiImages.Add("GetDictionaryValueCommand", taskt.Properties.Resources.command_dictionary);
uiImages.Add("LoadDictionaryCommand", taskt.Properties.Resources.command_dictionary);

uiImages.Add("LoadDictionaryCommand", taskt.Properties.Resources.command_dictionary);
uiImages.Add("PingCommand", taskt.Properties.Resources.command_web);
return uiImages;
}
public static ImageList UIImageList()
Expand Down

0 comments on commit 83ef97e

Please sign in to comment.