Пример #1
0
        public void loadSelectedThesisFile()
        {
            ViewModel.getInstance().ProgressBarColor = Color.Yellow;
            MaskedFileInfo selectedFileInfo          = ViewModel.getInstance().SelectedThesisFile;
            ViewModel      viewModel = ViewModel.getInstance();

            if (selectedFileInfo != null)
            {
                viewModel.SaveButtonEnabled = false;
                ThesisRecord thesisRecord = MainThread.getInstance().ThesisRecord;
                thesisRecord.clearExtractedData();
                viewModel.SelectedThesisFile       = selectedFileInfo;
                viewModel.EnableContentFileListbox = false;
                thesisRecord.PdfTexts = "";

                PdfReaderHelper.getInstance().unload();
                string tempPdfFileName = FileUtils.CopyPdfToTemp(selectedFileInfo.FileInfo.FullName);
                loadPDF(tempPdfFileName);
                viewModel.EnableContentFileListbox = true;

                determineThesisRecord(thesisRecord);

                MainThread.getInstance().MatchingInventoryList.Clear();
                List <InventoryRecord> matchingInventoryRecords = getMatchingInventoryRecordList(thesisRecord);
                if (matchingInventoryRecords.Count > 0)
                {
                    foreach (InventoryRecord matchingRecord in matchingInventoryRecords)
                    {
                        MainThread.getInstance().MatchingInventoryList.Add(matchingRecord);
                    }
                    InventoryStore.getInstance().updateSelectedInventoryRecord(matchingInventoryRecords.First());
                }
                else
                {
                    InventoryStore.getInstance().updateSelectedInventoryRecord(null);
                }
                //markupRecordDifference();
                thesisRecord.EnableValidation = true;
                viewModel.SaveButtonEnabled   = true;
            }
            ViewModel.getInstance().ProgressPercentage += 50;
        }
Пример #2
0
        public void loadPDF(string pdfFileName)
        {
            PdfReaderHelper.getInstance().load(pdfFileName);

            string parseResult = parsePDFTexts(pdfFileName);

            parseResult = Regex.Replace(parseResult, @"([^\S\r\n]*(\r\n|\r|\n)[^\S\r\n]*(\r\n|\r|\n))+", "\n");

            bool isOCRResult = false;

            if ((parseResult == null || "".Equals(parseResult)) && ReaderConfig.getInstance().EnableOCR)
            {
                parseResult = ocrPDFTexts(pdfFileName);
                isOCRResult = true;
            }

            if (parseResult == null || "".Equals(parseResult))
            {
                alert("Failed to extract any text from file.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            ViewModel.getInstance().OcrBackColor = isOCRResult ? Color.LightBlue : Color.White;
            MainThread.getInstance().ThesisRecord.PdfTexts = parseResult;
        }
        public void run()
        {
            this.started = true;

            ViewModel.getInstance().MenuButtonEnabled = true;
            ViewModel.getInstance().SaveButtonEnabled = false;

            if (String.IsNullOrWhiteSpace(ReaderConfig.getInstance().InstanceName))
            {
                var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                for (int i = 0; i < 2; i++)
                {
                    var random = new Random();
                    ReaderConfig.getInstance().InstanceName += chars[random.Next(chars.Length)];
                    Thread.Sleep(random.Next(500));
                }
                ReaderConfig.getInstance().SaveSettings();
            }

            if (String.IsNullOrWhiteSpace(ReaderConfig.getInstance().InstanceName))
            {
                while (!PdfReaderHelper.getInstance().ContainerPanel.IsHandleCreated)
                {
                    Thread.Sleep(100);
                }
                MessageBox.Show(PdfReaderHelper.getInstance().ContainerPanel, "Please enter a unique Instance Name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                while (String.IsNullOrWhiteSpace(ReaderConfig.getInstance().InstanceName))
                {
                    Thread.Sleep(100);
                }
            }

            while (started)
            {
                string contentPath = ReaderConfig.getInstance().ContentPath;
                ViewModel.getInstance().DatabaseStatusColor = initStorage() ? SystemColors.Control : Color.Red;
                try
                {
                    if (contentPath == null || "".Equals(contentPath) || !Directory.Exists(contentPath))
                    {
                        foreach (DriveInfo drive in DriveInfo.GetDrives())
                        {
                            if (drive.DriveType == DriveType.CDRom && drive.IsReady)
                            {
                                contentPath = drive.Name;
                            }
                        }
                        if (contentPath != null && !"".Equals(contentPath) && Directory.Exists(contentPath))
                        {
                            ReaderConfig.getInstance().ContentPath = contentPath;
                            ReaderConfig.getInstance().SaveSettings();
                        }
                    }
                    if (contentPath != null && !"".Equals(contentPath) && Directory.Exists(contentPath))
                    {
                        if (readDiscContent(contentPath))
                        {
                            PdfReaderHelper.getInstance().unload();
                            ViewModel viewModel = ViewModel.getInstance();
                            viewModel.ResetView();
                            this.ThesisRecord.clearExtractedData();
                            InventoryStore.getInstance().updateSelectedInventoryRecord(null);
                            MainThread.getInstance().MatchingInventoryList.Clear();

                            FileUtils.CleanUpStaging();
                            FileUtils.CleanUpTemp();

                            DiscContentsProcessor.getInstance().process();
                        }
                    }
                }
                catch (IOException ioe)
                {
                    MessageBox.Show(PdfReaderHelper.getInstance().ContainerPanel, ioe.Message + Environment.NewLine + ioe.StackTrace, ioe.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                Thread.Sleep(1000);
            }
        }