aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs57
1 files changed, 49 insertions, 8 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs
index 150649c0b..6249b3577 100644
--- a/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs
+++ b/Software/Visual_Studio/Utilities/Tango.Stubs.UI/StubManager.cs
@@ -7,6 +7,7 @@ using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using System.Windows.Controls;
using Tango.PMR;
using Tango.PMR.Common;
using Tango.Transport.Adapters;
@@ -19,6 +20,9 @@ namespace Tango.Stubs.UI
public class StubManager
{
private UsbTransportAdapter _adapter; //Holds the USB transport adapter.
+ private Action<String> _writeLine;
+ private Action<String> _write;
+ private Action _clear;
/// <summary>
/// Occurs when the stub has failed to execute.
@@ -44,8 +48,12 @@ namespace Tango.Stubs.UI
/// Initializes a new instance of the <see cref="StubManager"/> class.
/// </summary>
/// <param name="adapter">The adapter.</param>
- public StubManager(UsbTransportAdapter adapter)
+ public StubManager(UsbTransportAdapter adapter, Action<String> writeLine, Action<String> write, Action clear)
{
+ _writeLine = writeLine;
+ _write = write;
+ _clear = clear;
+
_adapter = adapter;
}
@@ -62,15 +70,15 @@ namespace Tango.Stubs.UI
/// </summary>
/// <param name="stubName">Name of the stub.</param>
/// <param name="args">The arguments.</param>
- public void Run(String stubName, params Object[] args)
+ public IMessage Run(String stubName, params Object[] args)
{
- if (Aborted) return;
+ if (Aborted) return null;
var stubType = StubBase.GetAvailableRequestStubs().SingleOrDefault(x => x.Name.ToLower() == stubName.ToLower() || x.Name.Replace("Request", "").ToLower() == stubName.ToLower());
if (stubType == null)
{
OnFailed(new ArgumentException("Invalid stub '" + stubName + "'."));
- return;
+ return null;
}
var stubProps = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
@@ -78,7 +86,7 @@ namespace Tango.Stubs.UI
if (stubProps.Length > args.Length)
{
OnFailed(new ArgumentOutOfRangeException("Not enough arguments for " + stubType.Name + "."));
- return;
+ return null;
}
Executed?.Invoke(this, stubType.Name);
@@ -117,7 +125,7 @@ namespace Tango.Stubs.UI
bool done = false;
- TaskCompletionSource<IMessage> _completionSource = new TaskCompletionSource<IMessage>();
+ IMessage message = null;
Task.Factory.StartNew(() =>
{
@@ -144,9 +152,8 @@ namespace Tango.Stubs.UI
}
}
- IMessage message = MessageFactory.ExtractMessageFromContainer(responseContainer);
+ message = MessageFactory.ExtractMessageFromContainer(responseContainer);
OnCompleted(JsonConvert.SerializeObject(message, Formatting.Indented));
- _completionSource.SetResult(message);
done = true;
});
@@ -154,11 +161,45 @@ namespace Tango.Stubs.UI
{
Thread.Sleep(2);
}
+
+ return message;
}
catch (Exception ex)
{
OnFailed(ex);
}
+
+ return null;
+ }
+
+ public T Run<T>(String stubName, params Object[] args) where T : class, IMessage
+ {
+ return Run(stubName, args) as T;
+ }
+
+ public void WriteLine(Object obj)
+ {
+ _writeLine(obj.ToString());
+ }
+
+ public void Write(Object obj)
+ {
+ _write(obj.ToString());
+ }
+
+ public void WriteLineHex(Object number, int digits)
+ {
+ _writeLine("#" + Convert.ToInt32(number).ToString("X" + digits.ToString()));
+ }
+
+ public void WriteHex(Object number, int digits)
+ {
+ _write("#" + Convert.ToInt32(number).ToString("X" + digits.ToString()));
+ }
+
+ public void Clear()
+ {
+ _clear();
}
/// <summary>