aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-05 19:24:45 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-05 19:24:45 +0300
commit5571ab086f6288b27117e3eaae443415a162403c (patch)
treed189224b3bca6789532516d33d12ea2f0a1327b2 /Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
parentdd81a94133e1c5117e06e84cbddf45ffec30acfc (diff)
downloadTango-5571ab086f6288b27117e3eaae443415a162403c.tar.gz
Tango-5571ab086f6288b27117e3eaae443415a162403c.zip
Require Safety Level Operations !
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs')
-rw-r--r--Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs80
1 files changed, 50 insertions, 30 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
index a8ac2b24b..3b1e1e2f5 100644
--- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
+++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
@@ -332,29 +332,33 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM
{
- view.DataContext = datacontext;
-
- TangoIOC.Default.Inject(datacontext);
+ TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
- view.Loaded += (_, __) =>
+ InvokeUI(() =>
{
view.DataContext = datacontext;
- datacontext.OnShow();
- };
- TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();
+ TangoIOC.Default.Inject(datacontext);
- datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); };
- datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); };
+ view.Loaded += (_, __) =>
+ {
+ view.DataContext = datacontext;
+ datacontext.OnShow();
+ };
- if (CurrentDialog == null)
- {
- CurrentDialog = view;
- }
- else
- {
- _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source));
- }
+ datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); };
+ datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); };
+
+ if (CurrentDialog == null)
+ {
+ CurrentDialog = view;
+ }
+ else
+ {
+ _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source));
+ }
+
+ });
var result = await source.Task;
return result as T;
@@ -386,23 +390,31 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public Task<T> ShowDialog<T>(T datacontext) where T : DialogViewVM
{
- var callingAssembly = datacontext.GetType().Assembly;
- String viewName = datacontext.GetType().FullName.Replace("VM", "");
- var viewType = callingAssembly.GetType(viewName);
+ TaskCompletionSource<T> source = new TaskCompletionSource<T>();
- if (viewType == null)
+ InvokeUI(async () =>
{
- throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!");
- }
+ var callingAssembly = datacontext.GetType().Assembly;
+ String viewName = datacontext.GetType().FullName.Replace("VM", "");
+ var viewType = callingAssembly.GetType(viewName);
- var view = Activator.CreateInstance(viewType) as FrameworkElement;
+ if (viewType == null)
+ {
+ throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!");
+ }
- if (view == null)
- {
- throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
- }
+ var view = Activator.CreateInstance(viewType) as FrameworkElement;
+
+ if (view == null)
+ {
+ throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
+ }
- return ShowDialog<T>(datacontext, view);
+ T result = await ShowDialog<T>(datacontext, view);
+ source.SetResult(result);
+ });
+
+ return source.Task;
}
/// <summary>
@@ -414,7 +426,15 @@ namespace Tango.PPC.UI.Notifications
/// <returns></returns>
public Task<T> ShowDialog<T>() where T : DialogViewVM
{
- return ShowDialog<T>(Activator.CreateInstance<T>());
+ TaskCompletionSource<T> source = new TaskCompletionSource<T>();
+
+ InvokeUI(async () =>
+ {
+ var result = await ShowDialog<T>(Activator.CreateInstance<T>());
+ source.SetResult(result);
+ });
+
+ return source.Task;
}
/// <summary>