public static void Validate(this ListMapVariants listMapVariants)
        {
            var validationResult = new ValidationResult();

            if (!listMapVariants.Player.IsValidGamertag())
            {
                validationResult.Messages.Add("ListMapVariants query requires a valid Gamertag (Player) to be set.");
            }

            if (listMapVariants.Parameters.ContainsKey("count"))
            {
                int count;
                var parsed = int.TryParse(listMapVariants.Parameters["count"], out count);

                if (!parsed || count < 1 || count > 100)
                {
                    validationResult.Messages.Add($"ListMapVariants optional parameter 'Take' is invalid: {count}.");
                }
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetEmblemImage getEmblemImage)
        {
            var validationResult = new ValidationResult();

            if (!getEmblemImage.Player.IsValidGamertag())
            {
                validationResult.Messages.Add("GetEmblemImage query requires a valid Gamertag (Player) to be set.");
            }

            if (getEmblemImage.Parameters.ContainsKey("size"))
            {
                var validSizes = new List<int> { 95, 128, 190, 256, 512 };

                int size;
                var parsed = int.TryParse(getEmblemImage.Parameters["size"], out size);

                if (!parsed || !validSizes.Contains(size))
                {
                    validationResult.Messages.Add($"GetEmblemImage optional parameter 'size' is invalid: {size}.");
                }
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetArenaServiceRecord getArenaServiceRecord)
        {
            var validationResult = new ValidationResult();

            if (getArenaServiceRecord.Parameters.ContainsKey("players"))
            {
                var players = getArenaServiceRecord.Parameters["players"].Split(',');

                foreach (var player in players)
                {
                    if (!player.IsValidGamertag())
                    {
                        validationResult.Messages.Add("GetArenaServiceRecord query requires valid Gamertags (Players) to be set.");
                    }
                }
            }
            else
            {
                validationResult.Messages.Add("GetArenaServiceRecord query requires a Player to be set.");
            }



            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetLeaderboard getLeaderboard)
        {
            var validationResult = new ValidationResult();

            if (string.IsNullOrEmpty(getLeaderboard.SeasonId))
            {
                validationResult.Messages.Add("GetLeaderboard query requires a SeasonId to be set.");
            }

            if (string.IsNullOrEmpty(getLeaderboard.PlaylistId))
            {
                validationResult.Messages.Add("GetLeaderboard query requires a PlaylistId to be set.");
            }

            if (getLeaderboard.Parameters.ContainsKey("count"))
            {
                int count;
                var parsed = int.TryParse(getLeaderboard.Parameters["count"], out count);

                if (!parsed || count < 1 || count > 250)
                {
                    validationResult.Messages.Add($"GetLeaderboard optional parameter 'Take' is invalid: {count}.");
                }
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
Пример #5
0
        public static void Validate(this GetMatches getMatches)
        {
            var validationResult = new ValidationResult();

            if (!getMatches.Player.IsValidGamertag())
            {
                validationResult.Messages.Add("GetMatches query requires a valid Gamertag (Player) to be set.");
            }

            if (getMatches.Parameters.ContainsKey("modes"))
            {
                var modes = getMatches.Parameters["modes"].Split(',');

                foreach (var mode in modes)
                {
                    var defined = Enum.IsDefined(typeof (Enumeration.GameMode), mode);

                    if (!defined)
                    {
                        validationResult.Messages.Add($"GetMatches optional parameter 'Game Mode' is invalid: {mode}.");
                    }
                }
            }

            if (getMatches.Parameters.ContainsKey("start"))
            {
                int start;
                var parsed = int.TryParse(getMatches.Parameters["start"], out start);

                if (!parsed || start < 0)
                {
                    validationResult.Messages.Add($"GetMatches optional parameter 'Take' is invalid: {start}.");
                }
            }

            if (getMatches.Parameters.ContainsKey("count"))
            {
                int count;
                var parsed = int.TryParse(getMatches.Parameters["count"], out count);

                if (!parsed || count < 1 || count > 25)
                {
                    validationResult.Messages.Add($"GetMatches optional parameter 'Take' is invalid: {count}.");
                }
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetGameVariant getGameVariant)
        {
            var validationResult = new ValidationResult();

            if (string.IsNullOrWhiteSpace(getGameVariant.Id))
            {
                validationResult.Messages.Add("GetGameVariant query requires a GameVariantId to be set.");
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetArenaMatchDetails getArenaMatchDetails)
        {
            var validationResult = new ValidationResult();

            if (string.IsNullOrWhiteSpace(getArenaMatchDetails.MatchId))
            {
                validationResult.Messages.Add("GetArenaMatchDetails query requires a MatchId to be set.");
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetRequisition getRequisition)
        {
            var validationResult = new ValidationResult();

            if (string.IsNullOrWhiteSpace(getRequisition.Id))
            {
                validationResult.Messages.Add("GetRequisition query requires a RequisitionId to be set.");
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetMapVariant GetMapVariant)
        {
            var validationResult = new ValidationResult();

            if (!GetMapVariant.Player.IsValidGamertag())
            {
                validationResult.Messages.Add("GetMapVariant query requires a valid Gamertag (Player) to be set.");
            }

            if (string.IsNullOrWhiteSpace(GetMapVariant.Id))
            {
                validationResult.Messages.Add("GetMapVariant query requires a Map Variant (Id) to be set.");
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }
        public static void Validate(this GetSpartanImage getSpartanImage)
        {
            var validationResult = new ValidationResult();

            if (!getSpartanImage.Player.IsValidGamertag())
            {
                validationResult.Messages.Add("GetSpartanImage query requires a valid Gamertag (Player) to be set.");
            }

            if (getSpartanImage.Parameters.ContainsKey("size"))
            {
                var validSizes = new List<int> { 95, 128, 190, 256, 512 };

                int size;
                var parsed = int.TryParse(getSpartanImage.Parameters["size"], out size);

                if (!parsed || !validSizes.Contains(size))
                {
                    validationResult.Messages.Add($"GetSpartanImage optional parameter 'Size' is invalid: {size}.");
                }
            }

            if (getSpartanImage.Parameters.ContainsKey("crop"))
            {
                var crop = getSpartanImage.Parameters["crop"];

                var defined = Enum.IsDefined(typeof(Enumeration.CropType), crop);

                if (!defined)
                {
                    validationResult.Messages.Add($"GetSpartanImage optional parameter 'Crop' is invalid: {crop}.");
                }
            }

            if (!validationResult.Success)
            {
                throw new ValidationException(validationResult.Messages);
            }
        }