Skip to content

Commit 7452b1d

Browse files
committed
Removed UWP specific logic from the networking library
1 parent d4b2df8 commit 7452b1d

7 files changed

Lines changed: 41 additions & 166 deletions

File tree

MADE.App.Networking/NetworkRequestManager.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ namespace MADE.App.Networking
2323
/// </summary>
2424
public sealed class NetworkRequestManager : INetworkRequestManager
2525
{
26-
#if WINDOWS_UWP
27-
private readonly Windows.UI.Xaml.DispatcherTimer processTimer;
28-
#else
2926
private Timer processTimer;
30-
#endif
3127

3228
private bool isProcessingRequests;
3329

@@ -37,11 +33,6 @@ public sealed class NetworkRequestManager : INetworkRequestManager
3733
public NetworkRequestManager()
3834
{
3935
this.CurrentQueue = new ConcurrentDictionary<string, NetworkRequestCallback>();
40-
41-
#if WINDOWS_UWP
42-
this.processTimer = new Windows.UI.Xaml.DispatcherTimer { Interval = TimeSpan.FromMinutes(1) };
43-
this.processTimer.Tick += (sender, o) => this.ProcessCurrentQueue();
44-
#endif
4536
}
4637

4738
/// <summary>
@@ -65,14 +56,6 @@ public void Start()
6556
/// </param>
6657
public void Start(TimeSpan processPeriod)
6758
{
68-
#if WINDOWS_UWP
69-
this.processTimer.Interval = processPeriod;
70-
71-
if (!this.processTimer.IsEnabled)
72-
{
73-
this.processTimer.Start();
74-
}
75-
#else
7659
if (this.processTimer == null)
7760
{
7861
this.processTimer = new Timer(
@@ -85,22 +68,14 @@ public void Start(TimeSpan processPeriod)
8568
{
8669
this.processTimer.Change(TimeSpan.FromMinutes(0), processPeriod);
8770
}
88-
#endif
8971
}
9072

9173
/// <summary>
9274
/// Stops the processing of the network manager queues.
9375
/// </summary>
9476
public void Stop()
9577
{
96-
#if WINDOWS_UWP
97-
if (this.processTimer.IsEnabled)
98-
{
99-
this.processTimer.Stop();
100-
}
101-
#else
10278
this.processTimer?.Change(Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
103-
#endif
10479
}
10580

10681
/// <summary>

MADE.App.Networking/Requests/Json/JsonDeleteNetworkRequest.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,13 @@
99

1010
namespace MADE.App.Networking.Requests.Json
1111
{
12-
#if WINDOWS_UWP
13-
using System;
14-
using System.Collections.Generic;
15-
using System.Threading;
16-
using System.Threading.Tasks;
17-
18-
using Windows.Web.Http;
19-
20-
using Newtonsoft.Json;
21-
22-
#else
2312
using System;
2413
using System.Collections.Generic;
2514
using System.Net.Http;
2615
using System.Threading;
2716
using System.Threading.Tasks;
2817

2918
using Newtonsoft.Json;
30-
#endif
3119

3220
/// <summary>
3321
/// Defines a network request for a DELETE call with a JSON response.
@@ -128,15 +116,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
128116
}
129117
}
130118

131-
#if WINDOWS_UWP
132-
HttpResponseMessage response = cts == null
133-
? await this.client.SendRequestAsync(
134-
request,
135-
HttpCompletionOption.ResponseHeadersRead)
136-
: await this.client.SendRequestAsync(
137-
request,
138-
HttpCompletionOption.ResponseHeadersRead).AsTask(cts.Token);
139-
#else
140119
HttpResponseMessage response = cts == null
141120
? await this.client.SendAsync(
142121
request,
@@ -145,7 +124,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
145124
request,
146125
HttpCompletionOption.ResponseHeadersRead,
147126
cts.Token);
148-
#endif
149127

150128
response.EnsureSuccessStatusCode();
151129

MADE.App.Networking/Requests/Json/JsonGetNetworkRequest.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,13 @@
99

1010
namespace MADE.App.Networking.Requests.Json
1111
{
12-
#if WINDOWS_UWP
13-
using System;
14-
using System.Collections.Generic;
15-
using System.Threading;
16-
using System.Threading.Tasks;
17-
18-
using Windows.Web.Http;
19-
20-
using Newtonsoft.Json;
21-
22-
#else
2312
using System;
2413
using System.Collections.Generic;
2514
using System.Net.Http;
2615
using System.Threading;
2716
using System.Threading.Tasks;
2817

2918
using Newtonsoft.Json;
30-
#endif
3119

3220
/// <summary>
3321
/// Defines a network request for a GET call with a JSON response.
@@ -128,15 +116,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
128116
}
129117
}
130118

131-
#if WINDOWS_UWP
132-
HttpResponseMessage response = cts == null
133-
? await this.client.SendRequestAsync(
134-
request,
135-
HttpCompletionOption.ResponseHeadersRead)
136-
: await this.client.SendRequestAsync(
137-
request,
138-
HttpCompletionOption.ResponseHeadersRead).AsTask(cts.Token);
139-
#else
140119
HttpResponseMessage response = cts == null
141120
? await this.client.SendAsync(
142121
request,
@@ -145,7 +124,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
145124
request,
146125
HttpCompletionOption.ResponseHeadersRead,
147126
cts.Token);
148-
#endif
149127

150128
response.EnsureSuccessStatusCode();
151129

MADE.App.Networking/Requests/Json/JsonPatchNetworkRequest.cs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
// </summary>
88
// --------------------------------------------------------------------------------------------------------------------
99

10-
#if WINDOWS_UWP
1110
namespace MADE.App.Networking.Requests.Json
1211
{
1312
using System;
1413
using System.Collections.Generic;
14+
using System.Net.Http;
15+
using System.Text;
1516
using System.Threading;
1617
using System.Threading.Tasks;
1718

18-
using Windows.Storage.Streams;
19-
using Windows.Web.Http;
20-
2119
using MADE.App.Networking.Requests;
2220

2321
using Newtonsoft.Json;
@@ -142,13 +140,15 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
142140

143141
Uri uri = new Uri(this.Url);
144142

145-
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Patch, uri)
146-
{
147-
Content = new HttpStringContent(
148-
this.Data,
149-
UnicodeEncoding.Utf8,
150-
"application/json")
151-
};
143+
HttpRequestMessage request = new HttpRequestMessage
144+
{
145+
Method = new HttpMethod("PATCH"),
146+
RequestUri = uri,
147+
Content = new StringContent(
148+
this.Data,
149+
Encoding.UTF8,
150+
"application/json")
151+
};
152152

153153
if (this.Headers != null)
154154
{
@@ -159,14 +159,17 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
159159
}
160160

161161
HttpResponseMessage response = cts == null
162-
? await this.client.SendRequestAsync(request, HttpCompletionOption.ResponseHeadersRead)
163-
: await this.client.SendRequestAsync(request, HttpCompletionOption.ResponseHeadersRead)
164-
.AsTask(cts.Token);
162+
? await this.client.SendAsync(
163+
request,
164+
HttpCompletionOption.ResponseHeadersRead)
165+
: await this.client.SendAsync(
166+
request,
167+
HttpCompletionOption.ResponseHeadersRead,
168+
cts.Token);
165169

166170
response.EnsureSuccessStatusCode();
167171

168172
return await response.Content.ReadAsStringAsync();
169173
}
170174
}
171-
}
172-
#endif
175+
}

MADE.App.Networking/Requests/Json/JsonPostNetworkRequest.cs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99

1010
namespace MADE.App.Networking.Requests.Json
1111
{
12-
#if WINDOWS_UWP
13-
using System;
14-
using System.Collections.Generic;
15-
using System.Threading;
16-
using System.Threading.Tasks;
17-
18-
using Windows.Storage.Streams;
19-
using Windows.Web.Http;
20-
21-
using Newtonsoft.Json;
22-
23-
#else
2412
using System;
2513
using System.Collections.Generic;
2614
using System.Net.Http;
@@ -30,8 +18,6 @@ namespace MADE.App.Networking.Requests.Json
3018

3119
using Newtonsoft.Json;
3220

33-
#endif
34-
3521
/// <summary>
3622
/// Defines a network request for a POST call with a JSON response.
3723
/// </summary>
@@ -152,17 +138,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
152138

153139
Uri uri = new Uri(this.Url);
154140

155-
#if WINDOWS_UWP
156-
157-
var request = new HttpRequestMessage(HttpMethod.Post, uri)
158-
{
159-
Content =
160-
new HttpStringContent(
161-
this.Data,
162-
UnicodeEncoding.Utf8,
163-
"application/json")
164-
};
165-
#else
166141
HttpRequestMessage request =
167142
new HttpRequestMessage(HttpMethod.Post, uri)
168143
{
@@ -171,7 +146,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
171146
Encoding.UTF8,
172147
"application/json")
173148
};
174-
#endif
175149

176150
if (this.Headers != null)
177151
{
@@ -181,15 +155,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
181155
}
182156
}
183157

184-
#if WINDOWS_UWP
185-
HttpResponseMessage response = cts == null
186-
? await this.client.SendRequestAsync(
187-
request,
188-
HttpCompletionOption.ResponseHeadersRead)
189-
: await this.client.SendRequestAsync(
190-
request,
191-
HttpCompletionOption.ResponseHeadersRead).AsTask(cts.Token);
192-
#else
193158
HttpResponseMessage response = cts == null
194159
? await this.client.SendAsync(
195160
request,
@@ -198,7 +163,6 @@ private async Task<string> GetJsonResponse(CancellationTokenSource cts = null)
198163
request,
199164
HttpCompletionOption.ResponseHeadersRead,
200165
cts.Token);
201-
#endif
202166

203167
response.EnsureSuccessStatusCode();
204168

0 commit comments

Comments
 (0)