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"); }
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); }
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)); }
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); } }
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); }
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); } } }
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); }
public async Task <List <MatchModel> > GetLeagueMatchesAsync(int leagueID) { return(await _httpManager.GetAsync <List <MatchModel> >(ApiConstants.MatchesURL, extension : ApiConstants.LeagueExtension, parameter : leagueID.ToString())); }
public Task <User> FindOneAsync(string userId) { return(_httpManager.GetAsync <User>($"userApi/User/{userId}")); }