aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs122
1 files changed, 122 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs
index b46b89a4a..c993be2d7 100644
--- a/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/Utilities/Tango.MachineEM.UI/ViewModels/MainViewVM.cs
@@ -13,6 +13,8 @@ using Tango.Transport.Transporters;
using Tango.Core;
using Tango.Settings;
using Tango.PMR.ThreadLoading;
+using Tango.PMR.DataStore;
+using System.Windows;
namespace Tango.MachineEM.UI.ViewModels
{
@@ -138,6 +140,10 @@ namespace Tango.MachineEM.UI.ViewModels
/// </summary>
public RelayCommand AbortJobCommand { get; set; }
+ public RelayCommand GetDataStoreItemCommand { get; set; }
+
+ public RelayCommand PutDataStoreItemCommand { get; set; }
+
public RelayCommand PerformDataStoreTestCommand { get; set; }
#endregion
@@ -191,6 +197,8 @@ namespace Tango.MachineEM.UI.ViewModels
SelectedPort = Ports.First();
PerformDataStoreTestCommand = new RelayCommand(Emulator.PerformDataStoreTest);
+ GetDataStoreItemCommand = new RelayCommand(GetDataStoreItem);
+ PutDataStoreItemCommand = new RelayCommand(PutDataStoreItem);
}
#endregion
@@ -282,6 +290,120 @@ namespace Tango.MachineEM.UI.ViewModels
InvalidateRelayCommands();
}
+ private void GetDataStoreItem()
+ {
+ try
+ {
+ var result = GetUserInput<String>("Get Data Store Item", "Enter collection name", String.Empty);
+ if (!result.Confirmed) return;
+ var collectionName = result.Value;
+
+ result = GetUserInput<String>("Get Data Store Item", "Enter item key", String.Empty);
+ if (!result.Confirmed) return;
+ var key = result.Value;
+
+ Emulator.GetDataStoreItem(new PMR.DataStore.GetDataStoreItemRequest()
+ {
+ Collection = collectionName,
+ Key = key
+ });
+ }
+ catch { }
+ }
+
+ private void PutDataStoreItem()
+ {
+ try
+ {
+ var result = GetUserInput<String>("Put Data Store Item", "Enter collection name", String.Empty);
+ if (!result.Confirmed) return;
+ var collectionName = result.Value;
+
+ result = GetUserInput<String>("Put Data Store Item", "Enter item key", String.Empty);
+ if (!result.Confirmed) return;
+ var key = result.Value;
+
+ result = GetUserInput<String>("Put Data Store Item", "Enter data type", "Int32");
+ if (!result.Confirmed) return;
+ DataType dataType = (DataType)Enum.Parse(typeof(DataType), result.Value);
+
+ result = GetUserInput<String>("Put Data Store Item", "Enter value", "10");
+ if (!result.Confirmed) return;
+ var value = result.Value;
+
+ DataStoreItem item = new DataStoreItem();
+ item.DataType = dataType;
+
+ switch (dataType)
+ {
+ case DataType.Int32:
+ item.Int32Value = int.Parse(value);
+ break;
+ case DataType.Float:
+ item.FloatValue = float.Parse(value);
+ break;
+ case DataType.Double:
+ item.DoubleValue = double.Parse(value);
+ break;
+ case DataType.Boolean:
+ item.BooleanValue = bool.Parse(value);
+ break;
+ case DataType.String:
+ item.StringValue = value;
+ break;
+ default:
+ LogManager.Log("Data type not supported by this emulator.");
+ throw new NotSupportedException();
+ }
+
+ Emulator.PutDataStoreItem(new PutDataStoreItemRequest()
+ {
+ Collection = collectionName,
+ Key = key,
+ Item = item
+ });
+ }
+ catch { }
+ }
+
+ #endregion
+
+ #region Private Methods
+
+ private class InputResult<T>
+ {
+ public bool Confirmed { get; set; }
+ public T Value { get; set; }
+ }
+
+ private InputResult<T> GetUserInput<T>(String title, String message, T defaultValue)
+ {
+ InputWindow window = new InputWindow();
+ window.Title = title;
+ window.Message = message;
+ window.Value = defaultValue.ToStringSafe();
+ window.Owner = Application.Current.MainWindow;
+ window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
+ window.WindowStyle = WindowStyle.ToolWindow;
+
+ try
+ {
+ if (window.ShowDialog().Value)
+ {
+ return new InputResult<T>() { Confirmed = true, Value = (T)Convert.ChangeType(window.Value, typeof(T)) };
+ }
+ else
+ {
+ return new InputResult<T>();
+ }
+ }
+ catch (Exception ex)
+ {
+ LogManager.Log(ex, "Error parsing input.");
+ throw ex;
+ }
+ }
+
#endregion
}
}