Beispiel #1
0
        public void AddPage2()
        {
            string base64image = servImage.ToBase64String(TakeDocModel.Environnement.JpegTestFile2);

            servDocument.AddPage(userId, entityId, MyDocument.DocumentId, base64image, "jpeg", 180);

            TakeDocModel.Version version = servVersion.GetById(MyDocument.LastVersion.VersionId, x => x.Page);

            Assert.AreEqual(version.LastPage.UserCreateData, userId);
            Assert.AreEqual(version.LastPage.EntityId, entityId);
            Assert.IsNotNull(version.LastPage.DateCreateData);
            Assert.IsNotNull(version.LastPage.PageNumber);
            Assert.AreNotEqual(version.LastPage.DateCreateData, System.DateTimeOffset.MinValue);
            Assert.IsFalse(version.LastPage.EtatDeleteData);
        }
Beispiel #2
0
        public TakeDocModel.Document Create(Guid userId, Guid entityId, Guid typeDocumentId, string documentLabel, Guid?folderId)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                this.Logger.Info(string.Format("Create document by {0}", userId));
                Guid documentId = System.Guid.NewGuid();
                Guid versionId  = documentId;
                TakeDocModel.Document document = daoDocument.Create(userId, entityId, documentId, versionId, typeDocumentId, documentLabel, folderId);

                TakeDocModel.Version version = servVersion.CreateMajor(userId, entityId, versionId, documentId, typeDocumentId);

                transaction.Complete();
                return(document);
            }
        }
Beispiel #3
0
        public ICollection <object> GetPages(Guid versionId, Guid entityId, Guid userId)
        {
            ICollection <object> back = new List <object>();

            TakeDocModel.Version version = daoVersion.GetBy(x => x.VersionId == versionId && x.EntityId == entityId, x => x.Page).First();
            foreach (TakeDocModel.Page page in version.Page.Where(x => x.EtatDeleteData == false))
            {
                var current = new {
                    id          = page.PageId,
                    pageNumber  = page.PageNumber,
                    base64Image = servPage.GetBase64(page.PageId),
                    rotation    = String.Format("{0:000}", page.PageRotation)
                };
                back.Add(current);
            }
            return(back.ToArray());
        }
Beispiel #4
0
        public TakeDocModel.Version CreateMajor(Guid userId, Guid entityId, Guid versionId, Guid documentId, Guid typeDocumentId)
        {
            ICollection <TakeDocModel.Version> versions = daoVersion.GetBy(x => x.VersionDocumentId == documentId);
            decimal nVersion = 0;

            if (versions.Count() > 0)
            {
                TakeDocModel.Version last = versions.OrderByDescending(x => x.VersionNumber).First();
                while (Math.Max(nVersion, last.VersionNumber) == last.VersionNumber)
                {
                    nVersion = nVersion + 1;
                }
            }

            TakeDocModel.Version version = this.Create(userId, entityId, versionId, documentId, nVersion);
            servMetaData.CreateMetaData(userId, entityId, versionId, typeDocumentId);
            return(version);
        }
        public byte[] Generate(TakeDocModel.Version version, TakeDocModel.Entity entity)
        {
            byte[] data = this.GenerateStarterPdf(version, entity);
            if (data == null)
            {
                return(null);
            }
            PdfReader entetePdf = new PdfReader(data);
            PdfReader imagePdf  = servImage.GetImagePdf(version);

            its.Document document  = new its.Document(iTextSharp.text.PageSize.A4, -70, -70, 0, 0);
            MemoryStream streamOut = new MemoryStream();

            using (PdfCopy copy = new PdfCopy(document, streamOut))
            {
                document.Open();
                for (int p = 1; p <= entetePdf.NumberOfPages; p++)
                {
                    PdfImportedPage page = copy.GetImportedPage(entetePdf, p);
                    copy.AddPage(page);
                }
                copy.FreeReader(entetePdf);
                entetePdf.Close();

                if (imagePdf != null)
                {
                    // add page image to the pdf
                    for (int p = 1; p <= imagePdf.NumberOfPages; p++)
                    {
                        PdfImportedPage page = copy.GetImportedPage(imagePdf, p);
                        copy.AddPage(page);
                    }
                    copy.FreeReader(imagePdf);
                    imagePdf.Close();
                }
            }

            System.IO.FileInfo file = this.GetGenerateFileInfo(entity.EntityReference, version.VersionReference, "pdf");
            System.IO.File.WriteAllBytes(file.FullName, streamOut.ToArray());

            version.VersionPath = file.FullName.Replace(TakeDocModel.Environnement.VersionStoreUNC, string.Empty);
            servVersion.Update(version);
            return(streamOut.ToArray());
        }
        /// <summary>
        /// Init tab with metadata name and value
        /// </summary>
        /// <param name="version"></param>
        /// <param name="entity"></param>
        /// <returns></returns>
        private byte[] GenerateStarterPdf(TakeDocModel.Version version, TakeDocModel.Entity entity)
        {
            byte[]   data   = null;
            FileInfo modele = new FileInfo(string.Concat(TakeDocModel.Environnement.ModelDirectory, entity.EntityReference, @"\", version.Document.Type_Document.TypeDocumentReference, "_", "starter.odt"));

            if (modele.Exists == false)
            {
                modele = new FileInfo(string.Concat(TakeDocModel.Environnement.ModelDirectory, "version_starter.odt"));
            }

            FileInfo destinationOdt = new FileInfo(string.Concat(TakeDocModel.Environnement.TempDirectory, Guid.NewGuid().ToString(), modele.Extension));
            FileInfo destinationPdf = new FileInfo(string.Concat(destinationOdt.FullName.Replace(destinationOdt.Extension, ".pdf")));

            modele.CopyTo(destinationOdt.FullName);
            try
            {
                this.FillField(version, entity, destinationOdt);

                System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(TakeDocModel.Environnement.BatchConvertPdf);
                info.WorkingDirectory = TakeDocModel.Environnement.TempDirectory;
                info.Arguments        = destinationOdt.FullName;
                System.Diagnostics.Process process = System.Diagnostics.Process.Start(info);
                process.WaitForExit();

                data = System.IO.File.ReadAllBytes(destinationPdf.FullName);
            }
            catch (Exception ex)
            {
                this.Logger.Error(ex);
            }
            finally
            {
                if (destinationOdt.Exists)
                {
                    destinationOdt.Delete();
                }
                if (destinationPdf.Exists)
                {
                    destinationPdf.Delete();
                }
            }
            return(data);
        }
        public void Update(Guid userId, Guid entityId, string json, bool startWorkflow)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                Newtonsoft.Json.Linq.JArray  data      = Newtonsoft.Json.Linq.JArray.Parse(json);
                Newtonsoft.Json.Linq.JObject context   = String.IsNullOrEmpty(data[0].ToString()) ? null : (Newtonsoft.Json.Linq.JObject)data[0];
                Newtonsoft.Json.Linq.JObject document  = String.IsNullOrEmpty(data[1].ToString()) ? null : (Newtonsoft.Json.Linq.JObject)data[1];
                Newtonsoft.Json.Linq.JArray  metadatas = String.IsNullOrEmpty(data[2].ToString()) ? null : (Newtonsoft.Json.Linq.JArray)data[2];
                Newtonsoft.Json.Linq.JArray  pages     = String.IsNullOrEmpty(data[3].ToString()) ? null : (Newtonsoft.Json.Linq.JArray)data[3];
                Guid versionId = new Guid(document.Value <string>("versionId"));

                TakeDocModel.Entity  entity  = daoEntity.GetBy(x => x.EntityId == entityId).First();
                TakeDocModel.Version version = servVersion.GetById(versionId);
                TakeDocModel.UserTk  user    = daoUser.GetBy(x => x.UserTkId == userId).First();

                if (pages != null)
                {
                    servPage.Update(pages, userId, version, entity.EntityId);
                }
                servDocument.Update(user, entity, version, document, metadatas, startWorkflow);
                transaction.Complete();
            }
        }
Beispiel #8
0
 public ICollection <TakeDocModel.Dto.Document.ReadOnlyMetadata> GetReadOnlyMetaData(TakeDocModel.Version version)
 {
     return(this.GetReadOnlyMetaData(version.VersionId, version.EntityId));
 }
Beispiel #9
0
        public PdfReader GetImagePdf(TakeDocModel.Version version)
        {
            ICollection <byte[]> data = this.GetImage(version);

            return(this.GetPdf(data));
        }
 public byte[] Generate(Guid versionId, Guid entityId)
 {
     TakeDocModel.Version version = servVersion.GetBy(x => x.VersionId == versionId && x.EntityId == entityId).First();
     TakeDocModel.Entity  entity  = daoEntity.GetBy(x => x.EntityId == entityId).First();
     return(this.Generate(version, entity));
 }
Beispiel #11
0
 public void Update(TakeDocModel.Version version)
 {
     daoVersion.Update(version);
 }