/// <summary> /// Closes the session. /// </summary> /// <returns></returns> public async Task CloseAsync() { if (authorizationHeader != null) { StringContent content = new StringContent(""); content.Headers.ContentType.MediaType = "application/json"; var uri = ServiceRoot.ToString().Replace("/odata", "/Logout").TrimEnd('/'); var result = await httpClient.PostAsync(uri, content); //var json = await result.Content.ReadAsStringAsync(); authorizationHeader = null; } }
private async Task RefreshEndpoints() { var endpoints = await _serviceControl.GetEndpoints(); if (endpoints == null) { return; } foreach (var endpoint in endpoints) { if (!ServiceRoot.EndpointExists(endpoint)) { ServiceRoot.Children.Add(new AuditEndpointExplorerItem(endpoint)); } } }
/// <summary> /// Logins the specified user. /// </summary> /// <param name="credentials">The credentials.</param> /// <returns></returns> /// <exception cref="Exception">Invalid user name or password.</exception> public async Task <string> LoginAsync(ErpCredentials credentials) { StringContent content = new StringContent( string.Format("{{\"app\":\"{0}\",\"user\":\"{1}\",\"pass\":\"{2}\",\"ln\":\"{3}\"}}", credentials.ApplicationName, credentials.UserName, credentials.Password, credentials.Language)); content.Headers.ContentType.MediaType = "application/json"; var uri = ServiceRoot.ToString().Replace("/odata", "/Login").TrimEnd('/'); HttpRequestMessage msg = new HttpRequestMessage() { RequestUri = new Uri(uri), Method = HttpMethod.Post, Content = content }; msg.Headers.ExpectContinue = false; var result = await httpClient.SendAsync(msg, HttpCompletionOption.ResponseContentRead); var json = await result.Content.ReadAsStringAsync(); try { if (!result.IsSuccessStatusCode) { throw new Exception(json); } } catch (Exception ex) { throw new Exception("Invalid user name or password.", ex); } authorizationHeader = json.Split(':')[1].Trim('"', '}'); httpClient.DefaultRequestHeaders.Add("Authorization", authorizationHeader); return(json); }
void RemoteDataServiceDataLoaded(object sender, string e) { ServiceRoot rootData = null; try { rootData = JsonConvert.DeserializeObject <ServiceRoot>(e); }catch { DateTime lastDate; DateTime.TryParse(StorageService.Instance.UpdatedDate, out lastDate); UpdatingError?.Invoke(this, new DataFailedArgs(DataError.DataException, lastDate)); } if (rootData != null) { StorageService.Instance.ServiceData = e; StorageService.Instance.UpdatedDate = DateTime.Now.ToString(); DataUpdated?.Invoke(this, rootData); } }
protected void Application_Start(object sender, EventArgs e) { ServiceRoot.Init(); }