public void SendNotification(object payload, string receiverConnectionId)
        {
            var dataNotification = new RawJsonNotification
            {
                EmbeddedType = payload.GetType().ToString(),
                JsonPayload  = JsonSerializer.Serialize(payload)
            };

            this.SendNotification(dataNotification, receiverConnectionId);
        }
        public void SendNotification(string type, string jsonSerializedPayload, string receiverConnectionId)
        {
            var dataNotification = new RawJsonNotification
            {
                EmbeddedType = type,
                JsonPayload  = jsonSerializedPayload
            };

            this.SendNotification(dataNotification, receiverConnectionId);
        }
        public void BroadcastNotification(string type, string jsonSerializedPayload)
        {
            var dataNotification = new RawJsonNotification
            {
                EmbeddedType = type,
                JsonPayload  = jsonSerializedPayload
            };

            this.BroadcastNotification(dataNotification);
        }
        public void BroadcastNotification(object payload)
        {
            var dataNotification = new RawJsonNotification
            {
                EmbeddedType = payload.GetType().ToString(),
                JsonPayload  = JsonSerializer.Serialize(payload)
            };

            this.BroadcastNotification(dataNotification);
        }
 public void SendNotification(RawJsonNotification payload, string receiverConnectionId)
 {
     this._pushNotificationSender.SendRemoteDataNotification(payload, receiverConnectionId);
 }
 public void BroadcastNotification(RawJsonNotification payload)
 {
     this._pushNotificationSender.BroadcastRemoteDataNotification(payload);
 }
        public void OnDataNotification(RawJsonNotification rawJsonNotification)
        {
            if (rawJsonNotification.EmbeddedType == null || string.IsNullOrEmpty(rawJsonNotification.JsonPayload))
            {
                return;
            }

            string typeString;

            if (rawJsonNotification.EmbeddedType.Contains(',') || string.IsNullOrEmpty(this._config.DefaultTypeSearchAssembly))
            {
                typeString = rawJsonNotification.EmbeddedType;
            }
            else
            {
                typeString = $"{rawJsonNotification.EmbeddedType}, {this._config.DefaultTypeSearchAssembly}";
            }

            var embeddedType = Type.GetType(typeString, false);

            if (embeddedType == null)
            {
                Console.WriteLine($"Unable to load embedded type from string '{typeString}'. Could not process data notification.");
                return;
            }

            dynamic?payloadObject = JsonSerializer.Deserialize(rawJsonNotification.JsonPayload, embeddedType);

            if (payloadObject == null)
            {
                return;
            }

            if (this.NotificationCallbackRegister.TryGetValue(embeddedType, out var registeredSubscriptions))
            {
                foreach (var subscription in registeredSubscriptions)
                {
                    if (string.IsNullOrEmpty(subscription.TopicFilter) || subscription.TopicFilter == rawJsonNotification.TopicIdentifier)
                    {
                        var callbackObject = subscription.SubscriptionAction;

                        var    actionType               = typeof(Action <>);
                        Type[] actionTypeArgs           = { embeddedType };
                        var    genericActionType        = actionType.MakeGenericType(actionTypeArgs);
                        var    actualCallbackObjectType = callbackObject.GetType();
                        if (actualCallbackObjectType == genericActionType)
                        {
                            dynamic callback = callbackObject;
                            try
                            {
                                callback.Invoke(payloadObject);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"There was an exception while executing the registered callback of the data notification: {ex}/{ex.Message}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($"Registered callback for notification is not of expected type {genericActionType} and thus cannot be executed (actual type: {actualCallbackObjectType}).");
                        }
                    }
                    //else
                    //{
                    //    Console.WriteLine($"Subscription {subscription.SubscriptionIdentifier} has configured filter {subscription.TopicFilter} which does not match the topic of the notification {rawJsonNotification.TopicIdentifier}");
                    //}
                }
            }
            //else
            //{
            //    Console.WriteLine($"No active subscriptions found for payload type '{typeString}'");
            //}
        }