예제 #1
0
        private async void LoadRooms()
        {
            var resp = await _httpManager.GetAsync <IEnumerable <RoomDTO> >("api/Rooms/Other");

            if (resp.Error != null)
            {
                ShowNotification(resp.Error.ErrorDescription);
                return;
            }

            OtherRooms = new ObservableCollection <RoomModel>();
            foreach (var r in resp.Data)
            {
                OtherRooms.Insert(0, new RoomModel(r, await GetUserAsync(r.AdminId)));
            }
            OnPropertyChanged("OtherRooms");

            resp = await _httpManager.GetAsync <IEnumerable <RoomDTO> >("api/Rooms/My");

            if (resp.Error != null)
            {
                ShowNotification(resp.Error.ErrorDescription);
                return;
            }

            MyRooms = new ObservableCollection <RoomModel>();
            foreach (var r in resp.Data)
            {
                MyRooms.Insert(0, new RoomModel(r, await GetUserAsync(r.AdminId)));
            }
            OnPropertyChanged("MyRooms");
        }
예제 #2
0
        public async Task <LeaderboardModel> GetLeaderboardAsync(int id)
        {
            var response = await _httpManager.GetAsync <LeaderboardModel>(ApiConstants.LeaderboardsURL, ApiConstants.IdExtension, id.ToString());

            if (response == null)
            {
                return(null);
            }

            return(response);
        }
예제 #3
0
        public async Task <UserRealm> GetUserRealmAsync(CancellationToken cancellationToken)
        {
            var uri      = _authenticationParameters.AuthorityUri.GetUserRealmEndpoint(_authenticationParameters.UserName);
            var response = await _httpManager.GetAsync(uri, GetVersionHeaders(), cancellationToken);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                // todo: exception type
                throw new Exception("User Realm Error");
            }

            return(UserRealm.Create(response.ResponseData));
        }
예제 #4
0
        public async Task <bool> CheckUsernameRegisteredAsync(string username)
        {
            try
            {
                var response = await _httpManager.GetAsync <bool>(ApiConstants.LogInURL, parameter : username);

                return(response);
            }
            catch (Exception e)
            {
                _logger.Error(e.Message);
                return(false);
            }
        }
예제 #5
0
        public async Task <string> Get(string id, string key, List <string> compositeKey = null, TimeSpan?expireTime = null, TimeSpan?idleTime = null)
        {
            try
            {
                var getTask = _httpManager.GetAsync($"/{_prefixUrl}{Urlfy(id)}/{GenerateKey(key, compositeKey)}",
                                                    GetRequestHeaders(null, null),
                                                    ServerPool.Next().ToString(), mediaType: "text/plain");

                if (!getTask.Wait(TimeSpan.FromSeconds(_cacheTimeout)))
                {
                    return(string.Empty);
                }

                var response = await getTask;
                if (response.IsSuccessStatusCode)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    return(result);
                }
            }
            catch (Exception)
            {
                //Supress
            }

            return(string.Empty);
        }
예제 #6
0
        public async void Download(FileDTO file)
        {
            var directory = "Downloads";

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            var destination = Path.Combine(directory, $"{file.Id.ToString()}{Path.GetExtension(file.Name)}");

            for (int part = 1; part <= file.Parts; part++)
            {
                var filePartResponse = await _httpManager.GetAsync <FilePartDTO>($"api/Files/{file.Id}/DownloadPart/{part}");

                if (filePartResponse.Error != null)
                {
                    Failed?.Invoke(filePartResponse.Error.ErrorDescription);
                    return;
                }

                using (var fs = new FileStream(destination, FileMode.Append, FileAccess.Write, FileShare.Write))
                {
                    fs.Write(filePartResponse.Data.Content, 0, filePartResponse.Data.Content.Length);
                    //fs.BeginWrite(
                    //    filePartResponse.Data.Content,
                    //    0,
                    //    filePartResponse.Data.Content.Length,
                    //    new AsyncCallback((a) => { PartDownloaded(part); }),
                    //    null);
                    PartDownloaded(part);
                }
            }
        }
예제 #7
0
        public async Task <bool> LoginAsync(string serverUrl, string username, string password, CancellationTokenSource cancellationTokenSource)
        {
            var requestUrl = string.Format("{0}{1}/", App.BaseUrl, JiraRequestType.Search.ToString().ToLower());
            var response   = await httpManager.GetAsync(requestUrl, true, username, password);

            if (response == null)
            {
                return(false);
            }
            if (response.IsSuccessStatusCode)
            {
                return(true);
            }

            throw new HttpRequestStatusCodeException(response.StatusCode);
        }
예제 #8
0
 public async Task <List <MatchModel> > GetLeagueMatchesAsync(int leagueID)
 {
     return(await _httpManager.GetAsync <List <MatchModel> >(ApiConstants.MatchesURL, extension : ApiConstants.LeagueExtension, parameter : leagueID.ToString()));
 }
예제 #9
0
 public Task <User> FindOneAsync(string userId)
 {
     return(_httpManager.GetAsync <User>($"userApi/User/{userId}"));
 }