示例#1
0
        private async Task SendToGroup <T>(T message, Constants.Enums.MessageReponseKey action, string groupName, bool isMySelf = false)
        {
            if (!string.IsNullOrEmpty(groupName))
            {
                HubResponse <T> result = new HubResponse <T>()
                {
                    IsSucceed   = true,
                    Data        = message,
                    ResponseKey = GetResponseKey(action)
                };

                if (isMySelf)
                {
                    await Clients.Group(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None));
                }
                else
                {
                    await Clients.OthersInGroup(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None));
                }
            }
            else
            {
                await SendToCaller(Constants.HubMessages.UnknowErrorMsg, Constants.Enums.MessageReponseKey.Error);
            }
        }
示例#2
0
        private Task SendToConnection <T>(T message, Constants.Enums.MessageReponseKey action, string connectionId, bool isMySelf)
        {
            if (!string.IsNullOrEmpty(connectionId))
            {
                HubResponse <T> result = new HubResponse <T>()
                {
                    IsSucceed   = true,
                    Data        = message,
                    ResponseKey = GetResponseKey(action)
                };

                if (isMySelf)
                {
                    return(Clients.Client(connectionId).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result)));
                }
                else
                {
                    return(Clients.OthersInGroup(connectionId).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result)));
                }
            }
            else
            {
                return(SendToCaller(Constants.HubMessages.UnknowErrorMsg, Constants.Enums.MessageReponseKey.Error));
            }
        }
示例#3
0
 private async Task SendToCaller <T>(T message, Constants.Enums.MessageReponseKey action)
 {
     HubResponse <T> result = new HubResponse <T>()
     {
         IsSucceed   = true,
         Data        = message,
         ResponseKey = GetResponseKey(action)
     };
     await Clients.Caller.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None));
 }
示例#4
0
        private void SendToCaller <T>(T message, Constants.Enums.MessageReponseKey action)
        {
            HubResponse <T> result = new HubResponse <T>()
            {
                IsSucceed   = true,
                Data        = message,
                ResponseKey = GetResponseKey(action)
            };

            Clients.Caller.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result));
        }
示例#5
0
        private void SendToAll <T>(T message, Constants.Enums.MessageReponseKey action, bool isMySelf)
        {
            HubResponse <T> result = new HubResponse <T>()
            {
                IsSucceed   = true,
                Data        = message,
                ResponseKey = GetResponseKey(action)
            };

            if (isMySelf)
            {
                Clients.All.SendAsync(Constants.HubMethods.ReceiveMethod, result);
            }
            else
            {
                Clients.Others.SendAsync(Constants.HubMethods.ReceiveMethod, result);
            }
        }
示例#6
0
        private async Task SendToAll <T>(T message, Constants.Enums.MessageReponseKey action, bool isMySelf)
        {
            HubResponse <T> result = new HubResponse <T>()
            {
                IsSucceed   = true,
                Data        = message,
                ResponseKey = GetResponseKey(action)
            };

            if (isMySelf)
            {
                await Clients.All.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None));
            }
            else
            {
                await Clients.Others.SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result).ToString(Newtonsoft.Json.Formatting.None));
            }
        }
示例#7
0
        private void SendToGroup <T>(T message, Constants.Enums.MessageReponseKey action, string groupName, bool isMySelf)
        {
            if (!string.IsNullOrEmpty(groupName))
            {
                HubResponse <T> result = new HubResponse <T>()
                {
                    IsSucceed   = true,
                    Data        = message,
                    ResponseKey = GetResponseKey(action)
                };

                if (isMySelf)
                {
                    Clients.Group(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result));
                }
                else
                {
                    Clients.OthersInGroup(groupName).SendAsync(Constants.HubMethods.ReceiveMethod, JObject.FromObject(result));
                }
            }
        }