Moved hires rasterization to new BSO structure
This commit is contained in:
@@ -14,6 +14,7 @@ using Swarmops.Logic.Cache;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Support.BackendServices;
|
||||
using Swarmops.Logic.Swarm;
|
||||
using WebSocketSharp;
|
||||
using WebSocketSharp.Server;
|
||||
@@ -61,9 +62,16 @@ namespace Swarmops.Frontend.Socket
|
||||
{
|
||||
pdfFilesList.Add(pdfFileString);
|
||||
}
|
||||
string[] pdfFiles = pdfFilesList.ToArray();
|
||||
|
||||
ConvertPdf (pdfFiles, (string) json["Guid"], Person.FromIdentity((int) json["PersonId"]), Organization.FromIdentity((int) json["OrganizationId"]));
|
||||
JArray pdfClientNamesArray = (JArray) json["ClientFileNames"];
|
||||
List<string> pdfClientNames = new List<string>();
|
||||
foreach (string pdfClientName in pdfClientNamesArray)
|
||||
{
|
||||
pdfClientNames.Add(pdfClientName);
|
||||
}
|
||||
|
||||
ConvertPdf(pdfFilesList.ToArray(), pdfClientNames.ToArray(), (string) json["Guid"], Person.FromIdentity((int) json["PersonId"]), Organization.FromIdentity((int) json["OrganizationId"]));
|
||||
|
||||
break;
|
||||
case "ConvertPdfHires":
|
||||
// Send to backend
|
||||
@@ -134,7 +142,7 @@ namespace Swarmops.Frontend.Socket
|
||||
// Sessions.Broadcast("{\"messageType\":\"EditorCount\"," + String.Format("\"editorCount\":\"{0}\"", Sessions.ActiveIDs.ToArray().Length) + '}');
|
||||
}
|
||||
|
||||
private void ConvertPdf(string[] pdfFiles, string guid, Person person, Organization organization)
|
||||
private void ConvertPdf(string[] pdfFiles, string[] pdfClientNames, string guid, Person person, Organization organization)
|
||||
{
|
||||
List<string> failedConversionFileNames = new List<string>();
|
||||
|
||||
@@ -276,8 +284,7 @@ namespace Swarmops.Frontend.Socket
|
||||
long fileLength = new FileInfo(Document.StorageRoot + lastPageFileName).Length;
|
||||
debugWriter.WriteLine("{0:D2}%, saving page #{1}, bytecount {2}", progress, pageCounter, fileLength);
|
||||
|
||||
Document.Create(lastPageFileName,
|
||||
"(BackendConvertedFile) " + pageCounter.ToString(CultureInfo.InvariantCulture),
|
||||
Document.Create(lastPageFileName, pdfClientNames[fileIndex] + " " + pageCounter.ToString(CultureInfo.InvariantCulture),
|
||||
fileLength, guid, null, person);
|
||||
|
||||
// Set to readonly, lock out changes, permit all read
|
||||
@@ -310,7 +317,7 @@ namespace Swarmops.Frontend.Socket
|
||||
debugWriter.WriteLine("{0:D2}%, saving last page #{1}, bytecount {2}", progress, pageCounter, fileLengthLastPage);
|
||||
|
||||
lastDocument = Document.Create(lastPageFileName,
|
||||
"(BackendConvertedFile) " + pageCounter.ToString(CultureInfo.InvariantCulture),
|
||||
pdfClientNames[fileIndex] + " " + pageCounter.ToString(CultureInfo.InvariantCulture),
|
||||
fileLengthLastPage, guid, null, person);
|
||||
|
||||
// Set to readonly, lock out changes, permit all read
|
||||
@@ -320,13 +327,8 @@ namespace Swarmops.Frontend.Socket
|
||||
|
||||
// Finally, ask the backend to do the high-res conversions, but now we have the basic, fast ones
|
||||
|
||||
JObject backendRequest = new JObject();
|
||||
backendRequest["BackendRequest"] = "ConvertPdfHires";
|
||||
backendRequest["DocumentId"] = lastDocument.Identity;
|
||||
FrontendLoop.SendMessageUpstream(backendRequest);
|
||||
|
||||
backendRequest["MessageType"] = "Echo";
|
||||
Sessions.Broadcast(backendRequest.ToString());
|
||||
RasterizeDocumentHiresOrder backendOrder = new RasterizeDocumentHiresOrder(lastDocument);
|
||||
backendOrder.Create();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -220,6 +220,7 @@
|
||||
<Compile Include="Support\BackendServiceOrder.cs" />
|
||||
<Compile Include="Support\BackendServiceOrders.cs" />
|
||||
<Compile Include="Support\BackendServices\BackendServiceOrderBase.cs" />
|
||||
<Compile Include="Support\BackendServices\RasterizeDocumentHiresOrder.cs" />
|
||||
<Compile Include="Support\BackendServices\ReturnBitcoinEchoUtxoOrder.cs" />
|
||||
<Compile Include="Support\BlockchainTransaction.cs" />
|
||||
<Compile Include="Support\DocumentImage.cs" />
|
||||
@@ -385,6 +386,7 @@
|
||||
<Compile Include="Support\LogEntries\SecurityActionBase.cs" />
|
||||
<Compile Include="Support\LogEntries\VolunteerForPositionLogEntry.cs" />
|
||||
<Compile Include="Support\ObjectOptionalData.cs" />
|
||||
<Compile Include="Support\PdfProcessor.cs" />
|
||||
<Compile Include="Support\PilotInstallationIds.cs" />
|
||||
<Compile Include="Support\PluralBase.cs" />
|
||||
<Compile Include="Security\ActivityEnum.cs" />
|
||||
|
||||
@@ -7,7 +7,9 @@ using System.Threading.Tasks;
|
||||
using Swarmops.Basic.Types.System;
|
||||
using Swarmops.Common.Exceptions;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support.BackendServices;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Logic.Support
|
||||
{
|
||||
@@ -58,6 +60,11 @@ namespace Swarmops.Logic.Support
|
||||
IBackendServiceOrderBase order = (IBackendServiceOrderBase) methodFromXml.Invoke(null, new object[] { this.OrderXml });
|
||||
order.ServiceOrderIdentity = this.Identity; // not part of serialization
|
||||
|
||||
// Supply with organization and person, if we have them
|
||||
|
||||
order.Person = this.PersonId == 0 ? null : Person.FromIdentity(this.PersonId);
|
||||
order.Organization = this.OrganizationId == 0 ? null : Organization.FromIdentity(this.OrganizationId);
|
||||
|
||||
// Mark as started
|
||||
|
||||
SwarmDb.GetDatabaseForWriting().SetBackendServiceOrderActive(this.Identity);
|
||||
@@ -72,6 +79,10 @@ namespace Swarmops.Logic.Support
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
if (!order.HasWorkerThread)
|
||||
{
|
||||
order.HasTerminated = true;
|
||||
}
|
||||
order.Close();
|
||||
SwarmDb.GetDatabaseForWriting().SetBackendServiceOrderException(this.Identity, exception);
|
||||
}
|
||||
@@ -81,6 +92,7 @@ namespace Swarmops.Logic.Support
|
||||
{
|
||||
try
|
||||
{
|
||||
order.HasTerminated = true;
|
||||
order.Close();
|
||||
}
|
||||
catch (DatabaseConcurrencyException)
|
||||
|
||||
@@ -71,6 +71,15 @@ namespace Swarmops.Logic.Support.BackendServices
|
||||
throw new NotImplementedException("The base Run() has no implementation. Derive and declare 'override'!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If you are deriving this class into something that spawns a worker thread, then that derived
|
||||
/// class MUST have the worker thread terminate within 1.00 seconds from when Terminate is called.
|
||||
/// </summary>
|
||||
public virtual void Terminate()
|
||||
{
|
||||
throw new NotImplementedException("The base Terminate() has no implementation. Derive and declare 'override'!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function MUST be called when the task has been completed, either on completion of Run()
|
||||
/// if you take a short amount of time, or at the end of your worker thread.
|
||||
@@ -99,6 +108,12 @@ namespace Swarmops.Logic.Support.BackendServices
|
||||
public DateTime CreatedDateTime { get; set; }
|
||||
public string BackendServiceClass { get; set; }
|
||||
public int ServiceOrderIdentity { get; set; }
|
||||
public bool HasTerminated { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public Organization Organization { get; set; }
|
||||
[XmlIgnore]
|
||||
public Person Person { get; set; }
|
||||
|
||||
[XmlIgnore]
|
||||
public bool HasWorkerThread { get; set; }
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Swarmops.Logic.Support.BackendServices
|
||||
{
|
||||
[Serializable]
|
||||
public class RasterizeDocumentHiresOrder: BackendServiceOrderBase<RasterizeDocumentHiresOrder>, IBackendServiceOrderBase
|
||||
{
|
||||
[Obsolete("Do not call the parameterless public ctor directly. It is needed for serialization.", true)]
|
||||
public RasterizeDocumentHiresOrder()
|
||||
{ }
|
||||
|
||||
public RasterizeDocumentHiresOrder(Document document)
|
||||
{
|
||||
this.DocumentId = document.Identity;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
Document document = Document.FromIdentity(this.DocumentId);
|
||||
HasWorkerThread = true;
|
||||
WorkerThread = new Thread(LongRun);
|
||||
WorkerThread.Start(this);
|
||||
}
|
||||
|
||||
private static void LongRun(object orderObject)
|
||||
{
|
||||
RasterizeDocumentHiresOrder order = (RasterizeDocumentHiresOrder) orderObject;
|
||||
Document document = Document.FromIdentity(order.DocumentId);
|
||||
|
||||
PdfProcessor.Rerasterize((Document) document, PdfProcessor.PdfProcessorOptions.HighQuality | PdfProcessor.PdfProcessorOptions.ForceOrphans);
|
||||
order.Close();
|
||||
order.HasTerminated = true;
|
||||
}
|
||||
|
||||
public override void Terminate()
|
||||
{
|
||||
|
||||
}
|
||||
int DocumentId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Logic.Support
|
||||
{
|
||||
@@ -12,8 +14,16 @@ namespace Swarmops.Logic.Support
|
||||
{
|
||||
void Run();
|
||||
void Close();
|
||||
|
||||
|
||||
bool HasWorkerThread { get; set; }
|
||||
Thread WorkerThread { get; set; }
|
||||
void Terminate();
|
||||
bool HasTerminated { get; set; }
|
||||
|
||||
|
||||
int ServiceOrderIdentity { get; set; }
|
||||
Organization Organization { get; set; }
|
||||
Person Person { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Utility.BotCode
|
||||
namespace Swarmops.Logic.Support
|
||||
{
|
||||
public class PdfProcessor
|
||||
{
|
||||
@@ -20,6 +20,7 @@ using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Swarm;
|
||||
using WebSocketSharp;
|
||||
using Mono.Unix.Native;
|
||||
using Swarmops.Logic.Support.BackendServices;
|
||||
|
||||
namespace Swarmops.Frontend.Automation
|
||||
{
|
||||
@@ -157,6 +158,7 @@ namespace Swarmops.Frontend.Automation
|
||||
{
|
||||
HttpPostedFile file = context.Request.Files[i];
|
||||
string fullName = Path.GetFileName(file.FileName);
|
||||
string clientFileName = string.Empty;
|
||||
|
||||
Person uploadingPerson = authData.CurrentUser;
|
||||
Organization currentOrg = authData.CurrentOrganization;
|
||||
@@ -377,6 +379,10 @@ namespace Swarmops.Frontend.Automation
|
||||
|
||||
// Ask backend for high-res conversion
|
||||
|
||||
RasterizeDocumentHiresOrder backendOrder = new RasterizeDocumentHiresOrder(lastDocument);
|
||||
backendOrder.Create();
|
||||
|
||||
/*
|
||||
using (WebSocket socket =
|
||||
new WebSocket("ws://localhost:" + SystemSettings.WebsocketPortFrontend + "/Front?Auth=" +
|
||||
Uri.EscapeDataString(authData.Authority.ToEncryptedXml())))
|
||||
@@ -388,7 +394,7 @@ namespace Swarmops.Frontend.Automation
|
||||
socket.Send(data.ToString());
|
||||
socket.Ping(); // wait a little little while for send to work
|
||||
socket.Close();
|
||||
}
|
||||
}*/
|
||||
|
||||
statuses.Add(new FilesStatus(fullName, file.ContentLength));
|
||||
}
|
||||
@@ -433,6 +439,7 @@ namespace Swarmops.Frontend.Automation
|
||||
data["ServerRequest"] = "ConvertPdf";
|
||||
data["PdfFiles"] = JArray.FromObject(pdfsForConversion.ToArray());
|
||||
data["Guid"] = (string) guid;
|
||||
data["ClientFileNames"] = JArray.FromObject(pdfClientNames.ToArray());
|
||||
data["PersonId"] = authData.CurrentUser.Identity;
|
||||
data["OrganizationId"] = authData.CurrentOrganization.Identity;
|
||||
socket.Send(data.ToString());
|
||||
|
||||
@@ -96,7 +96,6 @@
|
||||
<Compile Include="BotCode\Mappery.cs" />
|
||||
<Compile Include="BotCode\MediaWatcher.cs" />
|
||||
<Compile Include="BotCode\NewsletterChecker.cs" />
|
||||
<Compile Include="BotCode\PdfProcessor.cs" />
|
||||
<Compile Include="BotCode\PressReleaseChecker.cs" />
|
||||
<Compile Include="BotCode\RosterHousekeeping.cs" />
|
||||
<Compile Include="BotCode\SalaryProcessor.cs" />
|
||||
|
||||
Reference in New Issue
Block a user