Exemple #1
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            try
            {
                var messageLogEntity = new MessageLogEntity
                {
                    Id             = Guid.NewGuid(),
                    Timestamp      = TimeZoneExtensions.GetCurrentTime(),
                    TypeId         = _logLevelMapper.Map(logLevel),
                    Message        = $"{formatter(state, exception)}",
                    Exception      = exception?.ToString(),
                    InnerException = exception?.InnerException?.ToString(),
                    StackTrace     = exception?.StackTrace,
                    Source         = exception?.Source,
                    CreatedOn      = TimeZoneExtensions.GetCurrentTime(),
                    CreatedBy      = _createdBy
                };

                Task.Run(() =>
                {
                    _tableStorageRepository.InsertAsync(messageLogEntity);
                }).Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                // do nothing
            }
        }
        /// <summary>
        /// Will always go through here
        /// </summary>
        /// <param name="view"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task <bool> UpdateSummonerInfoAsync(SummonerInfoView view, UserEntity user)
        {
            try
            {
                view.RemoveEmptyViewsForDb();
                var readEntity = await _summonerInfoRepository.ReadOneByUserIdAsync(user.Id);

                if (readEntity == null)
                {
                    return(await CreateSummonerInfoAsync(view, user));
                }

                var summonerInfo = _summonerMapper.Map(view);
                summonerInfo.Id            = readEntity.Id;
                summonerInfo.UserId        = readEntity.UserId;
                summonerInfo.IsValidPlayer = readEntity.IsValidPlayer;
                summonerInfo.UpdatedOn     = TimeZoneExtensions.GetCurrentTime();

                var altAccountTask         = UpdateAlternateAccountsAsync(summonerInfo.Id, view.AlternateAccounts);
                var updateSummonerInfoTask = _summonerInfoRepository.UpdateAsync(new List <SummonerInfoEntity> {
                    summonerInfo
                });
                return(await altAccountTask && await updateSummonerInfoTask);
            }
            catch (SummonerInfoException)
            {
                throw;
            }
            catch (Exception e)
            {
                var message = $"Error updating summoner info for: {user.Email}";
                _logger.LogError(e, message);
                throw new Exception(message, e);
            }
        }