/// <summary>
        /// Initialises a new instance of the request with the given description.
        /// </summary>
        ///
        /// <param name="desc">The description.</param>
        /// <param name="gameToken">The Game to log in to.</param>
        /// <param name="serverUrl">The server url for this call.</param>
        public LogInUsingChilliConnectRequest(LogInUsingChilliConnectRequestDesc desc, string gameToken, string serverUrl)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

            ReleaseAssert.IsNotNull(desc.ChilliConnectId, "ChilliConnectId cannot be null.");
            ReleaseAssert.IsNotNull(desc.ChilliConnectSecret, "ChilliConnectSecret cannot be null.");

            ReleaseAssert.IsNotNull(gameToken, "Game Token cannot be null.");

            ChilliConnectId     = desc.ChilliConnectId;
            ChilliConnectSecret = desc.ChilliConnectSecret;
            Country             = desc.Country;
            DeviceModel         = desc.DeviceModel;
            if (desc.DeviceType == null)
            {
                DeviceType = DeviceTypeDefaultProvider.GetDefault();
            }
            else
            {
                DeviceType = desc.DeviceType;
            }
            if (desc.Platform == null)
            {
                Platform = PlatformDefaultProvider.GetDefault();
            }
            else
            {
                Platform = desc.Platform;
            }
            AppVersion = desc.AppVersion;
            GameToken  = gameToken;
            Date       = DateTime.Now;

            Url = serverUrl + "/2.0/player/login/chilli";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
        /// <summary>
        /// Initialises a new instance of the request with the given description.
        /// </summary>
        ///
        /// <param name="desc">The description.</param>
        /// <param name="connectAccessToken">A valid session ConnectAccessToken obtained through one of the login endpoints.</param>
        public QueryCollectionRequest(QueryCollectionRequestDesc desc, string connectAccessToken)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

            ReleaseAssert.IsNotNull(desc.Key, "Key cannot be null.");

            ReleaseAssert.IsNotNull(connectAccessToken, "Connect Access Token cannot be null.");

            Key   = desc.Key;
            Query = desc.Query;
            if (desc.Params != null)
            {
                Params = Mutability.ToImmutable(desc.Params);
            }
            if (desc.SortFields != null)
            {
                SortFields = Mutability.ToImmutable(desc.SortFields);
            }
            Page = desc.Page;
            ConnectAccessToken = connectAccessToken;

            Url = "https://connect.chilliconnect.com/1.0/data/collection/query";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
Exemple #3
0
        /// <summary>
        /// Initialises a new instance of the request with the given description.
        /// </summary>
        ///
        /// <param name="desc">The description.</param>
        /// <param name="connectAccessToken">A valid session ConnectAccessToken obtained through one of the login endpoints.</param>
        /// <param name="serverUrl">The server url for this call.</param>
        public QueryAvailableMatchesRequest(QueryAvailableMatchesRequestDesc desc, string connectAccessToken, string serverUrl)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

            ReleaseAssert.IsNotNull(desc.MatchTypeKey, "MatchTypeKey cannot be null.");

            ReleaseAssert.IsNotNull(connectAccessToken, "Connect Access Token cannot be null.");

            MatchTypeKey = desc.MatchTypeKey;
            Query        = desc.Query;
            if (desc.Params != null)
            {
                Params = Mutability.ToImmutable(desc.Params);
            }
            if (desc.SortFields != null)
            {
                SortFields = Mutability.ToImmutable(desc.SortFields);
            }
            Page = desc.Page;
            ConnectAccessToken = connectAccessToken;

            Url = serverUrl + "/1.0/multiplayer/async/match/query";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
        /// <summary>
        /// Initialises a new instance of the request with the given description.
        /// </summary>
        ///
        /// <param name="desc">The description.</param>
        /// <param name="gameToken">The Game to log in to.</param>
        /// <param name="serverUrl">The server url for this call.</param>
        public LogInUsingUserNameRequest(LogInUsingUserNameRequestDesc desc, string gameToken, string serverUrl)
        {
            ReleaseAssert.IsNotNull(desc, "A description object cannot be null.");

            ReleaseAssert.IsNotNull(desc.UserName, "UserName cannot be null.");
            ReleaseAssert.IsNotNull(desc.Password, "Password cannot be null.");

            ReleaseAssert.IsNotNull(gameToken, "Game Token cannot be null.");

            UserName    = desc.UserName;
            Password    = desc.Password;
            Country     = desc.Country;
            DeviceModel = desc.DeviceModel;
            if (desc.DeviceType == null)
            {
                DeviceType = DeviceTypeDefaultProvider.GetDefault();
            }
            else
            {
                DeviceType = desc.DeviceType;
            }
            if (desc.Platform == null)
            {
                Platform = PlatformDefaultProvider.GetDefault();
            }
            else
            {
                Platform = desc.Platform;
            }
            AppVersion = desc.AppVersion;
            GameToken  = gameToken;
            Date       = DateTime.Now;

            Url = serverUrl + "/2.0/player/login/username";
            HttpRequestMethod = HttpRequestMethod.Post;
        }
Exemple #5
0
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="key">The Custom Data Key to set value of. Maximum length is 50 characters.</param>
        public SetPlayerDataRequestDesc(string key)
        {
            ReleaseAssert.IsNotNull(key, "Key cannot be null.");

            Key = key;
        }
        /// <summary>
        /// Initialises the response with the given json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the JSON data.</param>
        public GetPlayerDetailsResponse(IDictionary <string, object> jsonDictionary)
        {
            ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null.");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("ChilliConnectID"), "Json is missing required field 'ChilliConnectID'");

            foreach (KeyValuePair <string, object> entry in jsonDictionary)
            {
                // Chilli Connect Id
                if (entry.Key == "ChilliConnectID")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    ChilliConnectId = (string)entry.Value;
                }

                // User Name
                else if (entry.Key == "UserName")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        UserName = (string)entry.Value;
                    }
                }

                // Display Name
                else if (entry.Key == "DisplayName")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        DisplayName = (string)entry.Value;
                    }
                }

                // Email
                else if (entry.Key == "Email")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        Email = (string)entry.Value;
                    }
                }

                // Country
                else if (entry.Key == "Country")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        Country = (string)entry.Value;
                    }
                }

                // Device Model
                else if (entry.Key == "DeviceModel")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type.");
                        DeviceModel = JsonSerialisation.DeserialiseList((IList <object>)entry.Value, (object element) =>
                        {
                            ReleaseAssert.IsTrue(element is string, "Invalid element type.");
                            return((string)element);
                        });
                    }
                }

                // Device Type
                else if (entry.Key == "DeviceType")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        DeviceType = (string)entry.Value;
                    }
                }

                // Platform
                else if (entry.Key == "Platform")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        Platform = (string)entry.Value;
                    }
                }
            }
        }
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="authCode">Authorisation Code provided by Google, obtainable on the Client through Google
        /// Play.</param>
        public LogInUsingGoogleRequestDesc(string authCode)
        {
            ReleaseAssert.IsNotNull(authCode, "Auth Code cannot be null.");

            AuthCode = authCode;
        }
Exemple #8
0
        /// <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;
                    }
                }
            }
        }
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="matchTypeKey">The MatchType Key.</param>
        public QueryAvailableMatchesRequestDesc(string matchTypeKey)
        {
            ReleaseAssert.IsNotNull(matchTypeKey, "Match Type Key cannot be null.");

            MatchTypeKey = matchTypeKey;
        }
Exemple #10
0
        /// <summary>
        /// Parses the response body to get the response code.
        /// </summary>
        ///
        /// <returns>The error code in the given response body.</returns>
        ///
        /// <param name="serverResponse">The server response from which to get the error code. This
        /// must describe an successful response from the server which contains an error in the
        /// response body.</param>
        private static Error GetErrorCode(ServerResponse serverResponse)
        {
            const string JsonKeyErrorCode = "Code";

            ReleaseAssert.IsNotNull(serverResponse, "A server response must be supplied.");
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success, "The result must describe a successful server response.");
            ReleaseAssert.IsTrue(serverResponse.HttpResponseCode != SuccessHttpResponseCode && serverResponse.HttpResponseCode != UnexpectedErrorHttpResponseCode,
                                 "Must not be a successful or unexpected HTTP response code.");

            object errorCodeObject = serverResponse.Body[JsonKeyErrorCode];

            ReleaseAssert.IsTrue(errorCodeObject is long, "'Code' must be a long.");

            long errorCode = (long)errorCodeObject;

            switch (errorCode)
            {
            case 1007:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.InvalidRequest);

            case 10003:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 429, @"Invalid HTTP response code for error code.");
                return(Error.RateLimitReached);

            case 1008:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 503, @"Invalid HTTP response code for error code.");
                return(Error.TemporaryServiceError);

            case 2020:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.SuppliedAuthCodeMalformed);

            case 2021:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.SuppliedAuthCodeInvalid);

            case 2019:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.SuppliedAuthCodeAlreadyRedeemed);

            case 1003:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.ExpiredConnectAccessToken);

            case 1004:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.InvalidConnectAccessToken);

            case 2022:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.DeviceIdLinkedWithAnotherUser);

            case 1011:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 403, @"Invalid HTTP response code for error code.");
                return(Error.MethodDisabled);

            case 10002:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 403, @"Invalid HTTP response code for error code.");
                return(Error.AccountRestriction);

            default:
                return(Error.UnexpectedError);
            }
        }
Exemple #11
0
        /// <summary>
        /// Parses the response body to get the response code.
        /// </summary>
        ///
        /// <returns>The error code in the given response body.</returns>
        ///
        /// <param name="serverResponse">The server response from which to get the error code. This
        /// must describe an successful response from the server which contains an error in the
        /// response body.</param>
        private static Error GetErrorCode(ServerResponse serverResponse)
        {
            const string JsonKeyErrorCode = "Code";

            ReleaseAssert.IsNotNull(serverResponse, "A server response must be supplied.");
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success, "The result must describe a successful server response.");
            ReleaseAssert.IsTrue(serverResponse.HttpResponseCode != SuccessHttpResponseCode && serverResponse.HttpResponseCode != UnexpectedErrorHttpResponseCode,
                                 "Must not be a successful or unexpected HTTP response code.");

            object errorCodeObject = serverResponse.Body[JsonKeyErrorCode];

            ReleaseAssert.IsTrue(errorCodeObject is long, "'Code' must be a long.");

            long errorCode = (long)errorCodeObject;

            switch (errorCode)
            {
            case 1007:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.InvalidRequest);

            case 10002:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 429, @"Invalid HTTP response code for error code.");
                return(Error.RateLimitReached);

            case 1008:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 503, @"Invalid HTTP response code for error code.");
                return(Error.TemporaryServiceError);

            case 1003:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.ExpiredConnectAccessToken);

            case 1004:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.InvalidConnectAccessToken);

            case 2036:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.SuppliedTwitchAuthCodeInvalid);

            case 2032:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.NoTwitchOauthHasBeenConfiguredForApplication);

            case 1011:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 403, @"Invalid HTTP response code for error code.");
                return(Error.MethodDisabled);

            case 2033:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.PlayerAlreadyLinkedToTwitchAccount);

            case 2034:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.TwitchAccountLinked);

            case 2035:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.PlayerNotLinkedToTwitch);

            default:
                return(Error.UnexpectedError);
            }
        }
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public MinimalMatch(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("State"), "Json is missing required field 'State'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("TurnType"), "Json is missing required field 'TurnType'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("CanSubmitTurn"), "Json is missing required field 'CanSubmitTurn'");
            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;
                }

                // State
                else if (entry.Key == "State")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    State = (string)entry.Value;
                }

                // Turn Type
                else if (entry.Key == "TurnType")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    TurnType = (string)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;
                    }
                }

                // 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);
                    }
                }

                // Can Submit Turn
                else if (entry.Key == "CanSubmitTurn")
                {
                    ReleaseAssert.IsTrue(entry.Value is bool, "Invalid serialised type.");
                    CanSubmitTurn = (bool)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 of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="to">ChilliConnectID of the Player to send the message to.</param>
        public SendMessageRequestDesc(string to)
        {
            ReleaseAssert.IsNotNull(to, "To cannot be null.");

            To = to;
        }
Exemple #14
0
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public DlcPackage(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("Name"), "Json is missing required field 'Name'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Checksum"), "Json is missing required field 'Checksum'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DateUploaded"), "Json is missing required field 'DateUploaded'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Url"), "Json is missing required field 'Url'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Size"), "Json is missing required field 'Size'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Files"), "Json is missing required field 'Files'");

            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;
                }

                // Name
                else if (entry.Key == "Name")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    Name = (string)entry.Value;
                }

                // Checksum
                else if (entry.Key == "Checksum")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    Checksum = (string)entry.Value;
                }

                // Date Uploaded
                else if (entry.Key == "DateUploaded")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    DateUploaded = JsonSerialisation.DeserialiseDate((string)entry.Value);
                }

                // Url
                else if (entry.Key == "Url")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    Url = (string)entry.Value;
                }

                // Size
                else if (entry.Key == "Size")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    Size = (int)(long)entry.Value;
                }

                // Files
                else if (entry.Key == "Files")
                {
                    ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type.");
                    Files = JsonSerialisation.DeserialiseList((IList <object>)entry.Value, (object element) =>
                    {
                        ReleaseAssert.IsTrue(element is IDictionary <string, object>, "Invalid element type.");
                        return(new DlcPackageFile((IDictionary <string, object>)element));
                    });
                }
            }
        }
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="messageId">An identifier for the message.</param>
        public GetMessageRequestDesc(string messageId)
        {
            ReleaseAssert.IsNotNull(messageId, "Message Id cannot be null.");

            MessageId = messageId;
        }
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public MatchTypeDefinition(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("TurnTypes"), "Json is missing required field 'TurnTypes'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DefaultWaitingTimeout"), "Json is missing required field 'DefaultWaitingTimeout'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DefaultTurnTimeout"), "Json is missing required field 'DefaultTurnTimeout'");

            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;
                }

                // Turn Types
                else if (entry.Key == "TurnTypes")
                {
                    ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type.");
                    TurnTypes = JsonSerialisation.DeserialiseList((IList <object>)entry.Value, (object element) =>
                    {
                        ReleaseAssert.IsTrue(element is string, "Invalid element type.");
                        return((string)element);
                    });
                }

                // Properties
                else if (entry.Key == "Properties")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type.");
                        Properties = JsonSerialisation.DeserialiseList((IList <object>)entry.Value, (object element) =>
                        {
                            ReleaseAssert.IsTrue(element is IDictionary <string, object>, "Invalid element type.");
                            return(new MatchTypePropertyDefinition((IDictionary <string, object>)element));
                        });
                    }
                }

                // Default Waiting Timeout
                else if (entry.Key == "DefaultWaitingTimeout")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    DefaultWaitingTimeout = (int)(long)entry.Value;
                }

                // Default Turn Timeout
                else if (entry.Key == "DefaultTurnTimeout")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    DefaultTurnTimeout = (int)(long)entry.Value;
                }

                // 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);
                    }
                }
            }
        }
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public Message(IDictionary <string, object> jsonDictionary)
        {
            ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null.");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("MessageID"), "Json is missing required field 'MessageID'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("From"), "Json is missing required field 'From'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("SentOn"), "Json is missing required field 'SentOn'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Read"), "Json is missing required field 'Read'");

            foreach (KeyValuePair <string, object> entry in jsonDictionary)
            {
                // Message Id
                if (entry.Key == "MessageID")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    MessageId = (string)entry.Value;
                }

                // From
                else if (entry.Key == "From")
                {
                    ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type.");
                    From = new MessageSender((IDictionary <string, object>)entry.Value);
                }

                // Sent On
                else if (entry.Key == "SentOn")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    SentOn = JsonSerialisation.DeserialiseDate((string)entry.Value);
                }

                // Read
                else if (entry.Key == "Read")
                {
                    ReleaseAssert.IsTrue(entry.Value is bool, "Invalid serialised type.");
                    Read = (bool)entry.Value;
                }

                // Read On
                else if (entry.Key == "ReadOn")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        ReadOn = JsonSerialisation.DeserialiseDate((string)entry.Value);
                    }
                }

                // Redeemed
                else if (entry.Key == "Redeemed")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is bool, "Invalid serialised type.");
                        Redeemed = (bool)entry.Value;
                    }
                }

                // Redeemed On
                else if (entry.Key == "RedeemedOn")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        RedeemedOn = JsonSerialisation.DeserialiseDate((string)entry.Value);
                    }
                }

                // Tags
                else if (entry.Key == "Tags")
                {
                    if (entry.Value != null)
                    {
                        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);
                        });
                    }
                }

                // Expiry
                else if (entry.Key == "Expiry")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                        Expiry = (int)(long)entry.Value;
                    }
                }

                // Title
                else if (entry.Key == "Title")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        Title = (string)entry.Value;
                    }
                }

                // Text
                else if (entry.Key == "Text")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        Text = (string)entry.Value;
                    }
                }

                // Data
                else if (entry.Key == "Data")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type.");
                        Data = new MultiTypeValue((object)entry.Value);
                    }
                }

                // Rewards
                else if (entry.Key == "Rewards")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type.");
                        Rewards = new MessageReward((IDictionary <string, object>)entry.Value);
                    }
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public CollectionDataObject(IDictionary <string, object> jsonDictionary)
        {
            ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null.");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("ObjectID"), "Json is missing required field 'ObjectID'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("CreatedBy"), "Json is missing required field 'CreatedBy'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DateCreated"), "Json is missing required field 'DateCreated'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Value"), "Json is missing required field 'Value'");

            foreach (KeyValuePair <string, object> entry in jsonDictionary)
            {
                // Object Id
                if (entry.Key == "ObjectID")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    ObjectId = (string)entry.Value;
                }

                // Created By
                else if (entry.Key == "CreatedBy")
                {
                    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);
                }

                // Modified By
                else if (entry.Key == "ModifiedBy")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type.");
                        ModifiedBy = new Player((IDictionary <string, object>)entry.Value);
                    }
                }

                // Date Modified
                else if (entry.Key == "DateModified")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        DateModified = JsonSerialisation.DeserialiseDate((string)entry.Value);
                    }
                }

                // Value
                else if (entry.Key == "Value")
                {
                    ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type.");
                    Value = new MultiTypeValue((object)entry.Value);
                }

                // Write Lock
                else if (entry.Key == "WriteLock")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        WriteLock = (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 FacebookPlayerData(IDictionary <string, object> jsonDictionary)
        {
            ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null.");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("ChilliConnectID"), "Json is missing required field 'ChilliConnectID'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Key"), "Json is missing required field 'Key'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Value"), "Json is missing required field 'Value'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("FacebookName"), "Json is missing required field 'FacebookName'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DateCreated"), "Json is missing required field 'DateCreated'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DateModified"), "Json is missing required field 'DateModified'");

            foreach (KeyValuePair <string, object> entry in jsonDictionary)
            {
                // Chilli Connect Id
                if (entry.Key == "ChilliConnectID")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    ChilliConnectId = (string)entry.Value;
                }

                // Key
                else if (entry.Key == "Key")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    Key = (string)entry.Value;
                }

                // Value
                else if (entry.Key == "Value")
                {
                    ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type.");
                    Value = new MultiTypeValue((object)entry.Value);
                }

                // User Name
                else if (entry.Key == "UserName")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        UserName = (string)entry.Value;
                    }
                }

                // Display Name
                else if (entry.Key == "DisplayName")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        DisplayName = (string)entry.Value;
                    }
                }

                // Facebook Name
                else if (entry.Key == "FacebookName")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    FacebookName = (string)entry.Value;
                }

                // Date Created
                else if (entry.Key == "DateCreated")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    DateCreated = JsonSerialisation.DeserialiseDate((string)entry.Value);
                }

                // Date Modified
                else if (entry.Key == "DateModified")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    DateModified = JsonSerialisation.DeserialiseDate((string)entry.Value);
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="key">The Custom Data Key to return.</param>
        public GetPlayerDataForFacebookFriendsRequestDesc(string key)
        {
            ReleaseAssert.IsNotNull(key, "Key cannot be null.");

            Key = key;
        }
Exemple #21
0
        /// <summary>
        /// Parses the response body to get the response code.
        /// </summary>
        ///
        /// <returns>The error code in the given response body.</returns>
        ///
        /// <param name="serverResponse">The server response from which to get the error code. This
        /// must describe an successful response from the server which contains an error in the
        /// response body.</param>
        private static Error GetErrorCode(ServerResponse serverResponse)
        {
            const string JsonKeyErrorCode = "Code";

            ReleaseAssert.IsNotNull(serverResponse, "A server response must be supplied.");
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success, "The result must describe a successful server response.");
            ReleaseAssert.IsTrue(serverResponse.HttpResponseCode != SuccessHttpResponseCode && serverResponse.HttpResponseCode != UnexpectedErrorHttpResponseCode,
                                 "Must not be a successful or unexpected HTTP response code.");

            object errorCodeObject = serverResponse.Body[JsonKeyErrorCode];

            ReleaseAssert.IsTrue(errorCodeObject is long, "'Code' must be a long.");

            long errorCode = (long)errorCodeObject;

            switch (errorCode)
            {
            case 1007:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.InvalidRequest);

            case 10003:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 429, @"Invalid HTTP response code for error code.");
                return(Error.RateLimitReached);

            case 1003:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.ExpiredConnectAccessToken);

            case 1004:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.InvalidConnectAccessToken);

            case 1008:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 503, @"Invalid HTTP response code for error code.");
                return(Error.TemporaryServiceError);

            case 10501:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.PurchaseItemNotFound);

            case 8004:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 400, @"Invalid HTTP response code for error code.");
                return(Error.IapConfigurationNotSpecified);

            case 10503:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.ProductIdNotDefined);

            case 10502:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.ProductIdMismatch);

            case 10105:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.CatalogNotPublished);

            case 10002:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 403, @"Invalid HTTP response code for error code.");
                return(Error.AccountRestriction);

            default:
                return(Error.UnexpectedError);
            }
        }
Exemple #22
0
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public MatchTurn(IDictionary <string, object> jsonDictionary)
        {
            ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null.");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("TurnNumber"), "Json is missing required field 'TurnNumber'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("State"), "Json is missing required field 'State'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("DateStarted"), "Json is missing required field 'DateStarted'");

            foreach (KeyValuePair <string, object> entry in jsonDictionary)
            {
                // Turn Number
                if (entry.Key == "TurnNumber")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    TurnNumber = (int)(long)entry.Value;
                }

                // State
                else if (entry.Key == "State")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    State = (string)entry.Value;
                }

                // Players Waiting For
                else if (entry.Key == "PlayersWaitingFor")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type.");
                        PlayersWaitingFor = 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));
                        });
                    }
                }

                // Player Turns
                else if (entry.Key == "PlayerTurns")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is IList <object>, "Invalid serialised type.");
                        PlayerTurns = JsonSerialisation.DeserialiseList((IList <object>)entry.Value, (object element) =>
                        {
                            ReleaseAssert.IsTrue(element is IDictionary <string, object>, "Invalid element type.");
                            return(new PlayerTurn((IDictionary <string, object>)element));
                        });
                    }
                }

                // Pre State Data
                else if (entry.Key == "PreStateData")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type.");
                        PreStateData = new MultiTypeValue((object)entry.Value);
                    }
                }

                // Post State Data
                else if (entry.Key == "PostStateData")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type.");
                        PostStateData = new MultiTypeValue((object)entry.Value);
                    }
                }

                // Date Started
                else if (entry.Key == "DateStarted")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    DateStarted = JsonSerialisation.DeserialiseDate((string)entry.Value);
                }

                // Date Completed
                else if (entry.Key == "DateCompleted")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        DateCompleted = JsonSerialisation.DeserialiseDate((string)entry.Value);
                    }
                }
            }
        }
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="gameCenterId">GameCenterID is provided by iOS system on calling the Social system.</param>
        public LogInUsingGameCenterRequestDesc(string gameCenterId)
        {
            ReleaseAssert.IsNotNull(gameCenterId, "Game Center Id cannot be null.");

            GameCenterId = gameCenterId;
        }
Exemple #24
0
        /// <summary>
        /// Parses the response body to get the response code.
        /// </summary>
        ///
        /// <returns>The error code in the given response body.</returns>
        ///
        /// <param name="serverResponse">The server response from which to get the error code. This
        /// must describe an successful response from the server which contains an error in the
        /// response body.</param>
        private static Error GetErrorCode(ServerResponse serverResponse)
        {
            const string JsonKeyErrorCode = "Code";

            ReleaseAssert.IsNotNull(serverResponse, "A server response must be supplied.");
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success, "The result must describe a successful server response.");
            ReleaseAssert.IsTrue(serverResponse.HttpResponseCode != SuccessHttpResponseCode && serverResponse.HttpResponseCode != UnexpectedErrorHttpResponseCode,
                                 "Must not be a successful or unexpected HTTP response code.");

            object errorCodeObject = serverResponse.Body[JsonKeyErrorCode];

            ReleaseAssert.IsTrue(errorCodeObject is long, "'Code' must be a long.");

            long errorCode = (long)errorCodeObject;

            switch (errorCode)
            {
            case 1007:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.InvalidRequest);

            case 1013:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.TrialExpired);

            case 1008:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 503, @"Invalid HTTP response code for error code.");
                return(Error.TemporaryServiceError);

            case 1001:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.InvalidGameToken);

            case 1005:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.InvalidCredentials);

            case 10001:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 429, @"Invalid HTTP response code for error code.");
                return(Error.LimitReached);

            case 2026:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.NoSteamAppDetailsHaveBeenConfigured);

            case 2031:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.SteamAppIdIncompatibleWithSessionTicket);

            case 2030:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.SteamAppDetailsConfiguredIncorrectly);

            case 2025:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 409, @"Invalid HTTP response code for error code.");
                return(Error.SuppliedSteamTicketIsInvalid);

            default:
                return(Error.UnexpectedError);
            }
        }
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public FacebookScore(IDictionary <string, object> jsonDictionary)
        {
            ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null.");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("ChilliConnectID"), "Json is missing required field 'ChilliConnectID'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("FacebookName"), "Json is missing required field 'FacebookName'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("FacebookProfileImage"), "Json is missing required field 'FacebookProfileImage'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Date"), "Json is missing required field 'Date'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Score"), "Json is missing required field 'Score'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("GlobalRank"), "Json is missing required field 'GlobalRank'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("GlobalTotal"), "Json is missing required field 'GlobalTotal'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("LocalRank"), "Json is missing required field 'LocalRank'");

            foreach (KeyValuePair <string, object> entry in jsonDictionary)
            {
                // Chilli Connect Id
                if (entry.Key == "ChilliConnectID")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    ChilliConnectId = (string)entry.Value;
                }

                // User Name
                else if (entry.Key == "UserName")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        UserName = (string)entry.Value;
                    }
                }

                // Display Name
                else if (entry.Key == "DisplayName")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                        DisplayName = (string)entry.Value;
                    }
                }

                // Facebook Name
                else if (entry.Key == "FacebookName")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    FacebookName = (string)entry.Value;
                }

                // Facebook Profile Image
                else if (entry.Key == "FacebookProfileImage")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    FacebookProfileImage = (string)entry.Value;
                }

                // Date
                else if (entry.Key == "Date")
                {
                    ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type.");
                    Date = JsonSerialisation.DeserialiseDate((string)entry.Value);
                }

                // Data
                else if (entry.Key == "Data")
                {
                    if (entry.Value != null)
                    {
                        ReleaseAssert.IsTrue(entry.Value is object, "Invalid serialised type.");
                        Data = new MultiTypeValue((object)entry.Value);
                    }
                }

                // Score
                else if (entry.Key == "Score")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    Score = (int)(long)entry.Value;
                }

                // Global Rank
                else if (entry.Key == "GlobalRank")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    GlobalRank = (int)(long)entry.Value;
                }

                // Global Total
                else if (entry.Key == "GlobalTotal")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    GlobalTotal = (int)(long)entry.Value;
                }

                // Local Rank
                else if (entry.Key == "LocalRank")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    LocalRank = (int)(long)entry.Value;
                }

                // An error has occurred.
                else
                {
#if DEBUG
                    throw new ArgumentException("Input Json contains an invalid field.");
#endif
                }
            }
        }
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="matchId">The ID of the Match to update.</param>
        public UpdateMatchRequestDesc(string matchId)
        {
            ReleaseAssert.IsNotNull(matchId, "Match Id cannot be null.");

            MatchId = matchId;
        }
Exemple #27
0
        /// <summary>
        /// Parses the response body to get the response code.
        /// </summary>
        ///
        /// <returns>The error code in the given response body.</returns>
        ///
        /// <param name="serverResponse">The server response from which to get the error code. This
        /// must describe an successful response from the server which contains an error in the
        /// response body.</param>
        private static Error GetErrorCode(ServerResponse serverResponse)
        {
            const string JsonKeyErrorCode = "Code";

            ReleaseAssert.IsNotNull(serverResponse, "A server response must be supplied.");
            ReleaseAssert.IsTrue(serverResponse.Result == HttpResult.Success, "The result must describe a successful server response.");
            ReleaseAssert.IsTrue(serverResponse.HttpResponseCode != SuccessHttpResponseCode && serverResponse.HttpResponseCode != UnexpectedErrorHttpResponseCode,
                                 "Must not be a successful or unexpected HTTP response code.");

            object errorCodeObject = serverResponse.Body[JsonKeyErrorCode];

            ReleaseAssert.IsTrue(errorCodeObject is long, "'Code' must be a long.");

            long errorCode = (long)errorCodeObject;

            switch (errorCode)
            {
            case 1007:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 422, @"Invalid HTTP response code for error code.");
                return(Error.InvalidRequest);

            case 10002:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 429, @"Invalid HTTP response code for error code.");
                return(Error.RateLimitReached);

            case 1008:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 503, @"Invalid HTTP response code for error code.");
                return(Error.TemporaryServiceError);

            case 1003:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.ExpiredConnectAccessToken);

            case 1004:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.InvalidConnectAccessToken);

            case 1011:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 403, @"Invalid HTTP response code for error code.");
                return(Error.MethodDisabled);

            case 1009:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.PlayerNotFound);

            case 10203:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.CurrencyItemNotFound);

            case 10504:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.PurchaseCostsNotMet);

            case 6002:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.PlayerContextNotSet);

            case 10105:
                ReleaseAssert.IsTrue(serverResponse.HttpResponseCode == 401, @"Invalid HTTP response code for error code.");
                return(Error.EconomyNotPublished);

            default:
                return(Error.UnexpectedError);
            }
        }
Exemple #28
0
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="sessionTicket">Long Hex Code String supplied by the Steamworks Framework, used to verify that
        /// the Player is legitimate and belongs to configured Steam App.</param>
        public LogInUsingSteamRequestDesc(string sessionTicket)
        {
            ReleaseAssert.IsNotNull(sessionTicket, "Session Ticket cannot be null.");

            SessionTicket = sessionTicket;
        }
        /// <summary>
        /// Initialises a new instance from the given Json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the Json data.</param>
        public CurrencyDefinition(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("Initial"), "Json is missing required field 'Initial'");
            ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Max"), "Json is missing required field 'Max'");

            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);
                    }
                }

                // Initial
                else if (entry.Key == "Initial")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    Initial = (int)(long)entry.Value;
                }

                // Max
                else if (entry.Key == "Max")
                {
                    ReleaseAssert.IsTrue(entry.Value is long, "Invalid serialised type.");
                    Max = (int)(long)entry.Value;
                }
            }
        }
Exemple #30
0
        /// <summary>
        /// Initialises a new instance of the description with the given required properties.
        /// </summary>
        ///
        /// <param name="typeKey">The Key of the Custom Type.</param>
        public GetCustomDefinitionsRequestDesc(string typeKey)
        {
            ReleaseAssert.IsNotNull(typeKey, "Type Key cannot be null.");

            TypeKey = typeKey;
        }