Example #1
0
 public ConfigurationDataResult(ConfigurationSourceType source, byte[] data)
 {
     if (!Enum.IsDefined(typeof(ConfigurationSourceType), source))
     {
         throw new InvalidEnumArgumentException(nameof(source), (int)source, typeof(ConfigurationSourceType));
     }
     Source = source;
     Data   = data ?? throw new ArgumentNullException(nameof(data));
 }
        public GameConfigurationUpdateRequest(ConfigurationSourceType source, TConfigType configType, byte[] data)
        {
            if (!Enum.IsDefined(typeof(ConfigurationSourceType), source))
            {
                throw new InvalidEnumArgumentException(nameof(source), (int)source, typeof(ConfigurationSourceType));
            }

            //TODO: How should character specific config work?
            //Cannot remotely update default, and character requires additional information
            //so it's a request model. Maybe?
            Source     = source;
            ConfigType = configType;
            Data       = data ?? throw new ArgumentNullException(nameof(data));
        }
        private async Task <bool> ContainsConfigEntryAsync(ConfigurationSourceType source, TConfigType configType, int ownershipId, CancellationToken token = default)
        {
            if (configType == null)
            {
                throw new ArgumentNullException(nameof(configType));
            }
            if (!Enum.IsDefined(typeof(ConfigurationSourceType), source))
            {
                throw new InvalidEnumArgumentException(nameof(source), (int)source, typeof(ConfigurationSourceType));
            }

            switch (source)
            {
            case ConfigurationSourceType.Account:
                return(await AccountConfigRepository.ContainsAsync(new GameConfigurationKey <TConfigType>(ownershipId, configType), token));

            case ConfigurationSourceType.Character:
                return(await CharacterConfigRepository.ContainsAsync(new GameConfigurationKey <TConfigType>(ownershipId, configType), token));

            default:
                throw new ArgumentOutOfRangeException(nameof(source), source, null);
            }
        }
 private int RetrieveOwnershipId(ConfigurationSourceType source)
 {
     return(source == ConfigurationSourceType.Account ? ClaimsReader.GetAccountId <int>(User) : ClaimsReader.GetSubAccountId <int>(User));
 }
        public async Task <ResponseModel <ConfigurationDataResult, GameConfigQueryResponseCode> > RetrieveConfigAsync([FromRoute(Name = "source")] ConfigurationSourceType source, [FromRoute(Name = "config")] TConfigType configType, CancellationToken token = default)
        {
            int ownershipId = RetrieveOwnershipId(source);

            if (!await ContainsConfigEntryAsync(source, configType, ownershipId, token))
            {
                return(Failure <ConfigurationDataResult, GameConfigQueryResponseCode>(GameConfigQueryResponseCode.ContentNotFound));
            }

            var entry = await RetrieveConfigEntryAsync(source, configType, ownershipId, token);

            return(Success <ConfigurationDataResult, GameConfigQueryResponseCode>(new ConfigurationDataResult(source, entry.Data.Data)));
        }