public static async System.Threading.Tasks.Task <IQueryable <IndicativeExchangeRates.Model.Currency> > GetData() { string responseBody = string.Empty; using (System.Net.Http.HttpResponseMessage response = await ServiceClient.GetHttpResponse()) { if (response.IsSuccessStatusCode) { using (System.Net.Http.HttpContent content = response.Content) { responseBody = await content.ReadAsStringAsync(); } } else { Log.Logger.Instance.Error(new Exception($"UserName:{Authentication.AuthService.UserName} - Exchange rate data is not available. Response is {response.StatusCode.ToString()}")); throw new Exception("No data available!"); } } if (responseBody.EndsWith(@"</Tarih_Date")) { responseBody = responseBody.Replace("</Tarih_Date", "</Tarih_Date>"); } System.Xml.Linq.XDocument document = System.Xml.Linq.XDocument.Parse(responseBody); var resultSet = (from result in document.Descendants("Currency") .Where(result => result.Descendants("Isim").Any()) .Where(result => result.Descendants("CurrencyName").Any()) .Where(result => result.LastAttribute != null) .Where(result => result.Descendants("ForexBuying").Any()) .Where(result => result.Descendants("ForexSelling").Any()) .Where(result => result.Descendants("BanknoteBuying").Any()) .Where(result => result.Descendants("BanknoteSelling").Any()) select new IndicativeExchangeRates.Model.Currency { Tarih = document.Root.Attribute("Tarih").Value.Trim(), Date = document.Root.Attribute("Date").Value.Trim(), Bulten_No = document.Root.Attribute("Bulten_No").Value.Trim(), CrossOrder = result.Attribute("CrossOrder").Value.Trim(), Kod = result.Attribute("Kod").Value.Trim(), CurrencyCode = result.Attribute("CurrencyCode").Value.Trim(), Unit = Convert.ToByte(result.Element("Unit").Value.Trim()), Isim = result.Element("Isim").Value.Trim(), CurrencyName = result.Element("CurrencyName").Value.Trim(), ForexBuying = (!string.IsNullOrWhiteSpace(result.Element("ForexBuying").Value.Trim()) ? Convert.ToDecimal(result.Element("ForexBuying").Value.Trim()) : default(decimal?)), ForexSelling = (!string.IsNullOrWhiteSpace(result.Element("ForexSelling").Value.Trim()) ? Convert.ToDecimal(result.Element("ForexSelling").Value.Trim()) : default(decimal?)), BanknoteBuying = (!string.IsNullOrWhiteSpace(result.Element("BanknoteBuying").Value.Trim()) ? Convert.ToDecimal(result.Element("BanknoteBuying").Value.Trim()) : default(decimal?)), BanknoteSelling = (!string.IsNullOrWhiteSpace(result.Element("BanknoteSelling").Value.Trim()) ? Convert.ToDecimal(result.Element("BanknoteSelling").Value.Trim()) : default(decimal?)), CrossRateUSD = (!string.IsNullOrWhiteSpace(result.Element("CrossRateUSD").Value.Trim()) ? Convert.ToDecimal(result.Element("CrossRateUSD").Value.Trim()) : default(decimal?)), CrossRateOther = (!string.IsNullOrWhiteSpace(result.Element("CrossRateOther").Value.Trim()) ? Convert.ToDecimal(result.Element("CrossRateOther").Value.Trim()) : default(decimal?)) }).AsQueryable(); return(resultSet); }
public IAsyncOperationWithProgress <string, ulong> ReadAsStringAsync() { return(AsyncInfo.Run <string, ulong>((token, progress) => { return content.ReadAsStringAsync(); })); }
public static async Task <object> ToDictionaryAsync(this SystemHttpContent source) { if (source is null) { return(null); } return(Utils.Json.ToDictionary(await source.ReadAsStringAsync())); }
public static async Task <object> ToStringContentAsync(this SystemHttpContent source) { if (source is null) { return(null); } return(new StringContent(await source.ReadAsStringAsync())); }
public static async Task <object> ToObjectAsync(this SystemHttpContent source, Type type) { if (source is null) { return(null); } return(Utils.Json.ToObject(await source.ReadAsStringAsync(), type)); }
public async System.Threading.Tasks.Task <T> SendRequestAsync <T>(string requestMethod, string target, string jsonBody, int timeoutSeconds = 60) { System.Net.Http.HttpResponseMessage httpResponseMessage = await SendAsync(requestMethod, target, jsonBody, timeoutSeconds); System.Net.Http.HttpContent requestContent = httpResponseMessage.Content; string resultContent = requestContent.ReadAsStringAsync().Result; #if DEBUG try { string tempDirectory = System.IO.Path.GetTempPath(); string targetFilename = string.Format("hrworks-dbg-{0}.json", target); string tempFilepath = System.IO.Path.Combine(tempDirectory, targetFilename); string tmpContent = resultContent; try { Newtonsoft.Json.Linq.JObject jsonResult = Newtonsoft.Json.Linq.JObject.Parse(tmpContent); tmpContent = jsonResult.ToString(Newtonsoft.Json.Formatting.Indented); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } System.IO.File.WriteAllText(tempFilepath, tmpContent); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } #endif try { httpResponseMessage.EnsureSuccessStatusCode(); } catch (Exception ex) { System.Net.Http.HttpRequestException httpRequestException = new System.Net.Http.HttpRequestException(resultContent, ex); throw httpRequestException; } System.Threading.Tasks.Task <T> typedResponse = System.Threading.Tasks.Task.Factory.StartNew(() => Newtonsoft.Json.JsonConvert.DeserializeObject <T>(resultContent)); return(await typedResponse); }
public override object ReadFromStream(Type type, System.IO.Stream readStream, System.Net.Http.HttpContent content, IFormatterLogger formatterLogger) { using (var reader = new StreamReader(readStream)) { var ussdRequest = new UssdRequestMessage(); if (content != null) { var values = content.ReadAsStringAsync().Result.Split(new char[] { ',' }); ussdRequest = new UssdRequestMessage() { TransactionId = values[0], TransactionTime = values[1], MSISDN = values[2], USSDServiceCode = values[3], USSDRequestString = values[4], response = Convert.ToBoolean(values[5]), ChargeCode = Convert.ToDecimal(values[6]), ChargingFlag = Convert.ToBoolean(values[7]) }; return(ussdRequest); } else { throw new InvalidOperationException("Cannot DeSerialize Type"); } } readStream.Close(); }