private async Task<AppConfigurationServerResponse> Get()
{
if (string.IsNullOrEmpty(this.endpointService.Endpoint)) return null;
AppConfigurationServerResponse res = null;
var appConfigHash = string.Empty;
if (AppConfig != null)
{
appConfigHash = $"/{currentAppConfigurationMd5Hash}";
}
var endpoint = $"{this.endpointService.Endpoint}{appConfigHash}";
try
{
using (var client = new HttpClient())
{
//TODO: once we have BuildIt.General referenced, refactor this code to use for instance DoForEach
if (AdditionalHeaders != null)
{
foreach (var extraHeaderKeyValuePair in AdditionalHeaders)
{
client.DefaultRequestHeaders.Add(extraHeaderKeyValuePair.Key, extraHeaderKeyValuePair.Value);
}
}
var requestContent = new StringContent(JsonConvert.SerializeObject(Mapper.MappedValues));
requestContent.Headers.ContentType.MediaType = "application/json";
using (var response = await client.PostAsync(endpoint, requestContent))
{
if (response == null) return res;
using (var content = response.Content)
{
var responseContent = await content.ReadAsStringAsync();
res = JsonConvert.DeserializeObject<AppConfigurationServerResponse>(responseContent);
}
}
}
}
catch (Exception e)
{
#if DEBUG
await UserDialogService.AlertAsync($"{Strings.OpsSomethingWentWrong}: {JsonConvert.SerializeObject(e)}");
#endif
Debug.WriteLine(e.Message);
}
return res;
}