diff --git a/Disco.BI/BI/AttachmentBI/Utilities.cs b/Disco.BI/BI/AttachmentBI/Utilities.cs deleted file mode 100644 index 63799177..00000000 --- a/Disco.BI/BI/AttachmentBI/Utilities.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Disco.BI.Extensions; -using Exceptionless; -using iTextSharp.text.pdf; -using System; -using System.Drawing; -using System.IO; -using System.Linq; - -namespace Disco.BI.AttachmentBI -{ - public static class Utilities - { - - public static bool GenerateThumbnail(Stream Source, string SourceMimeType, Stream OutStream) - { - if (Source != null) - { - // GDI+ (jpg, png, gif, bmp) - if (SourceMimeType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase) || SourceMimeType.Contains("jpg") || - SourceMimeType.Equals("image/png", StringComparison.OrdinalIgnoreCase) || SourceMimeType.Contains("png") || - SourceMimeType.Equals("image/gif", StringComparison.OrdinalIgnoreCase) || SourceMimeType.Contains("gif") || - SourceMimeType.Equals("image/bmp", StringComparison.OrdinalIgnoreCase) || SourceMimeType.Contains("bmp")) - { - try - { - using (Image sourceImage = Image.FromStream(Source)) - { - using (Image thumbImage = sourceImage.ResizeImage(48, 48)) - { - using (Image mimeTypeIcon = Disco.Properties.Resources.MimeType_img16) - thumbImage.EmbedIconOverlay(mimeTypeIcon); - thumbImage.SaveJpg(90, OutStream); - return true; - } - } - } - catch (Exception ex) - { - ex.ToExceptionless().Submit(); - - // Ignore Thumbnail Generation exceptions for images - } - - } - - // PDF - if (SourceMimeType.Equals("application/pdf", StringComparison.OrdinalIgnoreCase) || SourceMimeType.Contains("pdf")) - { - PdfReader pdfReader = new PdfReader(Source); - try - { - using (DisposableImageCollection pdfPageImages = pdfReader.PdfPageImages(1)) - { - if (pdfPageImages.Count() > 0) - { - // Find Biggest Image on Page - Image biggestImage = pdfPageImages.OrderByDescending(i => i.Height * i.Width).First(); - using (Image thumbImage = biggestImage.ResizeImage(48, 48, Brushes.White)) - { - using (Image mimeTypeIcon = Disco.Properties.Resources.MimeType_pdf16) - thumbImage.EmbedIconOverlay(mimeTypeIcon); - thumbImage.SaveJpg(90, OutStream); - return true; - } - } - } - } - catch (Exception ex) - { - ex.ToExceptionless().Submit(); - } - finally - { - if (pdfReader != null) - pdfReader.Close(); - } - } - } - return false; - } - public static bool GenerateThumbnail(string SourceFilename, string SourceMimeType, string DestinationFilename) - { - using (FileStream sourceStream = new FileStream(SourceFilename, FileMode.Open, FileAccess.Read)) - { - return GenerateThumbnail(sourceStream, SourceMimeType, DestinationFilename); - } - } - public static bool GenerateThumbnail(Stream Source, string SourceMimeType, string DestinationFilename) - { - bool result; - using (FileStream destinationStream = new FileStream(DestinationFilename, FileMode.Create, FileAccess.Write, FileShare.None)) - { - result = GenerateThumbnail(Source, SourceMimeType, destinationStream); - } - if (!result && File.Exists(DestinationFilename)) - File.Delete(DestinationFilename); - - return result; - } - - } -} diff --git a/Disco.BI/BI/DocumentTemplateBI/DocumentTemplateQRCodeLocationCache.cs b/Disco.BI/BI/DocumentTemplateBI/DocumentTemplateQRCodeLocationCache.cs deleted file mode 100644 index 2b66c007..00000000 --- a/Disco.BI/BI/DocumentTemplateBI/DocumentTemplateQRCodeLocationCache.cs +++ /dev/null @@ -1,78 +0,0 @@ -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> _Cache = new ConcurrentDictionary>(); - - public static List GetLocations(DocumentTemplate dt, DiscoDataContext Database) - { - // Check Cache - List locations; - if (_Cache.TryGetValue(dt.Id, out locations)) - { - return locations; - } - // Generate Cache - return GenerateLocations(dt, Database); - } - - public static bool InvalidateLocations(DocumentTemplate dt) - { - List locations; - return _Cache.TryRemove(dt.Id, out locations); - } - - private static bool SetValue(string DocumentTemplateId, List Locations) - { - if (_Cache.ContainsKey(DocumentTemplateId)) - { - List oldLocations; - if (_Cache.TryGetValue(DocumentTemplateId, out oldLocations)) - { - return _Cache.TryUpdate(DocumentTemplateId, Locations, oldLocations); - } - } - return _Cache.TryAdd(DocumentTemplateId, Locations); - } - - internal static List GenerateLocations(DocumentTemplate dt, DiscoDataContext Database) - { - string templateFilename = dt.RepositoryFilename(Database); - PdfReader pdfReader = new PdfReader(templateFilename); - List locations = new List(); - - if (pdfReader.AcroFields.Fields.ContainsKey("DiscoAttachmentId")) - { - foreach (var pdfFieldPosition in pdfReader.AcroFields.GetFieldPositions("DiscoAttachmentId")) - { - var pdfPageSize = pdfReader.GetPageSize(pdfFieldPosition.page); - // Original Position - locations.Add(new RectangleF( - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(pdfFieldPosition.position.Left / pdfPageSize.Width) - 0.05)), - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)((pdfPageSize.Height - pdfFieldPosition.position.Top) / pdfPageSize.Height) - 0.05)), - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(pdfFieldPosition.position.Width / pdfPageSize.Width) + 0.1)), - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(pdfFieldPosition.position.Height / pdfPageSize.Height) + 0.1)) - )); - } - } - pdfReader.Close(); - - // Update Cache - SetValue(dt.Id, locations); - return locations; - } - - } -} diff --git a/Disco.BI/BI/DocumentTemplateBI/DocumentUniqueIdentifier.cs b/Disco.BI/BI/DocumentTemplateBI/DocumentUniqueIdentifier.cs deleted file mode 100644 index 41a35f1b..00000000 --- a/Disco.BI/BI/DocumentTemplateBI/DocumentUniqueIdentifier.cs +++ /dev/null @@ -1,204 +0,0 @@ -using Disco.Data.Repository; -using Disco.Models.Repository; -using Disco.Services.Interop.ActiveDirectory; -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.OrdinalIgnoreCase); - } - 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 = ActiveDirectory.ParseDomainAccountId(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 = ActiveDirectory.ParseDomainAccountId(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 Database) - { - 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 = Database.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 = Database.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 = Database.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 = Database.Users.Find(ActiveDirectory.ParseDomainAccountId(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; - } - } -} diff --git a/Disco.BI/BI/DocumentTemplateBI/DocumentsLog.cs b/Disco.BI/BI/DocumentTemplateBI/DocumentsLog.cs deleted file mode 100644 index a2249651..00000000 --- a/Disco.BI/BI/DocumentTemplateBI/DocumentsLog.cs +++ /dev/null @@ -1,478 +0,0 @@ -using Disco.Models.Repository; -using Disco.Services.Logging; -using Disco.Services.Logging.Models; -using System; -using System.Collections.Generic; -using System.Diagnostics; -namespace Disco.BI.DocumentTemplateBI -{ - public class DocumentsLog : LogBase - { - public enum EventTypeIds - { - ImportStarting = 10, - ImportProgress, - ImportFinished, - ImportWarning = 15, - ImportError, - ImportAttachmentExpressionEvaluated = 50, - ImportPageStarting = 100, - ImportPageImageUpdate = 104, - ImportPageProgress, - ImportPageDetected = 110, - ImportPageUndetected = 115, - ImportPageError = 120, - ImportPageUndetectedStored = 150, - DocumentGenerated = 500, - DocumentGeneratedWithExpression - } - - private const int _ModuleId = 40; - - public static DocumentsLog Current - { - get - { - return (DocumentsLog)LogContext.LogModules[_ModuleId]; - } - } - - public override string ModuleDescription - { - get - { - return "Documents"; - } - } - public override int ModuleId - { - get - { - return _ModuleId; - } - } - public override string ModuleName - { - get - { - return "Documents"; - } - } - private static void Log(DocumentsLog.EventTypeIds EventTypeId, params object[] Args) - { - DocumentsLog.Current.Log((int)EventTypeId, Args); - } - public static void LogImportStarting(string SessionId, string DocumentName) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportStarting, new object[] - { - SessionId, - DocumentName - }); - } - public static void LogImportProgress(string SessionId, int? Progress, string Status) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportProgress, new object[] - { - SessionId, - Progress, - Status - }); - } - public static void LogImportFinished(string SessionId) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportFinished, new object[] - { - SessionId - }); - } - public static void LogImportWarning(string SessionId, string Message) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportWarning, new object[] - { - SessionId, - Message - }); - } - public static void LogImportError(string SessionId, string Message) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportError, new object[] - { - SessionId, - Message - }); - } - public static void LogImportAttachmentExpressionEvaluated(DocumentTemplate template, Device device, DeviceAttachment attachment, string Result) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportAttachmentExpressionEvaluated, new object[] - { - template.Id, - device.SerialNumber, - attachment.Id, - Result - }); - } - public static void LogImportAttachmentExpressionEvaluated(DocumentTemplate template, Job job, JobAttachment attachment, string Result) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportAttachmentExpressionEvaluated, new object[] - { - template.Id, - job.Id, - attachment.Id, - Result - }); - } - public static void LogImportAttachmentExpressionEvaluated(DocumentTemplate template, User user, UserAttachment attachment, string Result) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportAttachmentExpressionEvaluated, new object[] - { - template.Id, - user.UserId, - attachment.Id, - Result - }); - } - public static void LogImportAttachmentExpressionEvaluated(DocumentTemplate Template, object Data, object Attachment, string Result) - { - if (Data is Job) - LogImportAttachmentExpressionEvaluated(Template, (Job)Data, (JobAttachment)Attachment, Result); - else if (Data is User) - LogImportAttachmentExpressionEvaluated(Template, (User)Data, (UserAttachment)Attachment, Result); - else if (Data is Device) - LogImportAttachmentExpressionEvaluated(Template, (Device)Data, (DeviceAttachment)Attachment, Result); - else - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportAttachmentExpressionEvaluated, new object[] - { - Template.Id, - Data.ToString(), - Attachment.ToString(), - Result - }); - } - public static void LogImportPageStarting(string SessionId, int PageNumber) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportPageStarting, new object[] - { - SessionId, - PageNumber - }); - } - public static void LogImportPageImageUpdate(string SessionId, int PageNumber) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportPageImageUpdate, new object[] - { - SessionId, - PageNumber - }); - } - public static void LogImportPageProgress(string SessionId, int PageNumber, int? Progress, string Status) - { - DocumentsLog.Log(DocumentsLog.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) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportPageDetected, new object[] - { - SessionId, - PageNumber, - DocumentTypeId, - DocumentTypeName, - TargetType, - AssignedId, - AssignedName - }); - } - public static void LogImportPageUndetected(string SessionId, int PageNumber) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportPageUndetected, new object[] - { - SessionId, - PageNumber - }); - } - public static void LogImportPageError(string SessionId, int PageNumber, string Message) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportPageError, new object[] - { - SessionId, - PageNumber, - Message - }); - } - public static void LogImportPageUndetectedStored(string SessionId, int PageNumber) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.ImportPageUndetectedStored, new object[] - { - SessionId, - PageNumber - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, Device Device, User Author, string ExpressionResult) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGeneratedWithExpression, new object[] - { - Template.Id, - Device.SerialNumber, - Author.UserId, - ExpressionResult - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, Job Job, User Author, string ExpressionResult) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGeneratedWithExpression, new object[] - { - Template.Id, - Job.Id, - Author.UserId, - ExpressionResult - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, User User, User Author, string ExpressionResult) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGeneratedWithExpression, new object[] - { - Template.Id, - User.UserId, - Author.UserId, - ExpressionResult - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, object Data, User Author, string ExpressionResult) - { - if (Data is Job) - LogDocumentGenerated(Template, (Job)Data, Author, ExpressionResult); - else if (Data is User) - LogDocumentGenerated(Template, (User)Data, Author, ExpressionResult); - else if (Data is Device) - LogDocumentGenerated(Template, (Device)Data, Author, ExpressionResult); - else - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGeneratedWithExpression, new object[] - { - Template.Id, - "UNKNOWN", - Author.UserId, - ExpressionResult - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, Device Device, User Author) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGenerated, new object[] - { - Template.Id, - Device.SerialNumber, - Author.UserId - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, Job Job, User Author) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGenerated, new object[] - { - Template.Id, - Job.Id, - Author.UserId - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, User User, User Author) - { - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGenerated, new object[] - { - Template.Id, - User.UserId, - Author.UserId - }); - } - public static void LogDocumentGenerated(DocumentTemplate Template, object Data, User Author) - { - if (Data is Job) - LogDocumentGenerated(Template, (Job)Data, Author); - else if (Data is User) - LogDocumentGenerated(Template, (User)Data, Author); - else if (Data is Device) - LogDocumentGenerated(Template, (Device)Data, Author); - else - DocumentsLog.Log(DocumentsLog.EventTypeIds.DocumentGenerated, new object[] - { - Template.Id, - "UNKNOWN", - Author.UserId - }); - } - protected override System.Collections.Generic.List LoadEventTypes() - { - return new System.Collections.Generic.List - { - new LogEventType - { - Id = (int)EventTypeIds.ImportStarting, - ModuleId = _ModuleId, - Name = "Import Starting", - Format = "Starting import of document: {1} (SessionId: {0})", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportProgress, - ModuleId = _ModuleId, - Name = "Import Progress", - Format = "Processing: {1}% Complete; Status: {2}", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = false, - UseDisplay = false - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportFinished, - ModuleId = _ModuleId, - Name = "Import Finished", - Format = "Import of document complete (SessionId: {0})", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportWarning, - ModuleId = _ModuleId, - Name = "Import Warning", - Format = "Import Warning: {1} (SessionId: {0})", - Severity = (int)LogEventType.Severities.Warning, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportError, - ModuleId = _ModuleId, - Name = "Import Error", - Format = "Import Error: {1} (SessionId: {0})", - Severity = (int)LogEventType.Severities.Error, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportAttachmentExpressionEvaluated, - ModuleId = _ModuleId, - Name = "Import Attachment Expression Evaluated", - Format = "The import attachment expression for '{0}' was evaluated for '{1}' (attachment id: {2}) with the result: {3}", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportPageStarting, - ModuleId = _ModuleId, - Name = "Import Page Starting", - Format = "Starting import of page: {1} (SessionId: {0})", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportPageImageUpdate, - ModuleId = _ModuleId, - Name = "Import Page Image Update", - Format = null, - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = false, - UseDisplay = false - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportPageProgress, - ModuleId = _ModuleId, - Name = "Import Page Progress", - Format = "Processing: Page {1}; {2}% Complete; Status: {3}", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = false, - UseDisplay = false - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportPageDetected, - ModuleId = _ModuleId, - Name = "Import Page Assigned", - Format = "Page {1} of type '{3}' assigned to {4}: '{6}'", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportPageUndetected, - ModuleId = _ModuleId, - Name = "Import Page Undetected", - Format = "Page {1} not detected", - Severity = (int)LogEventType.Severities.Warning, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportPageError, - ModuleId = _ModuleId, - Name = "Import Page Error", - Format = "Page {1}, Import Error: {2}", - Severity = (int)LogEventType.Severities.Error, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.ImportPageUndetectedStored, - ModuleId = _ModuleId, - Name = "Import Page Undetected Stored", - Format = null, - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = false, - UseDisplay = false - }, - new LogEventType - { - Id = (int)EventTypeIds.DocumentGenerated, - ModuleId = _ModuleId, - Name = "Document Generated", - Format = "A '{0}' document was generated for '{1}' by '{2}'", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = true, - UseDisplay = true - }, - new LogEventType - { - Id = (int)EventTypeIds.DocumentGeneratedWithExpression, - ModuleId = _ModuleId, - Name = "Document Generated with Expression", - Format = "A '{0}' document was generated for '{1}' by '{2}'. The expression returned: {3}", - Severity = (int)LogEventType.Severities.Information, - UseLive = true, - UsePersist = true, - UseDisplay = true - } - }; - } - } -} diff --git a/Disco.BI/BI/DocumentTemplateBI/Importer/DocumentDropBoxMonitor.cs b/Disco.BI/BI/DocumentTemplateBI/Importer/DocumentDropBoxMonitor.cs deleted file mode 100644 index 1565643b..00000000 --- a/Disco.BI/BI/DocumentTemplateBI/Importer/DocumentDropBoxMonitor.cs +++ /dev/null @@ -1,85 +0,0 @@ -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 Database, ISchedulerFactory SchedulerFactory, Cache HttpCache) - { - if (Database == null) - throw new System.ArgumentNullException("Context"); - - this._httpCache = HttpCache; - - var location = DataStore.CreateLocation(Database, "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); - } - } -} diff --git a/Disco.BI/BI/DocumentTemplateBI/Importer/DocumentImporterJob.cs b/Disco.BI/BI/DocumentTemplateBI/Importer/DocumentImporterJob.cs deleted file mode 100644 index df4f9879..00000000 --- a/Disco.BI/BI/DocumentTemplateBI/Importer/DocumentImporterJob.cs +++ /dev/null @@ -1,123 +0,0 @@ -using Disco.Data.Repository; -using Exceptionless; -using Quartz; -using Quartz.Impl.Triggers; -using System; -using System.IO; -using System.Web.Caching; - -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); - - DocumentsLog.LogImportStarting(sessionId, friendlyFilename); - - if (!File.Exists(filename)) - { - DocumentsLog.LogImportWarning(sessionId, string.Format("File not found: {0}", filename)); - DocumentsLog.LogImportFinished(sessionId); - context.Scheduler.DeleteJob(context.JobDetail.Key); - return; - } - - try - { - using (DiscoDataContext database = new DiscoDataContext()) - { - if (retryCount < 18) - { - context.JobDetail.JobDataMap["RetryCount"] = (++retryCount); - bool processResult = Interop.Pdf.PdfImporter.ProcessPdfAttachment(filename, database, 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(database, "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 (Exception ex) - { - ex.ToExceptionless().Submit(); - // Ignore Errors - } - } - } - } - else - { - // To Many Errors - DocumentsLog.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(database, "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 - } - } - } - } - DocumentsLog.LogImportFinished(sessionId); - - // All Done - context.Scheduler.DeleteJob(context.JobDetail.Key); - } - catch (Exception ex) - { - ex.ToExceptionless().Submit(); - DocumentsLog.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); - } - - } - - } -} diff --git a/Disco.BI/BI/Expressions/ExpressionTypeMemberDescriptor.cs b/Disco.BI/BI/Expressions/ExpressionTypeMemberDescriptor.cs deleted file mode 100644 index f23efbed..00000000 --- a/Disco.BI/BI/Expressions/ExpressionTypeMemberDescriptor.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; - -namespace Disco.BI.Expressions -{ - public class ExpressionTypeMemberDescriptor - { - public const string FunctionKind = "function"; - public const string PropertyKind = "property"; - public const string ParameterKind = "parameter"; - - public string Kind {get;set;} - public string Name {get;set;} - public string ReturnType {get;set;} - public string ReturnExpressionType{get;set;} - public List Parameters{get;set;} - - public static ExpressionTypeMemberDescriptor Build(System.Reflection.MethodInfo m) - { - ExpressionTypeMemberDescriptor md = new ExpressionTypeMemberDescriptor - { - Kind = "function", - Name = m.Name, - ReturnType = m.ReturnType.Name, - ReturnExpressionType = m.ReturnType.AssemblyQualifiedName - }; - md.Parameters = ( - from mdp in m.GetParameters() - select ExpressionTypeMemberDescriptor.Build(mdp)).ToList(); - return md; - } - public static ExpressionTypeMemberDescriptor Build(System.Reflection.PropertyInfo p) - { - ExpressionTypeMemberDescriptor md = new ExpressionTypeMemberDescriptor - { - Kind = "property", - Name = p.Name, - ReturnType = p.PropertyType.Name, - ReturnExpressionType = p.PropertyType.AssemblyQualifiedName - }; - md.Parameters = ( - from mdp in p.GetIndexParameters() - select ExpressionTypeMemberDescriptor.Build(mdp)).ToList(); - return md; - } - public static ExpressionTypeMemberDescriptor Build(System.Reflection.ParameterInfo pi) - { - return new ExpressionTypeMemberDescriptor - { - Kind = "parameter", - Name = pi.Name, - ReturnType = pi.ParameterType.Name, - ReturnExpressionType = pi.ParameterType.AssemblyQualifiedName - }; - } - } -} diff --git a/Disco.BI/BI/Extensions/AttachmentActionExtensions.cs b/Disco.BI/BI/Extensions/AttachmentActionExtensions.cs index 6219d761..b394bbe0 100644 --- a/Disco.BI/BI/Extensions/AttachmentActionExtensions.cs +++ b/Disco.BI/BI/Extensions/AttachmentActionExtensions.cs @@ -7,6 +7,7 @@ using Disco.Data.Repository; using Disco.Services.Users; using Disco.Services.Authorization; using Disco.BI.DocumentTemplateBI.ManagedGroups; +using Disco.Services; namespace Disco.BI.Extensions { diff --git a/Disco.BI/BI/Extensions/AttachmentExtensions.cs b/Disco.BI/BI/Extensions/AttachmentExtensions.cs deleted file mode 100644 index df629521..00000000 --- a/Disco.BI/BI/Extensions/AttachmentExtensions.cs +++ /dev/null @@ -1,209 +0,0 @@ -using Disco.BI.DocumentTemplateBI; -using Disco.Data.Repository; -using Disco.Models.Repository; -using Disco.Services.Logging; -using Disco.Services.Users; -using Exceptionless; -using System; -using System.IO; - -namespace Disco.BI.Extensions -{ - public static class AttachmentExtensions - { - - public static bool ImportPdfAttachment(this DocumentUniqueIdentifier UniqueIdentifier, DiscoDataContext Database, System.IO.Stream PdfContent, byte[] PdfThumbnail) - { - UniqueIdentifier.LoadComponents(Database); - DocumentTemplate documentTemplate = UniqueIdentifier.DocumentTemplate; - string filename; - string comments; - object attachment; - - if (documentTemplate == null) - { - filename = string.Format("{0}_{1:yyyyMMdd-HHmmss}.pdf", UniqueIdentifier.DataId.Replace('\\', '_'), UniqueIdentifier.TimeStamp); - comments = string.Format("Uploaded: {0:s}", UniqueIdentifier.TimeStamp); - } - else - { - filename = string.Format("{0}_{1:yyyyMMdd-HHmmss}.pdf", UniqueIdentifier.TemplateTypeId, UniqueIdentifier.TimeStamp); - comments = string.Format("Generated: {0:s}", UniqueIdentifier.TimeStamp); - } - - User creatorUser = UserService.GetUser(UniqueIdentifier.CreatorId, Database); - if (creatorUser == null) - { - // No Creator User (or Username invalid) - creatorUser = UserService.CurrentUser; - } - switch (UniqueIdentifier.DataScope) - { - case DocumentTemplate.DocumentTemplateScopes.Device: - Device d = (Device)UniqueIdentifier.Data; - attachment = d.CreateAttachment(Database, creatorUser, filename, DocumentTemplate.PdfMimeType, comments, PdfContent, documentTemplate, PdfThumbnail); - break; - case DocumentTemplate.DocumentTemplateScopes.Job: - Job j = (Job)UniqueIdentifier.Data; - attachment = j.CreateAttachment(Database, creatorUser, filename, DocumentTemplate.PdfMimeType, comments, PdfContent, documentTemplate, PdfThumbnail); - break; - case DocumentTemplate.DocumentTemplateScopes.User: - User u = (User)UniqueIdentifier.Data; - attachment = u.CreateAttachment(Database, creatorUser, filename, DocumentTemplate.PdfMimeType, comments, PdfContent, documentTemplate, PdfThumbnail); - break; - default: - return false; - } - - if (documentTemplate != null && !string.IsNullOrWhiteSpace(documentTemplate.OnImportAttachmentExpression)) - { - try - { - var expressionResult = documentTemplate.EvaluateOnAttachmentImportExpression(attachment, Database, creatorUser, UniqueIdentifier.TimeStamp); - DocumentsLog.LogImportAttachmentExpressionEvaluated(documentTemplate, UniqueIdentifier.Data, attachment, expressionResult); - } - catch (Exception ex) - { - SystemLog.LogException("Document Importer - OnImportAttachmentExpression", ex); - } - } - return true; - } - - public static string RepositoryFilename(this DeviceAttachment da, DiscoDataContext Database) - { - return Path.Combine(DataStore.CreateLocation(Database, "DeviceAttachments", da.Timestamp), string.Format("{0}_{1}_file", da.DeviceSerialNumber, da.Id)); - } - public static string RepositoryFilename(this JobAttachment ja, DiscoDataContext Database) - { - return Path.Combine(DataStore.CreateLocation(Database, "JobAttachments", ja.Timestamp), string.Format("{0}_{1}_file", ja.JobId, ja.Id)); - } - public static string RepositoryFilename(this UserAttachment ua, DiscoDataContext Database) - { - return Path.Combine(DataStore.CreateLocation(Database, "UserAttachments", ua.Timestamp), string.Format("{0}_{1}_file", ua.UserId.Replace('\\', '_'), ua.Id)); - } - - private static string RepositoryThumbnailFilenameInternal(string DirectoryPath, string Filename) - { - return Path.Combine(DirectoryPath, Filename); - } - public static string RepositoryThumbnailFilename(this DeviceAttachment da, DiscoDataContext Database) - { - return RepositoryThumbnailFilenameInternal(DataStore.CreateLocation(Database, "DeviceAttachments", da.Timestamp), string.Format("{0}_{1}_thumb.jpg", da.DeviceSerialNumber, da.Id)); - } - public static string RepositoryThumbnailFilename(this JobAttachment ja, DiscoDataContext Database) - { - return RepositoryThumbnailFilenameInternal(DataStore.CreateLocation(Database, "JobAttachments", ja.Timestamp), string.Format("{0}_{1}_thumb.jpg", ja.JobId, ja.Id)); - } - public static string RepositoryThumbnailFilename(this UserAttachment ua, DiscoDataContext Database) - { - return RepositoryThumbnailFilenameInternal(DataStore.CreateLocation(Database, "UserAttachments", ua.Timestamp), string.Format("{0}_{1}_thumb.jpg", ua.UserId.Replace('\\', '_'), ua.Id)); - } - - public static void RepositoryDelete(this DeviceAttachment da, DiscoDataContext Database) - { - RepositoryDelete(da.RepositoryFilename(Database), da.RepositoryThumbnailFilename(Database)); - } - public static void RepositoryDelete(this JobAttachment ja, DiscoDataContext Database) - { - RepositoryDelete(ja.RepositoryFilename(Database), ja.RepositoryThumbnailFilename(Database)); - } - public static void RepositoryDelete(this UserAttachment ua, DiscoDataContext Database) - { - RepositoryDelete(ua.RepositoryFilename(Database), ua.RepositoryThumbnailFilename(Database)); - } - private static void RepositoryDelete(params string[] filePaths) - { - foreach (string filePath in filePaths) - { - if (File.Exists(filePath)) - File.Delete(filePath); - } - } - - public static string SaveAttachment(this DeviceAttachment da, DiscoDataContext Database, Stream FileContent) - { - string filePath = da.RepositoryFilename(Database); - SaveAttachment(filePath, FileContent); - return filePath; - } - public static string SaveAttachment(this JobAttachment ja, DiscoDataContext Database, Stream FileContent) - { - string filePath = ja.RepositoryFilename(Database); - SaveAttachment(filePath, FileContent); - return filePath; - } - public static string SaveAttachment(this UserAttachment ua, DiscoDataContext Database, Stream FileContent) - { - string filePath = ua.RepositoryFilename(Database); - SaveAttachment(filePath, FileContent); - return filePath; - } - public static string SaveThumbnailAttachment(this DeviceAttachment da, DiscoDataContext Database, byte[] FileContent) - { - string filePath = da.RepositoryThumbnailFilename(Database); - File.WriteAllBytes(filePath, FileContent); - return filePath; - } - public static string SaveThumbnailAttachment(this JobAttachment ja, DiscoDataContext Database, byte[] FileContent) - { - string filePath = ja.RepositoryThumbnailFilename(Database); - File.WriteAllBytes(filePath, FileContent); - return filePath; - } - public static string SaveThumbnailAttachment(this UserAttachment ua, DiscoDataContext Database, byte[] FileContent) - { - string filePath = ua.RepositoryThumbnailFilename(Database); - File.WriteAllBytes(filePath, FileContent); - return filePath; - } - private static void SaveAttachment(string FilePath, Stream FileContent) - { - using (FileStream sw = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None)) - { - FileContent.CopyTo(sw); - sw.Flush(); - sw.Close(); - } - } - - public static string GenerateThumbnail(this DeviceAttachment da, DiscoDataContext Database) - { - string filePath = da.RepositoryThumbnailFilename(Database); - AttachmentBI.Utilities.GenerateThumbnail(da.RepositoryFilename(Database), da.MimeType, filePath); - return filePath; - } - public static string GenerateThumbnail(this JobAttachment ja, DiscoDataContext Database) - { - string filePath = ja.RepositoryThumbnailFilename(Database); - AttachmentBI.Utilities.GenerateThumbnail(ja.RepositoryFilename(Database), ja.MimeType, filePath); - return filePath; - } - public static string GenerateThumbnail(this UserAttachment ua, DiscoDataContext Database) - { - string filePath = ua.RepositoryThumbnailFilename(Database); - AttachmentBI.Utilities.GenerateThumbnail(ua.RepositoryFilename(Database), ua.MimeType, filePath); - return filePath; - } - public static string GenerateThumbnail(this DeviceAttachment da, DiscoDataContext Database, Stream SourceFile) - { - string filePath = da.RepositoryThumbnailFilename(Database); - AttachmentBI.Utilities.GenerateThumbnail(SourceFile, da.MimeType, filePath); - return filePath; - } - public static string GenerateThumbnail(this JobAttachment ja, DiscoDataContext Database, Stream SourceFile) - { - string filePath = ja.RepositoryThumbnailFilename(Database); - AttachmentBI.Utilities.GenerateThumbnail(SourceFile, ja.MimeType, filePath); - return filePath; - } - public static string GenerateThumbnail(this UserAttachment ua, DiscoDataContext Database, Stream SourceFile) - { - string filePath = ua.RepositoryThumbnailFilename(Database); - AttachmentBI.Utilities.GenerateThumbnail(SourceFile, ua.MimeType, filePath); - return filePath; - } - - - } -} diff --git a/Disco.BI/BI/Extensions/DeviceActionExtensions.cs b/Disco.BI/BI/Extensions/DeviceActionExtensions.cs index b8bfd58d..56bc8624 100644 --- a/Disco.BI/BI/Extensions/DeviceActionExtensions.cs +++ b/Disco.BI/BI/Extensions/DeviceActionExtensions.cs @@ -1,5 +1,6 @@ using Disco.Data.Repository; using Disco.Models.Repository; +using Disco.Services; using Disco.Services.Authorization; using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Users; diff --git a/Disco.BI/BI/Extensions/DeviceExtensions.cs b/Disco.BI/BI/Extensions/DeviceExtensions.cs index 532fa2b6..5ae41af8 100644 --- a/Disco.BI/BI/Extensions/DeviceExtensions.cs +++ b/Disco.BI/BI/Extensions/DeviceExtensions.cs @@ -1,15 +1,16 @@ -using System.Linq; -using Disco.Data.Configuration; using Disco.Data.Repository; -using Disco.Models.BI.DocumentTemplates; using Disco.Models.Repository; -using System.Collections.Generic; -using System; -using System.IO; -using Disco.Services.Users; +using Disco.Models.Services.Documents; +using Disco.Services; using Disco.Services.Authorization; +using Disco.Services.Expressions; using Disco.Services.Interop.ActiveDirectory; +using Disco.Services.Users; using Exceptionless; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; namespace Disco.BI.Extensions { @@ -21,15 +22,15 @@ namespace Disco.BI.Extensions if (Domain == null) throw new ArgumentNullException("Domain"); - DeviceProfile deviceProfile = device.DeviceProfile; - Expressions.Expression computerNameTemplateExpression = null; - computerNameTemplateExpression = Expressions.ExpressionCache.GetValue(DeviceProfileExtensions.ComputerNameExpressionCacheModule, deviceProfile.Id.ToString(), () => + var deviceProfile = device.DeviceProfile; + Expression computerNameTemplateExpression = null; + computerNameTemplateExpression = ExpressionCache.GetValue(DeviceProfileExtensions.ComputerNameExpressionCacheModule, deviceProfile.Id.ToString(), () => { // Removed 2012-06-14 G# - Properties moved to DeviceProfile model & DB Migrated in DBv3. //return Expressions.Expression.TokenizeSingleDynamic(null, deviceProfile.Configuration(context).ComputerNameTemplate, 0); - return Expressions.Expression.TokenizeSingleDynamic(null, deviceProfile.ComputerNameTemplate, 0); + return Expression.TokenizeSingleDynamic(null, deviceProfile.ComputerNameTemplate, 0); }); - System.Collections.IDictionary evaluatorVariables = Expressions.Expression.StandardVariables(null, Database, UserService.CurrentUser, System.DateTime.Now, null); + var evaluatorVariables = Expression.StandardVariables(null, Database, UserService.CurrentUser, DateTime.Now, null); string rendered; try { @@ -42,53 +43,22 @@ namespace Disco.BI.Extensions } if (rendered == null || rendered.Length > 24) { - throw new System.InvalidOperationException("The rendered computer name would be invalid or longer than 24 characters"); + throw new InvalidOperationException("The rendered computer name would be invalid or longer than 24 characters"); } return string.Format(@"{0}\{1}", Domain.NetBiosName, rendered); } - public static System.Collections.Generic.List AvailableDocumentTemplates(this Device d, DiscoDataContext Database, User User, System.DateTime TimeStamp) + public static List AvailableDocumentTemplates(this Device d, DiscoDataContext Database, User User, DateTime TimeStamp) { List ats = Database.DocumentTemplates - .Where(at => at.Scope == Disco.Models.Repository.DocumentTemplate.DocumentTemplateScopes.Device).ToList(); + .Where(at => at.Scope == DocumentTemplate.DocumentTemplateScopes.Device).ToList(); return ats.Where(at => at.FilterExpressionMatches(d, Database, User, TimeStamp, DocumentState.DefaultState())).ToList(); } public static bool UpdateLastNetworkLogonDate(this Device Device) { - return Disco.Services.Interop.ActiveDirectory.ADNetworkLogonDatesUpdateTask.UpdateLastNetworkLogonDate(Device); - } - - public static DeviceAttachment CreateAttachment(this Device Device, DiscoDataContext Database, User CreatorUser, string Filename, string MimeType, string Comments, Stream Content, DocumentTemplate DocumentTemplate = null, byte[] PdfThumbnail = null) - { - if (string.IsNullOrEmpty(MimeType) || MimeType.Equals("unknown/unknown", StringComparison.OrdinalIgnoreCase)) - MimeType = Interop.MimeTypes.ResolveMimeType(Filename); - - DeviceAttachment da = new DeviceAttachment() - { - DeviceSerialNumber = Device.SerialNumber, - TechUserId = CreatorUser.UserId, - Filename = Filename, - MimeType = MimeType, - Timestamp = DateTime.Now, - Comments = Comments - }; - - if (DocumentTemplate != null) - da.DocumentTemplateId = DocumentTemplate.Id; - - Database.DeviceAttachments.Add(da); - Database.SaveChanges(); - - da.SaveAttachment(Database, Content); - Content.Position = 0; - if (PdfThumbnail == null) - da.GenerateThumbnail(Database, Content); - else - da.SaveThumbnailAttachment(Database, PdfThumbnail); - - return da; + return ADNetworkLogonDatesUpdateTask.UpdateLastNetworkLogonDate(Device); } public static Device AddOffline(this Device d, DiscoDataContext Database) @@ -189,15 +159,7 @@ namespace Disco.BI.Extensions return newDua; } - public static ADMachineAccount ActiveDirectoryAccount(this Device Device, params string[] AdditionalProperties) - { - if (ActiveDirectory.IsValidDomainAccountId(Device.DeviceDomainId)) - return ActiveDirectory.RetrieveADMachineAccount(Device.DeviceDomainId, AdditionalProperties: AdditionalProperties); - else - return null; - } - - public static string ReasonMessage(this Disco.Models.Repository.DecommissionReasons r) + public static string ReasonMessage(this DecommissionReasons r) { switch (r) { @@ -220,7 +182,7 @@ namespace Disco.BI.Extensions } } - public static string ReasonMessage(this Disco.Models.Repository.DecommissionReasons? r) + public static string ReasonMessage(this DecommissionReasons? r) { if (!r.HasValue) return "Not Decommissioned"; diff --git a/Disco.BI/BI/Extensions/DeviceModelExtensions.cs b/Disco.BI/BI/Extensions/DeviceModelExtensions.cs index a1b46923..d4599d33 100644 --- a/Disco.BI/BI/Extensions/DeviceModelExtensions.cs +++ b/Disco.BI/BI/Extensions/DeviceModelExtensions.cs @@ -1,79 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using Disco.Data.Repository; using Disco.Models.Repository; -using System.IO; -using System.Drawing; -using Disco.Data.Repository; -using Disco.Services.Users; +using Disco.Services; using Disco.Services.Authorization; +using Disco.Services.Users; +using System; +using System.IO; +using System.Linq; namespace Disco.BI.Extensions { public static class DeviceModelExtensions { - public static bool ImageImport(this DeviceModel deviceModel, Stream ImageStream) - { - try - { - using (Bitmap inputBitmap = new Bitmap(ImageStream)) - { - using (Image outputBitmap = inputBitmap.ResizeImage(256, 256)) - { - using (MemoryStream ms = new MemoryStream()) - { - outputBitmap.SavePng(ms); - ms.Position = 0; - - var deviceModelImagePath = deviceModel.ImageFilePath(); - - - using (var storeStream = new FileStream(deviceModelImagePath, FileMode.Create, FileAccess.Write, FileShare.None)) - { - ms.CopyTo(storeStream); - } - //deviceModel.Image = ms.ToArray(); - } - } - } - return true; - } - catch (Exception) - { - return false; - } - } - - public static FileStream Image(this DeviceModel deviceModel) - { - var deviceModelImagePath = deviceModel.ImageFilePath(); - - if (File.Exists(deviceModelImagePath)) - return new FileStream(deviceModelImagePath, FileMode.Open, FileAccess.Read, FileShare.Read); - else - return null; - } - - public static string ImageFilePath(this DeviceModel deviceModel) - { - var configCache = new Disco.Data.Configuration.SystemConfiguration(null); - - var deviceModelImagesDataStore = DataStore.CreateLocation(configCache, "DeviceModelImages"); - - return Path.Combine(deviceModelImagesDataStore, string.Format("{0}.png", deviceModel.Id)); - } - - public static string ImageHash(this DeviceModel deviceModel) - { - var deviceModelImagePath = deviceModel.ImageFilePath(); - - if (File.Exists(deviceModelImagePath)) - return File.GetLastWriteTimeUtc(deviceModelImagePath).ToBinary().ToString(); - else - return "-1"; - } - #region Actions public static bool CanDelete(this DeviceModel dm, DiscoDataContext Database) { diff --git a/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs b/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs index d9ae1454..b89844f8 100644 --- a/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs +++ b/Disco.BI/BI/Extensions/DeviceProfileExtensions.cs @@ -3,6 +3,7 @@ using Disco.Models.BI.Config; using Disco.Models.Repository; using Disco.Services.Authorization; using Disco.Services.Devices.ManagedGroups; +using Disco.Services.Expressions; using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Users; using System; @@ -16,7 +17,7 @@ namespace Disco.BI.Extensions public static void ComputerNameInvalidateCache(this DeviceProfile deviceProfile) { - Expressions.ExpressionCache.InvalidateKey(ComputerNameExpressionCacheModule, deviceProfile.Id.ToString()); + ExpressionCache.InvalidateKey(ComputerNameExpressionCacheModule, deviceProfile.Id.ToString()); } public static OrganisationAddress DefaultOrganisationAddressDetails(this DeviceProfile deviceProfile, DiscoDataContext Database) diff --git a/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs b/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs index ffc07aaa..d597363e 100644 --- a/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs +++ b/Disco.BI/BI/Extensions/DocumentTemplateExtensions.cs @@ -1,48 +1,27 @@ -using Disco.BI.DocumentTemplateBI; using Disco.BI.DocumentTemplateBI.ManagedGroups; -using Disco.BI.Expressions; using Disco.Data.Repository; -using Disco.Models.BI.DocumentTemplates; using Disco.Models.Repository; +using Disco.Models.Services.Documents; +using Disco.Services; +using Disco.Services.Documents; +using Disco.Services.Expressions; using Disco.Services.Interop.ActiveDirectory; using iTextSharp.text.pdf; using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.Drawing; -using System.IO; using System.Linq; namespace Disco.BI.Extensions { public static class DocumentTemplateExtensions { - private const string DocumentTemplateExpressionCacheTemplate = "DocumentTemplate_{0}"; - - public static string RepositoryFilename(this DocumentTemplate dt, DiscoDataContext Database) - { - return System.IO.Path.Combine(DataStore.CreateLocation(Database, "DocumentTemplates"), string.Format("{0}.pdf", dt.Id)); - } - public static string SavePdfTemplate(this DocumentTemplate dt, DiscoDataContext Database, Stream TemplateFile) - { - string filePath = dt.RepositoryFilename(Database); - using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) - { - TemplateFile.CopyTo(fs); - } - Expressions.ExpressionCache.InvalidModule(string.Format(DocumentTemplateExpressionCacheTemplate, dt.Id)); - return filePath; - } - - public static DisposableImageCollection PdfPageImages(this PdfReader pdfReader, int PageNumber) - { - return Interop.Pdf.PdfImporter.GetPageImages(pdfReader, PageNumber); - } + internal const string CacheTemplate = "DocumentTemplate_{0}"; public static ConcurrentDictionary PdfExpressionsFromCache(this DocumentTemplate dt, DiscoDataContext Database) { - string cacheModuleKey = string.Format(DocumentTemplateExpressionCacheTemplate, dt.Id); - var module = Expressions.ExpressionCache.GetModule(cacheModuleKey); + string cacheModuleKey = string.Format(CacheTemplate, dt.Id); + var module = ExpressionCache.GetModule(cacheModuleKey); if (module == null) { // Cache @@ -52,199 +31,46 @@ namespace Disco.BI.Extensions foreach (string pdfFieldKey in pdfReader.AcroFields.Fields.Keys) { var pdfFieldValue = pdfReader.AcroFields.GetField(pdfFieldKey); - Expressions.ExpressionCache.SetValue(cacheModuleKey, pdfFieldKey, Expressions.Expression.Tokenize(pdfFieldKey, pdfFieldValue, pdfFieldOrdinal)); + ExpressionCache.SetValue(cacheModuleKey, pdfFieldKey, Expression.Tokenize(pdfFieldKey, pdfFieldValue, pdfFieldOrdinal)); pdfFieldOrdinal++; } pdfReader.Close(); - module = Expressions.ExpressionCache.GetModule(cacheModuleKey, true); + module = ExpressionCache.GetModule(cacheModuleKey, true); } return module; } - public static List ExtractPdfExpressions(this DocumentTemplate dt, DiscoDataContext Database) + public static List ExtractPdfExpressions(this DocumentTemplate dt, DiscoDataContext Database) { return dt.PdfExpressionsFromCache(Database).Values.OrderBy(e => e.Ordinal).ToList(); } - public static System.IO.Stream GeneratePdfBulk(this DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, System.DateTime Timestamp, params string[] DataObjectsIds) + + public static System.IO.Stream GeneratePdfBulk(this DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, DateTime Timestamp, params string[] DataObjectsIds) { return Interop.Pdf.PdfGenerator.GenerateBulkFromTemplate(dt, Database, CreatorUser, Timestamp, DataObjectsIds); } - public static System.IO.Stream GeneratePdfBulk(this DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, System.DateTime Timestamp, params object[] DataObjects) + public static System.IO.Stream GeneratePdfBulk(this DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, DateTime Timestamp, params IAttachmentTarget[] DataObjects) { return Interop.Pdf.PdfGenerator.GenerateBulkFromTemplate(dt, Database, CreatorUser, Timestamp, DataObjects); } - public static System.IO.Stream GeneratePdf(this DocumentTemplate dt, DiscoDataContext Database, object Data, User CreatorUser, System.DateTime TimeStamp, DocumentState State, bool FlattenFields = false) + public static System.IO.Stream GeneratePdf(this DocumentTemplate dt, DiscoDataContext Database, IAttachmentTarget Target, User CreatorUser, DateTime TimeStamp, DocumentState State, bool FlattenFields = false) { bool generateExpression = !string.IsNullOrEmpty(dt.OnGenerateExpression); string generateExpressionResult = null; if (generateExpression) - generateExpressionResult = dt.EvaluateOnGenerateExpression(Data, Database, CreatorUser, TimeStamp, State); + generateExpressionResult = dt.EvaluateOnGenerateExpression(Target, Database, CreatorUser, TimeStamp, State); - var pdfStream = Interop.Pdf.PdfGenerator.GenerateFromTemplate(dt, Database, Data, CreatorUser, TimeStamp, State, FlattenFields); + var pdfStream = Interop.Pdf.PdfGenerator.GenerateFromTemplate(dt, Database, Target, CreatorUser, TimeStamp, State, FlattenFields); if (generateExpression) - DocumentsLog.LogDocumentGenerated(dt, Data, CreatorUser, generateExpressionResult); + DocumentsLog.LogDocumentGenerated(dt, Target, CreatorUser, generateExpressionResult); else - DocumentsLog.LogDocumentGenerated(dt, Data, CreatorUser); + DocumentsLog.LogDocumentGenerated(dt, Target, CreatorUser); return pdfStream; } - - public static Expression FilterExpressionFromCache(this DocumentTemplate dt) - { - return ExpressionCache.GetValue("DocumentTemplate_FilterExpression", dt.Id, () => { return Expression.TokenizeSingleDynamic(null, dt.FilterExpression, 0); }); - } - public static void FilterExpressionInvalidateCache(this DocumentTemplate dt) - { - ExpressionCache.InvalidateKey("DocumentTemplate_FilterExpression", dt.Id); - } - public static bool FilterExpressionMatches(this DocumentTemplate dt, object Data, DiscoDataContext Database, User User, System.DateTime TimeStamp, DocumentState State) - { - if (!string.IsNullOrEmpty(dt.FilterExpression)) - { - Expression compiledExpression = dt.FilterExpressionFromCache(); - System.Collections.IDictionary evaluatorVariables = Expression.StandardVariables(dt, Database, User, TimeStamp, State); - try - { - object er = compiledExpression.EvaluateFirst(Data, evaluatorVariables); - if (er is bool) - { - return (bool)er; - } - bool erBool; - if (bool.TryParse(er.ToString(), out erBool)) - { - return erBool; - } - } - catch - { - return false; - } - } - return true; - } - - public static Expression OnImportAttachmentExpressionFromCache(this DocumentTemplate dt) - { - return ExpressionCache.GetValue("DocumentTemplate_OnImportExpression", dt.Id, () => { return Expression.TokenizeSingleDynamic(null, dt.OnImportAttachmentExpression, 0); }); - } - public static void OnImportAttachmentExpressionInvalidateCache(this DocumentTemplate dt) - { - ExpressionCache.InvalidateKey("DocumentTemplate_OnImportExpression", dt.Id); - } - public static string EvaluateOnAttachmentImportExpression(this DocumentTemplate dt, object Data, DiscoDataContext Database, User User, System.DateTime TimeStamp) - { - if (!string.IsNullOrEmpty(dt.OnImportAttachmentExpression)) - { - Expression compiledExpression = dt.OnImportAttachmentExpressionFromCache(); - System.Collections.IDictionary evaluatorVariables = Expression.StandardVariables(dt, Database, User, TimeStamp, null); - try - { - object result = compiledExpression.EvaluateFirst(Data, evaluatorVariables); - if (result == null) - return null; - else - return result.ToString(); - } - catch - { - throw; - } - } - return null; - } - - public static Expression OnGenerateExpressionFromCache(this DocumentTemplate dt) - { - return ExpressionCache.GetValue("DocumentTemplate_OnGenerateExpression", dt.Id, () => { return Expression.TokenizeSingleDynamic(null, dt.OnGenerateExpression, 0); }); - } - public static void OnGenerateExpressionInvalidateCache(this DocumentTemplate dt) - { - ExpressionCache.InvalidateKey("DocumentTemplate_OnGenerateExpression", dt.Id); - } - public static string EvaluateOnGenerateExpression(this DocumentTemplate dt, object Data, DiscoDataContext Database, User User, System.DateTime TimeStamp, DocumentState State) - { - if (!string.IsNullOrEmpty(dt.OnGenerateExpression)) - { - Expression compiledExpression = dt.OnGenerateExpressionFromCache(); - System.Collections.IDictionary evaluatorVariables = Expression.StandardVariables(dt, Database, User, TimeStamp, State); - try - { - object result = compiledExpression.EvaluateFirst(Data, evaluatorVariables); - return result.ToString(); - } - catch - { - throw; - } - } - return null; - } - - public static string GetDataId(this DocumentTemplate dt, object Data) - { - if (Data is string) - { - return (string)Data; - } - else - { - switch (dt.Scope) - { - case Models.Repository.DocumentTemplate.DocumentTemplateScopes.Device: - if (!(Data is Device)) - throw new ArgumentException("This Document Template is configured for Devices only", "Data"); - Device d = (Device)Data; - return d.SerialNumber; - case Models.Repository.DocumentTemplate.DocumentTemplateScopes.Job: - if (!(Data is Job)) - throw new ArgumentException("This Document Template is configured for Jobs only", "Data"); - Job d2 = (Job)Data; - return d2.Id.ToString(); - case Models.Repository.DocumentTemplate.DocumentTemplateScopes.User: - if (!(Data is User)) - throw new ArgumentException("This Document Template is configured for Users only", "Data"); - User d3 = (User)Data; - return d3.UserId; - default: - throw new InvalidOperationException("Invalid Document Template Scope"); - } - } - } - public static string UniqueIdentifier(string DocumentTemplateId, string DataId, string CreatorId, System.DateTime Timestamp) - { - return string.Format("Disco|1|{0}|{1}|{2}|{3:s}", - DocumentTemplateId, - DataId, - CreatorId, - Timestamp - ); - } - public static string UniqueIdentifier(this DocumentTemplate dt, object Data, string CreatorId, System.DateTime Timestamp) - { - return string.Format("Disco|1|{0}|{1}|{2}|{3:s}", - dt.Id, - dt.GetDataId(System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(Data)), - CreatorId, - Timestamp - ); - } - public static string UniquePageIdentifier(this DocumentTemplate dt, object Data, string CreatorId, System.DateTime Timestamp, int Page) - { - return string.Format("Disco|1|{0}|{1}|{2}|{3:s}|{4}", - dt.Id, - dt.GetDataId(System.Runtime.CompilerServices.RuntimeHelpers.GetObjectValue(Data)), - CreatorId, - Timestamp, - Page - ); - } - public static List QRCodeLocations(this DocumentTemplate dt, DiscoDataContext Database) - { - return DocumentTemplateBI.DocumentTemplateQRCodeLocationCache.GetLocations(dt, Database); - } + public static void Delete(this DocumentTemplate dt, DiscoDataContext Database) { // Find & Rename all references diff --git a/Disco.BI/BI/Extensions/JobActionExtensions.cs b/Disco.BI/BI/Extensions/JobActionExtensions.cs index c5bf5eb4..cd2cde55 100644 --- a/Disco.BI/BI/Extensions/JobActionExtensions.cs +++ b/Disco.BI/BI/Extensions/JobActionExtensions.cs @@ -13,6 +13,7 @@ using Disco.Services.Plugins.Features.RepairProvider; using PublishJobResult = Disco.Models.Services.Interop.DiscoServices.PublishJobResult; using DiscoServicesJobs = Disco.Services.Interop.DiscoServices.Jobs; +using Disco.Services; namespace Disco.BI.Extensions { @@ -176,7 +177,7 @@ namespace Disco.BI.Extensions null, FaultDescription, SendAttachments, - Disco.BI.Extensions.AttachmentExtensions.RepositoryFilename); + AttachmentDataStoreExtensions.RepositoryFilename); if (!publishJobResult.Success) throw new Exception(string.Format("Disco ICT Online Services failed with the following message: ", publishJobResult.ErrorMessage)); @@ -398,7 +399,7 @@ namespace Disco.BI.Extensions null, RepairDescription, SendAttachments, - Disco.BI.Extensions.AttachmentExtensions.RepositoryFilename); + AttachmentDataStoreExtensions.RepositoryFilename); if (!publishJobResult.Success) throw new Exception(string.Format("Disco ICT Online Services failed with the following message: ", publishJobResult.ErrorMessage)); diff --git a/Disco.BI/BI/Extensions/JobExtensions.cs b/Disco.BI/BI/Extensions/JobExtensions.cs index b8997270..5b94193f 100644 --- a/Disco.BI/BI/Extensions/JobExtensions.cs +++ b/Disco.BI/BI/Extensions/JobExtensions.cs @@ -1,50 +1,18 @@ -using System; +using Disco.Data.Repository; +using Disco.Models.Repository; +using Disco.Models.Services.Documents; +using Disco.Services; +using Disco.Services.Authorization; +using Disco.Services.Plugins; +using System; using System.Collections.Generic; using System.Linq; using System.Text; -using Disco.Models.Repository; -using Disco.Data.Repository; -using System.IO; -using Disco.Models.BI.DocumentTemplates; -using Disco.Services.Plugins; -using Disco.Models.BI.Job; -using Disco.Services.Authorization; namespace Disco.BI.Extensions { public static class JobExtensions { - public static JobAttachment CreateAttachment(this Job Job, DiscoDataContext Database, User CreatorUser, string Filename, string MimeType, string Comments, Stream Content, DocumentTemplate DocumentTemplate = null, byte[] PdfThumbnail = null) - { - if (string.IsNullOrEmpty(MimeType) || MimeType.Equals("unknown/unknown", StringComparison.OrdinalIgnoreCase)) - MimeType = Interop.MimeTypes.ResolveMimeType(Filename); - - JobAttachment ja = new JobAttachment() - { - JobId = Job.Id, - TechUserId = CreatorUser.UserId, - Filename = Filename, - MimeType = MimeType, - Timestamp = DateTime.Now, - Comments = Comments - }; - - if (DocumentTemplate != null) - ja.DocumentTemplateId = DocumentTemplate.Id; - - Database.JobAttachments.Add(ja); - Database.SaveChanges(); - - ja.SaveAttachment(Database, Content); - Content.Position = 0; - if (PdfThumbnail == null) - ja.GenerateThumbnail(Database, Content); - else - ja.SaveThumbnailAttachment(Database, PdfThumbnail); - - return ja; - } - public static List AvailableDocumentTemplates(this Job j, DiscoDataContext Database, User User, DateTime TimeStamp) { var dts = Database.DocumentTemplates.Include("JobSubTypes") diff --git a/Disco.BI/BI/Extensions/UserExtensions.cs b/Disco.BI/BI/Extensions/UserExtensions.cs index a28707ca..713717e4 100644 --- a/Disco.BI/BI/Extensions/UserExtensions.cs +++ b/Disco.BI/BI/Extensions/UserExtensions.cs @@ -1,48 +1,15 @@ -using System; +using Disco.Data.Repository; +using Disco.Models.Repository; +using Disco.Models.Services.Documents; +using Disco.Services; +using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using Disco.Models.Repository; -using Disco.Data.Repository; -using System.IO; -using Disco.Models.BI.DocumentTemplates; -using Disco.Services.Interop.ActiveDirectory; namespace Disco.BI.Extensions { public static class UserExtensions { - public static UserAttachment CreateAttachment(this User User, DiscoDataContext Database, User CreatorUser, string Filename, string MimeType, string Comments, Stream Content, DocumentTemplate DocumentTemplate = null, byte[] PdfThumbnail = null) - { - if (string.IsNullOrEmpty(MimeType) || MimeType.Equals("unknown/unknown", StringComparison.OrdinalIgnoreCase)) - MimeType = Interop.MimeTypes.ResolveMimeType(Filename); - - UserAttachment ua = new UserAttachment() - { - UserId = User.UserId, - TechUserId = CreatorUser.UserId, - Filename = Filename, - MimeType = MimeType, - Timestamp = DateTime.Now, - Comments = Comments - }; - - if (DocumentTemplate != null) - ua.DocumentTemplateId = DocumentTemplate.Id; - - Database.UserAttachments.Add(ua); - Database.SaveChanges(); - - ua.SaveAttachment(Database, Content); - Content.Position = 0; - if (PdfThumbnail == null) - ua.GenerateThumbnail(Database, Content); - else - ua.SaveThumbnailAttachment(Database, PdfThumbnail); - - return ua; - } - public static List AvailableDocumentTemplates(this User u, DiscoDataContext Database, User User, DateTime TimeStamp) { var dts = Database.DocumentTemplates.Include("JobSubTypes") @@ -57,10 +24,6 @@ namespace Disco.BI.Extensions { return u.DeviceUserAssignments.Where(dua => !dua.UnassignedDate.HasValue).ToList(); } - public static ADUserAccount ActiveDirectoryAccount(this User User, params string[] AdditionalProperties) - { - return ActiveDirectory.RetrieveADUserAccount(User.UserId, AdditionalProperties); - } public static bool CanCreateJob(this User u) { diff --git a/Disco.BI/BI/Extensions/UtilityExtensions.cs b/Disco.BI/BI/Extensions/UtilityExtensions.cs index d6a07af7..d335c0e5 100644 --- a/Disco.BI/BI/Extensions/UtilityExtensions.cs +++ b/Disco.BI/BI/Extensions/UtilityExtensions.cs @@ -22,240 +22,6 @@ namespace Disco.BI.Extensions return sr.ReadToEnd(); } } - - #region Image Extensions - - public static Bitmap RotateImage(this Image Source, float Angle, Brush BackgroundColor = null, bool ResizeIfOver45Deg = true) - { - int destWidth = Source.Width; - int destHeight = Source.Height; - bool resizedDest = false; - - if (ResizeIfOver45Deg && ((Angle > 45 && Angle < 135) || (Angle < -45 && Angle > -135))) - { - destWidth = Source.Height; - destHeight = Source.Width; - resizedDest = true; - } - - Bitmap destination = new Bitmap(destWidth, destHeight); - destination.SetResolution(Source.HorizontalResolution, Source.VerticalResolution); - - using (Graphics destinationGraphics = Graphics.FromImage(destination)) - { - destinationGraphics.CompositingQuality = CompositingQuality.HighQuality; - destinationGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - destinationGraphics.SmoothingMode = SmoothingMode.HighQuality; - - if (BackgroundColor != null) - destinationGraphics.FillRectangle(BackgroundColor, destinationGraphics.VisibleClipBounds); - - float offsetWidth = destWidth / 2; - float offsetHeight = destHeight / 2; - - destinationGraphics.TranslateTransform(offsetWidth, offsetHeight); - destinationGraphics.RotateTransform(Angle); - - RectangleF destinationLocation; - - if (resizedDest) - destinationLocation = new RectangleF( - offsetHeight * -1, offsetWidth * -1, - destHeight, destWidth); - else - destinationLocation = new RectangleF( - offsetWidth * -1, offsetHeight * -1, - destWidth, destHeight); - - destinationGraphics.DrawImage(Source, destinationLocation, new RectangleF(0, 0, Source.Width, Source.Height), GraphicsUnit.Pixel); - } - return destination; - } - - public static Bitmap ResizeImage(this Image Source, int Width, int Height, Brush BackgroundColor = null) - { - Bitmap destination = new Bitmap(Width, Height); - destination.SetResolution(72, 72); - using (Graphics destinationGraphics = Graphics.FromImage(destination)) - { - destinationGraphics.CompositingQuality = CompositingQuality.HighQuality; - destinationGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic; - destinationGraphics.SmoothingMode = SmoothingMode.HighQuality; - - if (BackgroundColor != null) - destinationGraphics.FillRectangle(BackgroundColor, destinationGraphics.VisibleClipBounds); - - float ratio = Math.Min((float)(destination.Width) / (float)(Source.Width), (float)(destination.Height) / (float)(Source.Height)); - - destinationGraphics.DrawImageResized(Source, ratio); - } - - return destination; - } - public static void DrawImageResized(this Graphics graphics, Image SourceImage, float? Scale = null, float LocationX = -1, float LocationY = -1) - { - RectangleF clipBounds = graphics.VisibleClipBounds; - if (Scale == null) // Calculate Scale - Scale = Math.Min(clipBounds.Width / SourceImage.Width, clipBounds.Height / SourceImage.Height); - float newWidth = SourceImage.Width * Scale.Value; - float newHeight = SourceImage.Height * Scale.Value; - float newLeft = LocationX; - float newTop = LocationY; - - if (newLeft < 0 || newTop < 0) - { - if (newWidth < clipBounds.Width) - newLeft = (clipBounds.Width - newWidth) / 2; - else - newLeft = 0; - if (newHeight < clipBounds.Height) - newTop = (clipBounds.Height - newHeight) / 2; - else - newTop = 0; - } - newLeft += clipBounds.Left; - newTop += clipBounds.Top; - - graphics.DrawImage(SourceImage, new RectangleF(newLeft, newTop, newWidth, newHeight), new RectangleF(0, 0, SourceImage.Width, SourceImage.Height), GraphicsUnit.Pixel); - } - public static void EmbedIconOverlay(this Image Source, Image Icon) - { - int top = Math.Max(0, Source.Height - Icon.Height); - int left = Math.Max(0, Source.Width - Icon.Width); - - using (Graphics sourceGraphics = Graphics.FromImage(Source)) - { - sourceGraphics.DrawImage(Icon, left, top); - } - } - public static void SavePng(this Image Source, string Filename) - { - using (FileStream outStream = new FileStream(Filename, FileMode.Create, FileAccess.Write, FileShare.None)) - { - SavePng(Source, outStream); - outStream.Flush(); - outStream.Close(); - } - } - public static void SavePng(this Image Source, Stream OutStream) - { - Source.Save(OutStream, ImageFormat.Png); - } - public static Stream SavePng(this Image Source) - { - MemoryStream outStream = new MemoryStream(); - Source.SavePng(outStream); - outStream.Position = 0; - return outStream; - } - public static Stream SaveJpg(this Image Source, int Quality) - { - MemoryStream outStream = new MemoryStream(); - Source.SaveJpg(Quality, outStream); - outStream.Position = 0; - return outStream; - } - public static void SaveJpg(this Image Source, int Quality, string Filename) - { - using (FileStream outStream = new FileStream(Filename, FileMode.Create, FileAccess.Write, FileShare.None)) - { - SaveJpg(Source, Quality, outStream); - outStream.Flush(); - outStream.Close(); - } - } - public static void SaveJpg(this Image Source, int Quality, Stream OutStream) - { - ImageCodecInfo jpgCodec = ImageCodecInfo.GetImageEncoders().Where(c => c.MimeType.Equals("image/jpeg", StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); - if (jpgCodec != null) - { - if (Quality < 0 || Quality > 100) - throw new ArgumentOutOfRangeException("Quality", "Quality must be a positive integer <= 100"); - using (EncoderParameters ep = new EncoderParameters(1)) - { - ep.Param[0] = new EncoderParameter(Encoder.Quality, Quality); - Source.Save(OutStream, jpgCodec, ep); - } - } - else - { - // Fallback - Source.Save(OutStream, ImageFormat.Jpeg); - } - } - public static ImageMontage BuildImageMontage(this IEnumerable Images, int MaxHeight = -1, int MaxWidth = -1, bool EnforceDimensions = false) - { - if (EnforceDimensions && (MaxHeight < 0 || MaxWidth < 0)) - throw new ArgumentOutOfRangeException("EnforceDimensions", "Dimensions can only be enforced when a MaxHeight and MaxWidth is supplied"); - - Dictionary imageLocations = new Dictionary(); - double imageScale = 1.0; - int totalHeight = Images.Max(i => i.Height); - int totalWidth = Images.Sum(i => i.Width); - if (MaxHeight > 0 && totalHeight > MaxHeight) - { - imageScale = (double)MaxHeight / (double)totalHeight; - } - if (MaxWidth > 0 && totalWidth > MaxWidth) - { - imageScale = System.Math.Min(imageScale, (double)MaxWidth / (double)totalWidth); - } - int scaledHeight = EnforceDimensions ? MaxHeight : (int)System.Math.Round((double)totalHeight * imageScale); - int scaledWidth = EnforceDimensions ? MaxWidth : (int)System.Math.Round((double)totalWidth * imageScale); - System.Drawing.Bitmap imageResult = new System.Drawing.Bitmap(scaledWidth, scaledHeight); - imageResult.SetResolution(72f, 72f); - - using (Graphics g = Graphics.FromImage(imageResult)) - { - g.FillRectangle(Brushes.White, new Rectangle(Point.Empty, imageResult.Size)); - - int imageResultNextOffset = 0; - foreach (Image i in Images) - { - Rectangle imagePosition = new Rectangle(imageResultNextOffset, 0, (int)System.Math.Round((double)i.Width * imageScale), (int)System.Math.Round((double)i.Height * imageScale)); - System.Drawing.Rectangle imageSize = new System.Drawing.Rectangle(0, 0, i.Width, i.Height); - g.DrawImage(i, imagePosition, imageSize, System.Drawing.GraphicsUnit.Pixel); - imageLocations[i] = imageResultNextOffset; - imageResultNextOffset += imagePosition.Width; - } - } - - return new ImageMontage() { Montage = imageResult, MontageScale = imageScale, MontageSourceImageOffsets = imageLocations }; - } - public class ImageMontage : IDisposable - { - - public Image Montage { get; set; } - public double MontageScale { get; set; } - public Dictionary MontageSourceImageOffsets { get; set; } - - public void Dispose() - { - if (Montage != null) - { - Montage.Dispose(); - Montage = null; - } - if (MontageSourceImageOffsets != null) - { - MontageSourceImageOffsets.Clear(); - MontageSourceImageOffsets = null; - } - } - } - - public static Color InterpolateColours(this Color Start, Color End, double Progress) - { - if (Progress > 1 || Progress < 0) - throw new ArgumentOutOfRangeException("Progress", "Progress must be >= 0 && <= 1"); - - return Color.FromArgb( - (byte)(Start.A * (1 - Progress) + (End.A * Progress)), - (byte)(Start.R * (1 - Progress) + (End.R * Progress)), - (byte)(Start.G * (1 - Progress) + (End.G * Progress)), - (byte)(Start.B * (1 - Progress) + (End.B * Progress)) - ); - } - #endregion + } } diff --git a/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs b/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs index 399a1ad8..6373ee77 100644 --- a/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs +++ b/Disco.BI/BI/Interop/Pdf/PdfGenerator.cs @@ -1,9 +1,10 @@ -using Disco.BI.Expressions; -using Disco.BI.Extensions; +using Disco.BI.Extensions; using Disco.Data.Repository; -using Disco.Models.BI.DocumentTemplates; using Disco.Models.BI.Expressions; using Disco.Models.Repository; +using Disco.Models.Services.Documents; +using Disco.Services; +using Disco.Services.Expressions; using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Users; using iTextSharp.text.pdf; @@ -19,14 +20,14 @@ namespace Disco.BI.Interop.Pdf public static class PdfGenerator { - public static System.IO.Stream GenerateBulkFromTemplate(DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, System.DateTime Timestamp, params object[] DataObjects) + public static Stream GenerateBulkFromTemplate(DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, System.DateTime Timestamp, params IAttachmentTarget[] DataObjects) { if (DataObjects.Length > 0) { List generatedPdfs = new List(DataObjects.Length); - using (Models.BI.DocumentTemplates.DocumentState state = Models.BI.DocumentTemplates.DocumentState.DefaultState()) + using (var state = DocumentState.DefaultState()) { - foreach (object d in DataObjects) + foreach (var d in DataObjects) { generatedPdfs.Add(dt.GeneratePdf(Database, d, CreatorUser, Timestamp, state, true)); state.SequenceNumber++; @@ -48,9 +49,9 @@ namespace Disco.BI.Interop.Pdf return null; } - public static System.IO.Stream GenerateBulkFromTemplate(DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, System.DateTime Timestamp, params string[] DataObjectsIds) + public static Stream GenerateBulkFromTemplate(DocumentTemplate dt, DiscoDataContext Database, User CreatorUser, DateTime Timestamp, params string[] DataObjectsIds) { - object[] DataObjects; + IAttachmentTarget[] DataObjects; switch (dt.Scope) { @@ -62,7 +63,7 @@ namespace Disco.BI.Interop.Pdf DataObjects = Database.Jobs.Where(j => intDataObjectsIds.Contains(j.Id)).ToArray(); break; case DocumentTemplate.DocumentTemplateScopes.User: - DataObjects = new object[DataObjectsIds.Length]; + DataObjects = new IAttachmentTarget[DataObjectsIds.Length]; for (int idIndex = 0; idIndex < DataObjectsIds.Length; idIndex++) { string dataObjectId = DataObjectsIds[idIndex]; @@ -79,7 +80,7 @@ namespace Disco.BI.Interop.Pdf return GenerateBulkFromTemplate(dt, Database, CreatorUser, Timestamp, DataObjects); } - public static System.IO.Stream GenerateFromTemplate(DocumentTemplate dt, DiscoDataContext Database, object Data, User CreatorUser, System.DateTime TimeStamp, DocumentState State, bool FlattenFields = false) + public static Stream GenerateFromTemplate(DocumentTemplate dt, DiscoDataContext Database, IAttachmentTarget Data, User CreatorUser, DateTime TimeStamp, DocumentState State, bool FlattenFields = false) { // Validate Data switch (dt.Scope) @@ -124,7 +125,7 @@ namespace Disco.BI.Interop.Pdf if (pdfFieldKey.Equals("DiscoAttachmentId", StringComparison.OrdinalIgnoreCase)) { AcroFields.Item fields = pdfStamper.AcroFields.Fields[pdfFieldKey]; - string fieldValue = dt.UniqueIdentifier(Data, CreatorUser.UserId, TimeStamp); + string fieldValue = dt.CreateUniqueIdentifier(Database, Data, CreatorUser, TimeStamp, 0).ToJson(); if (FlattenFields) pdfStamper.AcroFields.SetField(pdfFieldKey, String.Empty); else @@ -134,7 +135,7 @@ namespace Disco.BI.Interop.Pdf for (int pdfFieldOrdinal = 0; pdfFieldOrdinal < fields.Size; pdfFieldOrdinal++) { AcroFields.FieldPosition pdfFieldPosition = pdfFieldPositions[pdfFieldOrdinal]; - string pdfBarcodeContent = dt.UniquePageIdentifier(Data, CreatorUser.UserId, TimeStamp, pdfFieldPosition.page); + string pdfBarcodeContent = dt.CreateUniqueIdentifier(Database, Data, CreatorUser, TimeStamp, pdfFieldPosition.page).ToQRCodeString(); BarcodeQRCode pdfBarcode = new BarcodeQRCode(pdfBarcodeContent, (int)pdfFieldPosition.position.Width, (int)pdfFieldPosition.position.Height, null); iTextSharp.text.Image pdfBarcodeImage = pdfBarcode.GetImage(); pdfBarcodeImage.SetAbsolutePosition(pdfFieldPosition.position.Left, pdfFieldPosition.position.Bottom); diff --git a/Disco.BI/BI/Interop/Pdf/PdfImporter.cs b/Disco.BI/BI/Interop/Pdf/PdfImporter.cs deleted file mode 100644 index 71b21611..00000000 --- a/Disco.BI/BI/Interop/Pdf/PdfImporter.cs +++ /dev/null @@ -1,977 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using iTextSharp.text.pdf; -using System.IO; -using System.Drawing; -using Disco.BI.DocumentTemplateBI.Importer; -using Disco.BI.DocumentTemplateBI; -using System.Drawing.Drawing2D; -using com.google.zxing; -using com.google.zxing.multi.qrcode; -using Disco.Data.Repository; -using System.Web.Caching; -using Disco.BI.Extensions; -using Disco.Models.Repository; -using System.Collections; -using com.google.zxing.common; -using BitMiracle.LibTiff.Classic; -using System.Drawing.Imaging; -using System.Runtime.InteropServices; - -namespace Disco.BI.Interop.Pdf -{ - public static class PdfImporter - { - public static RectangleF CalculateLocationRatio(this Result zxingResult, int ImageWidth, int ImageHeight) - { - var orderedPoints = zxingResult.ResultPoints.OrderBy(p => p.X * p.Y).ToArray(); - var topLeftPoint = orderedPoints.First(); - var bottomRightPoint = orderedPoints.Last(); - - var x = topLeftPoint.X; - var y = topLeftPoint.Y; - var width = bottomRightPoint.X - x; - var height = bottomRightPoint.Y - y; - - return new RectangleF( - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(x / ImageWidth) - 0.05)), - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(y / ImageHeight) - 0.05)), - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(width / ImageWidth) + 0.1)), - (float)System.Math.Min(1.0, System.Math.Max(0.0, (double)(height / ImageHeight) + 0.1)) - ); - } - - private class DetectImageResult : IDisposable - { - public Result Result { get; set; } - public Point ResultOffset { get; set; } - public double ResultScale { get; set; } - - public float CalculateRotation() - { - var p1 = this.Result.ResultPoints[0]; - var p2 = this.Result.ResultPoints[1]; - double rotOpposite = p1.X - p2.X; - double rotAdjacent = p1.Y - p2.Y; - float rotation = 0; - - if (rotOpposite != 0 || rotAdjacent != 0) - { - rotation = (float)(Math.Atan2(rotOpposite, rotAdjacent) * (180 / Math.PI)); // Degrees - } - - return rotation; - } - - public void Dispose() - { - // Do Nothing; yet... - } - } - - private class DetectStateHints - { - public List> PriorDetections { get; set; } - - public DetectStateHints() - { - this.PriorDetections = new List>(); - } - } - - private enum Rotation - { - None = 0, - Degrees90 = 1, - DegreesNeg90 = 2, - Degrees180 = 3 - } - - private class DetectPageResult : IDisposable - { - public int PageNumber { get; set; } - public DocumentUniqueIdentifier DetectedIdentifier { get; set; } - public Disco.BI.Extensions.UtilityExtensions.ImageMontage ThumbnailImage { get; set; } - public MemoryStream AttachmentThumbnailImage { get; set; } - public Disco.BI.Extensions.UtilityExtensions.ImageMontage UndetectedPageImage { get; set; } - - public void DrawThumbnailImageResult(DetectImageResult Result, Image DetectedImage) - { - if (Result.Result.ResultPoints.Length == 4) - { // Draw Square on Thumbnail - using (Graphics thumbnailGraphics = Graphics.FromImage(ThumbnailImage.Montage)) - { - var thumbnailOffset = ThumbnailImage.MontageSourceImageOffsets[DetectedImage]; - - var linePoints = Result.Result.ResultPoints.Select(p => new Point((int)(thumbnailOffset + ((Result.ResultOffset.X + p.X) * Result.ResultScale * ThumbnailImage.MontageScale)), (int)((p.Y + Result.ResultOffset.Y) * Result.ResultScale * ThumbnailImage.MontageScale))).ToArray(); - using (GraphicsPath graphicsPath = new GraphicsPath()) - { - for (int linePointIndex = 0; linePointIndex < (linePoints.Length - 1); linePointIndex++) - graphicsPath.AddLine(linePoints[linePointIndex], linePoints[linePointIndex + 1]); - graphicsPath.AddLine(linePoints[linePoints.Length - 1], linePoints[0]); - using (SolidBrush graphicsBrush = new SolidBrush(Color.FromArgb(128, 255, 0, 0))) - thumbnailGraphics.FillPath(graphicsBrush, graphicsPath); - using (Pen graphicsPen = new Pen(Color.FromArgb(200, 255, 0, 0), 2)) - thumbnailGraphics.DrawPath(graphicsPen, graphicsPath); - } - } - } - } - - public void Dispose() - { - if (ThumbnailImage != null) - { - ThumbnailImage.Dispose(); - ThumbnailImage = null; - } - if (AttachmentThumbnailImage != null) - { - AttachmentThumbnailImage.Dispose(); - AttachmentThumbnailImage = null; - } - if (UndetectedPageImage != null) - { - UndetectedPageImage.Dispose(); - UndetectedPageImage = null; - } - } - } - - private static Tuple DetectImageFromSegment(Bitmap pageImage, QRCodeMultiReader zxingReader, Hashtable zxingReaderHints, RectangleF LocationPercentage, Rotation Rotation) - { - System.Drawing.Rectangle region; - - switch (Rotation) - { - case Rotation.None: // Original Position - region = new Rectangle( - (int)(pageImage.Width * LocationPercentage.Left), - (int)(pageImage.Height * LocationPercentage.Top), - (int)(pageImage.Width * LocationPercentage.Width), - (int)(pageImage.Height * LocationPercentage.Height)); - break; - case Rotation.Degrees90: // Clockwise 90 degrees - region = new Rectangle( - (int)(pageImage.Width - (pageImage.Width * (LocationPercentage.Top + LocationPercentage.Height))), - (int)(pageImage.Height * LocationPercentage.Left), - (int)(pageImage.Width * LocationPercentage.Height), - (int)(pageImage.Height * LocationPercentage.Width)); - break; - case Rotation.DegreesNeg90: // Anti-clockwise 90 degrees - region = new Rectangle( - (int)(pageImage.Width * LocationPercentage.Top), - (int)(pageImage.Height - (pageImage.Height * (LocationPercentage.Left + LocationPercentage.Width))), - (int)(pageImage.Width * LocationPercentage.Height), - (int)(pageImage.Height * LocationPercentage.Width)); - break; - case Rotation.Degrees180: // 180 degrees - region = new Rectangle( - (int)(pageImage.Width - (pageImage.Width * (LocationPercentage.Left + LocationPercentage.Width))), - (int)(pageImage.Height - (pageImage.Height * (LocationPercentage.Top + LocationPercentage.Height))), - (int)(pageImage.Width * LocationPercentage.Width), - (int)(pageImage.Height * LocationPercentage.Height)); - break; - default: - throw new InvalidOperationException("Unknown Rotation"); - } - - LuminanceSource zxingSource; - using (Bitmap pageImageRegion = new Bitmap(region.Width, region.Height)) - { - pageImageRegion.SetResolution(pageImage.HorizontalResolution, pageImage.VerticalResolution); - - using (Graphics pageImageRegionGraphics = Graphics.FromImage(pageImageRegion)) - { - pageImageRegionGraphics.DrawImage(pageImage, 0, 0, region, GraphicsUnit.Pixel); - } - - zxingSource = new BitmapLuminanceSource(pageImageRegion); - } - var zxingHB = new HybridBinarizer(zxingSource); - var zxingBB = new BinaryBitmap(zxingHB); - try - { - var zxingResult = zxingReader.decode(zxingBB, zxingReaderHints); - if (zxingResult != null) - return new Tuple(zxingResult, region, Rotation); - } - catch (ReaderException) - { - // Ignore Location Errors - } - return null; - } - - private static DetectImageResult DetectImage(DiscoDataContext Database, Bitmap pageImageOriginal, string SessionId, IEnumerable detectDocumentTemplates, DetectStateHints StateHints) - { - Bitmap pageImage = pageImageOriginal; - double pageImageModifiedScale = 1; - - try - { - // Resize if Resolution > 80; Set to 72 Dpi - if (pageImage.HorizontalResolution > 80 || pageImage.VerticalResolution > 80) - { - pageImageModifiedScale = pageImage.HorizontalResolution / 72; - int newWidth = (int)((72 / pageImage.HorizontalResolution) * pageImage.Width); - int newHeight = (int)((72 / pageImage.VerticalResolution) * pageImage.Height); - - pageImage = pageImage.ResizeImage(newWidth, newHeight); - } - - Tuple result = default(Tuple); - QRCodeMultiReader zxingMfr = new QRCodeMultiReader(); - Hashtable zxingMfrHints = new Hashtable(); - zxingMfrHints.Add(DecodeHintType.TRY_HARDER, true); - - - // Look in previously found locations - if (StateHints.PriorDetections.Count > 0) - { - foreach (var previousLocation in StateHints.PriorDetections) - { - result = DetectImageFromSegment(pageImage, zxingMfr, zxingMfrHints, - previousLocation.Item1, previousLocation.Item2); - if (result != null) - break; - } - } - if (result == null) - { - // Try the whole image - var zxingSource = new BitmapLuminanceSource(pageImage); - var zxingHB = new HybridBinarizer(zxingSource); - var zxingBB = new BinaryBitmap(zxingHB); - try - { - var zxingResult = zxingMfr.decode(zxingBB, zxingMfrHints); - if (zxingResult != null) - { - result = new Tuple(zxingResult, new Rectangle(0, 0, pageImage.Width, pageImage.Height), Rotation.None); - - StateHints.PriorDetections.Insert(0, new Tuple( - result.Item1.CalculateLocationRatio(pageImage.Width, pageImage.Height) - , Rotation.None)); - - } - } - catch (ReaderException) - { - // Ignore Errors - } - } - if (result == null) - { - // Look in 'Known' locations - for (int rotationIndex = 0; rotationIndex < 4; rotationIndex++) - { - foreach (DocumentTemplate dt in detectDocumentTemplates) - { - var locationBag = dt.QRCodeLocations(Database); - foreach (var location in locationBag) - { - result = DetectImageFromSegment(pageImage, zxingMfr, zxingMfrHints, - location, (Rotation)rotationIndex); - - StateHints.PriorDetections.Insert(0, new Tuple(location, (Rotation)rotationIndex)); - } - if (result != null) - break; - } - if (result != null) - break; - } - } - - if (result != null) - - return new DetectImageResult() { Result = result.Item1, ResultOffset = result.Item2.Location, ResultScale = pageImageModifiedScale }; - else - return null; - } - catch (Exception ex) - { - throw ex; - } - finally - { - if (pageImageOriginal != pageImage) - pageImage.Dispose(); - } - } - - private static DetectPageResult DetectPage(DiscoDataContext Database, PdfReader pdfReader, int PageNumber, string SessionId, string DataStoreSessionCacheLocation, IEnumerable detectDocumentTemplates, DetectStateHints StateHints) - { - DetectPageResult result = new DetectPageResult() { PageNumber = PageNumber }; - - DocumentsLog.LogImportPageProgress(SessionId, PageNumber, 10, "Loading Page Images"); - - using (DisposableImageCollection pageImages = pdfReader.PdfPageImages(PageNumber)) - { - if (pageImages.Count > 0) - { - result.ThumbnailImage = pageImages.BuildImageMontage(256, 256); - var pageThumbnailFilename = Path.Combine(DataStoreSessionCacheLocation, string.Format("{0}-{1}", SessionId, PageNumber)); - - result.ThumbnailImage.Montage.SavePng(pageThumbnailFilename); - DocumentsLog.LogImportPageImageUpdate(SessionId, PageNumber); - - double pageProgressInterval = 90 / pageImages.Count; - - foreach (var pageImageOriginal in pageImages) - { - DocumentsLog.LogImportPageProgress(SessionId, PageNumber, (int)(10 + (pageProgressInterval * pageImages.IndexOf(pageImageOriginal))), String.Format("Processing Page Image {0} of {1}", pageImages.IndexOf(pageImageOriginal) + 1, pageImages.Count)); - - using (var zxingResult = DetectImage(Database, pageImageOriginal, SessionId, detectDocumentTemplates, StateHints)) - { - if (zxingResult != null) - { - if (DocumentUniqueIdentifier.IsDocumentUniqueIdentifier(zxingResult.Result.Text)) - { - float imageRotation = zxingResult.CalculateRotation(); - - result.DrawThumbnailImageResult(zxingResult, pageImageOriginal); - - if (imageRotation != 0) - { - var preImageRotation = result.ThumbnailImage.Montage; - result.ThumbnailImage.Montage = result.ThumbnailImage.Montage.RotateImage(imageRotation); - preImageRotation.Dispose(); - } - - result.ThumbnailImage.Montage.SavePng(pageThumbnailFilename); - DocumentsLog.LogImportPageImageUpdate(SessionId, PageNumber); - - result.AttachmentThumbnailImage = new MemoryStream(); - using (var attachmentThumbImage = pageImages.BuildImageMontage(48, 48, true)) - { - using (Image mimeTypeIcon = Disco.Properties.Resources.MimeType_pdf16) - attachmentThumbImage.Montage.EmbedIconOverlay(mimeTypeIcon); - - if (imageRotation != 0) - { - var preImageRotation = attachmentThumbImage.Montage; - attachmentThumbImage.Montage = attachmentThumbImage.Montage.RotateImage(imageRotation, Brushes.White); - preImageRotation.Dispose(); - } - - attachmentThumbImage.Montage.SaveJpg(95, result.AttachmentThumbnailImage); - } - - result.DetectedIdentifier = new DocumentUniqueIdentifier(zxingResult.Result.Text, PageNumber.ToString()); - - return result; - } - } - } - } - - // Page Unassigned - result.UndetectedPageImage = pageImages.BuildImageMontage(700, 700); - } - - return result; - } - } - - public static bool ProcessPdfAttachment(string Filename, DiscoDataContext Database, string SessionId, Cache HttpCache) - { - var dataStoreUnassignedLocation = DataStore.CreateLocation(Database, "DocumentDropBox_Unassigned"); - - DocumentsLog.LogImportProgress(SessionId, 0, "Reading File"); - - using (FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) - { - var pdfReader = new PdfReader(fs); - - var pdfPagesAssigned = new Dictionary>(); - - var dataStoreSessionPagesCacheLocation = DataStore.CreateLocation(Database, "Cache\\DocumentDropBox_SessionPages"); - var detectDocumentTemplates = Database.DocumentTemplates.ToArray(); - - double progressInterval = 70 / pdfReader.NumberOfPages; - - DetectStateHints detectStateHints = new DetectStateHints(); - - for (int PageNumber = 1; PageNumber <= pdfReader.NumberOfPages; PageNumber++) - { - DocumentsLog.LogImportProgress(SessionId, (int)(PageNumber * progressInterval), string.Format("Processing Page {0} of {1}", PageNumber, pdfReader.NumberOfPages)); - DocumentsLog.LogImportPageStarting(SessionId, PageNumber); - - using (var pageResult = DetectPage(Database, pdfReader, PageNumber, SessionId, dataStoreSessionPagesCacheLocation, detectDocumentTemplates, detectStateHints)) - { - if (pageResult.DetectedIdentifier != null) - { - var docId = pageResult.DetectedIdentifier; - pdfPagesAssigned.Add(PageNumber, new Tuple(docId, pageResult.AttachmentThumbnailImage.ToArray())); - - docId.LoadComponents(Database); - DocumentsLog.LogImportPageDetected(SessionId, PageNumber, docId.TemplateTypeId, docId.DocumentTemplate.Description, docId.DocumentTemplate.Scope, docId.DataId, docId.DataDescription); - } - else - { - // Undetected Page - Write Preview-Images while still in Memory - DocumentsLog.LogImportPageUndetected(SessionId, PageNumber); - - // Thumbnail: - string unassignedImageThumbnailFilename = Path.Combine(dataStoreUnassignedLocation, string.Format("{0}_{1}_thumbnail.png", SessionId, PageNumber)); - if (pageResult.ThumbnailImage != null) - pageResult.ThumbnailImage.Montage.SavePng(unassignedImageThumbnailFilename); - else - Disco.Properties.Resources.MimeType_pdf48.SavePng(unassignedImageThumbnailFilename); - // Large Preview - string unassignedImageFilename = Path.Combine(dataStoreUnassignedLocation, string.Format("{0}_{1}.jpg", SessionId, PageNumber)); - if (pageResult.UndetectedPageImage != null) - pageResult.UndetectedPageImage.Montage.SaveJpg(90, unassignedImageFilename); - else - Disco.Properties.Resources.MimeType_pdf48.SaveJpg(90, unassignedImageFilename); - } - } - - } - - // Write out Assigned Documents - var assignedDocuments = pdfPagesAssigned.GroupBy(u => u.Value.Item1.DocumentUniqueId).ToList(); - if (assignedDocuments.Count > 0) - { - progressInterval = 20 / assignedDocuments.Count; - - foreach (var documentPortion in assignedDocuments) - { - DocumentsLog.LogImportProgress(SessionId, (int)(70 + (assignedDocuments.IndexOf(documentPortion) * progressInterval)), string.Format("Importing Documents {0} of {1}", assignedDocuments.IndexOf(documentPortion) + 1, assignedDocuments.Count)); - - var documentPortionInfo = documentPortion.First().Value; - var documentPortionIdentifier = documentPortionInfo.Item1; - var documentPortionThumbnail = documentPortionInfo.Item2; - - if (!documentPortionIdentifier.LoadComponents(Database)) - { - // Unknown Document Unique Id - foreach (var dp in documentPortion) - { - var tag = int.Parse(dp.Value.Item1.Tag); - if (pdfPagesAssigned.ContainsKey(tag)) - pdfPagesAssigned.Remove(tag); - } - } - else - { - using (MemoryStream msBuilder = new MemoryStream()) - { - var pdfDoc = new iTextSharp.text.Document(); - var pdfCopy = new PdfCopy(pdfDoc, msBuilder); - - pdfDoc.Open(); - pdfCopy.CloseStream = false; - - foreach (var dp in documentPortion.OrderBy(dg => dg.Value.Item1.Page)) - { - var pageSize = pdfReader.GetPageSizeWithRotation(dp.Key); - var page = pdfCopy.GetImportedPage(pdfReader, dp.Key); - - pdfDoc.SetPageSize(pageSize); - pdfDoc.NewPage(); - - pdfCopy.AddPage(page); - } - - pdfDoc.Close(); - pdfCopy.Close(); - - msBuilder.Position = 0; - - var attachmentSuccess = documentPortionIdentifier.ImportPdfAttachment(Database, msBuilder, documentPortionThumbnail); - - if (!attachmentSuccess) - { // Unable to add Attachment - foreach (var dp in documentPortion) - { - var tag = int.Parse(dp.Value.Item1.Tag); - if (pdfPagesAssigned.ContainsKey(tag)) - pdfPagesAssigned.Remove(tag); - } - } - } - } - - - } - } - - // Write out Unassigned Pages - List pdfPagesUnassigned = new List(); - for (int PageNumber = 1; PageNumber <= pdfReader.NumberOfPages; PageNumber++) - if (!pdfPagesAssigned.ContainsKey(PageNumber)) - pdfPagesUnassigned.Add(PageNumber); - if (pdfPagesUnassigned.Count > 0) - { - progressInterval = 10 / pdfPagesUnassigned.Count; - //dataStoreUnassignedLocation - foreach (var PageNumber in pdfPagesUnassigned) - { - DocumentsLog.LogImportProgress(SessionId, (int)(90 + (pdfPagesUnassigned.IndexOf(PageNumber) * progressInterval)), string.Format("Processing Undetected Documents {0} of {1}", pdfPagesUnassigned.IndexOf(PageNumber) + 1, pdfPagesUnassigned.Count)); - - using (MemoryStream msBuilder = new MemoryStream()) - { - var pdfDoc = new iTextSharp.text.Document(); - var pdfCopy = new PdfCopy(pdfDoc, msBuilder); - - pdfDoc.Open(); - pdfCopy.CloseStream = false; - - var pageSize = pdfReader.GetPageSizeWithRotation(PageNumber); - var page = pdfCopy.GetImportedPage(pdfReader, PageNumber); - pdfDoc.SetPageSize(pageSize); - pdfDoc.NewPage(); - - pdfCopy.AddPage(page); - pdfDoc.Close(); - pdfCopy.Close(); - - File.WriteAllBytes(Path.Combine(dataStoreUnassignedLocation, string.Format("{0}_{1}.pdf", SessionId, PageNumber)), msBuilder.ToArray()); - - DocumentsLog.LogImportPageUndetectedStored(SessionId, PageNumber); - } - } - } - - } - - DocumentsLog.LogImportProgress(SessionId, 100, "Finished Importing Document"); - - return true; - } - public static bool ProcessPdfAttachment(string Filename, DiscoDataContext Database, string DocumentTemplateId, string DataId, string UserId, DateTime Timestamp) - { - using (FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.ReadWrite, FileShare.None)) - { - DocumentUniqueIdentifier identifier = new DocumentUniqueIdentifier(DocumentTemplateId, DataId, UserId, Timestamp); - identifier.LoadComponents(Database); - return identifier.ImportPdfAttachment(Database, fs, null); - } - } - - public static DisposableImageCollection GetPageImages(PdfReader pdfReader, int PageNumber) - { - var pageImages = new DisposableImageCollection(); - - var pdfPage = pdfReader.GetPageN(PageNumber); - PdfDictionary pdfPageResouces = (PdfDictionary)((PdfDictionary)pdfPage.GetDirectObject(PdfName.RESOURCES)).GetDirectObject(PdfName.XOBJECT); - - foreach (var pdfResKey in pdfPageResouces.Keys) - { - var pdfRes = pdfPageResouces.GetDirectObject(pdfResKey); - if (pdfRes.IsStream()) - { - var pdfResStream = (PdfStream)pdfRes; - var pdfResSubType = pdfResStream.Get(PdfName.SUBTYPE); - if (pdfResSubType != null && pdfResSubType == PdfName.IMAGE) - { - if (pdfResStream.Get(PdfName.FILTER) == PdfName.CCITTFAXDECODE) - { // TIFF - // Try Using GDI+ for TIFF... - var width = ((PdfNumber)(pdfResStream.Get(PdfName.WIDTH))).IntValue; - var height = ((PdfNumber)(pdfResStream.Get(PdfName.HEIGHT))).IntValue; - var bpc = ((PdfNumber)(pdfResStream.Get(PdfName.BITSPERCOMPONENT))).IntValue; - - var compressionMethod = Compression.CCITTFAX3; - - var decodeParams = pdfResStream.GetAsDict(PdfName.DECODEPARMS); - if (decodeParams != null && decodeParams.Contains(PdfName.K) && decodeParams.GetAsNumber(PdfName.K).IntValue < 0) - compressionMethod = Compression.CCITTFAX4; - - using (MemoryStream tiffStream = PdfToTiffStream(PdfReader.GetStreamBytesRaw((PRStream)pdfResStream), width, height, bpc, compressionMethod)) - { - pageImages.Add((Bitmap)Bitmap.FromStream(tiffStream)); - } - continue; - } - if (pdfResStream.Get(PdfName.FILTER) == PdfName.DCTDECODE) - { // JPG - using (MemoryStream jpgStream = new MemoryStream(PdfReader.GetStreamBytesRaw((PRStream)pdfResStream))) - { - pageImages.Add((Bitmap)Bitmap.FromStream(jpgStream, true, true)); - } - continue; - } - } - } - } - - return pageImages; - } - - private static MemoryStream PdfToTiffStream(byte[] PdfStream, int Width, int Height, int BitsPerComponent, Compression CompressionMethod) - { - var ms = new MemoryStream(); - - Tiff tif = Tiff.ClientOpen("in-memory", "w", ms, new TiffStream()); - tif.SetField(TiffTag.IMAGEWIDTH, Width); - tif.SetField(TiffTag.IMAGELENGTH, Height); - tif.SetField(TiffTag.COMPRESSION, CompressionMethod); - tif.SetField(TiffTag.BITSPERSAMPLE, BitsPerComponent); - tif.SetField(TiffTag.SAMPLESPERPIXEL, 1); - tif.WriteRawStrip(0, PdfStream, PdfStream.Length); - tif.Flush(); - - return ms; - } - - } - - /* -* Copyright 2012 ZXing.Net authors -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - /// - /// The base class for luminance sources which supports - /// cropping and rotating based upon the luminance values. - /// - public abstract class BaseLuminanceSource : LuminanceSource - { - /// - /// - /// - protected sbyte[] luminances; - - /// - /// Initializes a new instance of the class. - /// - /// The width. - /// The height. - protected BaseLuminanceSource(int width, int height) - : base(width, height) - { - luminances = new sbyte[width * height]; - } - - /// - /// Initializes a new instance of the class. - /// - /// The luminance array. - /// The width. - /// The height. - protected BaseLuminanceSource(sbyte[] luminanceArray, int width, int height) - : base(width, height) - { - luminances = luminanceArray; - //Buffer.BlockCopy(luminanceArray, 0, luminances, 0, width * height); - } - - /// - /// Fetches one row of luminance data from the underlying platform's bitmap. Values range from - /// 0 (black) to 255 (white). It is preferable for implementations of this method - /// to only fetch this row rather than the whole image, since no 2D Readers may be installed and - /// getMatrix() may never be called. - /// - /// The row to fetch, 0 <= y < Height. - /// An optional preallocated array. If null or too small, it will be ignored. - /// Always use the returned object, and ignore the .length of the array. - /// - /// An array containing the luminance data. - /// - override public sbyte[] getRow(int y, sbyte[] row) - { - int width = Width; - if (row == null || row.Length < width) - { - row = new sbyte[width]; - } - //for (int i = 0; i < width; i++) - // row[i] = luminances[y * width + i]; - Buffer.BlockCopy(luminances, y * width, row, 0, width); - return row; - } - - public override sbyte[] Matrix - { - get { return luminances; } - } - - /// - /// Returns a new object with rotated image data by 90 degrees counterclockwise. - /// Only callable if {@link #isRotateSupported()} is true. - /// - /// - /// A rotated version of this object. - /// - public override LuminanceSource rotateCounterClockwise() - { - var rotatedLuminances = new sbyte[Width * Height]; - var newWidth = Height; - var newHeight = Width; - var localLuminances = Matrix; - for (var yold = 0; yold < Height; yold++) - { - for (var xold = 0; xold < Width; xold++) - { - var ynew = xold; - var xnew = newWidth - yold - 1; - rotatedLuminances[ynew * newWidth + xnew] = localLuminances[yold * Width + xold]; - } - } - return CreateLuminanceSource(rotatedLuminances, newWidth, newHeight); - } - - /// - /// - /// Whether this subclass supports counter-clockwise rotation. - public override bool RotateSupported - { - get - { - return true; - } - } - - /// - /// Returns a new object with cropped image data. Implementations may keep a reference to the - /// original data rather than a copy. Only callable if CropSupported is true. - /// - /// The left coordinate, 0 <= left < Width. - /// The top coordinate, 0 <= top <= Height. - /// The width of the rectangle to crop. - /// The height of the rectangle to crop. - /// - /// A cropped version of this object. - /// - public override LuminanceSource crop(int left, int top, int width, int height) - { - if (left + width > Width || top + height > Height) - { - throw new ArgumentException("Crop rectangle does not fit within image data."); - } - var croppedLuminances = new sbyte[width * height]; - for (int yold = top, ynew = 0; yold < height; yold++, ynew++) - { - for (int xold = left, xnew = 0; xold < width; xold++, xnew++) - { - croppedLuminances[ynew * width + xnew] = luminances[yold * Width + xold]; - } - } - return CreateLuminanceSource(croppedLuminances, width, height); - } - - /// - /// - /// Whether this subclass supports cropping. - public override bool CropSupported - { - get - { - return true; - } - } - - /// - /// Should create a new luminance source with the right class type. - /// The method is used in methods crop and rotate. - /// - /// The new luminances. - /// The width. - /// The height. - /// - protected abstract LuminanceSource CreateLuminanceSource(sbyte[] newLuminances, int width, int height); - } - public partial class BitmapLuminanceSource : BaseLuminanceSource - { - /// - /// Initializes a new instance of the class. - /// - /// The width. - /// The height. - protected BitmapLuminanceSource(int width, int height) - : base(width, height) - { - } - - /// - /// Initializes a new instance of the class - /// with the image of a Bitmap instance - /// - /// The bitmap. - public BitmapLuminanceSource(Bitmap bitmap) - : base(bitmap.Width, bitmap.Height) - { - var height = bitmap.Height; - var width = bitmap.Width; - - // In order to measure pure decoding speed, we convert the entire image to a greyscale array - luminances = new sbyte[width * height]; - - // The underlying raster of image consists of bytes with the luminance values -#if WindowsCE - var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); -#else - var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat); -#endif - try - { - var stride = Math.Abs(data.Stride); - var pixelWidth = stride / width; - - if (pixelWidth > 4) - { - // old slow way for unsupported bit depth - Color c; - for (int y = 0; y < height; y++) - { - int offset = y * width; - for (int x = 0; x < width; x++) - { - c = bitmap.GetPixel(x, y); - luminances[offset + x] = (sbyte)(0.3 * c.R + 0.59 * c.G + 0.11 * c.B + 0.01); - } - } - } - else - { - var strideStep = data.Stride; - var buffer = new byte[stride]; - var ptrInBitmap = data.Scan0; - -#if !WindowsCE - // prepare palette for 1 and 8 bit indexed bitmaps - var luminancePalette = new sbyte[bitmap.Palette.Entries.Length]; - for (var index = 0; index < bitmap.Palette.Entries.Length; index++) - { - var color = bitmap.Palette.Entries[index]; - luminancePalette[index] = (sbyte)(0.3 * color.R + - 0.59 * color.G + - 0.11 * color.B + 0.01); - } - if (bitmap.PixelFormat == PixelFormat.Format32bppArgb || - bitmap.PixelFormat == PixelFormat.Format32bppPArgb) - { - pixelWidth = 40; - } -#endif - - for (int y = 0; y < height; y++) - { - // copy a scanline not the whole bitmap because of memory usage - Marshal.Copy(ptrInBitmap, buffer, 0, stride); -#if NET40 - ptrInBitmap = IntPtr.Add(ptrInBitmap, strideStep); -#else - ptrInBitmap = new IntPtr(ptrInBitmap.ToInt64() + strideStep); -#endif - var offset = y * width; - switch (pixelWidth) - { -#if !WindowsCE - case 0: - for (int x = 0; x * 8 < width; x++) - { - for (int subX = 0; subX < 8 && 8 * x + subX < width; subX++) - { - var index = (buffer[x] >> (7 - subX)) & 1; - luminances[offset + 8 * x + subX] = luminancePalette[index]; - } - } - break; - case 1: - for (int x = 0; x < width; x++) - { - luminances[offset + x] = luminancePalette[buffer[x]]; - } - break; -#endif - case 2: - // should be RGB565 or RGB555, assume RGB565 - { - for (int index = 0, x = 0; index < 2 * width; index += 2, x++) - { - var byte1 = buffer[index]; - var byte2 = buffer[index + 1]; - - var b5 = byte1 & 0x1F; - var g5 = (((byte1 & 0xE0) >> 5) | ((byte2 & 0x03) << 3)) & 0x1F; - var r5 = (byte2 >> 2) & 0x1F; - var r8 = (r5 * 527 + 23) >> 6; - var g8 = (g5 * 527 + 23) >> 6; - var b8 = (b5 * 527 + 23) >> 6; - - luminances[offset + x] = (sbyte)(0.3 * r8 + 0.59 * g8 + 0.11 * b8 + 0.01); - } - } - break; - case 3: - for (int x = 0; x < width; x++) - { - var luminance = (sbyte)(0.3 * buffer[x * 3] + - 0.59 * buffer[x * 3 + 1] + - 0.11 * buffer[x * 3 + 2] + 0.01); - luminances[offset + x] = luminance; - } - break; - case 4: - // 4 bytes without alpha channel value - for (int x = 0; x < width; x++) - { - var luminance = (sbyte)(0.30 * buffer[x * 4] + - 0.59 * buffer[x * 4 + 1] + - 0.11 * buffer[x * 4 + 2] + 0.01); - - luminances[offset + x] = luminance; - } - break; - case 40: - // with alpha channel; some barcodes are completely black if you - // only look at the r, g and b channel but the alpha channel controls - // the view - for (int x = 0; x < width; x++) - { - var luminance = (sbyte)(0.30 * buffer[x * 4] + - 0.59 * buffer[x * 4 + 1] + - 0.11 * buffer[x * 4 + 2] + 0.01); - - // calculating the resulting luminance based upon a white background - // var alpha = buffer[x * pixelWidth + 3] / 255.0; - // luminance = (byte)(luminance * alpha + 255 * (1 - alpha)); - var alpha = buffer[x * 4 + 3]; - luminance = (sbyte)(((luminance * alpha) >> 8) + (255 * (255 - alpha) >> 8)); - luminances[offset + x] = luminance; - } - break; - default: - throw new NotSupportedException(); - } - } - } - } - finally - { - bitmap.UnlockBits(data); - } - } - - /// - /// Should create a new luminance source with the right class type. - /// The method is used in methods crop and rotate. - /// - /// The new luminances. - /// The width. - /// The height. - /// - protected override LuminanceSource CreateLuminanceSource(sbyte[] newLuminances, int width, int height) - { - return new BitmapLuminanceSource(width, height) { luminances = newLuminances }; - } - } - -} diff --git a/Disco.BI/Disco.BI.csproj b/Disco.BI/Disco.BI.csproj index 44cdf0d9..fb809c58 100644 --- a/Disco.BI/Disco.BI.csproj +++ b/Disco.BI/Disco.BI.csproj @@ -64,9 +64,6 @@ ..\..\..\Resources\Libraries\SshNet\Renci.SshNet.dll - - ..\Resources\Libraries\Spring.NET\Spring.Core.dll - @@ -106,33 +103,16 @@ - - ..\Resources\Libraries\ZXing\zxing.dll - - - - - - - - - - - - - - - @@ -154,21 +134,7 @@ - - - - - - - - - - - - - - diff --git a/Disco.Data/Configuration/SystemConfiguration.cs b/Disco.Data/Configuration/SystemConfiguration.cs index 3311fd34..9252c230 100644 --- a/Disco.Data/Configuration/SystemConfiguration.cs +++ b/Disco.Data/Configuration/SystemConfiguration.cs @@ -276,6 +276,22 @@ namespace Disco.Data.Configuration return this.Get(null); } } + public short DeploymentChecksum + { + get + { + var deploymentIdBytes = Guid.Parse(DeploymentId).ToByteArray(); + return + (short)(BitConverter.ToInt16(deploymentIdBytes, 0) ^ + BitConverter.ToInt16(deploymentIdBytes, 2) ^ + BitConverter.ToInt16(deploymentIdBytes, 2) ^ + BitConverter.ToInt16(deploymentIdBytes, 2) ^ + BitConverter.ToInt16(deploymentIdBytes, 2) ^ + BitConverter.ToInt16(deploymentIdBytes, 2) ^ + BitConverter.ToInt16(deploymentIdBytes, 2) ^ + BitConverter.ToInt16(deploymentIdBytes, 2)); + } + } public UpdateResponseV2 UpdateLastCheckResponse { get diff --git a/Disco.Models/Disco.Models.csproj b/Disco.Models/Disco.Models.csproj index 614db263..f1c31c49 100644 --- a/Disco.Models/Disco.Models.csproj +++ b/Disco.Models/Disco.Models.csproj @@ -51,7 +51,10 @@ + + + @@ -60,7 +63,7 @@ - + @@ -181,7 +184,9 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\resources\mimetype-doc48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\mimetype-img16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\mimetype-pdf16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\mimetype-pdf48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\resources\mimetype-unknown48.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Disco.Services/Resources/MimeType-doc48.png b/Disco.Services/Resources/MimeType-doc48.png new file mode 100644 index 00000000..cf7caee9 Binary files /dev/null and b/Disco.Services/Resources/MimeType-doc48.png differ diff --git a/Disco.Services/Resources/MimeType-img16.png b/Disco.Services/Resources/MimeType-img16.png new file mode 100644 index 00000000..60d7f35b Binary files /dev/null and b/Disco.Services/Resources/MimeType-img16.png differ diff --git a/Disco.Services/Resources/MimeType-pdf16.png b/Disco.Services/Resources/MimeType-pdf16.png new file mode 100644 index 00000000..9d115de1 Binary files /dev/null and b/Disco.Services/Resources/MimeType-pdf16.png differ diff --git a/Disco.Services/Resources/MimeType-pdf48.png b/Disco.Services/Resources/MimeType-pdf48.png new file mode 100644 index 00000000..34f1b26c Binary files /dev/null and b/Disco.Services/Resources/MimeType-pdf48.png differ diff --git a/Disco.Services/Resources/MimeType-unknown48.png b/Disco.Services/Resources/MimeType-unknown48.png new file mode 100644 index 00000000..ccbf7b3a Binary files /dev/null and b/Disco.Services/Resources/MimeType-unknown48.png differ diff --git a/Disco.Services/packages.config b/Disco.Services/packages.config index 6badf0aa..e0d81d99 100644 --- a/Disco.Services/packages.config +++ b/Disco.Services/packages.config @@ -16,6 +16,8 @@ + + @@ -24,4 +26,5 @@ + \ No newline at end of file diff --git a/Disco.Services/x86/pdfium.dll b/Disco.Services/x86/pdfium.dll new file mode 100644 index 00000000..e006d59d Binary files /dev/null and b/Disco.Services/x86/pdfium.dll differ diff --git a/Disco.Web/App_Start/AppConfig.cs b/Disco.Web/App_Start/AppConfig.cs index 990a4e10..0701d939 100644 --- a/Disco.Web/App_Start/AppConfig.cs +++ b/Disco.Web/App_Start/AppConfig.cs @@ -1,10 +1,10 @@ using Disco.Data.Repository; +using Disco.Services; using Disco.Services.Interop.DiscoServices; using Exceptionless; using Exceptionless.Configuration; using System; using System.Linq; -using System.Web; [assembly: Exceptionless("https://errors.discoict.com.au", "c81e644582374f68aaf1fb546e3db0cd")] @@ -67,7 +67,7 @@ namespace Disco.Web InitalizeCoreEnvironment(Database); // Initialize Expressions - BI.Expressions.Expression.InitializeExpressions(); + Disco.Services.Expressions.Expression.InitializeExpressions(); // Initialize Job Queues Disco.Services.Jobs.JobQueues.JobQueueService.Initialize(Database); @@ -93,10 +93,11 @@ namespace Disco.Web } // Setup Attachment Monitor - DiscoApplication.DocumentDropBoxMonitor = new BI.DocumentTemplateBI.Importer.DocumentDropBoxMonitor(Database, DiscoApplication.SchedulerFactory, HttpContext.Current.Cache); + var dropboxLocation = DataStore.CreateLocation(Database, "DocumentDropBox"); + DiscoApplication.DocumentDropBoxMonitor = new Services.Documents.AttachmentImport.ImportDirectoryMonitor(dropboxLocation, DiscoApplication.SchedulerFactory.GetScheduler(), 5000); - DiscoApplication.DocumentDropBoxMonitor.StartWatching(); - DiscoApplication.DocumentDropBoxMonitor.ScheduleCurrentFiles(10); + DiscoApplication.DocumentDropBoxMonitor.Start(); + DiscoApplication.DocumentDropBoxMonitor.ScheduleCurrentFiles(10000); // 10 Second Delay } public static void InitializeUpdateEnvironment(DiscoDataContext Database, Version PreviousVersion) diff --git a/Disco.Web/Areas/API/Controllers/DeviceBatchController.cs b/Disco.Web/Areas/API/Controllers/DeviceBatchController.cs index cc051b60..4868321c 100644 --- a/Disco.Web/Areas/API/Controllers/DeviceBatchController.cs +++ b/Disco.Web/Areas/API/Controllers/DeviceBatchController.cs @@ -1,5 +1,6 @@ using Disco.BI.Extensions; using Disco.Models.Repository; +using Disco.Services; using Disco.Services.Authorization; using Disco.Services.Devices.ManagedGroups; using Disco.Services.Interop.ActiveDirectory; diff --git a/Disco.Web/Areas/API/Controllers/DeviceController.cs b/Disco.Web/Areas/API/Controllers/DeviceController.cs index 47e2da77..34d4992a 100644 --- a/Disco.Web/Areas/API/Controllers/DeviceController.cs +++ b/Disco.Web/Areas/API/Controllers/DeviceController.cs @@ -1,9 +1,12 @@ using Disco.BI.Extensions; using Disco.Models.Repository; using Disco.Models.Services.Devices.Importing; +using Disco.Models.Services.Documents; +using Disco.Services; using Disco.Services.Authorization; using Disco.Services.Devices.Exporting; using Disco.Services.Devices.Importing; +using Disco.Services.Interop; using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Users; using Disco.Services.Web; @@ -388,7 +391,7 @@ namespace Disco.Web.Areas.API.Controllers { var timeStamp = DateTime.Now; Stream pdf; - using (var generationState = Disco.Models.BI.DocumentTemplates.DocumentState.DefaultState()) + using (var generationState = DocumentState.DefaultState()) { pdf = documentTemplate.GeneratePdf(Database, device, UserService.CurrentUser, timeStamp, generationState); } @@ -485,7 +488,7 @@ namespace Disco.Web.Areas.API.Controllers { var contentType = file.ContentType; if (string.IsNullOrEmpty(contentType) || contentType.Equals("unknown/unknown", StringComparison.OrdinalIgnoreCase)) - contentType = BI.Interop.MimeTypes.ResolveMimeType(file.FileName); + contentType = MimeTypes.ResolveMimeType(file.FileName); var da = new DeviceAttachment() { diff --git a/Disco.Web/Areas/API/Controllers/DeviceModelController.cs b/Disco.Web/Areas/API/Controllers/DeviceModelController.cs index 87b67da3..3dc6bf92 100644 --- a/Disco.Web/Areas/API/Controllers/DeviceModelController.cs +++ b/Disco.Web/Areas/API/Controllers/DeviceModelController.cs @@ -1,5 +1,6 @@ using Disco.BI.Extensions; using Disco.Models.Repository; +using Disco.Services; using Disco.Services.Authorization; using Disco.Services.Plugins; using Disco.Services.Plugins.Features.RepairProvider; diff --git a/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs b/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs index 7b24258b..1f6475a8 100644 --- a/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs +++ b/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs @@ -2,7 +2,9 @@ using Disco.BI.DocumentTemplateBI.ManagedGroups; using Disco.BI.Extensions; using Disco.Models.Repository; +using Disco.Services; using Disco.Services.Authorization; +using Disco.Services.Documents; using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Tasks; using Disco.Services.Users; @@ -558,7 +560,9 @@ namespace Disco.Web.Areas.API.Controllers { var undetectedLocation = DataStore.CreateLocation(Database, "DocumentDropBox_Unassigned"); var filename = System.IO.Path.Combine(undetectedLocation, string.Concat(id, ".pdf")); - if (BI.Interop.Pdf.PdfImporter.ProcessPdfAttachment(filename, Database, DocumentTemplateId, DataId, UserService.CurrentUser.UserId, DateTime.Now)) + var identifier = DocumentUniqueIdentifier.Create(Database, DocumentTemplateId, DataId, UserService.CurrentUser.UserId, DateTime.Now, 0); + + if (Disco.Services.Documents.AttachmentImport.Importer.ImportPdfAttachment(identifier, Database, filename)) { // Delete File System.IO.File.Delete(filename); diff --git a/Disco.Web/Areas/API/Controllers/ExpressionsController.cs b/Disco.Web/Areas/API/Controllers/ExpressionsController.cs index 975250da..f6fd13ab 100644 --- a/Disco.Web/Areas/API/Controllers/ExpressionsController.cs +++ b/Disco.Web/Areas/API/Controllers/ExpressionsController.cs @@ -1,4 +1,5 @@ using Disco.Services.Authorization; +using Disco.Services.Expressions; using Disco.Services.Web; using System.Web.Mvc; @@ -9,7 +10,7 @@ namespace Disco.Web.Areas.API.Controllers { public virtual ActionResult ValidateExpression(string Expression) { - var part = new BI.Expressions.EvaluateExpressionPart(Expression); + var part = new EvaluateExpressionPart(Expression); return Json(Models.Expressions.ValidateExpressionModel.FromEvaluateExpressionPart(part), JsonRequestBehavior.AllowGet); } } diff --git a/Disco.Web/Areas/API/Controllers/JobController.cs b/Disco.Web/Areas/API/Controllers/JobController.cs index b7076b15..79900dcc 100644 --- a/Disco.Web/Areas/API/Controllers/JobController.cs +++ b/Disco.Web/Areas/API/Controllers/JobController.cs @@ -1,8 +1,10 @@ using Disco.BI.Extensions; using Disco.Models.Repository; +using Disco.Models.Services.Documents; using Disco.Models.Services.Jobs.JobLists; using Disco.Services; using Disco.Services.Authorization; +using Disco.Services.Interop; using Disco.Services.Jobs.JobLists; using Disco.Services.Users; using Disco.Services.Web; @@ -1920,9 +1922,9 @@ namespace Disco.Web.Areas.API.Controllers { var contentType = file.ContentType; if (string.IsNullOrEmpty(contentType) || contentType.Equals("unknown/unknown", StringComparison.OrdinalIgnoreCase)) - contentType = BI.Interop.MimeTypes.ResolveMimeType(file.FileName); + contentType = MimeTypes.ResolveMimeType(file.FileName); - var ja = new Disco.Models.Repository.JobAttachment() + var ja = new JobAttachment() { JobId = j.Id, TechUserId = CurrentUser.UserId, @@ -2096,7 +2098,7 @@ namespace Disco.Web.Areas.API.Controllers { var timeStamp = DateTime.Now; Stream pdf; - using (var generationState = Disco.Models.BI.DocumentTemplates.DocumentState.DefaultState()) + using (var generationState = DocumentState.DefaultState()) { pdf = documentTemplate.GeneratePdf(Database, job, CurrentUser, timeStamp, generationState); } diff --git a/Disco.Web/Areas/API/Controllers/SystemController.cs b/Disco.Web/Areas/API/Controllers/SystemController.cs index 45a7b88c..4b23fce4 100644 --- a/Disco.Web/Areas/API/Controllers/SystemController.cs +++ b/Disco.Web/Areas/API/Controllers/SystemController.cs @@ -1,5 +1,6 @@ using Disco.BI.Extensions; using Disco.Data.Configuration; +using Disco.Services; using Disco.Services.Authorization; using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Interop.DiscoServices; diff --git a/Disco.Web/Areas/API/Controllers/UserController.cs b/Disco.Web/Areas/API/Controllers/UserController.cs index 4e12d710..80d5d71f 100644 --- a/Disco.Web/Areas/API/Controllers/UserController.cs +++ b/Disco.Web/Areas/API/Controllers/UserController.cs @@ -1,5 +1,8 @@ using Disco.BI.Extensions; +using Disco.Models.Services.Documents; +using Disco.Services; using Disco.Services.Authorization; +using Disco.Services.Interop; using Disco.Services.Interop.ActiveDirectory; using Disco.Services.Users; using Disco.Services.Web; @@ -70,7 +73,7 @@ namespace Disco.Web.Areas.API.Controllers { var contentType = file.ContentType; if (string.IsNullOrEmpty(contentType) || contentType.Equals("unknown/unknown", StringComparison.OrdinalIgnoreCase)) - contentType = BI.Interop.MimeTypes.ResolveMimeType(file.FileName); + contentType = MimeTypes.ResolveMimeType(file.FileName); var ua = new Disco.Models.Repository.UserAttachment() { @@ -171,7 +174,7 @@ namespace Disco.Web.Areas.API.Controllers { var timeStamp = DateTime.Now; Stream pdf; - using (var generationState = Disco.Models.BI.DocumentTemplates.DocumentState.DefaultState()) + using (var generationState = DocumentState.DefaultState()) { pdf = documentTemplate.GeneratePdf(Database, user, UserService.CurrentUser, timeStamp, generationState); } diff --git a/Disco.Web/Areas/API/Models/Expressions/ValidateExpressionModel.cs b/Disco.Web/Areas/API/Models/Expressions/ValidateExpressionModel.cs index 1981e1ac..bde54a9f 100644 --- a/Disco.Web/Areas/API/Models/Expressions/ValidateExpressionModel.cs +++ b/Disco.Web/Areas/API/Models/Expressions/ValidateExpressionModel.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using Disco.Services.Expressions; using System.Web; -using Disco.BI.Expressions; namespace Disco.Web.Areas.API.Models.Expressions { diff --git a/Disco.Web/Areas/Config/Controllers/DocumentTemplateController.cs b/Disco.Web/Areas/Config/Controllers/DocumentTemplateController.cs index 5853b0c8..7c70dacd 100644 --- a/Disco.Web/Areas/Config/Controllers/DocumentTemplateController.cs +++ b/Disco.Web/Areas/Config/Controllers/DocumentTemplateController.cs @@ -1,7 +1,9 @@ using Disco.BI.DocumentTemplateBI.ManagedGroups; using Disco.BI.Extensions; using Disco.Models.UI.Config.DocumentTemplate; +using Disco.Services; using Disco.Services.Authorization; +using Disco.Services.Expressions; using Disco.Services.Plugins.Features.UIExtension; using Disco.Services.Web; using System; @@ -137,8 +139,8 @@ namespace Disco.Web.Areas.Config.Controllers DeviceType = typeof(Disco.Models.Repository.Device).AssemblyQualifiedName, JobType = typeof(Disco.Models.Repository.Job).AssemblyQualifiedName, UserType = typeof(Disco.Models.Repository.User).AssemblyQualifiedName, - Variables = BI.Expressions.Expression.StandardVariableTypes(), - ExtensionLibraries = BI.Expressions.Expression.ExtensionLibraryTypes() + Variables = Expression.StandardVariableTypes(), + ExtensionLibraries = Expression.ExtensionLibraryTypes() }; // UI Extensions @@ -151,7 +153,7 @@ namespace Disco.Web.Areas.Config.Controllers var t = Type.GetType(type); if (t != null) { - return Json(BI.Expressions.ExpressionTypeDescriptor.Build(t, StaticDeclaredMembersOnly), JsonRequestBehavior.AllowGet); + return Json(ExpressionTypeDescriptor.Build(t, StaticDeclaredMembersOnly), JsonRequestBehavior.AllowGet); } else { diff --git a/Disco.Web/Areas/Config/Models/DocumentTemplate/ShowModel.cs b/Disco.Web/Areas/Config/Models/DocumentTemplate/ShowModel.cs index 49aa31b2..e292354d 100644 --- a/Disco.Web/Areas/Config/Models/DocumentTemplate/ShowModel.cs +++ b/Disco.Web/Areas/Config/Models/DocumentTemplate/ShowModel.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; +using Disco.BI.DocumentTemplateBI.ManagedGroups; using Disco.Data.Repository; using Disco.Models.Repository; using Disco.Models.UI.Config.DocumentTemplate; -using Disco.BI.DocumentTemplateBI.ManagedGroups; +using Disco.Services.Expressions; +using System.Collections.Generic; +using System.Linq; namespace Disco.Web.Areas.Config.Models.DocumentTemplate { @@ -15,9 +14,9 @@ namespace Disco.Web.Areas.Config.Models.DocumentTemplate public int StoredInstanceCount { get; set; } - public List TemplateExpressions { get; set; } + public List TemplateExpressions { get; set; } - public List JobTypes { get; set; } + public List JobTypes { get; set; } public List Scopes { diff --git a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml index 77630b67..8d73ffba 100644 --- a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml +++ b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.cshtml @@ -306,7 +306,7 @@ logHub = $.connection.logNotifications; logHub.client.receiveLog = parseLog - $.connection.hub.qs = { LogModules: '@(Disco.BI.DocumentTemplateBI.DocumentsLog.Current.LiveLogGroupName)' }; + $.connection.hub.qs = { LogModules: '@(Disco.Services.Documents.DocumentsLog.Current.LiveLogGroupName)' }; $.connection.hub.error(onHubFailed); $.connection.hub.start() diff --git a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs index 532d95e7..53a975c6 100644 --- a/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs +++ b/Disco.Web/Areas/Config/Views/DocumentTemplate/ImportStatus.generated.cs @@ -2,7 +2,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -466,7 +466,7 @@ WriteLiteral(@"', #line 309 "..\..\Areas\Config\Views\DocumentTemplate\ImportStatus.cshtml" - Write(Disco.BI.DocumentTemplateBI.DocumentsLog.Current.LiveLogGroupName); + Write(Disco.Services.Documents.DocumentsLog.Current.LiveLogGroupName); #line default diff --git a/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.cshtml b/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.cshtml index 03745e59..c1512cc1 100644 --- a/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.cshtml +++ b/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.cshtml @@ -1,4 +1,4 @@ -@model IEnumerable +@model IEnumerable @{ Authorization.Require(Claims.Config.DocumentTemplate.Show); } diff --git a/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.generated.cs b/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.generated.cs index 0096f562..3ceb1bbd 100644 --- a/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.generated.cs +++ b/Disco.Web/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.generated.cs @@ -2,7 +2,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34014 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -37,9 +37,9 @@ namespace Disco.Web.Areas.Config.Views.DocumentTemplate [System.CodeDom.Compiler.GeneratedCodeAttribute("RazorGenerator", "2.0.0.0")] [System.Web.WebPages.PageVirtualPathAttribute("~/Areas/Config/Views/DocumentTemplate/_ExpressionsTable.cshtml")] - public partial class ExpressionsTable : Disco.Services.Web.WebViewPage> + public partial class _ExpressionsTable : Disco.Services.Web.WebViewPage> { - public ExpressionsTable() + public _ExpressionsTable() { } public override void Execute() @@ -107,14 +107,14 @@ WriteLiteral(@"> #line hidden WriteLiteral(" \r\n (expressionParts.Length +, Tuple.Create(Tuple.Create("", 735), Tuple.Create(expressionParts.Length #line default #line hidden -, 729), false) +, 735), false) ); WriteLiteral(">\r\n"); diff --git a/Disco.Web/Controllers/PluginWebHandlerController.cs b/Disco.Web/Controllers/PluginWebHandlerController.cs index 437b9d11..9762a793 100644 --- a/Disco.Web/Controllers/PluginWebHandlerController.cs +++ b/Disco.Web/Controllers/PluginWebHandlerController.cs @@ -7,6 +7,7 @@ using System.Web.Mvc; using Disco.Services.Plugins; using Disco.Services.Authorization; using Disco.Services.Users; +using Disco.Services.Interop; namespace Disco.Web.Controllers { @@ -57,7 +58,7 @@ namespace Disco.Web.Controllers var pluginResourcePath = pluginResource.Item1; - var mimeType = Disco.BI.Interop.MimeTypes.ResolveMimeType(pluginResourcePath); + var mimeType = MimeTypes.ResolveMimeType(pluginResourcePath); if (Download.HasValue && Download.Value) return File(pluginResourcePath, mimeType, Path.GetFileName(pluginResourcePath)); else diff --git a/Disco.Web/Global.asax.cs b/Disco.Web/Global.asax.cs index 2a763368..68669700 100644 --- a/Disco.Web/Global.asax.cs +++ b/Disco.Web/Global.asax.cs @@ -211,7 +211,7 @@ namespace Disco.Web } #endregion #region Dropbox Monitor - public static BI.DocumentTemplateBI.Importer.DocumentDropBoxMonitor DocumentDropBoxMonitor { get; set; } + public static Disco.Services.Documents.AttachmentImport.ImportDirectoryMonitor DocumentDropBoxMonitor { get; set; } #endregion #region Global Error Logging void DiscoApplication_Error(object sender, EventArgs e)