diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-03-12 15:26:36 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-03-12 15:26:36 +0200 |
| commit | db5c4418d90840ec033a8eacc948419b72755857 (patch) | |
| tree | 70be526f87898e133718b315bbf7b3b02e9d35c0 /Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs | |
| parent | 64326bd1599ef3855212c737ddfaeb6756337e2d (diff) | |
| download | Tango-db5c4418d90840ec033a8eacc948419b72755857.tar.gz Tango-db5c4418d90840ec033a8eacc948419b72755857.zip | |
Machine Studio v4.0.10
PPC v1.0.6
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs | 393 |
1 files changed, 236 insertions, 157 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs index 161177bf1..7c56115e3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs @@ -105,109 +105,148 @@ namespace Tango.MachineStudio.UI.Notifications } /// <summary> - /// Creates a new instance of the specified View type and displays it as a modal dialog. + /// Shows the specified view with the specified view model as it's data context. /// </summary> + /// <typeparam name="VM">The type of the mm.</typeparam> /// <typeparam name="View">The type of the view.</typeparam> - /// <typeparam name="VM">The type of the view model.</typeparam> - /// <param name="onAccept">Accept button callback.</param> - /// <param name="onCancel">Cancel button callback.</param> - public void ShowModalDialog<View, VM>(Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM + /// <param name="vm">The view model.</param> + /// <param name="view">The view.</param> + /// <param name="onAccept">The accept action.</param> + /// <param name="onCancel">The cancel action.</param> + public void ShowModalDialog<VM, View>(VM vm, View view, Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM { - var view = Activator.CreateInstance<View>(); - DialogWindow dialog = new DialogWindow(); - dialog.Owner = Application.Current.MainWindow; - dialog.InnerContent = view; - MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; - view.Loaded += (x, y) => + try { - VM context = view.DataContext as VM; - dialog.DataContext = context; + DialogWindow dialog = new DialogWindow(); + dialog.Owner = Application.Current.MainWindow; + dialog.InnerContent = view; + MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; + view.Loaded += (x, y) => + { + try + { + VM context = vm; + dialog.DataContext = context; - Action onAcceptAction = null; - Action onCancelAction = null; + Action onAcceptAction = null; + Action onCancelAction = null; - onAcceptAction = new Action(() => - { - dialog.Close(); - onAccept(context); - context.Accepted -= onAcceptAction; - context.Canceled -= onCancelAction; - }); + onAcceptAction = new Action(() => + { + dialog.Close(); + onAccept(context); + context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; + }); - onCancelAction = new Action(() => - { - dialog.Close(); + onCancelAction = new Action(() => + { + dialog.Close(); - if (onCancel != null) - { - onCancel(); - } + if (onCancel != null) + { + onCancel(); + } - context.Accepted -= onAcceptAction; - context.Canceled -= onCancelAction; - }); + context.Canceled -= onCancelAction; + context.Accepted -= onAcceptAction; + }); - context.Accepted += onAcceptAction; - context.Canceled += onCancelAction; + context.Accepted += onAcceptAction; + context.Canceled += onCancelAction; - context.OnShow(); - }; - dialog.ShowDialog(); - MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + context.OnShow(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + }; + + dialog.ShowDialog(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + finally + { + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + } } /// <summary> - /// Shows the specified view with the specified view model as it's data context. + /// Creates a new instance of the specified View type and displays it as a modal dialog. /// </summary> - /// <typeparam name="VM">The type of the mm.</typeparam> /// <typeparam name="View">The type of the view.</typeparam> - /// <param name="vm">The view model.</param> - /// <param name="view">The view.</param> - /// <param name="onAccept">The accept action.</param> - /// <param name="onCancel">The cancel action.</param> - public void ShowModalDialog<VM, View>(VM vm, Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM + /// <typeparam name="VM">The type of the view model.</typeparam> + /// <param name="onAccept">Accept button callback.</param> + /// <param name="onCancel">Cancel button callback.</param> + public void ShowModalDialog<View, VM>(Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM { - var view = Activator.CreateInstance<View>(); - DialogWindow dialog = new DialogWindow(); - dialog.Owner = Application.Current.MainWindow; - dialog.InnerContent = view; - MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; - view.Loaded += (x, y) => + try { - VM context = vm; - dialog.DataContext = context; + var view = Activator.CreateInstance<View>(); + DialogWindow dialog = new DialogWindow(); + dialog.Owner = Application.Current.MainWindow; + dialog.InnerContent = view; + MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; + view.Loaded += (x, y) => + { + try + { + VM context = view.DataContext as VM; + dialog.DataContext = context; - Action onAcceptAction = null; - Action onCancelAction = null; + Action onAcceptAction = null; + Action onCancelAction = null; - onAcceptAction = new Action(() => - { - dialog.Close(); - onAccept(context); - context.Accepted -= onAcceptAction; - context.Canceled -= onCancelAction; - }); + onAcceptAction = new Action(() => + { + dialog.Close(); + onAccept(context); + context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; + }); - onCancelAction = new Action(() => - { - dialog.Close(); + onCancelAction = new Action(() => + { + dialog.Close(); - if (onCancel != null) - { - onCancel(); - } + if (onCancel != null) + { + onCancel(); + } - context.Accepted -= onAcceptAction; - context.Canceled -= onCancelAction; - }); + context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; + }); - context.Accepted += onAcceptAction; - context.Canceled += onCancelAction; + context.Accepted += onAcceptAction; + context.Canceled += onCancelAction; - context.OnShow(); - }; - dialog.ShowDialog(); - MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + context.OnShow(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + }; + dialog.ShowDialog(); + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + finally + { + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + } } /// <summary> @@ -219,48 +258,68 @@ namespace Tango.MachineStudio.UI.Notifications /// <param name="view">The view.</param> /// <param name="onAccept">The accept action.</param> /// <param name="onCancel">The cancel action.</param> - public void ShowModalDialog<VM, View>(VM vm, View view, Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM + public void ShowModalDialog<VM, View>(VM vm, Action<VM> onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM { - DialogWindow dialog = new DialogWindow(); - dialog.Owner = Application.Current.MainWindow; - dialog.InnerContent = view; - MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; - view.Loaded += (x, y) => + try { - VM context = vm; - dialog.DataContext = context; + var view = Activator.CreateInstance<View>(); + DialogWindow dialog = new DialogWindow(); + dialog.Owner = Application.Current.MainWindow; + dialog.InnerContent = view; + MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; + view.Loaded += (x, y) => + { + try + { + VM context = vm; + dialog.DataContext = context; - Action onAcceptAction = null; - Action onCancelAction = null; + Action onAcceptAction = null; + Action onCancelAction = null; - onAcceptAction = new Action(() => - { - dialog.Close(); - onAccept(context); - context.Accepted -= onAcceptAction; - context.Canceled -= onCancelAction; - }); + onAcceptAction = new Action(() => + { + dialog.Close(); + onAccept(context); + context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; + }); - onCancelAction = new Action(() => - { - dialog.Close(); + onCancelAction = new Action(() => + { + dialog.Close(); - if (onCancel != null) - { - onCancel(); - } + if (onCancel != null) + { + onCancel(); + } - context.Canceled -= onCancelAction; - context.Accepted -= onAcceptAction; - }); + context.Accepted -= onAcceptAction; + context.Canceled -= onCancelAction; + }); - context.Accepted += onAcceptAction; - context.Canceled += onCancelAction; + context.Accepted += onAcceptAction; + context.Canceled += onCancelAction; - context.OnShow(); - }; - dialog.ShowDialog(); - MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + context.OnShow(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + }; + dialog.ShowDialog(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + finally + { + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + } } /// <summary> @@ -272,67 +331,87 @@ namespace Tango.MachineStudio.UI.Notifications /// <exception cref="NullReferenceException">Could not locate view " + viewName</exception> public void ShowModalDialog<VM>(Action<VM> onAccept, Action onCancel) where VM : DialogViewVM { - String viewName = typeof(VM).Name.Replace("VM", ""); - - if (viewTypes == null) + try { - viewTypes = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains("MachineStudio")).SelectMany(x => x.GetTypes()).ToList(); - } + String viewName = typeof(VM).Name.Replace("VM", ""); - var viewType = viewTypes.SingleOrDefault(x => x.Name == viewName); + if (viewTypes == null) + { + viewTypes = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains("MachineStudio")).SelectMany(x => x.GetTypes()).ToList(); + } - if (viewType == null) - { - throw new NullReferenceException("Could not locate view " + viewName); - } + var viewType = viewTypes.SingleOrDefault(x => x.Name == viewName); - var view = Activator.CreateInstance(viewType) as FrameworkElement; - DialogWindow dialog = new DialogWindow(); - dialog.Owner = Application.Current.MainWindow; - dialog.InnerContent = view; - MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; - view.Loaded += (x, y) => - { - VM context = view.DataContext as VM; - if (context == null) + if (viewType == null) { - context = Activator.CreateInstance<VM>(); + throw new NullReferenceException("Could not locate view " + viewName); } - dialog.DataContext = context; - - Action onCancelAction = null; - Action onAcceptAction = null; - onAcceptAction = new Action(() => + var view = Activator.CreateInstance(viewType) as FrameworkElement; + DialogWindow dialog = new DialogWindow(); + dialog.Owner = Application.Current.MainWindow; + dialog.InnerContent = view; + MainWindow.Instance.shadowGrid.Visibility = Visibility.Visible; + view.Loaded += (x, y) => { - dialog.Close(); - onAccept(context); + try + { + VM context = view.DataContext as VM; + if (context == null) + { + context = Activator.CreateInstance<VM>(); + } + dialog.DataContext = context; - context.Canceled -= onCancelAction; - context.Accepted -= onAcceptAction; - }); + Action onCancelAction = null; + Action onAcceptAction = null; - onCancelAction = new Action(() => - { - dialog.Close(); + onAcceptAction = new Action(() => + { + dialog.Close(); + onAccept(context); - if (onCancel != null) - { - onCancel(); - } + context.Canceled -= onCancelAction; + context.Accepted -= onAcceptAction; + }); - context.Canceled -= onCancelAction; - context.Accepted -= onAcceptAction; - }); + onCancelAction = new Action(() => + { + dialog.Close(); - context.Accepted += onAcceptAction; - context.Canceled += onCancelAction; + if (onCancel != null) + { + onCancel(); + } - context.OnShow(); - }; + context.Canceled -= onCancelAction; + context.Accepted -= onAcceptAction; + }); - dialog.ShowDialog(); - MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + context.Accepted += onAcceptAction; + context.Canceled += onCancelAction; + + context.OnShow(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + return; + } + }; + + dialog.ShowDialog(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + finally + { + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + } } /// <summary> |
