- Scheduler.cs, PDFBurner.cs und Constants.cs entfernt.
This commit is contained in:
parent
c459828706
commit
181ee67bab
@ -1,192 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using DigitalData.Modules.Base;
|
||||
using DigitalData.Modules.Logging;
|
||||
using GdPicture14;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Classes
|
||||
{
|
||||
public partial class PDFBurner : BaseClass
|
||||
{
|
||||
|
||||
private readonly string LicenseKey;
|
||||
private readonly AnnotationManager Manager;
|
||||
private readonly LicenseManager LicenseManager;
|
||||
|
||||
private const string ANNOTATION_TYPE_IMAGE = "pspdfkit/image";
|
||||
private const string ANNOTATION_TYPE_INK = "pspdfkit/ink";
|
||||
|
||||
public PDFBurner(LogConfig pLogConfig, string pGDPictureLicenseKey) : base(pLogConfig)
|
||||
{
|
||||
|
||||
LicenseKey = pGDPictureLicenseKey;
|
||||
LicenseManager = new LicenseManager();
|
||||
LicenseManager.RegisterKEY(pGDPictureLicenseKey);
|
||||
|
||||
Manager = new AnnotationManager();
|
||||
}
|
||||
|
||||
public bool BurnInstantJSONAnnotationsToPDF(string pSourcePath, List<string> pInstantJSONList, string pDestinationPath)
|
||||
{
|
||||
if (Manager.InitFromFile(pSourcePath) != GdPictureStatus.OK)
|
||||
{
|
||||
Logger.Warn("Could not open file [{0}] for burning.", pSourcePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var oJSON in pInstantJSONList)
|
||||
{
|
||||
if (AddInstantJSONAnnotationToPDF(oJSON) == false)
|
||||
{
|
||||
Logger.Warn("Adding Annotation failed. Exiting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Manager.BurnAnnotationsToPage(RemoveInitialAnnots: true, VectorMode: true);
|
||||
Manager.SaveDocumentToPDF(pDestinationPath);
|
||||
Manager.Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Could not burn and save annotations to file [{0}]!", pDestinationPath);
|
||||
Logger.Error(ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool AddInstantJSONAnnotationToPDF(string pInstantJSON)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oAnnotationData = JsonConvert.DeserializeObject<AnnotationData>(pInstantJSON);
|
||||
|
||||
foreach (Annotation oAnnotation in oAnnotationData.annotations)
|
||||
{
|
||||
switch (oAnnotation.type)
|
||||
{
|
||||
case ANNOTATION_TYPE_IMAGE:
|
||||
{
|
||||
AddImageAnnotation(oAnnotation, oAnnotationData.attachments);
|
||||
break;
|
||||
}
|
||||
case ANNOTATION_TYPE_INK:
|
||||
{
|
||||
AddInkAnnotation(oAnnotation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Could not create annotation from InstantJSON");
|
||||
Logger.Error(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool AddImageAnnotation(Annotation pAnnotation, Dictionary<string, Attachment> pAttachments)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oAttachment = pAttachments.Where(a => (a.Key ?? "") == (pAnnotation.imageAttachmentId ?? "")).SingleOrDefault();
|
||||
|
||||
// Convert pixels to Inches
|
||||
var oBounds = pAnnotation.bbox.Select(ToInches).ToList();
|
||||
|
||||
float oX = oBounds[0];
|
||||
float oY = oBounds[1];
|
||||
float oWidth = oBounds[2];
|
||||
float oHeight = oBounds[3];
|
||||
|
||||
Manager.AddEmbeddedImageAnnotFromBase64(oAttachment.Value.binary, oX, oY, oWidth, oHeight);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Could not add image annotation!");
|
||||
Logger.Error(ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool AddInkAnnotation(Annotation pAnnotation)
|
||||
{
|
||||
try
|
||||
{
|
||||
var oSegments = pAnnotation.lines.points;
|
||||
var oColor = ColorTranslator.FromHtml(pAnnotation.strokeColor);
|
||||
Manager.SelectPage(pAnnotation.pageIndex);
|
||||
|
||||
foreach (List<List<float>> oSegment in oSegments)
|
||||
{
|
||||
var oPoints = oSegment.Select(ToPointF).ToArray();
|
||||
Manager.AddFreeHandAnnot(oColor, oPoints);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Could not add image annotation!");
|
||||
Logger.Error(ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PointF ToPointF(List<float> pPoints)
|
||||
{
|
||||
var oPoints = pPoints.Select(ToInches).ToList();
|
||||
return new PointF(oPoints[0], oPoints[1]);
|
||||
}
|
||||
|
||||
private float ToInches(float pValue)
|
||||
{
|
||||
return pValue / 72f;
|
||||
}
|
||||
|
||||
internal partial class AnnotationData
|
||||
{
|
||||
public List<Annotation> annotations { get; set; }
|
||||
public Dictionary<string, Attachment> attachments { get; set; }
|
||||
}
|
||||
|
||||
internal partial class Annotation
|
||||
{
|
||||
public string id { get; set; }
|
||||
public List<float> bbox { get; set; }
|
||||
public string type { get; set; }
|
||||
public bool isSignature { get; set; }
|
||||
public string imageAttachmentId { get; set; }
|
||||
public Lines lines { get; set; }
|
||||
public int pageIndex { get; set; }
|
||||
public string strokeColor { get; set; }
|
||||
}
|
||||
|
||||
internal partial class Lines
|
||||
{
|
||||
public List<List<List<float>>> points { get; set; }
|
||||
}
|
||||
|
||||
internal partial class Attachment
|
||||
{
|
||||
public string binary { get; set; }
|
||||
public string contentType { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Entities
|
||||
{
|
||||
[Table("TBSIG_CONFIG", Schema = "dbo")]
|
||||
public class TBSIG_CONFIG
|
||||
{
|
||||
[Column("DOCUMENT_PATH", TypeName = "nvarchar(256)")]
|
||||
public string DocumentPath { get; set; }
|
||||
|
||||
[Column("SENDING_PROFILE", TypeName = "int")]
|
||||
[Required]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.None)] // Assuming SENDING_PROFILE is manually entered or controlled by the application logic
|
||||
[DefaultValue(0)] // This sets the default value for SENDING_PROFILE
|
||||
public int SendingProfile { get; set; }
|
||||
|
||||
[Column("SIGNATURE_HOST", TypeName = "nvarchar(128)")]
|
||||
public string SignatureHost { get; set; }
|
||||
|
||||
[Column("EXTERNAL_PROGRAM_NAME", TypeName = "nvarchar(30)")]
|
||||
public string ExternalProgramName { get; set; }
|
||||
|
||||
[Column("EXPORT_PATH", TypeName = "nvarchar(256)")]
|
||||
public string ExportPath { get; set; }
|
||||
|
||||
[Column("DOCUMENT_PATH_DMZ", TypeName = "nvarchar(512)")]
|
||||
[Required]
|
||||
[DefaultValue("")] // This sets the default value for DOCUMENT_PATH_DMZ
|
||||
public string DocumentPathDmz { get; set; }
|
||||
|
||||
[Column("EXPORT_PATH_DMZ", TypeName = "nvarchar(512)")]
|
||||
[Required]
|
||||
[DefaultValue("")] // This sets the default value for EXPORT_PATH_DMZ
|
||||
public string ExportPathDmz { get; set; }
|
||||
|
||||
[Column("SIGNED_MAIL_PATH", TypeName = "nvarchar(512)")]
|
||||
[Required]
|
||||
[DefaultValue("")] // This sets the default value for SIGNED_MAIL_PATH
|
||||
public string SignedMailPath { get; set; }
|
||||
|
||||
[Column("DOCUMENT_PATH_MOVE_AFTSEND", TypeName = "nvarchar(512)")]
|
||||
[Required]
|
||||
[DefaultValue("")] // This sets the default value for DOCUMENT_PATH_MOVE_AFTSEND
|
||||
public string DocumentPathMoveAftsend { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Entities
|
||||
{
|
||||
[Table("TBSIG_ENVELOPE_DOCUMENT", Schema = "dbo")]
|
||||
public class EnvelopeDocument
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Column("GUID", TypeName = "int")]
|
||||
public int Guid { get; set; }
|
||||
|
||||
[Column("ENVELOPE_ID", TypeName = "int")]
|
||||
[Required]
|
||||
public int EnvelopeId { get; set; }
|
||||
|
||||
[Column("FILENAME", TypeName = "nvarchar(256)")]
|
||||
[Required]
|
||||
public string Filename { get; set; }
|
||||
|
||||
[Column("FILEPATH", TypeName = "nvarchar(256)")]
|
||||
[Required]
|
||||
public string Filepath { get; set; }
|
||||
|
||||
[Column("ADDED_WHEN", TypeName = "datetime")]
|
||||
[Required]
|
||||
public DateTime AddedWhen { get; set; }
|
||||
|
||||
[Column("FILENAME_ORIGINAL", TypeName = "nvarchar(256)")]
|
||||
public string FilenameOriginal { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,6 +0,0 @@
|
||||
namespace EnvelopeGenerator.Web.Repositories
|
||||
{
|
||||
public class ConfigRepository
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
using DigitalData.Modules.Base;
|
||||
using DigitalData.Modules.Logging;
|
||||
using EnvelopeGenerator.Common;
|
||||
using Quartz;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace EnvelopeGenerator.Web
|
||||
{
|
||||
public class Scheduler : BaseClass
|
||||
{
|
||||
private const string DATABASE = "DATABASE";
|
||||
private const string LOGCONFIG = "LOGCONFIG";
|
||||
|
||||
private string ConnectionString;
|
||||
|
||||
public Scheduler(LogConfig logConfig, string connectionString) : base(logConfig)
|
||||
{
|
||||
this.ConnectionString = connectionString;
|
||||
}
|
||||
|
||||
public void ScheduleJob<TJob>(IServiceCollectionQuartzConfigurator q, string name, int interval) where TJob : IJob
|
||||
{
|
||||
var jobKey = new JobKey(name);
|
||||
var jobData = new JobDataMap
|
||||
{
|
||||
{ DATABASE, ConnectionString },
|
||||
{ LOGCONFIG, LogConfig }
|
||||
};
|
||||
|
||||
q.AddJob<TJob>(opts => opts
|
||||
.WithIdentity(jobKey)
|
||||
.UsingJobData(jobData));
|
||||
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(jobKey)
|
||||
.WithIdentity($"{name}-trigger")
|
||||
.WithSimpleSchedule(s => s
|
||||
.RepeatForever()
|
||||
.WithIntervalInMinutes(interval)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user