Ejemplo n.º 1
0
        public virtual async Task <HiRezApiSession> AcquireAsync()
        {
            await this._semaphore.WaitAsync();

            try
            {
                HiRezApiSession existingSession = await this._sessionRepository.GetAsync(this._apiClient.Platform);

                // Session needs to be valid and is platform specific
                if (existingSession?.IsValid == true && this._apiClient.Platform == existingSession.Platform)
                {
                    return(existingSession);
                }

                HiRezApiSession newSession = await this.TryFetchNewSessionAsync();

                await this._sessionRepository.SetAsync(newSession);

                return(newSession);
            }
            finally
            {
                this._semaphore.Release();
            }
        }
Ejemplo n.º 2
0
 public Task SetAsync(HiRezApiSession session)
 {
     this._sessions[session.Platform] = session;
     return(Task.CompletedTask);
 }
Ejemplo n.º 3
0
        private async Task SaveAsync(HiRezApiSession session)
        {
            var filePath = this.GetFilePath(session.Platform);

            using (var sw = new StreamWriter(filePath, false, Encoding.UTF8)) await sw.WriteAsync(JsonConvert.SerializeObject(session));
        }
Ejemplo n.º 4
0
 public async Task SetAsync(HiRezApiSession session)
 {
     await this.SaveAsync(session);
 }