From e1889185216436cb362b7f84a05993ada870635c Mon Sep 17 00:00:00 2001 From: Mads Johansen Date: Wed, 4 Jul 2018 16:35:58 +0200 Subject: [PATCH 1/6] Rewrite to use new webAPI --- Diplomatic/Models/Field.cs | 2 +- Diplomatic/Models/Signature.cs | 20 +++++++++++ Diplomatic/Models/Template.cs | 18 ++++------ Diplomatic/Utils/WebSignatureProvider.cs | 31 ++++++++++++++++ ...urceProvider.cs => WebTemplateProvider.cs} | 8 ++++- .../ViewModels/SignaturePickerViewModel.cs | 33 ++++------------- .../ViewModels/TemplatePickerViewModel.cs | 6 ++-- Diplomatic/ViewModels/TextFieldViewModel.cs | 1 + Diplomatic/Views/MainPage.xaml.cs | 3 -- Diplomatic/Views/Signatures.xaml | 11 ++---- Diplomatic/Views/Signatures.xaml.cs | 13 ++++--- Diplomatic/Views/Templates.xaml | 11 ++++-- Diplomatic/Views/Templates.xaml.cs | 11 +++--- Diplomatic/Views/TextFields.xaml.cs | 35 ++++++++++++++++--- 14 files changed, 135 insertions(+), 68 deletions(-) create mode 100644 Diplomatic/Models/Signature.cs create mode 100644 Diplomatic/Utils/WebSignatureProvider.cs rename Diplomatic/Utils/{WebResourceProvider.cs => WebTemplateProvider.cs} (71%) diff --git a/Diplomatic/Models/Field.cs b/Diplomatic/Models/Field.cs index ad804ac..f7235f0 100644 --- a/Diplomatic/Models/Field.cs +++ b/Diplomatic/Models/Field.cs @@ -1,7 +1,7 @@ using Newtonsoft.Json; using System; -namespace Diplomatic +namespace Diplomatic.Models { [Serializable] public class Field diff --git a/Diplomatic/Models/Signature.cs b/Diplomatic/Models/Signature.cs new file mode 100644 index 0000000..2f60a79 --- /dev/null +++ b/Diplomatic/Models/Signature.cs @@ -0,0 +1,20 @@ +using System; +using Newtonsoft.Json; + +namespace Diplomatic.Models +{ + [Serializable] + public class Signature + { + [JsonProperty("name")] + public string Name { get; set; } + [JsonProperty("id")] + public string Id { get; set; } + public Uri ImageUri { + get { + string basePath = $"https://qri7p78aml.execute-api.eu-west-2.amazonaws.com/dev/preview/signature/{Id}"; + return new Uri(basePath + "?width=200&height=80"); + } + } + } +} diff --git a/Diplomatic/Models/Template.cs b/Diplomatic/Models/Template.cs index 174e3f1..0a9452a 100644 --- a/Diplomatic/Models/Template.cs +++ b/Diplomatic/Models/Template.cs @@ -1,24 +1,20 @@ -using System; using System.Collections.Generic; using Newtonsoft.Json; -namespace Diplomatic +namespace Diplomatic.Models { - [Serializable] public class Template { - [JsonProperty("name")] - public string TemplateName { get; set; } - [JsonProperty("path")] - public string Path { get; set; } [JsonProperty("fields")] - public IEnumerable Fields { get; set; } + public IEnumerable Fields { get; } + public Signature Signature { get; set; } + public string Name { get; set; } + public bool HasSignature { get; } - public Template(string name, string path, IEnumerable fields) + public Template(bool signature, IEnumerable fields) { - TemplateName = name; - Path = path; Fields = fields; + HasSignature = signature; } } } diff --git a/Diplomatic/Utils/WebSignatureProvider.cs b/Diplomatic/Utils/WebSignatureProvider.cs new file mode 100644 index 0000000..a8d821c --- /dev/null +++ b/Diplomatic/Utils/WebSignatureProvider.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using Newtonsoft.Json; + +namespace Diplomatic.Utils +{ + using Models; + + public class WebSignatureProvider + { + private readonly IEnumerable signatures; + public IEnumerable GetTemplates() => signatures.Select(obj => obj); + + public WebSignatureProvider() + { + var request = WebRequest.Create(new Uri("https://qri7p78aml.execute-api.eu-west-2.amazonaws.com/dev/signatures.json")); + request.ContentType = "application/json"; + request.Method = "GET"; + + using (var response = request.GetResponse() as HttpWebResponse) + using (var reader = new StreamReader(response.GetResponseStream())) + { + string content = reader.ReadToEnd(); + signatures = JsonConvert.DeserializeObject>(content); + } + } + } +} diff --git a/Diplomatic/Utils/WebResourceProvider.cs b/Diplomatic/Utils/WebTemplateProvider.cs similarity index 71% rename from Diplomatic/Utils/WebResourceProvider.cs rename to Diplomatic/Utils/WebTemplateProvider.cs index e257e67..199d039 100644 --- a/Diplomatic/Utils/WebResourceProvider.cs +++ b/Diplomatic/Utils/WebTemplateProvider.cs @@ -7,6 +7,7 @@ namespace Diplomatic.Utils { + using Models; public class WebTemplateProvider { private readonly List