initial source commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Concurrent;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.BI.Extensions;
|
||||
using System.Web;
|
||||
using System.Drawing;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace Disco.BI.DocumentTemplateBI
|
||||
{
|
||||
class DocumentTemplateQRCodeLocationCache
|
||||
{
|
||||
private static ConcurrentDictionary<string, List<RectangleF>> _Cache = new ConcurrentDictionary<string, List<RectangleF>>();
|
||||
|
||||
public static List<RectangleF> GetLocations(DocumentTemplate dt, DiscoDataContext dbContext)
|
||||
{
|
||||
// Check Cache
|
||||
List<RectangleF> locations;
|
||||
if (_Cache.TryGetValue(dt.Id, out locations))
|
||||
{
|
||||
return locations;
|
||||
}
|
||||
// Generate Cache
|
||||
return GenerateLocations(dt, dbContext);
|
||||
}
|
||||
|
||||
public static bool InvalidateLocations(DocumentTemplate dt)
|
||||
{
|
||||
List<RectangleF> locations;
|
||||
return _Cache.TryRemove(dt.Id, out locations);
|
||||
}
|
||||
|
||||
private static bool SetValue(string DocumentTemplateId, List<RectangleF> Locations)
|
||||
{
|
||||
if (_Cache.ContainsKey(DocumentTemplateId))
|
||||
{
|
||||
List<RectangleF> oldLocations;
|
||||
if (_Cache.TryGetValue(DocumentTemplateId, out oldLocations))
|
||||
{
|
||||
return _Cache.TryUpdate(DocumentTemplateId, Locations, oldLocations);
|
||||
}
|
||||
}
|
||||
return _Cache.TryAdd(DocumentTemplateId, Locations);
|
||||
}
|
||||
|
||||
internal static List<RectangleF> GenerateLocations(DocumentTemplate dt, DiscoDataContext dbContext)
|
||||
{
|
||||
string templateFilename = dt.RepositoryFilename(dbContext);
|
||||
PdfReader pdfReader = new PdfReader(templateFilename);
|
||||
List<RectangleF> locations = new List<RectangleF>();
|
||||
|
||||
if (pdfReader.AcroFields.Fields.ContainsKey("DiscoAttachmentId"))
|
||||
{
|
||||
foreach (var pdfFieldPosition in pdfReader.AcroFields.GetFieldPositions("DiscoAttachmentId"))
|
||||
{
|
||||
var pdfPageSize = pdfReader.GetPageSize(pdfFieldPosition.page);
|
||||
locations.Add(new RectangleF((float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(pdfFieldPosition.position.Left / pdfPageSize.Width) - 0.1)), (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)((pdfPageSize.Height - pdfFieldPosition.position.Top) / pdfPageSize.Height) - 0.1)), (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(pdfFieldPosition.position.Width / pdfPageSize.Width) + 0.2)), (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(pdfFieldPosition.position.Height / pdfPageSize.Height) + 0.2))));
|
||||
}
|
||||
}
|
||||
pdfReader.Close();
|
||||
|
||||
// Update Cache
|
||||
SetValue(dt.Id, locations);
|
||||
return locations;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using System;
|
||||
namespace Disco.BI.DocumentTemplateBI
|
||||
{
|
||||
public class DocumentUniqueIdentifier
|
||||
{
|
||||
private bool? _loadedComponentsOk;
|
||||
private DocumentTemplate _documentTemplate;
|
||||
private object _data;
|
||||
private string _dataDescription;
|
||||
public string TemplateTypeId { get; private set; }
|
||||
public string DataId { get; private set; }
|
||||
public string DocumentUniqueId
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Format("{0}|{1}", this.TemplateTypeId, this.DataId);
|
||||
}
|
||||
}
|
||||
public string CreatorId { get; private set; }
|
||||
public System.DateTime TimeStamp { get; private set; }
|
||||
public int Page { get; private set; }
|
||||
public string Tag { get; private set; }
|
||||
public DocumentTemplate DocumentTemplate
|
||||
{
|
||||
get
|
||||
{
|
||||
bool flag = this._loadedComponentsOk.HasValue && this._loadedComponentsOk.Value;
|
||||
if (flag)
|
||||
{
|
||||
return this._documentTemplate;
|
||||
}
|
||||
throw new System.Exception("Document Unique Identifier Components not loaded or invalid");
|
||||
}
|
||||
}
|
||||
public object Data
|
||||
{
|
||||
get
|
||||
{
|
||||
bool flag = this._loadedComponentsOk.HasValue && this._loadedComponentsOk.Value;
|
||||
if (flag)
|
||||
{
|
||||
return this._data;
|
||||
}
|
||||
throw new System.Exception("Document Unique Identifier Components not loaded or invalid");
|
||||
}
|
||||
}
|
||||
public string DataDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
bool flag = this._loadedComponentsOk.HasValue && this._loadedComponentsOk.Value;
|
||||
if (flag)
|
||||
{
|
||||
return this._dataDescription;
|
||||
}
|
||||
throw new System.Exception("Document Unique Identifier Components not loaded or invalid");
|
||||
}
|
||||
}
|
||||
public string DataScope { get; private set; }
|
||||
public static bool IsDocumentUniqueIdentifier(string UniqueIdentifier)
|
||||
{
|
||||
return UniqueIdentifier.StartsWith("Disco|", System.StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
public DocumentUniqueIdentifier(string TemplateTypeId, string DataId, string CreatorId, DateTime TimeStamp, int? Page = null, string Tag = null)
|
||||
{
|
||||
this.Tag = Tag;
|
||||
this.TemplateTypeId = TemplateTypeId;
|
||||
this.DataId = DataId;
|
||||
this.CreatorId = CreatorId;
|
||||
this.TimeStamp = TimeStamp;
|
||||
this.Page = Page ?? 0;
|
||||
}
|
||||
public DocumentUniqueIdentifier(string UniqueIdentifier, string Tag)
|
||||
{
|
||||
if (!DocumentUniqueIdentifier.IsDocumentUniqueIdentifier(UniqueIdentifier))
|
||||
{
|
||||
throw new System.ArgumentException("Invalid Document Unique Identifier", "UniqueIdentifier");
|
||||
}
|
||||
this.Tag = Tag;
|
||||
string[] s = UniqueIdentifier.Split(new char[] { '|' });
|
||||
string left = s[1].ToUpper();
|
||||
if (left == "AT" || left == "1")
|
||||
{
|
||||
if (s.Length >= 3)
|
||||
{
|
||||
this.TemplateTypeId = s[2];
|
||||
}
|
||||
if (s.Length >= 4)
|
||||
{
|
||||
this.DataId = s[3];
|
||||
}
|
||||
if (s.Length >= 5)
|
||||
{
|
||||
this.CreatorId = s[4];
|
||||
}
|
||||
if (s.Length >= 6)
|
||||
{
|
||||
System.DateTime timeStamp;
|
||||
if (System.DateTime.TryParse(s[5], out timeStamp))
|
||||
{
|
||||
this.TimeStamp = timeStamp;
|
||||
}
|
||||
}
|
||||
if (s.Length >= 7)
|
||||
{
|
||||
int page = 0;
|
||||
if (int.TryParse(s[6], out page))
|
||||
{
|
||||
this.Page = page;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
throw new System.ArgumentException(string.Format("Invalid Document Unique Identifier Version ({0})", s[1]), "UniqueIdentifier");
|
||||
}
|
||||
public bool LoadComponents(DiscoDataContext Context)
|
||||
{
|
||||
bool LoadComponents;
|
||||
if (!this._loadedComponentsOk.HasValue)
|
||||
{
|
||||
string scopeType;
|
||||
if (this.TemplateTypeId.StartsWith("--"))
|
||||
{
|
||||
string templateTypeId = this.TemplateTypeId;
|
||||
switch (this.TemplateTypeId)
|
||||
{
|
||||
case "--DEVICE":
|
||||
scopeType = DocumentTemplate.DocumentTemplateScopes.Device;
|
||||
break;
|
||||
case "--JOB":
|
||||
scopeType = DocumentTemplate.DocumentTemplateScopes.Job;
|
||||
break;
|
||||
case "--USER":
|
||||
scopeType = DocumentTemplate.DocumentTemplateScopes.User;
|
||||
break;
|
||||
default:
|
||||
scopeType = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._documentTemplate = Context.DocumentTemplates.Find(this.TemplateTypeId);
|
||||
if (this._documentTemplate != null)
|
||||
{
|
||||
scopeType = this._documentTemplate.Scope;
|
||||
}
|
||||
else
|
||||
{
|
||||
scopeType = null;
|
||||
}
|
||||
}
|
||||
if (scopeType != null)
|
||||
{
|
||||
this.DataScope = scopeType;
|
||||
switch (scopeType)
|
||||
{
|
||||
case DocumentTemplate.DocumentTemplateScopes.Device:
|
||||
Device d = Context.Devices.Find(this.DataId);
|
||||
if (d != null)
|
||||
{
|
||||
this._data = d;
|
||||
this._dataDescription = d.SerialNumber;
|
||||
this._loadedComponentsOk = true;
|
||||
LoadComponents = true;
|
||||
return LoadComponents;
|
||||
}
|
||||
break;
|
||||
case DocumentTemplate.DocumentTemplateScopes.Job:
|
||||
Job i = Context.Jobs.Find(int.Parse(this.DataId));
|
||||
if (i != null)
|
||||
{
|
||||
this._data = i;
|
||||
this._dataDescription = i.Id.ToString();
|
||||
this._loadedComponentsOk = true;
|
||||
LoadComponents = true;
|
||||
return LoadComponents;
|
||||
}
|
||||
break;
|
||||
case DocumentTemplate.DocumentTemplateScopes.User:
|
||||
User u = Context.Users.Find(this.DataId);
|
||||
if (u != null)
|
||||
{
|
||||
this._data = u;
|
||||
this._dataDescription = u.DisplayName;
|
||||
this._loadedComponentsOk = true;
|
||||
LoadComponents = true;
|
||||
return LoadComponents;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._loadedComponentsOk = false;
|
||||
}
|
||||
LoadComponents = this._loadedComponentsOk.Value;
|
||||
return LoadComponents;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web.Caching;
|
||||
using Disco.Data.Repository;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Impl.Triggers;
|
||||
|
||||
namespace Disco.BI.DocumentTemplateBI.Importer
|
||||
{
|
||||
public class DocumentDropBoxMonitor : System.IDisposable
|
||||
{
|
||||
private IScheduler _scheduler;
|
||||
private FileSystemWatcher _fsw;
|
||||
private Cache _httpCache;
|
||||
|
||||
public const string WatcherFilter = "*.pdf";
|
||||
public string DropBoxLocation { get; private set; }
|
||||
|
||||
public DocumentDropBoxMonitor(DiscoDataContext Context, ISchedulerFactory SchedulerFactory, Cache HttpCache)
|
||||
{
|
||||
if (Context == null)
|
||||
throw new System.ArgumentNullException("Context");
|
||||
|
||||
this._httpCache = HttpCache;
|
||||
|
||||
var location = DataStore.CreateLocation(Context, "DocumentDropBox");
|
||||
this.DropBoxLocation = location.EndsWith(@"\") ? location : string.Concat(location, @"\");
|
||||
|
||||
this._scheduler = SchedulerFactory.GetScheduler();
|
||||
this._scheduler.Start();
|
||||
}
|
||||
public void ScheduleCurrentFiles(int Delay)
|
||||
{
|
||||
foreach (var filename in System.IO.Directory.GetFiles(this.DropBoxLocation, "*.pdf"))
|
||||
{
|
||||
this.ScheduleFile(filename, Delay);
|
||||
}
|
||||
}
|
||||
public void StartWatching()
|
||||
{
|
||||
if (this._fsw == null)
|
||||
{
|
||||
this._fsw = new FileSystemWatcher(this.DropBoxLocation, "*.pdf");
|
||||
this._fsw.Created += new FileSystemEventHandler(this.FSW_Created);
|
||||
}
|
||||
this._fsw.EnableRaisingEvents = true;
|
||||
}
|
||||
public void StopWatching()
|
||||
{
|
||||
if (this._fsw != null)
|
||||
{
|
||||
this._fsw.EnableRaisingEvents = false;
|
||||
}
|
||||
}
|
||||
public void ScheduleFile(string Filename, int Delay)
|
||||
{
|
||||
System.Guid guid = System.Guid.NewGuid();
|
||||
JobDetailImpl jd = new JobDetailImpl(guid.ToString(), typeof(DocumentImporterJob));
|
||||
jd.JobDataMap.Add("Filename", Filename);
|
||||
jd.JobDataMap.Add("RetryCount", 0);
|
||||
jd.JobDataMap.Add("HttpCache", this._httpCache);
|
||||
guid = System.Guid.NewGuid();
|
||||
|
||||
System.DateTimeOffset startTimeUtc = new System.DateTimeOffset(DateTime.Now.AddSeconds((double)Delay));
|
||||
SimpleTriggerImpl trig = new SimpleTriggerImpl(guid.ToString(), startTimeUtc);
|
||||
|
||||
this._scheduler.ScheduleJob(jd, trig);
|
||||
}
|
||||
private void FSW_Created(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
if ((e.ChangeType & WatcherChangeTypes.Deleted) != WatcherChangeTypes.Deleted)
|
||||
this.ScheduleFile(e.FullPath, 5);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.StopWatching();
|
||||
if (this._fsw != null)
|
||||
this._fsw.Dispose();
|
||||
if (this._scheduler != null)
|
||||
this._scheduler.Shutdown(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Services.Logging;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Disco.Services.Tasks;
|
||||
|
||||
namespace Disco.BI.DocumentTemplateBI.Importer
|
||||
{
|
||||
public class DocumentImporterCleanCacheJob : ScheduledTask
|
||||
{
|
||||
public override string TaskName { get { return "Document Importer - Clean Cache Task"; } }
|
||||
|
||||
public override bool SingleInstanceTask { get { return true; } }
|
||||
public override bool CancelInitiallySupported { get { return false; } }
|
||||
|
||||
public override void InitalizeScheduledTask(DiscoDataContext dbContext)
|
||||
{
|
||||
// Trigger Daily @ 12:30am
|
||||
TriggerBuilder triggerBuilder = TriggerBuilder.Create().WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 30));
|
||||
|
||||
this.ScheduleTask(triggerBuilder);
|
||||
}
|
||||
|
||||
protected override void ExecuteTask()
|
||||
{
|
||||
string dataStoreLocation;
|
||||
using (DiscoDataContext dbContext = new DiscoDataContext())
|
||||
{
|
||||
dataStoreLocation = DataStore.CreateLocation(dbContext, "Cache\\DocumentDropBox_SessionPages");
|
||||
}
|
||||
|
||||
int deleteCount = 0;
|
||||
int errorCount = 0;
|
||||
|
||||
System.IO.DirectoryInfo dataStoreInfo = new System.IO.DirectoryInfo(dataStoreLocation);
|
||||
|
||||
System.DateTime today = System.DateTime.Today;
|
||||
|
||||
foreach (System.IO.FileInfo file in dataStoreInfo.GetFiles())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (file.CreationTime < today)
|
||||
{
|
||||
file.Delete();
|
||||
deleteCount++;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
errorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
SystemLog.LogInformation(
|
||||
string.Format("Cleared DocumentDropBox_SessionPages Cache, Deleted {0} File/s, with {1} Error/s", deleteCount, errorCount),
|
||||
deleteCount,
|
||||
errorCount
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Web.Caching;
|
||||
using Disco.Data.Repository;
|
||||
using Quartz;
|
||||
using Quartz.Impl.Triggers;
|
||||
|
||||
namespace Disco.BI.DocumentTemplateBI.Importer
|
||||
{
|
||||
[PersistJobDataAfterExecution]
|
||||
public class DocumentImporterJob : IJob
|
||||
{
|
||||
|
||||
void IJob.Execute(IJobExecutionContext context)
|
||||
{
|
||||
string sessionId = context.JobDetail.JobDataMap["SessionId"] as string;
|
||||
if (string.IsNullOrEmpty(sessionId))
|
||||
{
|
||||
sessionId = Guid.NewGuid().ToString();
|
||||
context.JobDetail.JobDataMap["SessionId"] = sessionId;
|
||||
}
|
||||
|
||||
string filename = context.JobDetail.JobDataMap["Filename"] as string;
|
||||
int retryCount = (int)context.JobDetail.JobDataMap["RetryCount"];
|
||||
Cache httpCache = context.JobDetail.JobDataMap["HttpCache"] as Cache;
|
||||
|
||||
var friendlyFilename = filename;
|
||||
if (!string.IsNullOrEmpty(friendlyFilename))
|
||||
friendlyFilename = System.IO.Path.GetFileName(friendlyFilename);
|
||||
|
||||
DocumentImporterLog.LogImportStarting(sessionId, friendlyFilename);
|
||||
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
DocumentImporterLog.LogImportWarning(sessionId, string.Format("File not found: {0}", filename));
|
||||
DocumentImporterLog.LogImportFinished(sessionId);
|
||||
context.Scheduler.DeleteJob(context.JobDetail.Key);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (DiscoDataContext dbContext = new DiscoDataContext())
|
||||
{
|
||||
if (retryCount < 18)
|
||||
{
|
||||
context.JobDetail.JobDataMap["RetryCount"] = (++retryCount);
|
||||
bool processResult = Interop.Pdf.PdfImporter.ProcessPdfAttachment(filename, dbContext, sessionId, httpCache);
|
||||
|
||||
if (processResult)
|
||||
{
|
||||
// Import Successful - Delete
|
||||
if (File.Exists(filename))
|
||||
File.Delete(filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Import Failed - Move to Errors Folder
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
try
|
||||
{
|
||||
string folderError = DataStore.CreateLocation(dbContext, "DocumentDropBox_Errors");
|
||||
string filenameError = Path.Combine(folderError, Path.GetFileName(filename));
|
||||
int filenameErrorCount = 0;
|
||||
while (File.Exists(filenameError))
|
||||
{
|
||||
filenameError = Path.Combine(folderError, string.Format("{0} ({1}){2}", Path.GetFileNameWithoutExtension(filename), ++filenameErrorCount, Path.GetExtension(filename)));
|
||||
}
|
||||
File.Move(filename, filenameError);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore Errors
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// To Many Errors
|
||||
DocumentImporterLog.LogImportError(sessionId, string.Format("To many errors occurred trying to import '{1}' (SessionId: {0})", sessionId, friendlyFilename));
|
||||
// Move to Errors Folder
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
try
|
||||
{
|
||||
string folderError = DataStore.CreateLocation(dbContext, "DocumentDropBox_Errors");
|
||||
string filenameError = Path.Combine(folderError, Path.GetFileName(filename));
|
||||
int filenameErrorCount = 0;
|
||||
while (File.Exists(filenameError))
|
||||
{
|
||||
filenameError = Path.Combine(folderError, string.Format("{0} ({1}){2}", Path.GetFileNameWithoutExtension(filename), ++filenameErrorCount, Path.GetExtension(filename)));
|
||||
}
|
||||
File.Move(filename, filenameError);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore Errors
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
DocumentImporterLog.LogImportFinished(sessionId);
|
||||
|
||||
// All Done
|
||||
context.Scheduler.DeleteJob(context.JobDetail.Key);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DocumentImporterLog.LogImportWarning(sessionId, string.Format("{0}; Will try again in 10 Seconds", ex.Message));
|
||||
// Reschedule Job for 10 seconds
|
||||
SimpleTriggerImpl trig = new SimpleTriggerImpl(Guid.NewGuid().ToString(), new DateTimeOffset(DateTime.Now.AddSeconds(10)));
|
||||
context.Scheduler.RescheduleJob(context.Trigger.Key, trig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
using Disco.Services.Logging;
|
||||
using Disco.Services.Logging.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
namespace Disco.BI.DocumentTemplateBI.Importer
|
||||
{
|
||||
public class DocumentImporterLog : LogBase
|
||||
{
|
||||
public enum EventTypeIds
|
||||
{
|
||||
ImportStarting = 10,
|
||||
ImportProgress,
|
||||
ImportFinished,
|
||||
ImportWarning = 15,
|
||||
ImportError,
|
||||
ImportPageStarting = 100,
|
||||
ImportPageImageUpdate = 104,
|
||||
ImportPageProgress,
|
||||
ImportPageDetected = 110,
|
||||
ImportPageUndetected = 115,
|
||||
ImportPageError = 120,
|
||||
ImportPageUndetectedStored = 150
|
||||
}
|
||||
|
||||
private const int _ModuleId = 40;
|
||||
|
||||
public static DocumentImporterLog Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return (DocumentImporterLog)LogContext.LogModules[_ModuleId];
|
||||
}
|
||||
}
|
||||
|
||||
public override string ModuleDescription
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Document Importer";
|
||||
}
|
||||
}
|
||||
public override int ModuleId
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ModuleId;
|
||||
}
|
||||
}
|
||||
public override string ModuleName
|
||||
{
|
||||
get
|
||||
{
|
||||
return "DocumentImporter";
|
||||
}
|
||||
}
|
||||
private static void Log(DocumentImporterLog.EventTypeIds EventTypeId, params object[] Args)
|
||||
{
|
||||
DocumentImporterLog.Current.Log((int)EventTypeId, Args);
|
||||
}
|
||||
public static void LogImportStarting(string SessionId, string DocumentName)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportStarting, new object[]
|
||||
{
|
||||
SessionId,
|
||||
DocumentName
|
||||
});
|
||||
}
|
||||
public static void LogImportProgress(string SessionId, int? Progress, string Status)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportProgress, new object[]
|
||||
{
|
||||
SessionId,
|
||||
Progress,
|
||||
Status
|
||||
});
|
||||
}
|
||||
public static void LogImportFinished(string SessionId)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportFinished, new object[]
|
||||
{
|
||||
SessionId
|
||||
});
|
||||
}
|
||||
public static void LogImportWarning(string SessionId, string Message)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportWarning, new object[]
|
||||
{
|
||||
SessionId,
|
||||
Message
|
||||
});
|
||||
}
|
||||
public static void LogImportError(string SessionId, string Message)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportError, new object[]
|
||||
{
|
||||
SessionId,
|
||||
Message
|
||||
});
|
||||
}
|
||||
public static void LogImportPageStarting(string SessionId, int PageNumber)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportPageStarting, new object[]
|
||||
{
|
||||
SessionId,
|
||||
PageNumber
|
||||
});
|
||||
}
|
||||
public static void LogImportPageImageUpdate(string SessionId, int PageNumber)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportPageImageUpdate, new object[]
|
||||
{
|
||||
SessionId,
|
||||
PageNumber
|
||||
});
|
||||
}
|
||||
public static void LogImportPageProgress(string SessionId, int PageNumber, int? Progress, string Status)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportPageProgress, new object[]
|
||||
{
|
||||
SessionId,
|
||||
PageNumber,
|
||||
Progress,
|
||||
Status
|
||||
});
|
||||
}
|
||||
public static void LogImportPageDetected(string SessionId, int PageNumber, string DocumentTypeId, string DocumentTypeName, string TargetType, string AssignedId, string AssignedName)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportPageDetected, new object[]
|
||||
{
|
||||
SessionId,
|
||||
PageNumber,
|
||||
DocumentTypeId,
|
||||
DocumentTypeName,
|
||||
TargetType,
|
||||
AssignedId,
|
||||
AssignedName
|
||||
});
|
||||
}
|
||||
public static void LogImportPageUndetected(string SessionId, int PageNumber)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportPageUndetected, new object[]
|
||||
{
|
||||
SessionId,
|
||||
PageNumber
|
||||
});
|
||||
}
|
||||
public static void LogImportPageError(string SessionId, int PageNumber, string Message)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportPageError, new object[]
|
||||
{
|
||||
SessionId,
|
||||
PageNumber,
|
||||
Message
|
||||
});
|
||||
}
|
||||
public static void LogImportPageUndetectedStored(string SessionId, int PageNumber)
|
||||
{
|
||||
DocumentImporterLog.Log(DocumentImporterLog.EventTypeIds.ImportPageUndetectedStored, new object[]
|
||||
{
|
||||
SessionId,
|
||||
PageNumber
|
||||
});
|
||||
}
|
||||
protected override System.Collections.Generic.List<LogEventType> LoadEventTypes()
|
||||
{
|
||||
return new System.Collections.Generic.List<LogEventType>
|
||||
{
|
||||
new LogEventType
|
||||
{
|
||||
Id = 10,
|
||||
ModuleId = 40,
|
||||
Name = "Import Starting",
|
||||
Format = "Starting import of document: {1} (SessionId: {0})",
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 11,
|
||||
ModuleId = 40,
|
||||
Name = "Import Progress",
|
||||
Format = "Processing: {1}% Complete; Status: {2}",
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = false,
|
||||
UseDisplay = false
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 12,
|
||||
ModuleId = 40,
|
||||
Name = "Import Finished",
|
||||
Format = "Import of document complete (SessionId: {0})",
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 15,
|
||||
ModuleId = 40,
|
||||
Name = "Import Warning",
|
||||
Format = "Import Warning: {1} (SessionId: {0})",
|
||||
Severity = 1,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 16,
|
||||
ModuleId = 40,
|
||||
Name = "Import Error",
|
||||
Format = "Import Error: {1} (SessionId: {0})",
|
||||
Severity = 2,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 100,
|
||||
ModuleId = 40,
|
||||
Name = "Import Page Starting",
|
||||
Format = "Starting import of page: {1} (SessionId: {0})",
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 104,
|
||||
ModuleId = 40,
|
||||
Name = "Import Page Image Update",
|
||||
Format = null,
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = false,
|
||||
UseDisplay = false
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 105,
|
||||
ModuleId = 40,
|
||||
Name = "Import Page Progress",
|
||||
Format = "Processing: Page {1}; {2}% Complete; Status: {3}",
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = false,
|
||||
UseDisplay = false
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 110,
|
||||
ModuleId = 40,
|
||||
Name = "Import Page Assigned",
|
||||
Format = "Page {1} of type '{3}' assigned to {4}: '{6}'",
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 115,
|
||||
ModuleId = 40,
|
||||
Name = "Import Page Undetected",
|
||||
Format = "Page {1} not detected",
|
||||
Severity = 1,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 120,
|
||||
ModuleId = 40,
|
||||
Name = "Import Page Error",
|
||||
Format = "Page {1}, Import Error: {2}",
|
||||
Severity = 2,
|
||||
UseLive = true,
|
||||
UsePersist = true,
|
||||
UseDisplay = true
|
||||
},
|
||||
new LogEventType
|
||||
{
|
||||
Id = 150,
|
||||
ModuleId = 40,
|
||||
Name = "Import Page Undetected Stored",
|
||||
Format = null,
|
||||
Severity = 0,
|
||||
UseLive = true,
|
||||
UsePersist = false,
|
||||
UseDisplay = false
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using iTextSharp.text;
|
||||
using iTextSharp.text.pdf;
|
||||
|
||||
namespace Disco.BI.DocumentTemplateBI
|
||||
{
|
||||
public static class Utilities
|
||||
{
|
||||
public static System.IO.Stream JoinPdfs(params System.IO.Stream[] Pdfs)
|
||||
{
|
||||
if (Pdfs.Length == 0)
|
||||
throw new System.ArgumentNullException("Pdfs");
|
||||
|
||||
// Only One PDF - Possible Reference Bug v's Memory/Speed (Returning Param Memory Stream)
|
||||
if (Pdfs.Length == 1)
|
||||
return Pdfs[0];
|
||||
|
||||
// Join Pdfs
|
||||
System.IO.MemoryStream msBuilder = new System.IO.MemoryStream();
|
||||
|
||||
Document pdfDoc = new Document();
|
||||
PdfCopy pdfCopy = new PdfCopy(pdfDoc, msBuilder);
|
||||
pdfDoc.Open();
|
||||
pdfCopy.CloseStream = false;
|
||||
|
||||
for (int i = 0; i < Pdfs.Length; i++)
|
||||
{
|
||||
System.IO.Stream pdf = Pdfs[i];
|
||||
PdfReader pdfReader = new PdfReader(pdf);
|
||||
|
||||
for (int indexPage = 1; indexPage <= pdfReader.NumberOfPages; indexPage++)
|
||||
{
|
||||
iTextSharp.text.Rectangle pageSize = pdfReader.GetPageSizeWithRotation(indexPage);
|
||||
PdfImportedPage page = pdfCopy.GetImportedPage(pdfReader, indexPage);
|
||||
pdfDoc.SetPageSize(pageSize);
|
||||
pdfDoc.NewPage();
|
||||
pdfCopy.AddPage(page);
|
||||
}
|
||||
|
||||
pdfReader.Close();
|
||||
}
|
||||
|
||||
pdfDoc.Close();
|
||||
pdfCopy.Close();
|
||||
msBuilder.Position = 0;
|
||||
|
||||
return msBuilder;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user