private void setImageOrImages(IEnumerable <string> filters) { if (Path != null) { int iteration = 0; string[] filtersToGo = (string[])filters; foreach (string extenction in filters) { iteration++; if (Path.EndsWith(extenction)) { try { Image.Path = Path; Image.BitmapImg = dataProvider.getBitmapFromPath(Path); Image.Size = UnitConversion.ConvertBytesToMegabytes(dataProvider.getFileSizeMb(Path)); Image.CreationDate = dataProvider.getFileCreationTime(Path); Image.LastModificationDate = dataProvider.getFileLastModificationTime(Path); Image.Name = dataProvider.getFileName(Path); } catch (System.IO.FileNotFoundException) { ShowMessageWithoutGetingResult("Please select another file.", "File not found", MessageBoxButton.OK, MessageBoxImage.Error); } catch (System.IO.FileFormatException) { ShowMessageWithoutGetingResult("Please select file with supported format.", "Wrong file format", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception e) { ShowMessageWithoutGetingResult("Unknown Error", e.Message, MessageBoxButton.OK, MessageBoxImage.Error); } break; } else if (iteration == filtersToGo.Length) { setImagesFormFolder(filtersToGo, Path); break; } } } }
private void setImagesFormFolder(string[] filters, string searchFolderPath) { Images.Clear(); try { var filePaths = dataProvider.getPathsFilesFromFolder(searchFolderPath, filters, false); for (int i = 0; i < filePaths.Length; i++) { Image image = new Image(); image.Path = filePaths[i]; image.BitmapImg = dataProvider.getBitmapFromPath(filePaths[i]); image.Size = UnitConversion.ConvertBytesToMegabytes(dataProvider.getFileSizeMb(filePaths[i])); image.CreationDate = dataProvider.getFileCreationTime(filePaths[i]); image.LastModificationDate = dataProvider.getFileLastModificationTime(filePaths[i]); image.Name = dataProvider.getFileName(filePaths[i]); Images.Add(image); } } catch (System.IO.DirectoryNotFoundException) { ShowMessageWithoutGetingResult("The directory was probably removed.", "Directory not found", MessageBoxButton.OK, MessageBoxImage.Error); } catch (System.IO.FileNotFoundException) { ShowMessageWithoutGetingResult("The file was probably removed from selected directory.", "File not found", MessageBoxButton.OK, MessageBoxImage.Error); } catch (System.IO.FileFormatException) { ShowMessageWithoutGetingResult("Please select file with supported format.", "Wrong file format", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception e) { ShowMessageWithoutGetingResult("Unknown Error", e.Message, MessageBoxButton.OK, MessageBoxImage.Error); } }