private void GenerateAndPrintSummary(TextFile textFile) { try { string summaryText = Summarizer.SummarizeByLSA(textFile); textFile.Summary = summaryText; SummaryText.Text = summaryText; string documentConcepts = ""; foreach (string s in textFile.DocumentConcepts) { documentConcepts += s + ", "; } Run r1 = new Run("File name: " + textFile.Name); Run r2 = new Run("Concepts: " + documentConcepts.Remove(documentConcepts.Length - 2)); Run r3 = new Run("Location: " + textFile.FullPath); FileInfo.Inlines.Clear(); FileInfo.Inlines.Add(r1); FileInfo.Inlines.Add(new LineBreak()); FileInfo.Inlines.Add(r2); FileInfo.Inlines.Add(new LineBreak()); FileInfo.Inlines.Add(r3); MDCardSummary.Visibility = Visibility.Visible; MDCardFileInfo.Visibility = Visibility.Visible; } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void ProcessSelectedFiles(string[] fileNames) { /* * Handle improper file types */ Form wf = new Form() { Size = new System.Drawing.Size(0, 0) }; Task.Delay(TimeSpan.FromSeconds(7)) .ContinueWith((t) => wf.Close(), TaskScheduler.FromCurrentSynchronizationContext()); if (fileNames.Length == 1) { string fileExt = System.IO.Path.GetExtension(fileNames[0]); if (fileExt == ".docx" || fileExt == ".odt" || fileExt == ".pdf") { AddProperties_Button.Visibility = Visibility.Visible; } else if (fileExt == ".txt" /* Txt file properties cannot be updated */) { AddProperties_Button.Visibility = Visibility.Hidden; } else { string message = "Unsupported file type selected: " + fileExt + "\nType must be .docx, .pdf, .odt, or .txt"; string caption = "Unsupported file type..."; System.Windows.Forms.MessageBox.Show(wf, message, caption); return; } _activeTextFile = new TextFile(fileNames[0]); _activeTextFile.DesiredSummaryLength = _desiredSummaryLength; GenerateAndPrintSummary(_activeTextFile); Regen_Button.Visibility = Visibility.Visible; DragAndDrop.Visibility = Visibility.Hidden; Copy_Button.Visibility = Visibility.Visible; Clear_Button.Visibility = Visibility.Visible; } else if (fileNames.Length > 1) { string overallSummary = ""; string overallPath = System.IO.Path.GetDirectoryName(fileNames[0]); foreach (string filePath in fileNames) { string fileExt = ""; try { fileExt = System.IO.Path.GetExtension(filePath); } catch (Exception ex) { Console.WriteLine(ex.Message); } // Handle invalid file types if (!"docx|odt|pdf|txt".Contains(fileExt)) { continue; } _activeTextFile = new TextFile(filePath); overallSummary += Summarizer.SummarizeByLSA(_activeTextFile); } if (overallSummary.Length == 0) { string message = "No supported file types were selected. " + "\nType must be .docx, .pdf, .odt, or .txt"; string caption = "Unsupported file types..."; System.Windows.Forms.MessageBox.Show(wf, message, caption); return; } _activeTextFile = new TextFile { RawText = overallSummary, Name = overallPath, FullPath = overallPath, Extension = null }; GenerateAndPrintSummary(_activeTextFile); } }