public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            JavaScriptSerializer        serializer       = new JavaScriptSerializer();
            Dictionary <string, object> deserializedJSON = serializer.Deserialize <Dictionary <string, object> >(Json);

            Type classType = typeof(ClientSystemStatesNotification);

            foreach (KeyValuePair <string, object> keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                if (f == null)
                {
                    Client.Log("New Client System State: " + keyPair.Key);
                    continue;
                }
                if (keyPair.Value.GetType() == typeof(ArrayList))
                {
                    ArrayList tempArrayList = keyPair.Value as ArrayList;
                    if (tempArrayList.Count > 0)
                    {
                        f.SetValue(this, tempArrayList.ToArray(f.PropertyType.GetElementType()));
                    }
                    else
                    {
                        f.SetValue(this, null);
                    }
                }
                else
                {
                    f.SetValue(this, keyPair.Value);
                }
            }
        }
Example #2
0
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            Dictionary <string, object> deserializedJSON = JsonConvert.DeserializeObject <Dictionary <string, object> >(Json);

            var classType = typeof(ClientSystemStatesNotification);

            foreach (var keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                if (f == null)
                {
                    //Client.Log("New Client System State: " + keyPair.Key);
                    continue;
                }
                if (keyPair.Value.GetType() == typeof(ArrayList))
                {
                    var tempArrayList = keyPair.Value as ArrayList;
                    if (tempArrayList != null && tempArrayList.Count > 0)
                    {
                        f.SetValue(this, tempArrayList.ToArray(f.PropertyType.GetElementType()));
                    }
                    else
                    {
                        f.SetValue(this, null);
                    }
                }
                else
                {
                    f.SetValue(this, keyPair.Value);
                }
            }
        }
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            var json   = JSONParser.ParseObject(Json, 0);
            var states = JSONDeserializer.Deserialize <ClientSystemStatesNotification>(json);

            foreach (PropertyInfo prop in typeof(ClientSystemStatesNotification).GetProperties())
            {
                prop.SetValue(this, prop.GetValue(states));
            }
            //foreach (KeyValuePair<string, object> keyPair in json) {
            //  var f = typeof(ClientSystemStatesNotification).GetProperty(keyPair.Key);
            //  if (f == null) continue;
            //  if (keyPair.Value is MFroehlich.Parsing.JSON.JSONArray) {
            //    var tempArrayList = keyPair.Value as MFroehlich.Parsing.JSON.JSONArray;
            //    if (tempArrayList.Count > 0) {
            //      var array = Array.CreateInstance(f.PropertyType.GetElementType(), tempArrayList.Count);
            //      for (int i = 0; i < tempArrayList.Count; i++) array.SetValue(tempArrayList[i], i);
            //      f.SetValue(this, array);
            //    } else
            //      f.SetValue(this, null);
            //  } else {
            //    f.SetValue(this, (dynamic) keyPair.Value);
            //  }
            //}
        }
    public void ReadExternal(IDataInput input) {
      Json = input.ReadUtf((int) input.ReadUInt32());

      var json = JSONParser.ParseObject(Json, 0);

      if (json.ContainsKey("broadcastMessages")) {

        BroadcastMessages = JSONDeserializer.Deserialize<List<BroadcastMessage>>(json["broadcastMessages"]);
      }
    }
        public void ReadExternal(IDataInput input)
        {
            this.Json = input.ReadUtf((int)input.ReadUInt32());
            Dictionary <string, object> dictionary = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(this.Json);
            Type type = typeof(BroadcastNotification);

            foreach (KeyValuePair <string, object> keyValuePair in dictionary)
            {
                type.GetProperty(keyValuePair.Key).SetValue((object)this, keyValuePair.Value);
            }
        }
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            var json = JSONParser.ParseObject(Json);

            if (json.ContainsKey("broadcastMessages"))
            {
                BroadcastMessages = JSONDeserializer.Deserialize <List <BroadcastMessage> >(json["broadcastMessages"]);
            }
        }
Example #7
0
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            var json   = JSONParser.ParseObject(Json);
            var states = JSONDeserializer.Deserialize <ClientSystemStatesNotification>(json);

            foreach (PropertyInfo prop in typeof(ClientSystemStatesNotification).GetProperties())
            {
                prop.SetValue(this, prop.GetValue(states));
            }
        }
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            JavaScriptSerializer        serializer       = new JavaScriptSerializer();
            Dictionary <string, object> deserializedJSON = serializer.Deserialize <Dictionary <string, object> >(Json);

            Type classType = typeof(ClientSystemStatesNotification);

            foreach (KeyValuePair <string, object> keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                if (keyPair.Value.GetType() == typeof(ArrayList))
                {
                    ArrayList tempArrayList = keyPair.Value as ArrayList;

                    if (tempArrayList.Count > 0)
                    {
                        if (Type.GetTypeCode(tempArrayList[0].GetType()) == TypeCode.Int32)
                        {
                            f.SetValue(this, (((ArrayList)keyPair.Value).ToArray(tempArrayList[0].GetType())).Cast <Int32>().ToArray());
                        }
                        else
                        {
                            f.SetValue(this, ((ArrayList)keyPair.Value).ToArray(tempArrayList[0].GetType()));
                        }
                    }
                    else
                    {
                        f.SetValue(this, null);
                    }

                    /*
                     * ArrayList tempArrayList = keyPair.Value as ArrayList;
                     * if (tempArrayList.Count > 0)
                     * {
                     *  Type tempArrayListType = tempArrayList[0].GetType();
                     *  if (tempArrayListType == typeof(Int32))
                     *      Int32[] arr = ((ArrayList)keyPair.Value).ToArray(tempArrayListType).Cast<Int32>().ToArray();
                     *  int[] arr = objarr.Cast<int>().ToArray();
                     *
                     *  f.SetValue(this, arrayList.ToArray(typeof(object)));
                     * }
                     * else
                     *  f.SetValue(this, null);
                     */
                }
                else
                {
                    f.SetValue(this, keyPair.Value);
                }
            }
        }
        public void ReadExternal(IDataInput input)
        {
            this.Json = input.ReadUtf((int)input.ReadUInt32());
            Dictionary <string, object> deserializedJSON = JsonConvert.DeserializeObject <Dictionary <string, object> >(this.Json);
            Type classType = typeof(BroadcastNotification);

            foreach (KeyValuePair <string, object> keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                //f.SetValue(this, keyPair.Value);
            }
        }
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(Json);

            Type classType = typeof(BroadcastNotification);
            foreach (KeyValuePair<string, object> keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                f.SetValue(this, keyPair.Value);
            }
        }
Example #11
0
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            JavaScriptSerializer        serializer       = new JavaScriptSerializer();
            Dictionary <string, object> deserializedJSON = serializer.Deserialize <Dictionary <string, object> >(Json);

            Type classType = typeof(BroadcastNotification);

            foreach (KeyValuePair <string, object> keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                f.SetValue(this, keyPair.Value);
            }
        }
Example #12
0
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            JavaScriptSerializer        serializer       = new JavaScriptSerializer();
            Dictionary <string, object> deserializedJSON = serializer.Deserialize <Dictionary <string, object> >(Json);

            Type classType = typeof(ClientSystemStatesNotification);

            foreach (KeyValuePair <string, object> keyPair in deserializedJSON)
            {
                try
                {
                    var f = classType.GetProperty(keyPair.Key);
                    if (f == null)
                    {
                        continue;
                    }

                    if (keyPair.Value.GetType() == typeof(ArrayList))
                    {
                        ArrayList tempArrayList = keyPair.Value as ArrayList;
                        if (tempArrayList.Count > 0)
                        {
                            f.SetValue(this, ((ArrayList)keyPair.Value).ToArray(tempArrayList[0].GetType()));
                        }
                        else
                        {
                            f.SetValue(this, null);
                        }
                    }
                    else
                    {
                        f.SetValue(this, keyPair.Value);
                    }
                }
                catch (Exception e) { Console.WriteLine("Error: {0}", e); }
            }
        }
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            Dictionary <string, object> deserializedJSON = JsonConvert.DeserializeObject <Dictionary <string, object> >(Json);

            Type classType = typeof(ClientSystemStatesNotification);

            foreach (KeyValuePair <string, object> keyPair in deserializedJSON)
            {
                var  f         = classType.GetProperty(keyPair.Key);
                Type valueType = keyPair.Value.GetType();
                if (valueType == typeof(JArray))
                {
                    JArray myValue = (JArray)keyPair.Value;

                    if (myValue.Count == 0) //If the array is empty don't try parsing
                    {
                        continue;
                    }

                    if (myValue[0].GetType() != typeof(JValue)) //Don't parse complex arrays
                    {
                        f.SetValue(this, keyPair.Value);
                        continue;
                    }

                    JValue x               = (JValue)myValue[0];
                    Type   listType        = x.Value.GetType();
                    Type   genericListType = typeof(List <>).MakeGenericType(listType);

                    f.SetValue(this, myValue.ToObject(genericListType));
                }
                else
                {
                    f.SetValue(this, keyPair.Value);
                }
            }
        }
Example #14
0
        public void ReadExternal(IDataInput input)
        {
            this.Json = input.ReadUtf((int)input.ReadUInt32());
            Dictionary <string, object> dictionary = new JavaScriptSerializer().Deserialize <Dictionary <string, object> >(this.Json);
            Type type = typeof(ClientSystemStatesNotification);

            foreach (KeyValuePair <string, object> keyValuePair in dictionary)
            {
                try
                {
                    PropertyInfo property = type.GetProperty(keyValuePair.Key);
                    if (!(property == (PropertyInfo)null))
                    {
                        if (keyValuePair.Value.GetType() == typeof(ArrayList))
                        {
                            ArrayList arrayList = keyValuePair.Value as ArrayList;
                            if (arrayList != null && arrayList.Count > 0)
                            {
                                property.SetValue((object)this, (object)((ArrayList)keyValuePair.Value).ToArray(arrayList[0].GetType()));
                            }
                            else
                            {
                                property.SetValue((object)this, (object)null);
                            }
                        }
                        else
                        {
                            property.SetValue((object)this, keyValuePair.Value);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: {0}", (object)ex);
                }
            }
        }
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(Json);

            Type classType = typeof(ClientSystemStatesNotification);
            foreach (KeyValuePair<string, object> keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                if (keyPair.Value.GetType() == typeof(ArrayList))
                {
                    ArrayList tempArrayList = keyPair.Value as ArrayList;

                    if (tempArrayList.Count > 0)
                    {
                        if (Type.GetTypeCode(tempArrayList[0].GetType()) == TypeCode.Int32)
                            f.SetValue(this, (((ArrayList)keyPair.Value).ToArray(tempArrayList[0].GetType())).Cast<Int32>().ToArray());
                        else
                            f.SetValue(this, ((ArrayList)keyPair.Value).ToArray(tempArrayList[0].GetType()));
                    }
                    else
                        f.SetValue(this, null);
                    
                    /*
                    ArrayList tempArrayList = keyPair.Value as ArrayList;
                    if (tempArrayList.Count > 0)
                    {
                        Type tempArrayListType = tempArrayList[0].GetType();
                        if (tempArrayListType == typeof(Int32))
                            Int32[] arr = ((ArrayList)keyPair.Value).ToArray(tempArrayListType).Cast<Int32>().ToArray();
                        int[] arr = objarr.Cast<int>().ToArray();

                        f.SetValue(this, arrayList.ToArray(typeof(object)));
                    }
                    else
                        f.SetValue(this, null);
                     */
                }
                else
                {
                    f.SetValue(this, keyPair.Value);
                }
            }
        }
 public void ReadExternal(IDataInput input)
 {
     Json = input.ReadUtf((int)input.ReadUInt32());
 }
    public void ReadExternal(IDataInput input) {
      Json = input.ReadUtf((int) input.ReadUInt32());

      var json = JSONParser.ParseObject(Json, 0);
      var states = JSONDeserializer.Deserialize<ClientSystemStatesNotification>(json);
      foreach (PropertyInfo prop in typeof(ClientSystemStatesNotification).GetProperties()) {
        prop.SetValue(this, prop.GetValue(states));
      }
      //foreach (KeyValuePair<string, object> keyPair in json) {
      //  var f = typeof(ClientSystemStatesNotification).GetProperty(keyPair.Key);
      //  if (f == null) continue;
      //  if (keyPair.Value is MFroehlich.Parsing.JSON.JSONArray) {
      //    var tempArrayList = keyPair.Value as MFroehlich.Parsing.JSON.JSONArray;
      //    if (tempArrayList.Count > 0) {
      //      var array = Array.CreateInstance(f.PropertyType.GetElementType(), tempArrayList.Count);
      //      for (int i = 0; i < tempArrayList.Count; i++) array.SetValue(tempArrayList[i], i);
      //      f.SetValue(this, array);
      //    } else
      //      f.SetValue(this, null);
      //  } else {
      //    f.SetValue(this, (dynamic) keyPair.Value);
      //  }
      //}
    }
        public void ReadExternal(IDataInput input)
        {
            Json = input.ReadUtf((int)input.ReadUInt32());

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Dictionary<string, object> deserializedJSON = serializer.Deserialize<Dictionary<string, object>>(Json);

            Type classType = typeof(ClientSystemStatesNotification);
            foreach (KeyValuePair<string, object> keyPair in deserializedJSON)
            {
                var f = classType.GetProperty(keyPair.Key);
                if (f == null)
                {
                    Client.Log("New Client System State: " + keyPair.Key);
                    continue;
                }
                if (keyPair.Value.GetType() == typeof(ArrayList))
                {
                    ArrayList tempArrayList = keyPair.Value as ArrayList;
                    if (tempArrayList.Count > 0)
                        f.SetValue(this, tempArrayList.ToArray(f.PropertyType.GetElementType()));
                    else
                        f.SetValue(this, null);
                }
                else
                {
                    f.SetValue(this, keyPair.Value);
                }
            }
        }