| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 | using Comal.Classes;using Comal.Stores;using InABox.Core;using System;using System.Linq;using System.IO;using Syncfusion.Pdf.Parsing;using System.Drawing;using System.Drawing.Imaging;namespace PRSStores{    public abstract class EntityDocumentStore<TEntityDocument, TEntity, TEntityLink> : BaseStore<TEntityDocument>        where TEntityDocument : EntityDocument<TEntityLink>, new()        where TEntityLink : EntityLink<TEntity>, new()         where TEntity : Entity, new()    {        protected override void BeforeSave(TEntityDocument entity)        {            SaveThumbnail(entity); //current size for saved thumbnails is 256*256            base.BeforeSave(entity);                   }        private void SaveThumbnail(TEntityDocument entity)        {                     if (entity.DocumentLink.ID == Guid.Empty)                return;            if (entity.Thumbnail?.Any() == true)                return;                        CoreTable table = Provider.Query<Document>(new Filter<Document>(x => x.ID).IsEqualTo(entity.DocumentLink.ID),                new Columns<Document>(x => x.Data, x => x.FileName));            if (table.Rows.Count == 0)                return;            Document doc = table.Rows.FirstOrDefault().ToObject<Document>();            if (!doc.FileName.ToLower().EndsWith("pdf"))                return;            try            {                PdfLoadedDocument loadeddoc = new PdfLoadedDocument(doc.Data);                Bitmap image = loadeddoc.ExportAsImage(0, new SizeF(256, 256), true);                MemoryStream stream = new MemoryStream();                image.Save(stream, ImageFormat.Jpeg);                entity.Thumbnail = stream.ToArray();            }            catch (Exception ex)             {                Logger.Send(LogType.Information, UserID, ex.Message);            }        }    }    //In order to have BeforeSave active for a specific EntityDocument, it has to be concretized as below    public class JobDocumentSetSetMileStoneFileStore : EntityDocumentStore<JobDocumentSetMileStoneFile, JobDocumentSetMileStone, JobDocumentSetMileStoneLink> { }    public class MeetingItemDocumentStore : EntityDocumentStore<MeetingItemDocument, MeetingItem, MeetingItemLink> { }    public class SetoutDocumentStore : EntityDocumentStore<SetoutDocument, Setout, SetoutLink> { }}
 |