/// <summary> /// Fill the SlotCollection object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> public override void Fill(JsonMessage message) { var jsonArray = JArray.Parse(message.Value.ToString()); foreach (var token in jsonArray) { if (!token.HasValues) { continue; } var slot = new Slot(); var propertySetter = new MessagePropertySetter(slot); foreach (var prop in JObject.Parse(token.ToString()).Properties()) { propertySetter.SetProperty(prop); } Add(slot); } SetMessageValues(message); foreach (var slot in this) { slot.SlotOptions.SetMessageValues(message); } }
/// <summary> /// Fill the UnitCollection object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> public override void Fill(JsonMessage message) { var jsonArray = JArray.Parse(message.Value.ToString()); foreach (var token in jsonArray) { if (!token.HasValues) { continue; } JObject jObject; using (var reader = (JsonReader) new JsonTextReader(new StringReader(token.ToString()))) { reader.DateParseHandling = DateParseHandling.None; jObject = JObject.Load(reader); } var unit = new Unit(); var propertySetter = new MessagePropertySetter(unit); foreach (var prop in jObject.Properties()) { propertySetter.SetProperty(prop); } Add(unit); } SetMessageValues(message); }
/// <summary> /// Fill the Info object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> public override void Fill(JsonMessage message) { Debug.Assert(message != null); var propertySetter = new MessagePropertySetter(this); foreach (var token in JArray.Parse(message.Value.ToString())) { if (!token.HasValues) { continue; } object clientInfoProperty = propertySetter.GetPropertyValue((string)token[0]); if (clientInfoProperty != null) { var innerPropertySetter = new MessagePropertySetter(clientInfoProperty); foreach (var innerToken in token) { if (!innerToken.HasValues) { continue; } if (innerToken.Values().Count() >= 2) { innerPropertySetter.SetProperty((string)innerToken[0], (string)innerToken[1]); } } } } SetMessageValues(message); }
/// <summary> /// Fill the Info object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> internal override void Fill(JsonMessage message) { Debug.Assert(message != null); var propertySetter = new MessagePropertySetter(this); foreach (var token in JArray.Parse(message.Value.ToString())) { if (!token.HasValues) { continue; } object clientInfoProperty = propertySetter.GetPropertyValue((string)token[0]); if (clientInfoProperty != null) { var innerPropertySetter = new MessagePropertySetter(clientInfoProperty); foreach (var innerToken in token) { if (!innerToken.HasValues) { continue; } if (innerToken.Values().Count() >= 2) { innerPropertySetter.SetProperty((string)innerToken[0], (string)innerToken[1]); } } } } SetMessageValues(message); }
/// <summary> /// Fill the SlotCollection object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> internal override void Fill <T>(JsonMessage message) { Debug.Assert(message != null); var jsonArray = JArray.Parse(message.Value.ToString()); foreach (var token in jsonArray) { if (!token.HasValues) { continue; } var slot = Activator.CreateInstance <T>() as Slot; if (slot == null) { throw new InvalidCastException(String.Format(CultureInfo.CurrentCulture, "Type {0} cannot be converted to type Slot.", typeof(T))); } var propertySetter = new MessagePropertySetter(slot); foreach (var prop in JObject.Parse(token.ToString()).Properties()) { propertySetter.SetProperty(prop); } Add(slot); } SetMessageValues(message); foreach (var slot in this) { slot.SlotOptions.SetMessageValues(message); } }
#pragma warning restore 1591 #endregion /// <summary> /// Fill the SlotOptions object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> public override void Fill(JsonMessage message) { Debug.Assert(message != null); var propertySetter = new MessagePropertySetter(this); foreach (var prop in JObject.Parse(message.Value.ToString()).Properties()) { propertySetter.SetProperty(prop); } SetMessageValues(message); }
internal void SetProperty(JProperty jProperty) { if (jProperty == null) { return; } var properties = GetProperties(jProperty.Name).ToList(); if (!properties.Any()) { return; } if (jProperty.Value.Type == JTokenType.Object) { var propertyValue = GetPropertyValue(jProperty.Name); if (propertyValue != null) { var propertySetter = new MessagePropertySetter(propertyValue); foreach (var prop in JObject.Parse(jProperty.Value.ToString()).Properties()) { propertySetter.SetProperty(prop); } } } else { foreach (var classProperty in properties) { try { if (jProperty.Value.Type == JTokenType.String) { SetPropertyValue(classProperty, (string)jProperty); } else if (jProperty.Value.Type == JTokenType.Integer) { SetPropertyValue(classProperty, (int)jProperty); } } catch (Exception ex) { var typedMessageObject = _message as ITypedMessageObject; if (typedMessageObject != null) { typedMessageObject.AddError(new MessagePropertyConversionError(classProperty.Name, ex.Message)); } } } } }
#pragma warning restore 1591 #endregion /// <summary> /// Fill the SimulationInfo object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> internal override void Fill(JsonMessage message) { Debug.Assert(message != null); JObject jObject; using (var reader = (JsonReader) new JsonTextReader(new StringReader(message.Value.ToString()))) { reader.DateParseHandling = DateParseHandling.None; jObject = JObject.Load(reader); } var propertySetter = new MessagePropertySetter(this); foreach (var prop in jObject.Properties()) { propertySetter.SetProperty(prop); } SetMessageValues(message); }
/// <summary> /// Fill the UnitCollection object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> internal override void Fill <T>(JsonMessage message) { Debug.Assert(message != null); var jsonArray = JArray.Parse(message.Value.ToString()); foreach (var token in jsonArray) { if (!token.HasValues) { continue; } var unit = Activator.CreateInstance <T>() as Unit; if (unit == null) { throw new InvalidCastException(String.Format(CultureInfo.CurrentCulture, "Type {0} cannot be converted to type Unit.", typeof(T))); } JObject jObject; using (var reader = (JsonReader) new JsonTextReader(new StringReader(token.ToString()))) { reader.DateParseHandling = DateParseHandling.None; jObject = JObject.Load(reader); } var propertySetter = new MessagePropertySetter(unit); foreach (var prop in jObject.Properties()) { propertySetter.SetProperty(prop); } Add(unit); } SetMessageValues(message); }
#pragma warning restore 1591 #endregion /// <summary> /// Fill the Options object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> internal override void Fill(JsonMessage message) { Debug.Assert(message != null); var propertySetter = new MessagePropertySetter(this); foreach (var prop in JObject.Parse(message.Value.ToString()).Properties()) { propertySetter.SetProperty(prop); } SetMessageValues(message); }
#pragma warning restore 1591 #endregion /// <summary> /// Fill the SimulationInfo object with data from the given JsonMessage. /// </summary> /// <param name="message">Message object containing JSON value and meta-data.</param> public override void Fill(JsonMessage message) { Debug.Assert(message != null); JObject jObject; using (var reader = (JsonReader)new JsonTextReader(new StringReader(message.Value.ToString()))) { reader.DateParseHandling = DateParseHandling.None; jObject = JObject.Load(reader); } var propertySetter = new MessagePropertySetter(this); foreach (var prop in jObject.Properties()) { propertySetter.SetProperty(prop); } SetMessageValues(message); }
internal void SetProperty(JProperty jProperty) { if (jProperty == null) return; var properties = GetProperties(jProperty.Name).ToList(); if (!properties.Any()) { return; } if (jProperty.Value.Type == JTokenType.Object) { var propertyValue = GetPropertyValue(jProperty.Name); if (propertyValue != null) { var propertySetter = new MessagePropertySetter(propertyValue); foreach (var prop in JObject.Parse(jProperty.Value.ToString()).Properties()) { propertySetter.SetProperty(prop); } } } else { foreach (var classProperty in properties) { try { if (jProperty.Value.Type == JTokenType.String) { SetPropertyValue(classProperty, (string)jProperty); } else if (jProperty.Value.Type == JTokenType.Integer) { SetPropertyValue(classProperty, (int)jProperty); } } catch (Exception ex) { var typedMessageObject = _message as ITypedMessageObject; if (typedMessageObject != null) { typedMessageObject.AddError(new MessagePropertyConversionError(classProperty.Name, ex.Message)); } } } } }