예제 #1
0
        /// <summary>
        /// Imports the given ImportCandidate and adds a new entry in the database. The pages to be imported are extracted from the original document
        /// into a temporary PDF file, which is then moved to the archive folder.
        /// </summary>
        /// <param name="importCandidate">The ImportCandidate that shall be imported into the database.</param>
        /// <returns></returns>
        /// <exception cref="SheetAlreadyExistsException"></exception>
        public async Task ImportImportCandidate(ImportCandidate importCandidate)
        {
            //Check if Sheet is already in Database
            //Throw if true

            foreach (var sheet in importCandidate.AssignedPiece.Sheet)
            {
                if (sheet.Part == importCandidate.AssignedPart)
                {
                    throw new SheetAlreadyExistsException(sheet, importCandidate);
                }
            }

            //Create database entry (only if sheet does not exists yet)

            Sheet newSheet = new Sheet(importCandidate.AssignedPart, importCandidate.AssignedPiece);
            await Manager.Context.Sheet.AddAsync(newSheet);

            await Manager.Context.SaveChangesAsync();

            //Extract page
            Extractor.InputFile  = new FileInfo(importCandidate.DocumentPath);
            Extractor.OutputPath = new DirectoryInfo(Manager.ZebraConfig.TempDir);
            Extractor.OutputName = FileNameResolver.GetFileName(newSheet);

            int[] pages = new int[importCandidate.Pages.Count];

            for (int i = 0; i < importCandidate.Pages.Count; i++)
            {
                pages[i] = importCandidate.Pages[i].PageNumber;
            }

            try
            {
                //Extract pages to be imported and save into temp PDF file
                await Extractor.ExtractAsync(pages);

                //Push file to archive
                Manager.Archive.PushFile(new FileInfo(Manager.ZebraConfig.TempDir + "\\" + FileNameResolver.GetFileName(newSheet)), newSheet, FileImportMode.Copy, false);
            }
            catch (Exception)
            {
                //Undo Sheet creation in Database
                Manager.Context.Sheet.Remove(newSheet);
                Manager.Context.SaveChanges();

                throw;
            }
            finally
            {
                //Remove temp file if it has been created
                if (File.Exists(Manager.ZebraConfig.TempDir + "\\" + FileNameResolver.GetFileName(newSheet)))
                {
                    File.Delete(Manager.ZebraConfig.TempDir + "\\" + FileNameResolver.GetFileName(newSheet));
                }
            }
        }
예제 #2
0
        public void AddDocument(string pdfDocument)
        {
            PreviewablePdfDocument doc = new PreviewablePdfDocument(pdfDocument);

            SortedList <int, ImportPage> pages = new SortedList <int, ImportPage>();

            ImportCandidate newCandidate = new ImportCandidate(pdfDocument);

            for (int i = 0; i < doc.PageCount(); i++)
            {
                ImportPage page = new ImportPage(newCandidate, i + 1, doc.Pages[i].Thumbnail);
                newCandidate.Pages.Add(page);
            }

            ImportCandidates.Add(newCandidate);
        }
예제 #3
0
 public ImportPage(ImportCandidate parent, int pageNumber, System.Drawing.Image thumbnail)
 {
     PageNumber      = pageNumber;
     Thumbnail       = thumbnail;
     ImportCandidate = parent;
 }
예제 #4
0
        /// <summary>
        /// Imports the given importCandidate and removes it from the ImportBatch.
        /// </summary>
        /// <param name="importCandidate">ImportCandidate to be imported.</param>
        /// <returns></returns>
        public async Task ImportCandidateAsync(ImportCandidate importCandidate)
        {
            await Importer.ImportImportCandidate(importCandidate);

            ImportCandidates.Remove(importCandidate);
        }
예제 #5
0
 public SheetAlreadyExistsException(Sheet _sheet, ImportCandidate _candidate) : base($"Sheet {_sheet.Piece.Name} - {_sheet.Part.Name} already exists.")
 {
     ExistingSheet = _sheet;
     Candidate     = _candidate;
 }