示例#1
0
        public static IServerMessage Parse(IJsonEncoder encoder, string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                HTTPManager.Logger.Error("MessageFactory", "Parse - called with empty or null string!");
                return(null);
            }
            if (json.Length == 2 && json == "{}")
            {
                return(new KeepAliveMessage());
            }
            IDictionary <string, object> dictionary = null;

            try
            {
                dictionary = encoder.DecodeMessage(json);
            }
            catch (Exception ex)
            {
                HTTPManager.Logger.Exception("MessageFactory", "Parse - encoder.DecodeMessage", ex);
                return(null);

                IL_006f :;
            }
            if (dictionary == null)
            {
                HTTPManager.Logger.Error("MessageFactory", "Parse - Json Decode failed for json string: \"" + json + "\"");
                return(null);
            }
            IServerMessage serverMessage = null;

            serverMessage = (IServerMessage)(dictionary.ContainsKey("C") ? new MultiMessage() : (dictionary.ContainsKey("E") ? ((object)new FailureMessage()) : ((object)new ResultMessage())));
            serverMessage.Parse(dictionary);
            return(serverMessage);
        }
示例#2
0
        void IServerMessage.Parse(object data)
        {
            IDictionary <string, object> dictionary = data as IDictionary <string, object>;

            MessageId = dictionary["C"].ToString();
            if (dictionary.TryGetValue("S", out object value))
            {
                IsInitialization = ((int.Parse(value.ToString()) == 1) ? true : false);
            }
            else
            {
                IsInitialization = false;
            }
            if (dictionary.TryGetValue("G", out value))
            {
                GroupsToken = value.ToString();
            }
            if (dictionary.TryGetValue("T", out value))
            {
                ShouldReconnect = ((int.Parse(value.ToString()) == 1) ? true : false);
            }
            else
            {
                ShouldReconnect = false;
            }
            if (dictionary.TryGetValue("L", out value))
            {
                PollDelay = TimeSpan.FromMilliseconds(double.Parse(value.ToString()));
            }
            IEnumerable enumerable = dictionary["M"] as IEnumerable;

            if (enumerable != null)
            {
                Data = new List <IServerMessage>();
                foreach (object item in enumerable)
                {
                    IDictionary <string, object> dictionary2 = item as IDictionary <string, object>;
                    IServerMessage serverMessage             = null;
                    serverMessage = ((dictionary2 == null) ? new DataMessage() : ((!dictionary2.ContainsKey("H")) ? ((!dictionary2.ContainsKey("I")) ? ((IServerMessage) new DataMessage()) : ((IServerMessage) new ProgressMessage())) : new MethodCallMessage()));
                    serverMessage.Parse(item);
                    Data.Add(serverMessage);
                }
            }
        }