diff options
| author | ScottIsAFool Scott Lovegrove ScottIsAFool <ScottIsAFool Scott Lovegrove ScottIsAFool@gmail.com> | 2012-09-09 21:34:23 +0100 |
|---|---|---|
| committer | ScottIsAFool Scott Lovegrove ScottIsAFool <ScottIsAFool Scott Lovegrove ScottIsAFool@gmail.com> | 2012-09-09 21:34:23 +0100 |
| commit | 29cdf55e4491107b4bbaab7f4a3e88ef8509e6af (patch) | |
| tree | 2720fb9239d98d3dc264188e6a5b81798c575e78 | |
| parent | 8530e698782d16517359f594575bf9bfbb5cd6bb (diff) | |
Added Windows Phone specific code to BaseHttpApiClient that only compiles if it's a windows phone project.
| -rw-r--r-- | MediaBrowser.ApiInteraction/BaseHttpApiClient.cs | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs b/MediaBrowser.ApiInteraction/BaseHttpApiClient.cs index 7468b6039..0fa9465e1 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;
+#endif
namespace 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; }
+#else
public 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.ApiInteraction postContent += "&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);
+ }
+#else
HttpContent 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);
+#else
return HttpClient.GetStreamAsync(url);
+#endif
}
public override void Dispose()
{
+#if !WINDOWS_PHONE
HttpClient.Dispose();
+#endif
}
}
}
|
