Pdf Import Rewrite

Pdf Import rewritten to greatly improve QR Code detection, reduce
reliance on iTextSharp and improve thumbnails. Fixes #50
This commit is contained in:
Gary Sharp
2016-08-26 09:46:35 +10:00
parent 44f6d325db
commit 5ea9a814d6
98 changed files with 3168 additions and 3202 deletions
@@ -0,0 +1,89 @@
using Disco.Data.Repository;
using Disco.Models.Repository;
using System;
using System.Drawing;
using System.IO;
namespace Disco.Services
{
public static class AttachmentDataStoreExtensions
{
public static string RepositoryFilename(this IAttachment Attachment, DiscoDataContext Database)
{
switch (Attachment.AttachmentType)
{
case AttachmentTypes.Device:
return Path.Combine(DataStore.CreateLocation(Database, "DeviceAttachments", Attachment.Timestamp),
string.Format("{0}_{1}_file", Attachment.Reference, Attachment.Id));
case AttachmentTypes.Job:
return Path.Combine(DataStore.CreateLocation(Database, "JobAttachments", Attachment.Timestamp),
string.Format("{0}_{1}_file", Attachment.Reference, Attachment.Id));
case AttachmentTypes.User:
return Path.Combine(DataStore.CreateLocation(Database, "UserAttachments", Attachment.Timestamp),
string.Format("{0}_{1}_file", ((string)Attachment.Reference).Replace('\\', '_'), Attachment.Id));
default:
throw new ArgumentException("Unknown Attachment Type", nameof(Attachment));
}
}
public static string RepositoryThumbnailFilename(this IAttachment Attachment, DiscoDataContext Database)
{
switch (Attachment.AttachmentType)
{
case AttachmentTypes.Device:
return Path.Combine(DataStore.CreateLocation(Database, "DeviceAttachments", Attachment.Timestamp),
string.Format("{0}_{1}_thumb.jpg", Attachment.Reference, Attachment.Id));
case AttachmentTypes.Job:
return Path.Combine(DataStore.CreateLocation(Database, "JobAttachments", Attachment.Timestamp),
string.Format("{0}_{1}_thumb.jpg", Attachment.Reference, Attachment.Id));
case AttachmentTypes.User:
return Path.Combine(DataStore.CreateLocation(Database, "UserAttachments", Attachment.Timestamp),
string.Format("{0}_{1}_thumb.jpg", ((string)Attachment.Reference).Replace('\\', '_'), Attachment.Id));
default:
throw new ArgumentException("Unknown Attachment Type", nameof(Attachment));
}
}
public static string SaveAttachment(this IAttachment Attachment, DiscoDataContext Database, Stream FileContent)
{
string filePath = Attachment.RepositoryFilename(Database);
DataStore.WriteFile(filePath, FileContent);
return filePath;
}
public static string SaveAttachment(this IAttachment Attachment, DiscoDataContext Database, byte[] FileContent)
{
string filePath = Attachment.RepositoryFilename(Database);
DataStore.WriteFile(filePath, FileContent);
return filePath;
}
public static string SaveThumbnailAttachment(this IAttachment Attachment, DiscoDataContext Database, Image Thumbnail)
{
string filePath = Attachment.RepositoryThumbnailFilename(Database);
Thumbnail.SaveJpg(90, filePath);
return filePath;
}
public static string SaveThumbnailAttachment(this IAttachment Attachment, DiscoDataContext Database, Stream FileContent)
{
string filePath = Attachment.RepositoryThumbnailFilename(Database);
DataStore.WriteFile(filePath, FileContent);
return filePath;
}
public static string SaveThumbnailAttachment(this IAttachment Attachment, DiscoDataContext Database, byte[] FileContent)
{
string filePath = Attachment.RepositoryThumbnailFilename(Database);
DataStore.WriteFile(filePath, FileContent);
return filePath;
}
public static void RepositoryDelete(this IAttachment Attachment, DiscoDataContext Database)
{
DataStore.DeleteFiles(Attachment.RepositoryFilename(Database), Attachment.RepositoryThumbnailFilename(Database));
}
}
}