コード例 #1
0
        public void CallJSMethod(SocketResponseModel model)
        {
            var _UserId   = System.Web.HttpContext.Current.User.Identity.GetUserId();
            var allUsers  = _chatClients.Select(x => ((WebSocketEventHandler)x)).Where(m => m.UserId != _UserId).ToList();
            var receivers = allUsers.Select(m => m.UserId).Distinct().ToList();

            allUsers.ForEach(client =>
            {
                var data = Functions.EncodeTo64UTF8(Newtonsoft.Json.JsonConvert.SerializeObject(model));
                client.Send(data);
            });

            var otherServerUsers = allUsers
                                   .Where(m => !string.IsNullOrEmpty(m.ServerUrl))
                                   .Select(m => new { m.ServerUrl })
                                   .Distinct()
                                   .ToList();

            try
            {
                otherServerUsers.ForEach(s =>
                {
                    var sendRequest = new SocketSendRequestModel {
                        Recievers = receivers, ResponseModel = model
                    };
                    var postData = Newtonsoft.Json.JsonConvert.SerializeObject(sendRequest);
                    var url      = s.ServerUrl + "/RpcHandler/CallJsMethod?SignalRAuthKey=" + Settings.SignalRAuthKey;
                    var response = scrapper.GetData(url, "POST", postData, ContentTypes.Json);
                });
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
            }
        }
コード例 #2
0
        public void CallJSMethod(string reciever, SocketResponseModel model)
        {
            var list = new List <string>()
            {
                reciever
            }.Distinct().ToList();

            CallJSMethod(list, model);
        }