public async Task <bool> PutCoordinatorAsync(string registration, Models.Coordinator coordinator) { var uri = new Uri(string.Format(Constants.RestUrl, "coordinators/" + registration)); var oldCoordinator = await GetCoordinatorAsync(registration); var body = CoordinatorParser.PutCoordinatorBuilder(oldCoordinator, coordinator); var content = new StringContent(body.ToString(), Encoding.UTF8, "application/json"); var contentString = await content.ReadAsStringAsync(); try { var response = await _client.PutAsync(uri, content); if (response.IsSuccessStatusCode) { var responseContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("[Coordinator API] - Put result: " + responseContent); return(true); } else { var failedContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("[Coordinator API] - Put response unsuccessful " + failedContent); return(false); } } catch (Exception ex) { Debug.WriteLine("[Coordinator API exception]:" + ex.Message); return(false); } }
public async Task <Models.Coordinator> GetCoordinatorAsync(string registration) { var uri = new Uri(string.Format(Constants.RestUrl, "coordinators/" + registration)); try { var response = await _client.GetAsync(uri); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); return(CoordinatorParser.GetCoordinatorParser(content, registration)); } return(null); } catch (Exception ex) { Debug.WriteLine("[Coordinator API exception]: " + ex.Message); return(null); } }
public async Task <List <Models.Coordinator> > GetCoordinatorsAsync() { var uri = new Uri(string.Format(Constants.RestUrl, "coordinators")); try { var response = await _client.GetAsync(uri); List <Models.Coordinator> coordinators = new List <Models.Coordinator>(); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Debug.WriteLine("[Coordinator API] - Coordinators: " + content); coordinators = CoordinatorParser.GetCoordinatorsParser(content); } return(coordinators); } catch (Exception ex) { Debug.WriteLine("[Coordinator API exception]:" + ex.Message); return(null); } }