public async void Upload(FileMessageRequest file, Guid roomId) { file.Size = File.OpenRead(file.Path).Length; file.PartSize = BufferSize; file.Parts = (int)Math.Ceiling(file.Size / (double)BufferSize); var response = await _httpManager.PostAsync <FileDTO>($"api/Rooms/{roomId.ToString()}/FileMessages", file); if (response.Error != null) { Failed?.Invoke(response.Error.ErrorDescription); return; } var position = 0; var part = 1; while (position < file.Size) { byte[] buffer; if (position + BufferSize > file.Size) { buffer = new byte[(int)file.Size - position]; } else { buffer = new byte[BufferSize]; } using (BinaryReader reader = new BinaryReader(new FileStream(file.Path, FileMode.Open, FileAccess.Read))) { reader.BaseStream.Seek(position, SeekOrigin.Begin); if (position + BufferSize > file.Size) { reader.Read(buffer, 0, (int)file.Size - position); } else { reader.Read(buffer, 0, BufferSize); } } var request = new FilePartDTO { Content = buffer, PartNumber = part }; var resp = await _httpManager.PostAsync <bool>($"api/Files/{response.Data.Id}", request); if (resp.Error != null) { Failed?.Invoke(resp.Error.ErrorDescription); return; } position += BufferSize; } }
public async Task <LogInResponseCode> LogInAsync(AccountModel account) { var response = await _httpManager.PostAsync <LogInResponseCode>(ApiConstants.LogInURL, account); switch (response) { case LogInResponseCode.LogInSuccessful: await SecureStorage.SetAsync(SecureStorageTokens.Username, account.Username); break; } return(response); }
public async Task <bool> UpdateParticipantAsync(LeaderboardModel leaderboard, ParticipantModel participant) { if (participant == null | leaderboard == null) { return(false); } return(await _httpManager.PostAsync <bool>(ApiConstants.LeaderboardsURL, participant, ApiConstants.TrainerExtension, leaderboard.ID.ToString())); }
private async void AddRoom() { if (string.IsNullOrEmpty(NewRoomTitle)) { ShowNotification("Title cannot be empty"); return; } var resp = await _httpManager.PostAsync <Guid>("api/Rooms", new RoomRequest() { Title = NewRoomTitle }); if (resp.Error != null) { ShowNotification(resp.Error.ErrorDescription); return; } NewRoomTitle = string.Empty; }
public async void CheckIsAuthorized() { var token = Properties.Settings.Default["Token"].ToString(); if (String.IsNullOrEmpty(token)) { return; } //blocking btn Sign in IsActive = false; var tokenResponse = JsonConvert.DeserializeObject <TokenResponse>(token); Login = tokenResponse.UserLogin; ErrorLabel = "Logining ..."; _httpManager.Authorize(tokenResponse.Token); var response = await _httpManager.PostAsync <SocketTokenDTO>("api/Account/SocketToken"); if (response.Error != null) { IsActive = true; if (response.Error.ErrorCode == 401) { ErrorLabel = "You have to enter you password again"; Properties.Settings.Default["Token"] = ""; Properties.Settings.Default.Save(); return; } else { ErrorLabel = response.Error.ErrorDescription; return; } } Authorized(tokenResponse, response.Data.Id); //unblocking btn Sign in IsActive = true; }
public async Task <WsTrustResponse> GetWsTrustResponseAsync( string cloudAudienceUrn, WsTrustEndpoint endpoint, CancellationToken cancellationToken) { string wsTrustRequestMessage; var authorizationType = _authenticationParameters.AuthorizationType; switch (authorizationType) { case AuthorizationType.WindowsIntegratedAuth: wsTrustRequestMessage = endpoint.BuildTokenRequestMessageWia(cloudAudienceUrn); break; case AuthorizationType.UsernamePassword: wsTrustRequestMessage = endpoint.BuildTokenRequestMessageUsernamePassword( cloudAudienceUrn, _authenticationParameters.UserName, _authenticationParameters.Password); break; default: throw new InvalidOperationException(); } string soapAction = endpoint.Version == WsTrustVersion.WsTrust2005 ? WsTrustMexDocument.Trust2005Spec : WsTrustMexDocument.Trust13Spec; var requestHeaders = new Dictionary <string, string> { ["SOAPAction"] = soapAction, ["ContentType"] = "application/soap+xml" }; HttpContent body = new StringContent(wsTrustRequestMessage, Encoding.UTF8, requestHeaders["ContentType"]); var response = await _httpManager.PostAsync(endpoint.Uri, requestHeaders, body, cancellationToken) .ConfigureAwait(false); return(WsTrustResponse.Create(response.StatusCode, response.ResponseData)); }
public async Task <Auth> AuthenticateAsync(UserLogin userLogin) { try { await ClearAuthenticationAsync(); await _applicationData.SetTenantIdAsync(userLogin.TenantId); var auth = await _httpManager.PostAsync <Auth>("userApi/Authentication", userLogin); await _applicationData.SetAuthAsync(auth); await _applicationData.SetTenantIdAsync(userLogin.TenantId); return(auth); } catch { await ClearAuthenticationAsync(); throw; } }
public Task <User> CreateAsync(UserCreator userCreator) { return(_httpManager.PostAsync <User>("userApi/User", userCreator)); }
public async Task <ObservableCollection <Issue> > Search(string searchText, bool assignedToMe = false, bool reportedByMe = false, bool isFavourite = false, CancellationTokenSource tokenSource = null) { var fields = new List <string> { "summary", "status", "assignee", "reporter", "description", "issuetype", "priority", "comment", "project" }; var expands = new List <string> { "changelog" }; var url = string.Format("{0}{1}", App.BaseUrl, JiraRequestType.Search.ToString().ToLower()); var jql = string.Empty; if (!isFavourite) { if (!string.IsNullOrEmpty(searchText)) { jql += string.Format("text ~ {0}", searchText); } if (assignedToMe) { if (!string.IsNullOrEmpty(searchText)) { jql += string.Format("{0} AND assignee = currentUser()", jql); } else { jql += "assignee = currentUser()"; } } if (reportedByMe) { if (!string.IsNullOrEmpty(searchText)) { jql += string.Format("{0} AND reporter = currentUser()", jql); } else { jql += "reporter = currentUser()"; } } } else { jql = searchText; } var maxSearchResultSetting = new IsolatedStorageProperty <int>(Settings.MaxSearchResult, 50); var request = new SearchRequest { Fields = fields, Expands = expands, JQL = jql, MaxResults = maxSearchResultSetting.Value, StartAt = 0 }; var extras = BugSenseHandler.Instance.CrashExtraData; string data = JsonConvert.SerializeObject(request); try { extras.Add(new CrashExtraData { Key = "Method", Value = "JiraService.Search" }); var result = await httpManager.PostAsync(url, data, true, App.UserName, App.Password, tokenSource); result.EnsureSuccessStatusCode(); var responseString = await result.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(responseString)) { return(new ObservableCollection <Issue>()); } extras.Add(new CrashExtraData { Key = "Response String", Value = responseString }); var response = JsonConvert.DeserializeObject <SearchResponse>(responseString); return(new ObservableCollection <Issue>(response.Issues)); } catch (Exception exception) { BugSenseHandler.Instance.LogException(exception, extras); } return(null); }