private async Task<string> GetMessage() { HttpClient client; var response = await client.SendAsync(new HttpRequestMessage()); response.Content.ReadAsAsync<>() //await Task.Delay(5000); var streamContent = new StreamContent(File.OpenRead(@"C:\Build\PHM\Production\Web\CustomX\183\HA-HealthProfile_wlq.questions")); return await streamContent.ReadAsStringAsync(); }
private void HelloBtn_Click(object sender, RoutedEventArgs e) { var streamContent = new StreamContent(File.OpenRead(@"C:\Build\PHM\Production\Web\CustomX\183\HA-HealthProfile_wlq.questions")); streamContent.ReadAsStringAsync().ContinueWith(x => ShowMessage(x.Result)); //var message = await GetMessage(); //var task = GetMessage(); //task.ContinueWith(x => ShowMessage("done")); }
public static void UsingStreamContent() { // When you have a stream of data, StreamContent is your best bet. var bytes = Encoding.ASCII.GetBytes(Helpers.__); var stream = new MemoryStream(bytes); var content = new StreamContent(stream); var body = content.ReadAsStringAsync().Result; Helpers.AssertEquality("Hello, stream!", body); }
private static void Main(string[] args) { const int TotalRun = 10*1000; var customerController = new CustomerController(); var orderController = new OrderController(); var customer = customerController.Get(1); var orders = new List<Order>(); foreach (var orderId in customer.OrderIds) { orders.Add(orderController.Get(1, orderId)); } var fullCustomer = new FullCustomer(customer) { Orders = orders }; var s = JsonConvert.SerializeObject(fullCustomer); var bytes = Encoding.UTF8.GetBytes(s); var stream = new MemoryStream(bytes); var content = new StreamContent(stream); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var stopwatch = Stopwatch.StartNew(); for (int i = 1; i < TotalRun+1; i++) { var a = content.ReadAsAsync<FullCustomer>().Result; if(i % 100 == 0) Console.Write("\r" + i); } Console.WriteLine(); Console.WriteLine(stopwatch.Elapsed); stopwatch.Restart(); for (int i = 1; i < TotalRun+1; i++) { var sa = content.ReadAsStringAsync().Result; var a = JsonConvert.DeserializeObject<FullCustomer>(sa); if (i % 100 == 0) Console.Write("\r" + i); } Console.WriteLine(); Console.WriteLine(stopwatch.Elapsed); Console.Read(); }
/// <summary> /// Permet d'insérer un event dans un calendrier /// </summary> /// <param name="evt">L'event qu'on doit insérer.</param> public async Task<Event> InsertEvent(Event evt) { if (!String.IsNullOrEmpty(Calendar.Id)) { StreamContent eventJson = new StreamContent(Service.Serialize(evt)); eventJson.Headers.Add("Content-Type", "application/json;charset=utf-8"); Task<string> test = eventJson.ReadAsStringAsync(); Stream result = await Service.Post("https://www.googleapis.com/calendar/v3/calendars/" + Calendar.Id + "/events", eventJson); if (result != null) { DataContractJsonSerializer deserializer = new DataContractJsonSerializer(typeof(Event)); Event evtret = (Event)deserializer.ReadObject(result); mEvents.Add(evtret); return evtret; } } return null; }
public void ReadAsString () { var ms = new MemoryStream (); ms.WriteByte (77); ms.WriteByte (55); ms.Seek (0, SeekOrigin.Begin); var sc = new StreamContent (ms); var res = sc.ReadAsStringAsync ().Result; Assert.AreEqual ("M7", res, "#1"); }
public void ShouldBeAbleToCreateStreamContent() { //Arrange var ms = new MemoryStream(); var sr = new StreamWriter(ms); sr.Write("Hello World"); sr.Flush(); ms.Position = 0; //Act var content = new StreamContent(ms); //Assert Assert.IsNotNull(content); Assert.AreEqual("Hello World", content.ReadAsStringAsync().Result); Assert.AreEqual("Hello World", new StreamReader(content.ReadAsStreamAsync().Result).ReadToEnd()); }