/// <summary> /// Initialises a new instance from the given Json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the Json data.</param> public ZipPackageDefinition(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Key"), "Json is missing required field 'Key'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Name"), "Json is missing required field 'Name'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Tags"), "Json is missing required field 'Tags'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Packages"), "Json is missing required field 'Packages'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Key if (entry.Key == "Key") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Key = (string)entry.Value; } // Name else if (entry.Key == "Name") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Name = (string)entry.Value; } // Tags else if (entry.Key == "Tags") { ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type."); Tags = JsonSerialisation.DeserialiseList((IList <object>)entry.Value, (object element) => { ReleaseAssert.IsTrue(element is string, "Invalid element type."); return((string)element); }); } // Custom Data else if (entry.Key == "CustomData") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type."); CustomData = new MultiTypeValue((object)entry.Value); } } // Packages else if (entry.Key == "Packages") { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); Packages = JsonSerialisation.DeserialiseMap((IDictionary <string, object>)entry.Value, (object element) => { ReleaseAssert.IsTrue(element is IDictionary <string, object>, "Invalid element type."); return(new ZipPackageDefinitionPackage((IDictionary <string, object>)element)); }); } } }
/// <summary> /// Initialises a new instance from the given Json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the Json data.</param> public MetricsEvent(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Type"), "Json is missing required field 'Type'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Date"), "Json is missing required field 'Date'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Type if (entry.Key == "Type") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Type = (string)entry.Value; } // Date else if (entry.Key == "Date") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Date = JsonSerialisation.DeserialiseDate((string)entry.Value); } // Parameters else if (entry.Key == "Params") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); Parameters = JsonSerialisation.DeserialiseMap((IDictionary <string, object>)entry.Value, (object element) => { ReleaseAssert.IsTrue(element is string, "Invalid element type."); return((string)element); }); } } // Count else if (entry.Key == "Count") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); Count = (int)(long)entry.Value; } } } }
/// <summary> /// Initialises the response with the given json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the JSON data.</param> public GetPlayerPropertiesResponse(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Properties if (entry.Key == "Properties") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); Properties = JsonSerialisation.DeserialiseMap((IDictionary <string, object>)entry.Value, (object element) => { ReleaseAssert.IsTrue(element is object, "Invalid element type."); return(new MultiTypeValue((object)element)); }); } } } }
/// <summary> /// Initialises a new instance from the given Json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the Json data.</param> public Match(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("MatchID"), "Json is missing required field 'MatchID'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("MatchTypeKey"), "Json is missing required field 'MatchTypeKey'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("State"), "Json is missing required field 'State'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("WriteLock"), "Json is missing required field 'WriteLock'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("TurnType"), "Json is missing required field 'TurnType'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("AutoStart"), "Json is missing required field 'AutoStart'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("IsPrivate"), "Json is missing required field 'IsPrivate'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DateCreated"), "Json is missing required field 'DateCreated'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Match Id if (entry.Key == "MatchID") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); MatchId = (string)entry.Value; } // Match Type Key else if (entry.Key == "MatchTypeKey") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); MatchTypeKey = (string)entry.Value; } // State else if (entry.Key == "State") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); State = (string)entry.Value; } // Write Lock else if (entry.Key == "WriteLock") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); WriteLock = (string)entry.Value; } // Properties else if (entry.Key == "Properties") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); Properties = JsonSerialisation.DeserialiseMap((IDictionary <string, object>)entry.Value, (object element) => { ReleaseAssert.IsTrue(element is object, "Invalid element type."); return(new MultiTypeValue((object)element)); }); } } // State Data else if (entry.Key == "StateData") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type."); StateData = new MultiTypeValue((object)entry.Value); } } // Outcome Data else if (entry.Key == "OutcomeData") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type."); OutcomeData = new MultiTypeValue((object)entry.Value); } } // Turn Timeout else if (entry.Key == "TurnTimeout") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); TurnTimeout = new Timeout((IDictionary <string, object>)entry.Value); } } // Waiting Timeout else if (entry.Key == "WaitingTimeout") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); WaitingTimeout = new Timeout((IDictionary <string, object>)entry.Value); } } // Turn Type else if (entry.Key == "TurnType") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); TurnType = (string)entry.Value; } // Turn Order Type else if (entry.Key == "TurnOrderType") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); TurnOrderType = (string)entry.Value; } } // Player Limit else if (entry.Key == "PlayerLimit") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); PlayerLimit = (int)(long)entry.Value; } } // Players else if (entry.Key == "Players") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type."); Players = JsonSerialisation.DeserialiseList((IList <object>)entry.Value, (object element) => { ReleaseAssert.IsTrue(element is IDictionary <string, object>, "Invalid element type."); return(new Player((IDictionary <string, object>)element)); }); } } // Auto Start else if (entry.Key == "AutoStart") { ReleaseAssert.IsTrue(entry.Value is bool, "Invalid serialised type."); AutoStart = (bool)entry.Value; } // Is Private else if (entry.Key == "IsPrivate") { ReleaseAssert.IsTrue(entry.Value is bool, "Invalid serialised type."); IsPrivate = (bool)entry.Value; } // Turn Number else if (entry.Key == "TurnNumber") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); TurnNumber = (int)(long)entry.Value; } } // Last Turn else if (entry.Key == "LastTurn") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); LastTurn = new MatchTurn((IDictionary <string, object>)entry.Value); } } // Current Turn else if (entry.Key == "CurrentTurn") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); CurrentTurn = new MatchTurn((IDictionary <string, object>)entry.Value); } } // Created By else if (entry.Key == "CreatedBy") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); CreatedBy = new Player((IDictionary <string, object>)entry.Value); } } // Date Created else if (entry.Key == "DateCreated") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); DateCreated = JsonSerialisation.DeserialiseDate((string)entry.Value); } } }
/// <summary> /// Initialises a new instance from the given Json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the Json data.</param> public MetricsEvent(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Type"), "Json is missing required field 'Type'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Date"), "Json is missing required field 'Date'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Type if (entry.Key == "Type") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Type = (string)entry.Value; } // Date else if (entry.Key == "Date") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Date = JsonSerialisation.DeserialiseDate((string)entry.Value); } // User Grade else if (entry.Key == "UserGrade") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); UserGrade = (int)(long)entry.Value; } } // Test Group else if (entry.Key == "TestGroup") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); TestGroup = (string)entry.Value; } } // Parameters else if (entry.Key == "Params") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); Parameters = JsonSerialisation.DeserialiseMap((IDictionary <string, object>)entry.Value, (object element) => { ReleaseAssert.IsTrue(element is string, "Invalid element type."); return((string)element); }); } } // Count else if (entry.Key == "Count") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type."); Count = (int)(long)entry.Value; } } // An error has occurred. else { #if DEBUG throw new ArgumentException("Input Json contains an invalid field."); #endif } } }