Пример #1
0
        public object Any(PostChatToChannel request)
        {
            // Ensure the subscription sending this notification is still active
            var sub = ServerEvents.GetSubscriptionInfo(request.From);

            if (sub == null)
            {
                throw HttpError.NotFound("Subscription {0} does not exist".Fmt(request.From));
            }

            var channel = request.Channel;

            // Create a DTO ChatMessage to hold all required info about this message
            var msg = new ChatMessage
            {
                Id         = ChatHistory.GetNextMessageId(channel),
                Channel    = request.Channel,
                FromUserId = sub.UserId,
                FromName   = sub.DisplayName,
                Message    = request.Message,
            };

            // Check to see if this is a private message to a specific user
            if (request.ToUserId != null)
            {
                // Mark the message as private so it can be displayed differently in Chat
                msg.Private = true;
                // Send the message to the specific user Id
                ServerEvents.NotifyUserId(request.ToUserId, request.Selector, msg);

                // Also provide UI feedback to the user sending the private message so they
                // can see what was sent. Relay it to all senders active subscriptions
                var toSubs = ServerEvents.GetSubscriptionInfosByUserId(request.ToUserId);
                foreach (var toSub in toSubs)
                {
                    // Change the message format to contain who the private message was sent to
                    msg.Message = "@{0}: {1}".Fmt(toSub.DisplayName, msg.Message);
                    ServerEvents.NotifySubscription(request.From, request.Selector, msg);
                }
            }
            else
            {
                // Notify everyone in the channel for public messages
                ServerEvents.NotifyChannel(request.Channel, request.Selector, msg);
            }

            if (!msg.Private)
            {
                ChatHistory.Log(channel, msg);
            }

            return(msg);
        }
        public NotifyResponse Post(NotifySubscriptionRequest request)
        {
            NotifyResponse res = new NotifyResponse();

            try
            {
                Console.WriteLine("Reached in NotifySubscriptionRequest");
                SubscriptionInfo subscriptionInfos = ServerEvents.GetSubscriptionInfo(request.ToSubscriptionId);
                if (subscriptionInfos != null)
                {
                    if (!String.IsNullOrEmpty(subscriptionInfos.SubscriptionId))
                    {
                        Console.WriteLine("SubscriptionId :" + subscriptionInfos.SubscriptionId);
                        if (request.ToChannel == null)
                        {
                            ServerEvents.NotifySubscription(subscriptionInfos.SubscriptionId, request.Selector, request.Msg);
                        }
                        else
                        {
                            foreach (string channel in request.ToChannel)
                            {
                                ServerEvents.NotifySubscription(subscriptionInfos.SubscriptionId, request.Selector, request.Msg, channel);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("SubscriptionId doesn't Exist");
                        res.ResponseStatus.Message = "SubscriptionId doesn't Exist";
                    }
                }
                else
                {
                    Console.WriteLine("subscriptionInfos Is Null");
                    res.ResponseStatus.Message = "subscriptionInfos Is Null";
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + e.StackTrace);
                res.ResponseStatus.Message = e.Message;
            }
            return(res);
        }
        public NotifyResponse Post(NotifyUserIdRequest request)
        {
            Console.WriteLine("---------------------->Inside notifyUserIdReq \nUserId: " + request.ToUserAuthId);
            NotifyResponse res = new NotifyResponse();

            try
            {
                if (request.Selector == "cmd.onNotification")
                {
                    this.MessageProducer3.Publish(new NotificationToDBRequest()
                    {
                        SolnId         = request.SolnId,
                        UserId         = request.UserId,
                        NotifyUserId   = request.NotifyUserId,
                        Notification   = request.Msg,
                        NotificationId = request.NotificationId
                    });
                    Console.WriteLine("---------------------->After NotificationToDBRequest UserId: " + request.ToUserAuthId);
                }
                Console.WriteLine("request.Selector" + request.Selector + "------------No NotificationToDBRequest----------> UserId: " + request.ToUserAuthId);
                List <SubscriptionInfo> subscriptionInfos = ServerEvents.GetSubscriptionInfosByUserId(request.ToUserAuthId);

                foreach (SubscriptionInfo sub in subscriptionInfos)
                {
                    if (request.ToChannel == null)
                    {
                        ServerEvents.NotifySubscription(sub.SubscriptionId, request.Selector, request.Msg);
                    }
                    else
                    {
                        foreach (string channel in request.ToChannel)
                        {
                            ServerEvents.NotifySubscription(sub.SubscriptionId, request.Selector, request.Msg, channel);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + e.StackTrace);
                res.ResponseStatus.Message = e.Message;
            }
            return(res);
        }