internal async Task <bool> postRequest(Qso qso, string route) { bool result = false; try { LogEntry logEntry = Mapper.Map <LogEntry>(qso); LogEntryRequest request = new LogEntryRequest() { LogEntry = logEntry }; var json = JsonConvert.SerializeObject(request); using (var client = new HttpClient()) { string url = String.Format("{0}{1}", serviceUrl, route); var headerValue = new MediaTypeWithQualityHeaderValue("text/json"); client.DefaultRequestHeaders.Accept.Add(headerValue); HttpResponseMessage response = await client.PostAsync(url, new StringContent(json, Encoding.UTF8, "text/json")); if (response.IsSuccessStatusCode) { result = true; } } } catch { result = false; } return(result); }
private bool TryParse(ReadOnlySpan <char> span, out LogEntryRequest result) { span = span.TrimAndSlice(' ', ' ', out var methodSpan); span = span.TrimAndSlice(' ', ' ', out var uriSpan); span = span.TrimAndSlice(' ', ' ', out var protocolSpan); var method = methodSpan.ToString(); var protocol = protocolSpan.ToString(); if (!Uri.TryCreate(uriSpan.ToString(), UriKind.RelativeOrAbsolute, out var uri) || string.IsNullOrWhiteSpace(method) || string.IsNullOrWhiteSpace(protocol)) { result = null; return(false); } result = new LogEntryRequest { Method = method, Uri = uri, Protocol = protocol }; return(true); }
private async Task <bool> postQso(LogEntryRequest logEntryRequest, string path) { bool result = false; using (var client = new HttpClient()) { string url = String.Format("{0}/{1}", serviceUrl, path); var headerValue = new MediaTypeWithQualityHeaderValue("text/json"); client.DefaultRequestHeaders.Accept.Add(headerValue); HttpResponseMessage response = await client.PostAsync(url, null); if (response.IsSuccessStatusCode) { var json = response.Content.ReadAsStringAsync(); result = true; } } return(result); }
public async Task <bool> Update(Qso qso) { LogEntryRequest logEntryRequest = mapQsoToLogEntryRequest(qso); return(await postQso(logEntryRequest, "update")); }
public async Task <bool> Insert(Qso qso) { LogEntryRequest logEntryRequest = mapQsoToLogEntryRequest(qso); return(await postQso(logEntryRequest, "insert")); }