aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs76
1 files changed, 68 insertions, 8 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs
index 79d535aaf..f4e4aa124 100644
--- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/ViewModels/MainViewVM.cs
@@ -1,4 +1,5 @@
-using Microsoft.Win32;
+using Google.Protobuf;
+using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -115,6 +116,14 @@ namespace Tango.Stubs.UI.ViewModels
set { _isRunning = value; RaisePropertyChanged(nameof(IsRunning)); InvalidateRelayCommands(); }
}
+ private bool _appendLogAuto;
+
+ public bool AppendLogAuto
+ {
+ get { return _appendLogAuto; }
+ set { _appendLogAuto = value; RaisePropertyChangedAuto(); }
+ }
+
#endregion
#region Commands
@@ -188,6 +197,7 @@ namespace Tango.Stubs.UI.ViewModels
/// </summary>
public MainViewVM()
{
+ AppendLogAuto = true;
CodeTabs = new ObservableCollection<CodeTabVM>();
NewCommand = new RelayCommand(CreateNewTab);
CloseTabCommand = new RelayCommand<CodeTabVM>(OnTabClosing);
@@ -198,6 +208,11 @@ namespace Tango.Stubs.UI.ViewModels
HighlightTypes = new ObservableCollection<KeyValuePair<string, Type>>();
HighlightTypes.Add(new KeyValuePair<string, Type>("stubManager", typeof(StubManager)));
+ foreach (var stubType in StubBase.GetAvailableRequestResponseStubs())
+ {
+ HighlightTypes.Add(new KeyValuePair<string, Type>(stubType.GetType().Name, stubType));
+ }
+
StubSnippets = new ObservableCollection<StubSnippetVM>();
foreach (var stubType in StubBase.GetAvailableRequestStubs())
@@ -207,12 +222,26 @@ namespace Tango.Stubs.UI.ViewModels
snippet.Code = String.Empty;
+ snippet.Code += "// " + "Request ----" + Environment.NewLine;
+
foreach (var prop in stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
snippet.Code += "// " + prop.PropertyType.Name + " : " + prop.Name + Environment.NewLine;
}
- snippet.Code += String.Format("stubManager.Run(\"{0}\" ,{1});", stubType.Name, String.Join(", ", stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(x => x.PropertyType.Name == "string" ? "\"string\"" : x.PropertyType.Name)));
+ Type responseType = StubBase.GetAvailableRequestResponseStubs().SingleOrDefault(x => x.Name == stubType.Name.Replace("Request", "Response"));
+
+ if (responseType != null)
+ {
+ snippet.Code += Environment.NewLine + "// " + "Response ----" + Environment.NewLine;
+
+ foreach (var prop in responseType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
+ {
+ snippet.Code += "// " + prop.PropertyType.Name + " : " + prop.Name + Environment.NewLine;
+ }
+ }
+
+ snippet.Code += String.Format("var response = stubManager.Run<{2}>(\"{0}\" ,{1});", stubType.Name, String.Join(", ", stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Select(x => x.PropertyType.Name == "string" ? "\"string\"" : x.PropertyType.Name)), stubType.Name.Replace("Request", "Response"));
StubSnippets.Add(snippet);
}
@@ -412,7 +441,16 @@ namespace Tango.Stubs.UI.ViewModels
{
try
{
- _stubManager = new StubManager(_adapter);
+ _stubManager = new StubManager(_adapter, (txt) =>
+ {
+ AppendTextLog(txt + Environment.NewLine);
+ }, (txt) =>
+ {
+ AppendTextLog(txt);
+ }, () =>
+ {
+
+ });
var thisStubManager = _stubManager;
_stubManager.Completed += Manager_Completed;
_stubManager.Failed += Manager_Failed;
@@ -421,6 +459,8 @@ namespace Tango.Stubs.UI.ViewModels
ScriptEngine engine = new ScriptEngine(new StubOnExecuteParameters(_stubManager));
engine.ReferencedAssemblies.Add(this.GetType());
+ engine.ReferencedAssemblies.Add(typeof(PMR.Stubs.CalculateRequest));
+ engine.ReferencedAssemblies.Add(typeof(IMessage));
await engine.Run(SelectedCodeTab.Code);
if (!thisStubManager.Aborted)
@@ -473,7 +513,11 @@ namespace Tango.Stubs.UI.ViewModels
/// <param name="stubName">Name of the stub.</param>
private void Manager_Executed(object sender, string stubName)
{
- AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Executing '" + stubName + "'..." + Environment.NewLine);
+ if (AppendLogAuto)
+ {
+ AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Executing '" + stubName + "'..." + Environment.NewLine);
+ }
+
Status = "Executing " + stubName + "...";
}
@@ -486,7 +530,11 @@ namespace Tango.Stubs.UI.ViewModels
{
if (IsRunning)
{
- AppendTextLog((DateTime.Now.ToTimeString() + ": ") + ex.Message + Environment.NewLine);
+ if (AppendLogAuto)
+ {
+ AppendTextLog((DateTime.Now.ToTimeString() + ": ") + ex.Message + Environment.NewLine);
+ }
+
Status = "Failed!";
}
}
@@ -498,8 +546,11 @@ namespace Tango.Stubs.UI.ViewModels
/// <param name="response">The response.</param>
private void Manager_Completed(object sender, string response)
{
- AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Response Received:" + Environment.NewLine);
- AppendTextLog((DateTime.Now.ToTimeString() + ": ") + response + Environment.NewLine);
+ if (AppendLogAuto)
+ {
+ AppendTextLog((DateTime.Now.ToTimeString() + ": ") + "Response Received:" + Environment.NewLine);
+ AppendTextLog((DateTime.Now.ToTimeString() + ": ") + response + Environment.NewLine);
+ }
Status = "Completed";
}
@@ -512,11 +563,20 @@ namespace Tango.Stubs.UI.ViewModels
private void AppendTextLog(String log)
{
- InvokeUI(() =>
+ InvokeUI(() =>
{
_logTextBox.AppendText(log);
});
}
+
+ private void ClearTextLog()
+ {
+ InvokeUI(() =>
+ {
+ _logTextBox.Text = String.Empty;
+ });
+ }
+
#endregion
}
}