示例#1
0
 public RiotAPIAccountGetService(
     RiotAPIService riotApiService,
     RiotAccountModel riotAccountModel
     )
 {
     _riotApiService   = riotApiService;
     _riotAccountModel = riotAccountModel;
 }
示例#2
0
        public void Execute <TServicePayload>(TServicePayload payload) where TServicePayload : class, IServicePayload
        {
            if (!(payload is RiotAPIAccountPayload))
            {
                throw new InvalidOperationException($"Incorrect payload provided - Expected {typeof(RiotAPIAccountPayload)} | Got {typeof(TServicePayload)}");
            }

            var accountGetPayload = payload as RiotAPIAccountPayload;

            var api = _riotApiService.GetApi();

            var newAccount = new RiotAccountModel();

            try
            {
                var summoner = api.Summoner.GetSummonerByNameAsync(
                    region: accountGetPayload.AccountRegion,
                    summonerName: accountGetPayload.AccountName).Result;

                newAccount.Summoner = summoner;
            }
            catch (Exception)
            {
                newAccount = new RiotAccountModel
                {
                    Summoner = new Summoner
                    {
                        Name = "INVALID SUMMONER"
                    }
                };
            }
            finally
            {
                // Update singleton account model
                _riotAccountModel.Update(newAccount);
            }
        }