diff --git a/Asset.cs b/Asset.cs index f4881e3..88bfc45 100644 --- a/Asset.cs +++ b/Asset.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ScreenlyManager { diff --git a/Device.cs b/Device.cs index 28b1378..e7b3321 100644 --- a/Device.cs +++ b/Device.cs @@ -5,11 +5,14 @@ using System.Collections.ObjectModel; using System.IO; using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading; using System.Threading.Tasks; -using Windows.Storage; +using Windows.Security.Cryptography.Certificates; using Windows.Storage.AccessCache; +using Windows.Web.Http; +using Windows.Web.Http.Filters; +using Windows.Web.Http.Headers; namespace ScreenlyManager { @@ -59,24 +62,32 @@ public string HttpLink { get { - return $"http://{IpAddress}:{Port}"; + return $"{IpAddress}:{Port}"; } } + [Newtonsoft.Json.JsonIgnore] + public HttpBaseProtocolFilter HttpFilter { get; set; } + public Device() { this.Assets = new List(); this.IsUp = false; + + this.HttpFilter = new HttpBaseProtocolFilter(); + this.HttpFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Expired); + this.HttpFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.Untrusted); + this.HttpFilter.IgnorableServerCertificateErrors.Add(ChainValidationResult.InvalidName); } public async Task IsReachable() { try { - HttpClient client = new HttpClient(); - client.Timeout = new TimeSpan(0, 0, 3); + HttpClient client = new HttpClient(this.HttpFilter); + var cancellationTokenSource = new CancellationTokenSource(3000); - HttpResponseMessage response = await client.GetAsync(this.HttpLink); + HttpResponseMessage response = await client.GetAsync(new Uri(this.HttpLink)).AsTask(cancellationTokenSource.Token); if (response == null || !response.IsSuccessStatusCode) { this.IsUp = false; @@ -111,7 +122,7 @@ public async Task GetAssetsAsync() try { HttpClient request = new HttpClient(); - using (HttpResponseMessage response = await request.GetAsync(this.HttpLink + parameters)) + using (HttpResponseMessage response = await request.GetAsync(new Uri(this.HttpLink + parameters))) { resultJson = await response.Content.ReadAsStringAsync(); } @@ -138,7 +149,7 @@ public async Task RemoveAssetAsync(string assetId) try { HttpClient request = new HttpClient(); - using (HttpResponseMessage response = await request.DeleteAsync(this.HttpLink + parameters)) + using (HttpResponseMessage response = await request.DeleteAsync(new Uri(this.HttpLink + parameters))) { resultJson = await response.Content.ReadAsStringAsync(); } @@ -176,9 +187,9 @@ public async Task UpdateAssetAsync(Asset a) try { HttpClient client = new HttpClient(); - HttpContent content = new ByteArrayContent(data, 0, data.Length); - content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); - using (HttpResponseMessage response = await client.PutAsync(this.HttpLink + parameters, content)) + HttpBufferContent content = new HttpBufferContent(data.AsBuffer()); + content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded"); + using (HttpResponseMessage response = await client.PutAsync(new Uri(this.HttpLink + parameters), content)) { resultJson = await response.Content.ReadAsStringAsync(); } @@ -220,9 +231,9 @@ public async Task UpdateOrderAssetsAsync(string newOrder) try { HttpClient client = new HttpClient(); - HttpContent content = new ByteArrayContent(data, 0, data.Length); - content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); - using (HttpResponseMessage response = await client.PostAsync(this.HttpLink + parameters, content)) + HttpBufferContent content = new HttpBufferContent(data.AsBuffer()); + content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded"); + using (HttpResponseMessage response = await client.PostAsync(new Uri(this.HttpLink + parameters), content)) { resultJson = await response.Content.ReadAsStringAsync(); } @@ -276,10 +287,9 @@ public async Task CreateAssetAsync(Asset a) try { HttpClient client = new HttpClient(); - HttpContent content = new ByteArrayContent(data, 0, data.Length); - content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); - - using (HttpResponseMessage response = await client.PostAsync(this.HttpLink + parameters, content)) + HttpBufferContent content = new HttpBufferContent(data.AsBuffer()); + content.Headers.ContentType = new HttpMediaTypeHeaderValue("application/x-www-form-urlencoded"); + using (HttpResponseMessage response = await client.PostAsync(new Uri(this.HttpLink + parameters), content)) { resultJson = await response.Content.ReadAsStringAsync(); } @@ -322,7 +332,7 @@ public async Task GetAssetAsync(string assetId) try { HttpClient request = new HttpClient(); - using (HttpResponseMessage response = await request.GetAsync(this.HttpLink + parameters)) + using (HttpResponseMessage response = await request.GetAsync(new Uri(this.HttpLink + parameters))) { resultJson = await response.Content.ReadAsStringAsync(); } @@ -352,11 +362,11 @@ public async Task PostFileAssetAsync(byte[] itemToSend, string fileName, try { HttpClient request = new HttpClient(); - var content = new MultipartFormDataContent(); - var itemContent = new ByteArrayContent(itemToSend); - itemContent.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType); + var content = new HttpMultipartFormDataContent(); + HttpBufferContent itemContent = new HttpBufferContent(itemToSend.AsBuffer()); + itemContent.Headers.ContentType = HttpMediaTypeHeaderValue.Parse(contentType); content.Add(itemContent, "file_upload", fileName); - using (HttpResponseMessage response = await request.PostAsync(this.HttpLink + parameters, content)) + using (HttpResponseMessage response = await request.PostAsync(new Uri(this.HttpLink + parameters), content)) { resultJson = await response.Content.ReadAsStringAsync(); } diff --git a/Package.appxmanifest b/Package.appxmanifest index 73b7e16..d7389f9 100644 --- a/Package.appxmanifest +++ b/Package.appxmanifest @@ -1,6 +1,6 @@  - + ScreenlyManager diff --git a/Strings/de-DE/Resources.resw b/Strings/de-DE/Resources.resw index 7b8fbc4..5f0bbb3 100644 --- a/Strings/de-DE/Resources.resw +++ b/Strings/de-DE/Resources.resw @@ -194,11 +194,11 @@ AddOrChangeDevicePage.xaml - IP Adresse + URL AddOrChangeDevicePage.xaml - z.B. 192.168.1.10 + z.B. http://192.168.1.10 AddOrChangeDevicePage.xaml diff --git a/Strings/en-US/Resources.resw b/Strings/en-US/Resources.resw index 0f8e45c..db3d8c6 100644 --- a/Strings/en-US/Resources.resw +++ b/Strings/en-US/Resources.resw @@ -194,11 +194,11 @@ AddOrChangeDevicePage.xaml - IP Address + URL AddOrChangeDevicePage.xaml - Like 192.168.1.10 + Like http://192.168.1.10 AddOrChangeDevicePage.xaml diff --git a/Strings/fr-FR/Resources.resw b/Strings/fr-FR/Resources.resw index d2130ec..fa5ddc7 100644 --- a/Strings/fr-FR/Resources.resw +++ b/Strings/fr-FR/Resources.resw @@ -194,11 +194,11 @@ AddOrChangeDevicePage.xaml - Adresse IP + URL AddOrChangeDevicePage.xaml - Par exemple : 192.168.1.10 + Par exemple : http://192.168.1.10 AddOrChangeDevicePage.xaml diff --git a/Strings/nl-NL/Resources.resw b/Strings/nl-NL/Resources.resw index 40a131a..c40cfdd 100644 --- a/Strings/nl-NL/Resources.resw +++ b/Strings/nl-NL/Resources.resw @@ -194,11 +194,11 @@ AddOrChangeDevicePage.xaml - IP-adres + URL AddOrChangeDevicePage.xaml - Zoals 192.168.1.10 + Zoals http://192.168.1.10 AddOrChangeDevicePage.xaml