The Free Software Media System - Server Backend & API
Added Windows Phone specific code to BaseHttpApiClient that only compiles if it's a windows phone project.
ScottIsAFool Scott Lovegrove ScottIsAFool29cdf55e4491
diff --git a/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs b/MediaBrowser.ApiInteraction/BaseHttpApiClient.csindex 7468b60391..0fa9465e1b 100644--- a/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs+++ b/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs@@ -5,10 +5,13 @@ using MediaBrowser.Model.Weather;using System;using System.IO;using System.Net;-using System.Net.Http;using System.Text;using System.Threading.Tasks;-using MediaBrowser.Model.Entities;+#if WINDOWS_PHONE+using SharpGIS;+#else+using System.Net.Http;+#endifnamespace MediaBrowser.ApiInteraction{@@ -17,6 +20,14 @@ namespace MediaBrowser.ApiInteraction/// </summary>public abstract class BaseHttpApiClient : BaseApiClient{+#if WINDOWS_PHONE+ public BaseHttpApiClient()+ {+ HttpClient = new GZipWebClient();+ }++ private WebClient HttpClient { get; set; }+#elsepublic BaseHttpApiClient(HttpClientHandler handler): base(){@@ -26,6 +37,7 @@ namespace MediaBrowser.ApiInteraction}private HttpClient HttpClient { get; set; }+#endif/// <summary>/// Gets an image stream based on a url@@ -501,6 +513,16 @@ namespace MediaBrowser.ApiInteractionpostContent += "&password=" + password;}+#if WINDOWS_PHONE+ HttpClient.Headers["Content-Type"] = "application/x-www-form-urlencoded";+ var result = await HttpClient.UploadStringTaskAsync(url, "POST", postContent);++ var byteArray = Encoding.UTF8.GetBytes(result);+ using (MemoryStream stream = new MemoryStream(byteArray))+ {+ return DeserializeFromStream<AuthenticationResult>(stream);+ }+#elseHttpContent content = new StringContent(postContent, Encoding.UTF8, "application/x-www-form-urlencoded");HttpResponseMessage msg = await HttpClient.PostAsync(url, content).ConfigureAwait(false);@@ -509,6 +531,7 @@ namespace MediaBrowser.ApiInteraction{return DeserializeFromStream<AuthenticationResult>(stream);}+#endif}/// <summary>@@ -541,12 +564,18 @@ namespace MediaBrowser.ApiInteraction/// </summary>private Task<Stream> GetStreamAsync(string url){+#if WINDOWS_PHONE+ return HttpClient.OpenReadTaskAsync(url);+#elsereturn HttpClient.GetStreamAsync(url);+#endif}public override void Dispose(){+#if !WINDOWS_PHONEHttpClient.Dispose();+#endif}}}