From 51ba66ff19097d8e22cc9ad38b3a208621dec91c Mon Sep 17 00:00:00 2001 From: Stanislav Peichev Date: Mon, 12 Aug 2024 16:01:35 +0300 Subject: [PATCH] Notifications API - io.Connect.NET - .net framework demo --- .../Notifications/INotificationHandler.cs | 20 ++--- .../Notifications/MainWindow.xaml.cs | 90 +++++++++++-------- .../Notifications/Notifications.csproj | 4 +- notifications/Notifications/packages.config | 2 +- 4 files changed, 65 insertions(+), 51 deletions(-) diff --git a/notifications/Notifications/INotificationHandler.cs b/notifications/Notifications/INotificationHandler.cs index 3711d34..b93f8f4 100644 --- a/notifications/Notifications/INotificationHandler.cs +++ b/notifications/Notifications/INotificationHandler.cs @@ -1,19 +1,19 @@ -using DOT.AGM.Services; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System; +using DOT.AGM.Services; +using Tick42; namespace WPFApp { - [ServiceContract()] + [ServiceContract] public interface INotificationHandler : IDisposable { [ServiceOperation(AsyncIfPossible = true, ExceptionSafe = true)] - void AcceptNotification(string customerId); + void AcceptNotification(string customerId, double customerPrice); [ServiceOperation(AsyncIfPossible = true, ExceptionSafe = true)] - void RejectNotification(string customerId); + void RejectNotification(string customerId, double customerPrice); + + [ServiceOperation(AsyncIfPossible = true, ExceptionSafe = true)] + void NotificationRoutingDetail([AGMServiceOptions] IServiceOptions options = null); } -} +} \ No newline at end of file diff --git a/notifications/Notifications/MainWindow.xaml.cs b/notifications/Notifications/MainWindow.xaml.cs index 10569c6..5141e7a 100644 --- a/notifications/Notifications/MainWindow.xaml.cs +++ b/notifications/Notifications/MainWindow.xaml.cs @@ -1,11 +1,11 @@ using System; -using System.Collections.Generic; -using System.Threading.Tasks; using System.Windows; using System.Windows.Media; -using GnsDesktopManager.Model; +using DOT.Core.Extensions; using Tick42; +using Tick42.Notifications; using Tick42.Windows; +using Notification = Tick42.Notifications.Notification; namespace WPFApp { @@ -25,16 +25,23 @@ public MainWindow() UpdateUI(false); } - public void AcceptNotification(string customerId) + public void AcceptNotification(string customerId, double customerPrice) { //accept handler with notification object state - MessageBox.Show(customerId, "Accepted"); + MessageBox.Show(customerId + " price " + customerPrice, "Accepted"); } - public void RejectNotification(string customerId) + public void RejectNotification(string customerId, double customerPrice) { //reject handler with notification object state - MessageBox.Show(customerId, "Rejected"); + MessageBox.Show(customerId + " price " + customerPrice, "Rejected"); + } + + public void NotificationRoutingDetail(IServiceOptions options = null) + { + var ic = options.InvocationContext.InvocationContext; + // receiving notification object state and other service details in ic.Arguments + Console.WriteLine(ic.Arguments.AsString()); } public void Dispose() @@ -49,10 +56,10 @@ internal void RegisterGlue(Glue42 glue) //bounds are optional. With them we will just set initial placement of the application var defaultBounds = new GlueWindowBounds { - X = (int) ((SystemParameters.PrimaryScreenWidth / 2) - (Width / 2)), - Y = (int) ((SystemParameters.PrimaryScreenHeight / 2) - (Height / 2)), - Width = (int) Width, - Height = (int) Height + X = (int)((SystemParameters.PrimaryScreenWidth / 2) - (Width / 2)), + Y = (int)((SystemParameters.PrimaryScreenHeight / 2) - (Height / 2)), + Width = (int)Width, + Height = (int)Height }; var gwOptions = glue.GetStartupWindowOptions("Notification Publisher", defaultBounds); gwOptions.WithType(GlueWindowType.Tab); @@ -64,7 +71,7 @@ internal void RegisterGlue(Glue42 glue) glue.Interop.RegisterService(this); } - private void OnSendNotificationClick(object sender, RoutedEventArgs e) + private async void OnSendNotificationClick(object sender, RoutedEventArgs e) { if (glue_ == null) { @@ -72,35 +79,42 @@ private void OnSendNotificationClick(object sender, RoutedEventArgs e) return; } - //object state - var parameters = new List - { - new GlueMethodParameter("customerId", new GnsValue("11")) - }; - - var actions = new List + await glue_.Notifications.RaiseNotification(new Notification { - new GlueRoutingMethod("AcceptNotification", DisplayName: "Accept", Parameters: parameters), - new GlueRoutingMethod("RejectNotification", DisplayName: "Reject") - }; - - var notification = new DesktopNotification(Title.Text, - (NotificationSeverity) Enum.Parse(typeof(NotificationSeverity), Severity.Text), - "type", - Description.Text, - "category", - "source", - "AcceptedHandler", - actions - ); - - glue_.Notifications.Publish(notification) - .ContinueWith(r => + Title = Title.Text, + Severity = Enum.TryParse(Severity.Text, true, out var severity) + ? severity + : Tick42.Notifications.Severity.Low, + Type = NotificationType.Notification, + Category = "category", + Source = "source", + Description = Description.Text, + GlueRoutingDetailCallback = new NotificationCallback { - if (r.Status != TaskStatus.RanToCompletion) + Name = nameof(INotificationHandler.NotificationRoutingDetail), + SetTarget = c => c.WithTargetMatching(s => s.InstanceId, glue_.Identity.InstanceId), + Parameters = new object[] { new { customerId = "41234", notification = "$(this)" } }, + }, + Actions = new[] + { + new NotificationActionSettings + { + Name = nameof(INotificationHandler.AcceptNotification), + DisplayName = "Accept", + Description = "Accept", + Parameters = new object[] { new { customerId = "41234", customerPrice = 3.14 } }, + SetTarget = c => c.WithTargetMatching(s => s.InstanceId, glue_.Identity.InstanceId) + }, + new NotificationActionSettings { + Name = nameof(INotificationHandler.RejectNotification), + DisplayName = "Reject", + Description = "Reject", + Parameters = new object[] { new { customerId = "41234", customerPrice = 3.14 } }, + SetTarget = c => c.WithTargetMatching(s => s.InstanceId, glue_.Identity.InstanceId) } - }); + }, + }); } private void UpdateUI(bool isConnected) @@ -133,7 +147,7 @@ public string ConnectionStatusDescription public Brush ConnectionStatusColor { - get => (Brush) GetValue(ConnectionStatusColorProperty); + get => (Brush)GetValue(ConnectionStatusColorProperty); set => SetValue(ConnectionStatusColorProperty, value); } diff --git a/notifications/Notifications/Notifications.csproj b/notifications/Notifications/Notifications.csproj index 0980fbf..ee040e3 100644 --- a/notifications/Notifications/Notifications.csproj +++ b/notifications/Notifications/Notifications.csproj @@ -36,8 +36,8 @@ 4 - - ..\packages\Glue42.2018.2168.0.0\lib\net45\Glue42.dll + + ..\packages\io.Connect.NET.1.18.0.0\lib\net45\ioConnectNET.dll diff --git a/notifications/Notifications/packages.config b/notifications/Notifications/packages.config index eae9d41..3045e3d 100644 --- a/notifications/Notifications/packages.config +++ b/notifications/Notifications/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file