Skip to content

Commit

Permalink
Notifications API - io.Connect.NET - .net framework demo
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-peichev committed Aug 12, 2024
1 parent 1207e79 commit 51ba66f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 51 deletions.
20 changes: 10 additions & 10 deletions notifications/Notifications/INotificationHandler.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
90 changes: 52 additions & 38 deletions notifications/Notifications/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -64,43 +71,50 @@ internal void RegisterGlue(Glue42 glue)
glue.Interop.RegisterService<INotificationHandler>(this);
}

private void OnSendNotificationClick(object sender, RoutedEventArgs e)
private async void OnSendNotificationClick(object sender, RoutedEventArgs e)
{
if (glue_ == null)
{
//glue is not initialized
return;
}

//object state
var parameters = new List<GlueMethodParameter>
{
new GlueMethodParameter("customerId", new GnsValue("11"))
};

var actions = new List<GlueRoutingMethod>
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>(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)
Expand Down Expand Up @@ -133,7 +147,7 @@ public string ConnectionStatusDescription

public Brush ConnectionStatusColor
{
get => (Brush) GetValue(ConnectionStatusColorProperty);
get => (Brush)GetValue(ConnectionStatusColorProperty);
set => SetValue(ConnectionStatusColorProperty, value);
}

Expand Down
4 changes: 2 additions & 2 deletions notifications/Notifications/Notifications.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Glue42, Version=2018.2168.0.0, Culture=neutral, PublicKeyToken=dbb353f1544d18d3, processorArchitecture=MSIL">
<HintPath>..\packages\Glue42.2018.2168.0.0\lib\net45\Glue42.dll</HintPath>
<Reference Include="ioConnectNET, Version=1.18.0.0, Culture=neutral, PublicKeyToken=dbb353f1544d18d3, processorArchitecture=MSIL">
<HintPath>..\packages\io.Connect.NET.1.18.0.0\lib\net45\ioConnectNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
Expand Down
2 changes: 1 addition & 1 deletion notifications/Notifications/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Glue42" version="2018.2168.0.0" targetFramework="net45" />
<package id="io.Connect.NET" version="1.18.0.0" targetFramework="net45" />
</packages>

0 comments on commit 51ba66f

Please sign in to comment.