public MainForm() { InitializeComponent(); this.thesisRecordBindingSource.Add(MainThread.getInstance().ThesisRecord); this.viewModelBindingSource.Add(ViewModel.getInstance()); this.readerConfigBindingSource.Add(ReaderConfig.getInstance()); this.inventoryRecordBindingSource.Add(InventoryStore.getInstance().SelectedInventoryRecord); this.fileSelectListBox.DataSource = DiscContents.getInstance().MaskedFileInfoList; this.fileSelectListBox.DisplayMember = "MaskedFileName"; this.allFileListBox.DataSource = DiscContents.getInstance().DisplayFileInfoList; this.allFileListBox.DisplayMember = "DisplayFileName"; this.inventoryMatchesComboBox.DataSource = MainThread.getInstance().MatchingInventoryList; this.inventoryMatchesComboBox.DisplayMember = "DisplayString"; ViewModel.getInstance().ProgressBar = this.progressBar; PdfReaderHelper.getInstance().ContainerPanel = this.pdfReaderPanel; Version version = Assembly.GetExecutingAssembly().GetName().Version; this.Text = Text + " - v" + version.Major + "." + version.Minor + "." + version.Build; this.chineseAbstractTextBox.KeepLineBreaks = true; this.englishAbstractTextBox.KeepLineBreaks = true; this.menuPanel.DataBindings.Add(new Binding("Visible", this.viewModelBindingSource, "ShowMenu", true, DataSourceUpdateMode.OnPropertyChanged)); this.pdfTextsTextArea.DataBindings.Add(new Binding("Visible", this.viewModelBindingSource, "ShowPdfTexts", true, DataSourceUpdateMode.OnPropertyChanged)); }
private static void OnApplicationExit(object sender, EventArgs e) { PdfReaderHelper.getInstance().unload(); DriveHelper.disconnectStorageDrive(); FileUtils.CleanUpStaging(); FileUtils.CleanUpTemp(); m.stop(); }
protected void alert(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon) { Panel msgBoxOwner = PdfReaderHelper.getInstance().ContainerPanel; if (msgBoxOwner.InvokeRequired) { msgBoxOwner.BeginInvoke((MethodInvoker) delegate() { MessageBox.Show(msgBoxOwner, text, caption, buttons, icon); }); } else { MessageBox.Show(msgBoxOwner, text, caption, buttons, icon); } }
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; }
static void Main(string[] args) { runOnce(); // Setup application icon for "Add remove programs" Application.ApplicationExit += new EventHandler(OnApplicationExit); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 1 && "reset".Equals(args[0])) { ReaderConfig config = ReaderConfig.getInstance(); config.ContentPath = args[1]; config.PythonPath = @"lib\WinPython\python\python.exe"; config.PdfminerPath = @"lib\WinPython\python\Scripts\pdf2txt.py"; config.UseAdobeReader = true; config.EnableOCR = false; config.GhostscriptPath = @"lib\Ghostscript\bin\gswin32.exe"; config.TesseractPath = @"lib\Tesseract-ocr\tesseract.exe"; config.DBPath = @"Y:\rsdiconversion\db\ethesis2016.db3"; config.StoragePath = @"Y:\rsdiconversion\contents"; config.SaveSettings(); } Form mainForm = new MainForm(); // Initialize PDF viewer component PdfReaderHelper.getInstance().init(ReaderConfig.getInstance().UseAdobeReader); // Map network drive DriveHelper.connectStorageDrive(); // Start file monitor thread Thread readCDThread = new Thread(new ThreadStart(m.start)); readCDThread.SetApartmentState(ApartmentState.STA); readCDThread.Start(); Application.Run(mainForm); }
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); } }