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.
This commit is contained in:
Gary Sharp
2014-07-24 20:58:48 +10:00
parent 6700d092b3
commit 7cbed23a74
24 changed files with 1088 additions and 91 deletions
+15 -1
View File
@@ -79,6 +79,14 @@
</Reference>
<Reference Include="System.DirectoryServices" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Extensions">
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\net45\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives">
<HintPath>..\packages\Microsoft.Net.Http.2.2.22\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="System.Reactive.Core, Version=2.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Rx-Core.2.2.4\lib\net45\System.Reactive.Core.dll</HintPath>
@@ -237,6 +245,7 @@
<Compile Include="Interop\ActiveDirectory\Description.cs" />
<Compile Include="Interop\ActiveDirectory\IADObject.cs" />
<Compile Include="Interop\DiscoServices\DiscoServiceHelpers.cs" />
<Compile Include="Interop\DiscoServices\Jobs.cs" />
<Compile Include="Interop\VicEduDept\VicSmart.cs" />
<Compile Include="Interop\DiscoServices\UpdateQuery.cs" />
<Compile Include="Interop\DiscoServices\UpdateQueryTask.cs" />
@@ -368,7 +377,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_UseGlobalSettings="False" BuildVersion_DetectChanges="False" BuildVersion_BuildAction="Both" BuildVersion_StartDate="2014/6/1" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" />
<UserProperties BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.DeltaBaseYear.MonthAndDayStamp.TimeStamp" BuildVersion_StartDate="2014/6/1" BuildVersion_BuildAction="Both" BuildVersion_DetectChanges="False" BuildVersion_UseGlobalSettings="False" />
</VisualStudio>
</ProjectExtensions>
<PropertyGroup>
@@ -379,6 +388,11 @@
xcopy /s /y "$(SolutionDir)packages\Microsoft.SqlServer.Compact.4.0.8876.1\NativeBinaries\amd64\*.*" "$(TargetDir)amd64"</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
<Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
<Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
@@ -0,0 +1,103 @@
using Disco.Data.Repository;
using Disco.Models.Repository;
using Disco.Models.Services.Interop.DiscoServices;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
namespace Disco.Services.Interop.DiscoServices
{
public static class Jobs
{
private static string ServiceUrl(string Action)
{
return string.Concat(DiscoServiceHelpers.ServicesUrl, "API/Jobs/", Action);
}
public static PublishJobResult Publish(DiscoDataContext Database, Job Job, User TechUser, string Recipient, string RecipientReference, string Comments, List<JobAttachment> Attachments, Func<JobAttachment, DiscoDataContext, string> AttachmentFilenameRetriever)
{
var url = ServiceUrl("Publish");
using (var httpClient = new HttpClient())
{
using (var formData = new MultipartFormDataContent())
{
formData.Add(new StringContent(Database.DiscoConfiguration.DeploymentId), "DeploymentId");
formData.Add(new StringContent(Job.Id.ToString()), "JobId");
formData.Add(new StringContent(TechUser.UserId), "TechnicianId");
formData.Add(new StringContent(TechUser.DisplayName ?? TechUser.UserId), "TechnicianName");
if (!string.IsNullOrWhiteSpace(TechUser.PhoneNumber))
formData.Add(new StringContent(TechUser.PhoneNumber), "TechnicianPhone");
if (!string.IsNullOrWhiteSpace(TechUser.EmailAddress))
formData.Add(new StringContent(TechUser.EmailAddress), "TechnicianEmail");
formData.Add(new StringContent(Recipient), "Recipient");
if (!string.IsNullOrWhiteSpace(RecipientReference))
formData.Add(new StringContent(RecipientReference), "RecipientReference");
if (!string.IsNullOrWhiteSpace(Comments))
formData.Add(new StringContent(Comments), "PublishedComments");
if (Attachments != null && Attachments.Count > 0)
{
Attachments
.Select(a => new { Attachment = a, Filename = AttachmentFilenameRetriever(a, Database) })
.Where(a => System.IO.File.Exists(a.Filename))
.Select((a, i) => new { Attachment = a.Attachment, Filename = a.Filename, Index = i })
.ToList()
.ForEach(a =>
{
formData.Add(new StringContent(a.Attachment.Filename), string.Format("Attachments[{0}].Filename", a.Index));
formData.Add(new StringContent(a.Attachment.MimeType), string.Format("Attachments[{0}].MimeType", a.Index));
formData.Add(new StringContent(a.Attachment.Timestamp.ToISO8601()), string.Format("Attachments[{0}].CreatedDate", a.Index));
if (a.Attachment.DocumentTemplateId != null)
formData.Add(new StringContent(a.Attachment.DocumentTemplateId), string.Format("Attachments[{0}].DocumentTemplateId", a.Index));
if (a.Attachment.Comments != null)
formData.Add(new StringContent(a.Attachment.Comments), string.Format("Attachments[{0}].Comments", a.Index));
formData.Add(new ByteArrayContent(File.ReadAllBytes(a.Filename)), string.Format("Attachments[{0}].File", a.Index), a.Attachment.Filename);
});
}
var response = httpClient.PostAsync(url, formData).Result;
response.EnsureSuccessStatusCode();
var resultJson = response.Content.ReadAsStringAsync().Result;
var result = JsonConvert.DeserializeObject<PublishJobResult>(resultJson);
return result;
}
}
}
public static PublishJobResult UpdateRecipientReference(DiscoDataContext Database, Job Job, int PublishedJobId, string PublishedJobSecret, string RecipientReference)
{
var url = ServiceUrl("UpdateRecipientReference");
using (var httpClient = new HttpClient())
{
using (var formData = new FormUrlEncodedContent(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("PublishedJobId", PublishedJobId.ToString()),
new KeyValuePair<string, string>("PublishedJobSecret", PublishedJobSecret),
new KeyValuePair<string, string>("RecipientReference", RecipientReference)
}))
{
var response = httpClient.PostAsync(url, formData).Result;
response.EnsureSuccessStatusCode();
var resultJson = response.Content.ReadAsStringAsync().Result;
var result = JsonConvert.DeserializeObject<PublishJobResult>(resultJson);
return result;
}
}
}
}
}
@@ -141,7 +141,7 @@ namespace Disco.Services.Interop.DiscoServices
var whoAmIResponse = VicEduDept.VicSmart.WhoAmI();
if (whoAmIResponse != null && !string.IsNullOrWhiteSpace(whoAmIResponse.Item1))
m.BroadbandDoeWanId = whoAmIResponse.Item1;
m.VicEduDeptWanId = whoAmIResponse.Item1;
m.Stat_JobCounts = Database.Jobs.GroupBy(j => j.JobTypeId).Select(g => new StatisticInt() { K = g.Key, V = g.Count() }).ToList();
m.Stat_OpenJobCounts = Database.Jobs.Where(j => j.ClosedDate == null).GroupBy(j => j.JobTypeId).Select(g => new StatisticInt() { K = g.Key, V = g.Count() }).ToList();
+3
View File
@@ -6,6 +6,9 @@
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.AspNet.SignalR.Core" version="2.1.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net45" />
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
<package id="Microsoft.Net.Http" version="2.2.22" targetFramework="net45" />
<package id="Microsoft.Owin" version="2.0.1" targetFramework="net45" />
<package id="Microsoft.Owin.Security" version="2.0.1" targetFramework="net45" />
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net45" />