Skip to content

Commit

Permalink
Added Show Engine Context Command for easy display of engine context …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
saucepleez committed Jul 28, 2019
1 parent cf77fc2 commit 4159b87
Show file tree
Hide file tree
Showing 10 changed files with 1,063 additions and 10 deletions.
1 change: 1 addition & 0 deletions taskt/Core/Automation/Commands/ScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ namespace taskt.Core.Automation.Commands
[XmlInclude(typeof(IEBrowserNavigateURLCommand))]
[XmlInclude(typeof(AddToVariableCommand))]
[XmlInclude(typeof(SetVariableIndexCommand))]
[XmlInclude(typeof(ShowEngineContextCommand))]
public abstract class ScriptCommand
{
[XmlAttribute]
Expand Down
81 changes: 81 additions & 0 deletions taskt/Core/Automation/Commands/ShowEngineContextCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 show a message to the user.")]
[Attributes.ClassAttributes.UsesDescription("Use this command when you want to present or display a value on screen to the user.")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements 'MessageBox' and invokes VariableCommand to find variable data.")]
public class ShowEngineContextCommand : ScriptCommand
{

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Close After X (Seconds) - 0 to bypass")]
[Attributes.PropertyAttributes.InputSpecification("Specify how many seconds to display on screen. After the amount of seconds passes, the message box will be automatically closed and script will resume execution.")]
[Attributes.PropertyAttributes.SampleUsage("**0** to remain open indefinitely or **5** to stay open for 5 seconds.")]
[Attributes.PropertyAttributes.Remarks("")]
public int v_AutoCloseAfter { get; set; }
public ShowEngineContextCommand()
{
this.CommandName = "ShowEngineContextCommand";
this.SelectionName = "Show Engine Context";
this.CommandEnabled = true;
this.v_AutoCloseAfter = 0;
this.CustomRendering = true;
}

public override void RunCommand(object sender)
{
var engine = (Core.Automation.Engine.AutomationEngineInstance)sender;


if (engine.tasktEngineUI == null)
{
return;
}

//automatically close messageboxes for server requests
if (engine.serverExecution && v_AutoCloseAfter <= 0)
{
v_AutoCloseAfter = 10;
}

var result = engine.tasktEngineUI.Invoke(new Action(() =>
{
engine.tasktEngineUI.ShowEngineContext(engine.GetEngineContext(), v_AutoCloseAfter);
}

));

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


//create auto close control set
var autocloseControlSet = CommandControls.CreateDefaultInputGroupFor("v_AutoCloseAfter", this, editor);
RenderedControls.AddRange(autocloseControlSet);


return RenderedControls;

}

public override string GetDisplayValue()
{
return base.GetDisplayValue();
}

}
}
13 changes: 13 additions & 0 deletions taskt/Core/Automation/Engine/AutomationEngineInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,19 @@ public enum EngineStatus
Loaded, Running, Paused, Finished
}

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

return JsonConvert.SerializeObject(this, settings);
}

}
public class ReportProgressEventArgs : EventArgs
{
Expand Down
10 changes: 1 addition & 9 deletions taskt/Core/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,7 @@ public static string ConvertToUserVariable(this String str, object sender)

if (potentialVariable == "taskt.EngineContext")
{
//set json settings
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.Error = (serializer, err) =>
{
err.ErrorContext.Handled = true;
};
settings.Formatting = Formatting.Indented;

varCheck.VariableValue = Newtonsoft.Json.JsonConvert.SerializeObject(engine, settings);
varCheck.VariableValue = engine.GetEngineContext();
}


Expand Down
2 changes: 1 addition & 1 deletion taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("NLGGeneratePhraseCommand", taskt.Properties.Resources.command_nlg);
uiImages.Add("NLGSetParameterCommand", taskt.Properties.Resources.command_nlg);
uiImages.Add("NLGCreateInstanceCommand", taskt.Properties.Resources.command_nlg);

uiImages.Add("ShowEngineContextCommand", taskt.Properties.Resources.command_window);
return uiImages;
}
public static ImageList UIImageList()
Expand Down
134 changes: 134 additions & 0 deletions taskt/UI/Forms/Supplement Forms/frmEngineContextViewer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions taskt/UI/Forms/Supplement Forms/frmEngineContextViewer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace taskt.UI.Forms.Supplement_Forms
{
public partial class frmEngineContextViewer : ThemedForm
{
public frmEngineContextViewer(string context, int closeAfter)
{
InitializeComponent();
LoadEngineContext(context);
}

private void FrmEngineContextViewer_Load(object sender, EventArgs e)
{

}

private void LoadEngineContext(string context)
{

var root = Newtonsoft.Json.JsonConvert.DeserializeObject<JToken>(context);
DisplayTreeView(root, "Engine Context");

}
private void DisplayTreeView(JToken root, string rootName)
{
tvContext.BeginUpdate();
try
{
tvContext.Nodes.Clear();
var tNode = tvContext.Nodes[tvContext.Nodes.Add(new TreeNode(rootName))];
tNode.Tag = root;

AddNode(root, tNode);
}
finally
{
tvContext.EndUpdate();
}
}
private void AddNode(JToken token, TreeNode inTreeNode)
{
if (token == null)
return;
if (token is JValue)
{
var childNode = inTreeNode.Nodes[inTreeNode.Nodes.Add(new TreeNode(token.ToString()))];
childNode.Tag = token;
}
else if (token is JObject)
{
var obj = (JObject)token;
foreach (var property in obj.Properties())
{
var childNode = inTreeNode.Nodes[inTreeNode.Nodes.Add(new TreeNode(property.Name))];
childNode.Tag = property;
AddNode(property.Value, childNode);
}
}
else if (token is JArray)
{
var array = (JArray)token;
for (int i = 0; i < array.Count; i++)
{
var childNode = inTreeNode.Nodes[inTreeNode.Nodes.Add(new TreeNode(i.ToString()))];
childNode.Tag = array[i];
AddNode(array[i], childNode);
}
}
else
{
Console.WriteLine(string.Format("{0} not implemented", token.Type)); // JConstructor, JRaw
}
}

private void UiBtnOk_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
}
}
Loading

0 comments on commit 4159b87

Please sign in to comment.