To Create a Custom Destination Type
In MYOB Advanced or an MYOB Advanced Framework-based application, you can send push notifications to the notification destinations, which can be of a predefined type (which is webhook, message queue, SignalR hub, commerce push destination) or of a custom type, which you can implement in the code of the application.
The notification destination of a custom type can be implemented in a project of your MYOB Advanced extension library. To create a custom destination, follow the instructions in this topic.
To Create a Custom Destination Type
- In a project of your MYOB Advanced extension library, define a class that implements the PX.PushNotifications.NotificationSenders.IPushNotificationSender interface, which is a sender of push notifications.
- In the class that implements the IPushNotificationSender
interface, implement the following methods and properties of the interface:
- The Address property, which is the address to which
the system should send notifications. A user specifies the value of this
property in the Address box on the Push Notifications (SM302000) form. The property uses the following
syntax.
string Address { get; }
- The Name property, which is the name of the
notification destination. A user specifies the value of this property in
the Destination Name box on the Push Notifications (SM302000) form. Use the following syntax for the
property.
string Name { get; }
- The Send method, which sends a notification
synchronously and uses as the parameters the notification to be sent and
a cancellation token. The method uses the following
syntax.
void Send( NotificationResultWrapper results, CancellationToken cancellationToken );
- The SendAndForget method, which sends a notification
without blocking the current thread. We recommend that you use
HostingEnvironment.QueueBackgroundWorkItem in the
method implementation to delegate the execution to a parallel thread.
The following code shows a sample implementation of the
method.
using System; using System.Threading; using PX.PushNotifications; using PX.PushNotifications.NotificationSenders; public void SendAndForget( NotificationResultWrapper result, CancellationToken cancellationToken, Action onSendingFailed, Action finalizer) { try { Send(result, cancellationToken); } catch (Exception e) { onSendingFailed($"Send to target {Name} failed: ({e.Message})"); } finally { finalizer(); } }
- The Address property, which is the address to which
the system should send notifications. A user specifies the value of this
property in the Address box on the Push Notifications (SM302000) form. The property uses the following
syntax.
- Define a class that implements the PX.PushNotifications.NotificationSenders.IPushNotificationSenderFactory interface, which creates a sender of push notifications.
- In the class that implements the
IPushNotificationSenderFactory interface, implement the
following methods and properties of the interface:
- The Create method, which creates a sender and uses as
the parameters the destination address, the name of the notification
destination, and the additional parameters (such as a header for an HTTP
address). Use the following syntax for the
method.
IPushNotificationSender Create( string address, string name, IDictionary<string, object> additionalParameters );
- The Type property, which is a
string
identifier of the destination type that is exactly four characters long. The value of this property is stored in the database. The property uses the following syntax.string Type { get; }
- The TypeDescription property, which is a
string
label of the destination type. A user selects the value of this property in the Destination Type box on the Push Notifications (SM302000) form. Use the following syntax for the property.string TypeDescription { get; }
- The Create method, which creates a sender and uses as
the parameters the destination address, the name of the notification
destination, and the additional parameters (such as a header for an HTTP
address). Use the following syntax for the
method.
- Build the project of your MYOB Advanced extension library.
- Run MYOB Advanced and test the new destination type.