forked from manywho/sdk-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawSingleton.cs
619 lines (527 loc) · 30.9 KB
/
DrawSingleton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using ManyWho.Flow.SDK.Utils;
using ManyWho.Flow.SDK.Describe;
using ManyWho.Flow.SDK.Security;
using ManyWho.Flow.SDK.Draw.Flow;
using ManyWho.Flow.SDK.Draw.Elements.UI;
using ManyWho.Flow.SDK.Draw.Elements.Map;
using ManyWho.Flow.SDK.Draw.Elements.Type;
using ManyWho.Flow.SDK.Draw.Elements.Group;
using ManyWho.Flow.SDK.Draw.Elements.Config;
using ManyWho.Flow.SDK.Draw.Elements.Value;
using ManyWho.Flow.SDK.Errors;
using Polly;
namespace ManyWho.Flow.SDK
{
public class DrawSingleton
{
public const String MANYWHO_BASE_URL = "https://flow.manywho.com";
public const String MANYWHO_DRAW_URI_PART_TYPE_ELEMENT = "/api/draw/1/element/type";
public const String MANYWHO_DRAW_URI_PART_VALUE_ELEMENT = "/api/draw/1/element/value";
public const String MANYWHO_DRAW_URI_PART_SERVICE_ELEMENT = "/api/draw/1/element/service";
public const String MANYWHO_DRAW_URI_PART_PAGE_ELEMENT = "/api/draw/1/element/page";
public const String MANYWHO_DRAW_URI_PART_MAP_ELEMENT = "/api/draw/1/flow/{0}/{1}/element/map";
public const String MANYWHO_DRAW_URI_PART_GROUP_ELEMENT = "/api/draw/1/flow/{0}/{1}/element/group";
public const String MANYWHO_DRAW_URI_PART_FLOW = "/api/draw/1/flow";
public const String MANYWHO_DRAW_URI_PART_LOGIN = "/api/draw/1/authentication";
public const String MANYWHO_DRAW_URI_PART_ADD_ELEMENT_TO_FLOW = "/api/draw/1/element/flow/{0}/{1}/{2}";
public const String MANYWHO_DRAW_URI_PART_LOAD_FLOWS = "/api/draw/1/flow?filter=";
public const String MANYWHO_DRAW_URI_PART_SNAPSHOT_FLOW = "/api/draw/1/flow/snap/{0}";
public const String MANYWHO_DRAW_URI_PART_ACTIVATION = "/api/draw/1/flow/activation/{0}/{1}/{2}/{3}";
public const String MANYWHO_DRAW_URI_PART_ADMIN_PLUGIN_AUTHENTICATION = "/plugins/manywho/api/admin/1/authentication";
private static DrawSingleton drawSingleton;
private DrawSingleton()
{
}
public static DrawSingleton GetInstance()
{
if (drawSingleton == null)
{
drawSingleton = new DrawSingleton();
}
return drawSingleton;
}
/// <summary>
/// This method allows you to login as an author of flows.
/// </summary>
public IAuthenticatedWho Login(INotifier notifier, String tenantId, String manywhoBaseUrl, AuthenticationCredentialsAPI authenticationCredentials)
{
String authorizationToken = null;
IAuthenticatedWho authenticatedWho = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(null, tenantId, null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(authenticationCredentials));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the describe request
endpointUrl = manywhoBaseUrl + DrawSingleton.MANYWHO_DRAW_URI_PART_LOGIN;
// Send the describe request over to the remote service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the describe response object from the response message
authorizationToken = httpResponseMessage.Content.ReadAsStringAsync().Result;
// Trim the quotes from the JSON response token
authorizationToken = authorizationToken.Substring(1, authorizationToken.Length - 2);
// Deserialize the token back to an authenticated who object
authenticatedWho = AuthenticationUtils.Deserialize(Uri.UnescapeDataString(authorizationToken));
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return authenticatedWho;
}
/// <summary>
/// This method should be used to get descriptions of supported plugins.
/// </summary>
public DescribeServiceResponseAPI Describe(INotifier notifier, IAuthenticatedWho authenticatedWho, DescribeServiceRequestAPI describeServiceRequest)
{
using (var httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null, HttpUtils.SYSTEM_TIMEOUT_SECONDS))
{
// Use the JSON formatter to create the content of the request body.
HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(describeServiceRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the describe request
string endpointUrl = describeServiceRequest.uri + "/metadata";
// Send the describe request over to the remote service
HttpResponseMessage httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the describe response object from the response message
return JsonConvert.DeserializeObject<DescribeServiceResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
}
/// <summary>
/// This method allows you to save flows back to the service.
/// </summary>
public FlowResponseAPI SaveFlow(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, FlowRequestAPI flowRequest)
{
FlowResponseAPI flowResponse = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(flowRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + MANYWHO_DRAW_URI_PART_FLOW;
// Send the flow to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the flow response back from the save
flowResponse = JsonConvert.DeserializeObject<FlowResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return flowResponse;
}
/// <summary>
/// This method loads all of the flows in the draw service.
/// </summary>
public List<FlowResponseAPI> LoadFlows(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, String tenantId, String filter)
{
String endpointUrl = null;
HttpClient httpClient = null;
HttpResponseMessage httpResponseMessage = null;
List<FlowResponseAPI> flowResponses = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Construct the URL for the draw request
endpointUrl = manywhoBaseUrl + MANYWHO_DRAW_URI_PART_LOAD_FLOWS + filter;
// Get the flow responses from ManyWho
httpResponseMessage = httpClient.GetAsync(endpointUrl).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the flow responses list from the response message
flowResponses = JsonConvert.DeserializeObject<List<FlowResponseAPI>>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return flowResponses;
}
/// <summary>
/// This method snap shots the latest flow in the modelling environment.
/// </summary>
public FlowResponseAPI SnapShotFlow(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, String flowId)
{
FlowResponseAPI flowResponse = null;
HttpClient httpClient = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Construct the URL for the snapshot
endpointUrl = manywhoBaseUrl + String.Format(MANYWHO_DRAW_URI_PART_SNAPSHOT_FLOW, flowId);
// Send the flow to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, null).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the flow response back from the save
flowResponse = JsonConvert.DeserializeObject<FlowResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return flowResponse;
}
/// <summary>
/// This method takes a flow snap shot and activates it based on the provided settings.
/// </summary>
public FlowResponseAPI SetFlowActivation(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, FlowIdAPI flowId, Boolean isDefault, Boolean isActivated)
{
FlowResponseAPI flowResponse = null;
HttpClient httpClient = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Construct the URL for the activation
endpointUrl = manywhoBaseUrl + String.Format(MANYWHO_DRAW_URI_PART_ACTIVATION, flowId.id, flowId.versionId, isDefault.ToString().ToLower(), isActivated.ToString().ToLower());
// Send the flow to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, null).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the flow response back from the save
flowResponse = JsonConvert.DeserializeObject<FlowResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return flowResponse;
}
/// <summary>
/// This method allows you to save shared elements back to the service.
/// </summary>
public void AddElementToFlow(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, String flowId, String elementType, String elementId)
{
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + String.Format(MANYWHO_DRAW_URI_PART_ADD_ELEMENT_TO_FLOW, flowId, elementType, elementId);
// We construct an empty content request as we don't actually have any post values
httpContent = new StringContent("");
// Send the request over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (!httpResponseMessage.IsSuccessStatusCode)
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
}
/// <summary>
/// This method allows you to save value elements back to the service.
/// </summary>
public ValueElementResponseAPI SaveValueElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, ValueElementRequestAPI valueElementRequest)
{
ValueElementResponseAPI valueElementResponse = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(valueElementRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + MANYWHO_DRAW_URI_PART_VALUE_ELEMENT;
// Send the value element data to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the value element response back from the save
valueElementResponse = JsonConvert.DeserializeObject<ValueElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return valueElementResponse;
}
public TypeElementResponseAPI SaveTypeElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, TypeElementRequestAPI typeElementRequest)
{
TypeElementResponseAPI typeElementResponse = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(typeElementRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + MANYWHO_DRAW_URI_PART_TYPE_ELEMENT;
// Send the type element data to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the type element response back from the save
typeElementResponse = JsonConvert.DeserializeObject<TypeElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return typeElementResponse;
}
/// <summary>
/// This method allows you to save service elements back to the service.
/// </summary>
public ServiceElementResponseAPI SaveServiceElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, ServiceElementRequestAPI serviceElementRequest)
{
ServiceElementResponseAPI serviceElementResponse = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(serviceElementRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + MANYWHO_DRAW_URI_PART_SERVICE_ELEMENT;
// Send the service element data to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the service element response back from the save
serviceElementResponse = JsonConvert.DeserializeObject<ServiceElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return serviceElementResponse;
}
/// <summary>
/// This method allows you to save page elements back to the service.
/// </summary>
public PageElementResponseAPI SavePageElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, PageElementRequestAPI pageElementRequest)
{
PageElementResponseAPI pageElementResponse = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(pageElementRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + MANYWHO_DRAW_URI_PART_PAGE_ELEMENT;
// Send the page element data to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the page element response back from the save
pageElementResponse = JsonConvert.DeserializeObject<PageElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return pageElementResponse;
}
public MapElementResponseAPI LoadMapElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, String editingToken, String flowId, String mapElementId)
{
MapElementResponseAPI mapElementResponse = null;
HttpClient httpClient = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + String.Format(MANYWHO_DRAW_URI_PART_MAP_ELEMENT, flowId, editingToken) + "/" + mapElementId;
// Get the map element data to from the service
httpResponseMessage = httpClient.GetAsync(endpointUrl).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the map element response back from the load request
mapElementResponse = JsonConvert.DeserializeObject<MapElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return mapElementResponse;
}
public MapElementResponseAPI SaveMapElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, String editingToken, String flowId, MapElementRequestAPI mapElementRequest)
{
MapElementResponseAPI mapElementResponse = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(mapElementRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + String.Format(MANYWHO_DRAW_URI_PART_MAP_ELEMENT, flowId, editingToken);
// Send the map element data to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the map element response back from the save
mapElementResponse = JsonConvert.DeserializeObject<MapElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return mapElementResponse;
}
public GroupElementResponseAPI LoadGroupElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, String editingToken, String flowId, String groupElementId)
{
GroupElementResponseAPI groupElementResponse = null;
HttpClient httpClient = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + String.Format(MANYWHO_DRAW_URI_PART_GROUP_ELEMENT, flowId, editingToken) + "/" + groupElementId;
// Get the group element data to from the service
httpResponseMessage = httpClient.GetAsync(endpointUrl).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the group element response back from the load request
groupElementResponse = JsonConvert.DeserializeObject<GroupElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return groupElementResponse;
}
public GroupElementResponseAPI SaveGroupElement(INotifier notifier, IAuthenticatedWho authenticatedWho, String manywhoBaseUrl, String editingToken, String flowId, GroupElementRequestAPI groupElementRequest)
{
GroupElementResponseAPI groupElementResponse = null;
HttpClient httpClient = null;
HttpContent httpContent = null;
HttpResponseMessage httpResponseMessage = null;
String endpointUrl = null;
Policy.Handle<ServiceProblemException>().Retry(HttpUtils.MAXIMUM_RETRIES).Execute(() =>
{
using (httpClient = HttpUtils.CreateHttpClient(authenticatedWho, authenticatedWho.ManyWhoTenantId.ToString(), null))
{
// Use the JSON formatter to create the content of the request body.
httpContent = new StringContent(JsonConvert.SerializeObject(groupElementRequest));
httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
// Construct the URL for the save
endpointUrl = manywhoBaseUrl + String.Format(MANYWHO_DRAW_URI_PART_GROUP_ELEMENT, flowId, editingToken);
// Send the group element data to save over to the service
httpResponseMessage = httpClient.PostAsync(endpointUrl, httpContent).Result;
// Check the status of the response and respond appropriately
if (httpResponseMessage.IsSuccessStatusCode)
{
// Get the group element response back from the save
groupElementResponse = JsonConvert.DeserializeObject<GroupElementResponseAPI>(httpResponseMessage.Content.ReadAsStringAsync().Result);
}
else
{
throw new ServiceProblemException(new ServiceProblem(endpointUrl, httpResponseMessage, string.Empty));
}
}
});
return groupElementResponse;
}
}
}