From 7cbed23a742ba2a1ea4d303ac9bbe26f5b8cade8 Mon Sep 17 00:00:00 2001 From: Gary Sharp Date: Thu, 24 Jul 2014 20:58:48 +1000 Subject: [PATCH] Feature: Disco ICT Online Services - Job Publishing When warranty jobs are submitted (via plugins) users can choose to include attachments. These attachments are submitted to Disco ICT Online Services. A secure link is then provided to the plugin so the attachments can be retrieved. --- Disco.BI/BI/Extensions/JobActionExtensions.cs | 53 ++- Disco.BI/Disco.BI.csproj | 15 +- Disco.BI/app.config | 4 + Disco.BI/packages.config | 3 + Disco.Models/Disco.Models.csproj | 3 +- .../Interop/DiscoServices/PublishJobResult.cs | 15 + .../Interop/DiscoServices/UpdateRequestV2.cs | 2 +- Disco.Services/Disco.Services.csproj | 16 +- Disco.Services/Interop/DiscoServices/Jobs.cs | 103 +++++ .../Interop/DiscoServices/UpdateQuery.cs | 2 +- Disco.Services/packages.config | 3 + Disco.Web.Extensions/App.config | 4 + .../Disco.Web.Extensions.csproj | 15 +- Disco.Web.Extensions/packages.config | 3 + Disco.Web/ClientSource/Style/Job.css | 83 ++++ Disco.Web/ClientSource/Style/Job.less | 99 ++++- Disco.Web/ClientSource/Style/Job.min.css | 2 +- Disco.Web/Controllers/JobController.cs | 5 +- Disco.Web/Extensions/HtmlExtensions.cs | 6 +- Disco.Web/Models/Job/LogWarrantyModel.cs | 22 +- Disco.Web/Views/Job/LogWarranty.cshtml | 28 ++ Disco.Web/Views/Job/LogWarranty.generated.cs | 255 ++++++++++++- .../Views/Job/LogWarrantyDisclose.cshtml | 78 +++- .../Job/LogWarrantyDisclose.generated.cs | 360 ++++++++++++++++-- 24 files changed, 1088 insertions(+), 91 deletions(-) create mode 100644 Disco.Models/Services/Interop/DiscoServices/PublishJobResult.cs create mode 100644 Disco.Services/Interop/DiscoServices/Jobs.cs diff --git a/Disco.BI/BI/Extensions/JobActionExtensions.cs b/Disco.BI/BI/Extensions/JobActionExtensions.cs index 07410120..fefe32fe 100644 --- a/Disco.BI/BI/Extensions/JobActionExtensions.cs +++ b/Disco.BI/BI/Extensions/JobActionExtensions.cs @@ -10,6 +10,9 @@ using Disco.Services.Users; using Disco.Services.Authorization; using Disco.Services.Plugins.Features.RepairProvider; +using PublishJobResult = Disco.Models.Services.Interop.DiscoServices.PublishJobResult; +using DiscoServicesJobs = Disco.Services.Interop.DiscoServices.Jobs; + namespace Disco.BI.Extensions { public static class JobActionExtensions @@ -147,25 +150,50 @@ namespace Disco.BI.Extensions { if (!UserService.CurrentAuthorization.Has(Claims.Job.Actions.LogWarranty)) return false; - + return !j.ClosedDate.HasValue && (j.DeviceSerialNumber != null) && j.JobTypeId == JobType.JobTypeIds.HWar && !j.JobMetaWarranty.ExternalLoggedDate.HasValue; } - public static void OnLogWarranty(this Job j, DiscoDataContext Database, string FaultDescription, PluginFeatureManifest WarrantyProviderDefinition, OrganisationAddress Address, User TechUser, Dictionary WarrantyProviderProperties) + public static void OnLogWarranty(this Job j, DiscoDataContext Database, string FaultDescription, List SendAttachments, PluginFeatureManifest WarrantyProviderDefinition, OrganisationAddress Address, User TechUser, Dictionary WarrantyProviderProperties) { if (!j.CanLogWarranty()) throw new InvalidOperationException("Log Warranty was Denied"); - if (string.IsNullOrWhiteSpace(FaultDescription)) - FaultDescription = j.GenerateFaultDescriptionFooter(Database, WarrantyProviderDefinition); - else - FaultDescription = string.Concat(FaultDescription, Environment.NewLine, Environment.NewLine, j.GenerateFaultDescriptionFooter(Database, WarrantyProviderDefinition)); + PublishJobResult publishJobResult = null; using (WarrantyProviderFeature WarrantyProvider = WarrantyProviderDefinition.CreateInstance()) { - string providerRef = WarrantyProvider.SubmitJob(Database, j, Address, TechUser, FaultDescription, WarrantyProviderProperties); + if (SendAttachments != null && SendAttachments.Count > 0) + { + publishJobResult = DiscoServicesJobs.Publish( + Database, + j, + TechUser, + WarrantyProvider.WarrantyProviderId, + null, + FaultDescription, + SendAttachments, + Disco.BI.Extensions.AttachmentExtensions.RepositoryFilename); + + if (!publishJobResult.Success) + throw new Exception(string.Format("Disco ICT Online Services failed with the following message: ", publishJobResult.ErrorMessage)); + + if (string.IsNullOrWhiteSpace(FaultDescription)) + FaultDescription = publishJobResult.PublishMessage; + else + FaultDescription = string.Concat(FaultDescription, Environment.NewLine, "___", Environment.NewLine, publishJobResult.PublishMessage); + } + + string submitDescription; + + if (string.IsNullOrWhiteSpace(FaultDescription)) + submitDescription = j.GenerateFaultDescriptionFooter(Database, WarrantyProviderDefinition); + else + submitDescription = string.Concat(FaultDescription, Environment.NewLine, Environment.NewLine, j.GenerateFaultDescriptionFooter(Database, WarrantyProviderDefinition)); + + string providerRef = WarrantyProvider.SubmitJob(Database, j, Address, TechUser, submitDescription, WarrantyProviderProperties); j.JobMetaWarranty.ExternalLoggedDate = DateTime.Now; j.JobMetaWarranty.ExternalName = WarrantyProvider.WarrantyProviderId; @@ -184,6 +212,15 @@ namespace Disco.BI.Extensions Comments = string.Format("####Warranty Claim Submitted\r\nProvider: **{0}**\r\nAddress: **{1}**\r\nReference: **{2}**\r\n___\r\n{3}", WarrantyProvider.Manifest.Name, Address.Name, providerRef, FaultDescription) }; Database.JobLogs.Add(jobLog); + + if (publishJobResult != null) + { + try + { + DiscoServicesJobs.UpdateRecipientReference(Database, j, publishJobResult.Id, publishJobResult.Secret, j.JobMetaWarranty.ExternalReference); + } + catch (Exception) { } // Ignore Errors as this is not completely necessary + } } } public static void OnLogWarranty(this Job j, DiscoDataContext Database, string FaultDescription, string ManualProviderName, string ManualProviderReference, OrganisationAddress Address, User TechUser) @@ -458,7 +495,7 @@ namespace Disco.BI.Extensions return false; } - + public static bool CanCloseNormally(this Job j) { if (j.CanCloseNever()) diff --git a/Disco.BI/Disco.BI.csproj b/Disco.BI/Disco.BI.csproj index 290f2bd2..d7318f0e 100644 --- a/Disco.BI/Disco.BI.csproj +++ b/Disco.BI/Disco.BI.csproj @@ -59,6 +59,14 @@ + + + ..\packages\Microsoft.Net.Http.2.2.22\lib\net45\System.Net.Http.Extensions.dll + + + ..\packages\Microsoft.Net.Http.2.2.22\lib\net45\System.Net.Http.Primitives.dll + + False ..\packages\Rx-Core.2.2.4\lib\net45\System.Reactive.Core.dll @@ -205,10 +213,15 @@ - + + + + + +