Exemple #1
0
        public void save()
        {
            ViewModel.getInstance().ProgressBarColor = Color.Green;
            ViewModel.getInstance().ProgressBar.Maximum = 100;
            ThesisRecord record = MainThread.getInstance().ThesisRecord;

            if (!validateInput(record))
            {
                return;
            }

            ViewModel.getInstance().AllowInput(false);
            ViewModel.getInstance().MenuButtonEnabled = false;

            record.RecordId         = DBEtdRecords.generateRecordId();
            record.FilePath         = record.RecordId + ".zip";
            record.FullTextFilePath = record.RecordId + ".pdf";

            string storageFolderPath = ReaderConfig.getInstance().StoragePath;

            if (!storageFolderPath.EndsWith(@"\"))
            {
                storageFolderPath += @"\";
            }
            record.StorageFolderPath = storageFolderPath;

            FileUtils.CopyZipToStorage();
        }
Exemple #2
0
        public void fileCopySuccess()
        {
            ThesisRecord record = MainThread.getInstance().ThesisRecord;

            record.CreateDate = DateTime.Now;

            List <ThesisRecord> recordList = new List <ThesisRecord>();

            recordList.Add(record);
            int rowsInserted = DBEtdRecords.insertEtdRecords(recordList);

            if (rowsInserted == 1)
            {
                ViewModel.getInstance().ProgressBarColor = Color.Green;
                alert("Thesis record saved successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ViewModel.getInstance().MenuButtonEnabled = true;
            }
            else
            {
                string archiveFilePath  = record.StorageFolderPath + record.FilePath;
                string fullTextFilePath = record.StorageFolderPath + record.FullTextFilePath;
                if (File.Exists(archiveFilePath))
                {
                    File.Delete(archiveFilePath);
                }
                if (File.Exists(fullTextFilePath))
                {
                    File.Delete(fullTextFilePath);
                }
                ViewModel.getInstance().ProgressBarColor = Color.Red;
                alert("Failed to insert record into database!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ViewModel.getInstance().AllowInput(true);
                ViewModel.getInstance().MenuButtonEnabled = true;
            }
        }
Exemple #3
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;
        }
Exemple #4
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);
            }
        }