示例#1
0
 public FileDataDO(GvaFile gvaFile)
 {
     this.Name = gvaFile.Filename;
     this.Key = gvaFile.FileContentId;
     this.MimeType = gvaFile.MimeType ??
         MimeTypeHelper.GetFileMimeTypeByExtenstion(Path.GetExtension(gvaFile.Filename));
 }
示例#2
0
        public void UpdateLicenceEdition(Guid licenceEditionDocBlobKey, int editionPartIndex, Lot lot)
        {
            PartVersion<PersonLicenceEditionDO> licenceEditionPartVersion = lot.Index.GetPart<PersonLicenceEditionDO>(string.Format("licenceEditions/{0}", editionPartIndex));

            using (var transaction = this.unitOfWork.BeginTransaction())
            {
                licenceEditionPartVersion.Content.PrintedDocumentBlobKey = licenceEditionDocBlobKey;

                GvaFile printedLicenceFile = new GvaFile()
                {
                    Filename = "migratedLicence",
                    FileContentId = licenceEditionDocBlobKey,
                    MimeType = "application/pdf"
                };

                this.unitOfWork.DbContext.Set<GvaFile>().Add(printedLicenceFile);

                this.unitOfWork.Save();

                licenceEditionPartVersion.Content.PrintedFileId = printedLicenceFile.GvaFileId;

                lot.UpdatePart<PersonLicenceEditionDO>(string.Format("licenceEditions/{0}", licenceEditionPartVersion.Part.Index), licenceEditionPartVersion.Content, this.userContext);

                lot.Commit(this.userContext, this.lotEventDispatcher);
                this.lotRepository.ExecSpSetLotPartTokens(licenceEditionPartVersion.PartId);

                this.unitOfWork.Save();

                transaction.Commit();
            }
        }
示例#3
0
        private void UpdateLotFile(GvaLotFile lotFile, CaseDO caseDO)
        {
            lotFile.GvaCaseTypeId = caseDO.CaseType.NomValueId;
            lotFile.PageIndex = caseDO.BookPageNumber;
            lotFile.PageIndexInt = GetPageIndexInt(caseDO.BookPageNumber);
            lotFile.PageNumber = caseDO.PageCount;
            lotFile.Note = caseDO.Note;

            if (caseDO.File != null)
            {
                if (!lotFile.GvaFileId.HasValue)
                {
                    GvaFile file = new GvaFile()
                    {
                        Filename = caseDO.File.Name,
                        MimeType = caseDO.File.MimeType,
                        FileContentId = caseDO.File.Key
                    };

                    this.unitOfWork.DbContext.Set<GvaFile>().Add(file);
                    lotFile.GvaFile = file;
                }
                else if (lotFile.GvaFile.FileContentId != caseDO.File.Key)
                {
                    lotFile.GvaFile.Filename = caseDO.File.Name;
                    lotFile.GvaFile.MimeType = caseDO.File.MimeType;
                    lotFile.GvaFile.FileContentId = caseDO.File.Key;
                }
            }
            else if (lotFile.GvaFileId.HasValue)
            {
                this.unitOfWork.DbContext.Set<GvaFile>().Remove(lotFile.GvaFile);
            }

            var nonModifiedApps = lotFile.GvaAppLotFiles.Join(
                caseDO.Applications,
                gf => gf.GvaApplicationId,
                a => a.ApplicationId,
                (gf, a) => gf);

            var removedApplications = lotFile.GvaAppLotFiles.Except(nonModifiedApps).ToList();
            foreach (var application in removedApplications)
            {
                this.unitOfWork.DbContext.Set<GvaAppLotFile>().Remove(application);
            }

            foreach (var application in caseDO.Applications)
            {
                var appLotFile = lotFile.GvaAppLotFiles.SingleOrDefault(af => af.GvaApplicationId == (int)application.ApplicationId);
                if (appLotFile == null)
                {
                    appLotFile = new GvaAppLotFile()
                    {
                        GvaApplicationId = application.ApplicationId,
                        GvaLotFile = lotFile
                    };

                    this.unitOfWork.DbContext.Set<GvaAppLotFile>().Add(appLotFile);
                }
            }
        }
示例#4
0
        private GvaLotFile AddLotFile(Part part, CaseDO caseDO)
        {
            GvaFile file = null;
            if (caseDO.File != null)
            {
                file = new GvaFile()
                {
                    Filename = caseDO.File.Name,
                    MimeType = caseDO.File.MimeType,
                    FileContentId = caseDO.File.Key
                };

                this.unitOfWork.DbContext.Set<GvaFile>().Add(file);
            }

            GvaLotFile newLotFile = new GvaLotFile()
            {
                LotPart = part,
                GvaFile = file,
                GvaCaseTypeId = caseDO.CaseType.NomValueId,
                PageIndex = (string)caseDO.BookPageNumber,
                PageIndexInt = GetPageIndexInt(caseDO.BookPageNumber),
                PageNumber = (int?)caseDO.PageCount,
                Note = caseDO.Note,
            };

            this.unitOfWork.DbContext.Set<GvaLotFile>().Add(newLotFile);

            foreach (var application in caseDO.Applications)
            {
                GvaAppLotFile appLotFile = new GvaAppLotFile()
                {
                    GvaApplicationId = application.ApplicationId,
                    GvaLotFile = newLotFile
                };

                this.unitOfWork.DbContext.Set<GvaAppLotFile>().Add(appLotFile);
            }

            return newLotFile;
        }
示例#5
0
        public int SaveNewFile(string name, Guid blobKey)
        {
            var newFile = new GvaFile()
            {
                Filename = name,
                FileContentId = blobKey,
                MimeType = "application/pdf"
            };

            this.unitOfWork.DbContext.Set<GvaFile>().Add(newFile);

            this.unitOfWork.Save();

            return newFile.GvaFileId;
        }
示例#6
0
        public IHttpActionResult PostExtractPages(string fileKey, string name)
        {
            using (var transaction = this.unitOfWork.BeginTransaction())
            {
                GhostscriptVersionInfo lastInstalledVersion = GhostscriptVersionInfo.GetLastInstalledVersion(GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
                List<GvaFile> gvaFiles = new List<GvaFile>();
                int pageCount;

                using (MemoryStream m1 = new MemoryStream())
                {
                    using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString))
                    {
                        connection.Open();

                        using (var blobStream = new BlobReadStream(connection, "dbo", "Blobs", "Content", "Key", fileKey))
                        {
                            blobStream.CopyTo(m1);
                        }
                    }

                    using (GhostscriptRasterizer rasterizer = new GhostscriptRasterizer())
                    {
                        rasterizer.Open(m1, lastInstalledVersion, false);
                        pageCount = rasterizer.PageCount;

                        for (int i = 1; i <= pageCount; i++)
                        {
                            using (var ms = new MemoryStream())
                            {
                                GvaFile file = null;

                                Image img = rasterizer.GetPage(300, 300, i);
                                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

                                using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DbContext"].ConnectionString))
                                {
                                    connection.Open();
                                    using (var blobWriter = new BlobWriter(connection))
                                    using (var stream = blobWriter.OpenStream())
                                    {
                                        stream.Write(ms.ToArray(), 0, (int)ms.Length);

                                        file = new GvaFile()
                                        {
                                            Filename = Path.Combine(Path.GetFileNameWithoutExtension(name) + "-" + i.ToString() + ".jpg"),
                                            MimeType = "image/jpeg",
                                            FileContentId = blobWriter.GetBlobKey()
                                        };

                                        this.unitOfWork.DbContext.Set<GvaFile>().Add(file);
                                        gvaFiles.Add(file);
                                    }
                                }
                            }
                        }
                    }
                }

                this.unitOfWork.Save();
                transaction.Commit();

                List<int> gvaFileIds = gvaFiles.Select(e => e.GvaFileId).ToList();

                return Ok(new { pageCount = pageCount, gvaFileIds = gvaFileIds });
            }
        }