From db5c4418d90840ec033a8eacc948419b72755857 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 12 Mar 2019 15:26:36 +0200 Subject: Machine Studio v4.0.10 PPC v1.0.6 --- .../Notifications/DefaultNotificationProvider.cs | 399 ++++++++++++--------- 1 file changed, 239 insertions(+), 160 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Notifications/DefaultNotificationProvider.cs') 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 } /// - /// 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. /// + /// The type of the mm. /// The type of the view. - /// The type of the view model. - /// Accept button callback. - /// Cancel button callback. - public void ShowModalDialog(Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM + /// The view model. + /// The view. + /// The accept action. + /// The cancel action. + public void ShowModalDialog(VM vm, View view, Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM { - var view = Activator.CreateInstance(); - 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; + } } /// - /// 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. /// - /// The type of the mm. /// The type of the view. - /// The view model. - /// The view. - /// The accept action. - /// The cancel action. - public void ShowModalDialog(VM vm, Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM + /// The type of the view model. + /// Accept button callback. + /// Cancel button callback. + public void ShowModalDialog(Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM { - var view = Activator.CreateInstance(); - 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(); + 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; + } } /// @@ -219,48 +258,68 @@ namespace Tango.MachineStudio.UI.Notifications /// The view. /// The accept action. /// The cancel action. - public void ShowModalDialog(VM vm, View view, Action onAccept, Action onCancel) where View : FrameworkElement where VM : DialogViewVM + public void ShowModalDialog(VM vm, Action 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(); + 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; + } } /// @@ -272,67 +331,87 @@ namespace Tango.MachineStudio.UI.Notifications /// Could not locate view " + viewName public void ShowModalDialog(Action onAccept, Action onCancel) where VM : DialogViewVM { - String viewName = typeof(VM).Name.Replace("VM", ""); - - if (viewTypes == null) - { - viewTypes = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains("MachineStudio")).SelectMany(x => x.GetTypes()).ToList(); - } - - var viewType = viewTypes.SingleOrDefault(x => x.Name == viewName); - - if (viewType == null) + try { - throw new NullReferenceException("Could not locate view " + viewName); - } + String viewName = typeof(VM).Name.Replace("VM", ""); - 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 (viewTypes == null) { - context = Activator.CreateInstance(); + viewTypes = AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains("MachineStudio")).SelectMany(x => x.GetTypes()).ToList(); } - dialog.DataContext = context; - Action onCancelAction = null; - Action onAcceptAction = null; + var viewType = viewTypes.SingleOrDefault(x => x.Name == viewName); - onAcceptAction = new Action(() => + if (viewType == null) { - dialog.Close(); - onAccept(context); - - context.Canceled -= onCancelAction; - context.Accepted -= onAcceptAction; - }); + throw new NullReferenceException("Could not locate view " + viewName); + } - onCancelAction = 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(); - - if (onCancel != null) + try { - onCancel(); + VM context = view.DataContext as VM; + if (context == null) + { + context = Activator.CreateInstance(); + } + dialog.DataContext = context; + + Action onCancelAction = null; + Action onAcceptAction = null; + + onAcceptAction = new Action(() => + { + dialog.Close(); + onAccept(context); + + context.Canceled -= onCancelAction; + context.Accepted -= onAcceptAction; + }); + + onCancelAction = new Action(() => + { + dialog.Close(); + + if (onCancel != null) + { + onCancel(); + } + + context.Canceled -= onCancelAction; + context.Accepted -= onAcceptAction; + }); + + context.Accepted += onAcceptAction; + context.Canceled += onCancelAction; + + context.OnShow(); } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + return; + } + }; - context.Canceled -= onCancelAction; - context.Accepted -= onAcceptAction; - }); - - context.Accepted += onAcceptAction; - context.Canceled += onCancelAction; - - context.OnShow(); - }; - - dialog.ShowDialog(); - MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + dialog.ShowDialog(); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error display modal dialog. {typeof(VM).Name}"); + onCancel?.Invoke(); + } + finally + { + MainWindow.Instance.shadowGrid.Visibility = Visibility.Hidden; + } } /// -- cgit v1.3.1