From 1c586c2fdd6e27ba5bf8b06cb2a1e0ac3020e1a0 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 10 Feb 2018 15:45:38 +0100 Subject: [PATCH] Added some loc work for documents --- .../Logic.Support.Document.Designer.cs | 18 +++++++ Logic/Resources/Logic.Support.Document.resx | 8 +++- Logic/Support/BackendServiceOrders.cs | 1 - .../RasterizeDocumentHiresOrder.cs | 5 +- Logic/Support/Document.cs | 47 +++++++++++++++++++ 5 files changed, 73 insertions(+), 6 deletions(-) diff --git a/Logic/Resources/Logic.Support.Document.Designer.cs b/Logic/Resources/Logic.Support.Document.Designer.cs index 364c5448..b8ba2ffc 100644 --- a/Logic/Resources/Logic.Support.Document.Designer.cs +++ b/Logic/Resources/Logic.Support.Document.Designer.cs @@ -60,6 +60,24 @@ namespace Swarmops.Logic.Resources { } } + /// + /// Looks up a localized string similar to (Last page of {0}). + /// + internal static string LastPageOfX { + get { + return ResourceManager.GetString("LastPageOfX", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to (First page of {0}). + /// + internal static string PageOneOfX { + get { + return ResourceManager.GetString("PageOneOfX", resourceCulture); + } + } + /// /// Looks up a localized string similar to (Single page). /// diff --git a/Logic/Resources/Logic.Support.Document.resx b/Logic/Resources/Logic.Support.Document.resx index 9a575404..346d00fe 100644 --- a/Logic/Resources/Logic.Support.Document.resx +++ b/Logic/Resources/Logic.Support.Document.resx @@ -117,12 +117,18 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + (Last page of {0}) + + + (First page of {0}) + This should say there's more than is beeing looked at (first page is the one that shows up first) + (Single page) If it is possible to say "this is the only page" or "you're looking at the only page" in the translated language, it's preferable to the English wording. "Only page" doesn't sound like correct English, but your language might have a construct for it. (Page {0} of {1}) - This should convey a meaning that there's more than is being looked at. \ No newline at end of file diff --git a/Logic/Support/BackendServiceOrders.cs b/Logic/Support/BackendServiceOrders.cs index 1323e2fc..04c76afa 100644 --- a/Logic/Support/BackendServiceOrders.cs +++ b/Logic/Support/BackendServiceOrders.cs @@ -21,7 +21,6 @@ namespace Swarmops.Logic.Support { foreach (BackendServiceOrder order in this) { - Console.WriteLine("Excecuting backend order #" + order.Identity); // debug purposes order.Execute(); } } diff --git a/Logic/Support/BackendServices/RasterizeDocumentHiresOrder.cs b/Logic/Support/BackendServices/RasterizeDocumentHiresOrder.cs index d34f29c2..ce9b2340 100644 --- a/Logic/Support/BackendServices/RasterizeDocumentHiresOrder.cs +++ b/Logic/Support/BackendServices/RasterizeDocumentHiresOrder.cs @@ -25,7 +25,6 @@ namespace Swarmops.Logic.Support.BackendServices HasWorkerThread = true; WorkerThread = new Thread(LongRun); WorkerThread.Start(this); - Console.WriteLine(" - Worker thread for #" + this.ServiceOrderIdentity + " started"); // debugging } private static void LongRun(object orderObject) @@ -34,15 +33,13 @@ namespace Swarmops.Logic.Support.BackendServices try { order = (RasterizeDocumentHiresOrder)orderObject; - Console.WriteLine(" - Worker thread for #" + order.ServiceOrderIdentity + " running"); // debugging Document document = Document.FromIdentity(order.DocumentId); PdfProcessor.Rerasterize((Document)document, PdfProcessor.PdfProcessorOptions.HighQuality | PdfProcessor.PdfProcessorOptions.ForceOrphans); order.Close(); } catch (Exception exception) { - Console.WriteLine(" - Exception thrown: " + exception.ToString()); // debugging - order.ThrewException(exception); + order?.ThrewException(exception); } if (order != null) diff --git a/Logic/Support/Document.cs b/Logic/Support/Document.cs index 10e00b69..ffd3e6b5 100644 --- a/Logic/Support/Document.cs +++ b/Logic/Support/Document.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics; using System.IO; using System.Text; +using System.Text.RegularExpressions; using Swarmops.Basic.Types; using Swarmops.Basic.Types.Structure; using Swarmops.Common.Enums; @@ -30,6 +31,52 @@ namespace Swarmops.Logic.Support } } + public new string ClientFileName + { + get + { + string input = base.ClientFileName; + Regex regex = new Regex("{{LOCPAGE\\-(?[0-9]+)\\-(?[0-9]+)}}"); + + Match match = regex.Match(input); + if (match.Success) + { + input = input.Substring(0, input.IndexOf("{{LOCPAGE", StringComparison.InvariantCulture)); + int currentPage = Int32.Parse(match.Groups["current"].Value); + int totalPages = Int32.Parse(match.Groups["total"].Value); + + if (currentPage == 1 && totalPages == 1) + { + // Single page + + return input + Resources.Logic_Support_Document.PageSingle; + } + + if (currentPage == 1) + { + // First page of X + + return input + String.Format(Resources.Logic_Support_Document.PageOneOfX, totalPages); + } + + if (currentPage == totalPages) + { + // Last page of X + + return input + String.Format(Resources.Logic_Support_Document.LastPageOfX, totalPages); + } + + // Page X of Y + + return input + String.Format(Resources.Logic_Support_Document.PageXofY, currentPage, totalPages); + } + + // No localization + + return input; + } + } + public IHasIdentity ForeignObject { get