public Task <ResponseBase> Handle(HttpInformation context, SubscribeMessageCommand command,
                                          ExecutionContext executionContext)
        {
            if (!MessageTopicHelper.IsAllowedForSubscribe(command.Topic, context))
            {
                throw new UnauthorizedException("Not allowed to subscribe this topic(s)");
            }

            subscriptionManager.AddSubscription(command.Topic, command.ReferenceId, Connection);

            SapphireMessageSender.RetainedTopicMessages
            .Where(m => m.Key.MatchesGlobPattern(command.Topic))
            .ToList()
            .ForEach((retainedMessage) =>
            {
                _ = Connection.Send(new TopicResponse()
                {
                    ReferenceId = command.ReferenceId,
                    Message     = retainedMessage.Value,
                    Topic       = retainedMessage.Key
                });
            });

            return(Task.FromResult <ResponseBase>(null));
        }
Esempio n. 2
0
        public Task <ResponseBase> Handle(HttpInformation context, PublishCommand command,
                                          ExecutionContext executionContext)
        {
            if (!MessageTopicHelper.IsAllowedForPublish(command.Topic, context))
            {
                throw new UnauthorizedException("User is not allowed to publish data to this topic");
            }

            messageSender.Publish(command.Topic, command.Data, command.Retain);
            return(Task.FromResult <ResponseBase>(null));
        }