/// <summary> /// Called when the client receives an order to call a hub-function. /// </summary> void IHub.OnMethod(MethodCallMessage msg) { // Merge the newly received states with the old one MergeState(msg.State); if (OnMethodCall != null) { try { OnMethodCall(this, msg.Method, msg.Arguments); } catch(Exception ex) { HTTPManager.Logger.Exception("Hub - " + this.Name, "IHub.OnMethod - OnMethodCall", ex); } } OnMethodCallCallbackDelegate callback; if (MethodTable.TryGetValue(msg.Method, out callback) && callback != null) { try { callback(this, msg); } catch(Exception ex) { HTTPManager.Logger.Exception("Hub - " + this.Name, "IHub.OnMethod - callback", ex); } } else HTTPManager.Logger.Warning("Hub - " + this.Name, string.Format("[Client] {0}.{1} (args: {2})", this.Name, msg.Method, msg.Arguments.Length)); }
void IServerMessage.Parse(object data) { IDictionary <string, object> dic = data as IDictionary <string, object>; object value; this.MessageId = dic["C"].ToString(); if (dic.TryGetValue("S", out value)) { IsInitialization = int.Parse(value.ToString()) == 1 ? true : false; } else { IsInitialization = false; } if (dic.TryGetValue("G", out value)) { GroupsToken = value.ToString(); } if (dic.TryGetValue("T", out value)) { ShouldReconnect = int.Parse(value.ToString()) == 1 ? true : false; } else { ShouldReconnect = false; } if (dic.TryGetValue("L", out value)) { PollDelay = TimeSpan.FromMilliseconds(double.Parse(value.ToString())); } IEnumerable enumerable = dic["M"] as IEnumerable; if (enumerable != null) { Data = new List <IServerMessage>(); foreach (object subData in enumerable) { IDictionary <string, object> subObj = subData as IDictionary <string, object>; IServerMessage subMsg = null; if (subObj != null) { if (subObj.ContainsKey("H")) { subMsg = new MethodCallMessage(); } else if (subObj.ContainsKey("I")) { subMsg = new ProgressMessage(); } else { subMsg = new DataMessage(); } } else { subMsg = new DataMessage(); } subMsg.Parse(subData); Data.Add(subMsg); } } }
void IServerMessage.Parse(object data) { IDictionary<string, object> dic = data as IDictionary<string, object>; object value; this.MessageId = dic["C"].ToString(); if (dic.TryGetValue("S", out value)) IsInitialization = int.Parse(value.ToString()) == 1 ? true : false; else IsInitialization = false; if (dic.TryGetValue("G", out value)) GroupsToken = value.ToString(); if (dic.TryGetValue("T", out value)) ShouldReconnect = int.Parse(value.ToString()) == 1 ? true : false; else ShouldReconnect = false; if (dic.TryGetValue("L", out value)) PollDelay = TimeSpan.FromMilliseconds(double.Parse(value.ToString())); IEnumerable enumerable = dic["M"] as IEnumerable; if (enumerable != null) { Data = new List<IServerMessage>(); foreach (object subData in enumerable) { IDictionary<string, object> subObj = subData as IDictionary<string, object>; IServerMessage subMsg = null; if (subObj != null) { if (subObj.ContainsKey("H")) subMsg = new MethodCallMessage(); else if (subObj.ContainsKey("I")) subMsg = new ProgressMessage(); else subMsg = new DataMessage(); } else subMsg = new DataMessage(); subMsg.Parse(subData); Data.Add(subMsg); } } }
private void Invoked(Hub hub, MethodCallMessage methodCall) { messages.Add(string.Format("{0} invoked hub method at {1}", methodCall.Arguments[0], methodCall.Arguments[1])); }
private void Left(Hub hub, MethodCallMessage methodCall) { messages.Add(string.Format("{0} left at {1}", methodCall.Arguments[0], methodCall.Arguments[1])); }
private void Rejoined(Hub hub, MethodCallMessage methodCall) { messages.Add(string.Format("{0} reconnected at {1}", methodCall.Arguments[0], methodCall.Arguments[1])); }
private void Joined(Hub hub, MethodCallMessage methodCall) { Dictionary<string, object> AuthInfo = methodCall.Arguments[2] as Dictionary<string, object>; messages.Add(string.Format("{0} joined at {1}\n\tIsAuthenticated: {2} IsAdmin: {3} UserName: {4}", methodCall.Arguments[0], methodCall.Arguments[1], AuthInfo["IsAuthenticated"], AuthInfo["IsAdmin"], AuthInfo["UserName"])); }