private void GenerateAndPrintCaption(ImageFile _imageFile) { try { SelectedImage.Source = _imageFile.ImageBmp; CaptionText.Text = ImageCaptioner.CaptionImage(_imageFile); Run r1 = new Run("File name: " + _imageFile.Name); string tags = "Tags: "; if (_imageFile.Tags != null) { foreach (string tag in _imageFile.Tags) { tags += tag + ", "; } tags = tags.Remove(tags.Length - 2); } Run r2 = new Run(tags); Run r3 = new Run("Location: " + _imageFile.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); MDCardCaption.Visibility = Visibility.Visible; MDCardFileInfo.Visibility = Visibility.Visible; MDCardImage.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 == ".jpg" || fileExt == ".png" || fileExt == ".bmp") { AddProperties_Button.Visibility = Visibility.Visible; } else { string message = "Unsupported file type selected: " + fileExt + "\nType must be .jpg, .bmp, or .png"; string caption = "Unsupported file type..."; System.Windows.Forms.MessageBox.Show(wf, message, caption); return; } _activeImageFile = new ImageFile(fileNames[0]); GenerateAndPrintCaption(_activeImageFile); DragAndDrop.Visibility = Visibility.Hidden; Copy_Button.Visibility = Visibility.Visible; Clear_Button.Visibility = Visibility.Visible; } else if (fileNames.Length > 1) { string overallCaption = ""; 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 (!"jpg|png|bmp".Contains(fileExt)) { continue; } _activeImageFile = new ImageFile(filePath); overallCaption += ImageCaptioner.CaptionImage(_activeImageFile); } if (overallCaption.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; } _activeImageFile = new ImageFile { Caption = overallCaption, Name = overallPath, FullPath = overallPath, Extension = null }; GenerateAndPrintCaption(_activeImageFile); } }