public void MethodDeSerialisation() { SerialisationProcess_Binary makeDeSerialisation = new SerialisationProcess_Binary(); Dictionary <string, string> deserializedDict = makeDeSerialisation.DoDeserialisationB(); MethodMovePic(deserializedDict); }
void StartButtonMethod() { // disable button exit during run of the process IsEnabledExitButton = false; VisibilityStopButton = Visibility.Visible; // create dictionary to put all pairs what to Move where to Move and serialize it. var MovePicDictionary = new Dictionary <string, string>(); lock (block) { // if delete files after copy is true if (StaticProp.PropCheckBoxDelete) { #region Check Box Delete = true if (StaticProp.ScanningFolderPath != "empty" && StaticProp.CreateFolderPath != "empty") { // Change TextBoxStatus TextBoxStatus = "Process Started"; // Progress bar visible ProgressBarStatusVisible = Visibility.Visible; Pathes pathing = new Pathes(StaticProp.ScanningFolderPath); String searchFolder = pathing.InitialFolderPath; var filters = new String[] { "jpg", "jpeg", "png", "gif", "tiff", "bmp", "svg" }; MethodsFromStartButton methods = new MethodsFromStartButton(); filesNames = methods.GetLongFilesFrom(searchFolder, filters, false); var filtersVideo = new String[] { "mp4", "avi", "mpg", "mpeg", "m2v", "mp2", "mpe", "mpv", "m4p", "m4v", "amv", "rmvb", "rm", "yuv", "wmv", "mov", "qt", "mng", "gifv", "ogv", "ogg", "vob", "flv", "mkv" }; filesNamesVideo = methods.GetLongFilesFrom(searchFolder, filtersVideo, false); // ProgressBarStatusMax will be only pictures ProgressBarStatusMax = filesNames.Length; // i work with video files separately // make filter for video files if (StaticProp.CheckBoxVideoSeparateFolder) { // ProgressBarStatusMax will be pictures + Video ProgressBarStatusMax = filesNames.Length + filesNamesVideo.Length; MethodCopyVideoFiles(filesNamesVideo); } foreach (string item in filesNames) { ProgressBarStatusValue++; try { using (ExifReader reader = new ExifReader(item)) { // if exif data exist (!=null) if (reader != null) { // Extract the tag data using the ExifTags enumeration DateTime datePictureTaken; if (reader.GetTagValue <DateTime>(ExifTags.DateTimeDigitized, out datePictureTaken)) { // Do whatever is required with the extracted information string messageToWriteSuccess = "The picture was taken on " + datePictureTaken.ToString(); LoggingTxtIva ll4 = new LoggingTxtIva(messageToWriteSuccess); int intmonthOfPic = (Int32)datePictureTaken.Month; string monthOfPic = "NOMonth"; StaticProp.Monthes.TryGetValue(intmonthOfPic, out monthOfPic); string yearOfPic = datePictureTaken.Year.ToString(); // making extended Pathes string extendedYearPath = StaticProp.CreateFolderPath + string.Format("\\{0}", yearOfPic); string extendedMonthPath = extendedYearPath + string.Format("\\{0}", monthOfPic); //--------------------- // check if such a year exist in the new folder if (Directory.Exists(extendedYearPath)) { //check if such a month exist in the new folder if (Directory.Exists(extendedMonthPath)) { // Copy the file string fileToCopy = item; string destinationDirectory = extendedMonthPath + "\\"; MovePicDictionary.Add(fileToCopy, destinationDirectory); //CopyMethods instanceCopy = new CopyMethods(); //instanceCopy.Move_FileNameExistsMethod(fileToCopy, destinationDirectory); } else { // if month not exist Directory.CreateDirectory(extendedMonthPath); string fileToCopy = item; string destinationDirectory = extendedMonthPath + "\\"; MovePicDictionary.Add(fileToCopy, destinationDirectory); //CopyMethods instanceCopy = new CopyMethods(); //instanceCopy.Move_FileNameExistsMethod(fileToCopy, destinationDirectory); } } else { // if year not exist Directory.CreateDirectory(extendedYearPath); Directory.CreateDirectory(extendedMonthPath); string fileToCopy = item; string destinationDirectory = extendedMonthPath + "\\"; MovePicDictionary.Add(fileToCopy, destinationDirectory); //CopyMethods instanceCopy = new CopyMethods(); //instanceCopy.Move_FileNameExistsMethod(fileToCopy, destinationDirectory); } Thread.Sleep(2); } } else { // nothing } } } catch (Exception e) // this comes in case No Exif data found { string messageToWriteFailed = "Exception happen" + e.ToString(); LoggingTxtIva ll2 = new LoggingTxtIva(messageToWriteFailed); // here i need to create directory in case Exif Data not exist messageToWriteFailed = "No Exif data in the file"; LoggingTxtIva ll5 = new LoggingTxtIva(messageToWriteFailed); string extendedNoExif = StaticProp.CreateFolderPath + "\\No_Date"; Directory.CreateDirectory(extendedNoExif); // Copy the file string fileToCopy = item; string destinationDirectory = extendedNoExif + "\\"; MovePicDictionary.Add(fileToCopy, destinationDirectory); //CopyMethods instanceCopy = new CopyMethods(); //instanceCopy.Move_FileNameExistsMethod(fileToCopy, destinationDirectory); } } // Change TextBoxStatus TextBoxStatus = "Move process Started"; } else { //if (StaticProp.ScanningFolderPath != "empty" && StaticProp.CreateFolderPath != "empty") //MessageBox.Show("You have to choose SCAN folder and NEW folder", "Help", MessageBoxButtons.OK); TextBoxStatus = "Folders not determined"; } // Serialisation Process SerialisationProcess_Binary makeSerialisation = new SerialisationProcess_Binary(); // Make Serialisation: makeSerialisation.DoSerialisationB(MovePicDictionary); Thread.Sleep(1000); // Move Process through another thread - In case it hase influence to the access of the picture source files //object toPassDict = makeDeSerialisation.DoDeserialisation(); Thread t_potok = new Thread(() => MethodDeSerialisation()); t_potok.Start(); t_potok.Join(); #endregion } else { #region In case of CheckBox Delete files after copying is False // todo change belo line back if (StaticProp.ScanningFolderPath != "empty" && StaticProp.CreateFolderPath != "empty") //if (StaticProp.ScanningFolderPath != "empty") { // Change TextBoxStatus TextBoxStatus = "Process Started"; // Progress bar visible ProgressBarStatusVisible = Visibility.Visible; Pathes pathing = new Pathes(StaticProp.ScanningFolderPath); String searchFolder = pathing.InitialFolderPath; var filters = new String[] { "jpg", "jpeg", "png", "gif", "tiff", "bmp", "svg" }; MethodsFromStartButton methods = new MethodsFromStartButton(); filesNames = methods.GetLongFilesFrom(searchFolder, filters, false); var filtersVideo = new String[] { "mp4", "avi", "mpg", "mpeg", "m2v", "mp2", "mpe", "mpv", "m4p", "m4v", "amv", "rmvb", "rm", "yuv", "wmv", "mov", "qt", "mng", "gifv", "ogv", "ogg", "vob", "flv", "mkv" }; filesNamesVideo = methods.GetLongFilesFrom(searchFolder, filtersVideo, false); // ProgressBarStatusMax will be only pictures if video not needed to copy ProgressBarStatusMax = filesNames.Length; // i work with video files separately // make filter for video files if (StaticProp.CheckBoxVideoSeparateFolder) { // ProgressBarStatusMax will be pictures + Video ProgressBarStatusMax = filesNames.Length + filesNamesVideo.Length; MethodCopyVideoFiles(filesNamesVideo); } foreach (string item in filesNames) { ProgressBarStatusValue++; try { using (ExifReader reader = new ExifReader(item)) { // if exif data exist (!=null) if (reader != null) { // Extract the tag data using the ExifTags enumeration DateTime datePictureTaken; if (reader.GetTagValue <DateTime>(ExifTags.DateTimeDigitized, out datePictureTaken)) { // Do whatever is required with the extracted information string messageToWriteSuccess = "The picture was taken on " + datePictureTaken.ToString(); LoggingTxtIva ll4 = new LoggingTxtIva(messageToWriteSuccess); int intmonthOfPic = (Int32)datePictureTaken.Month; string monthOfPic = "NOMonth"; StaticProp.Monthes.TryGetValue(intmonthOfPic, out monthOfPic); string yearOfPic = datePictureTaken.Year.ToString(); // making extended Pathes string extendedYearPath = StaticProp.CreateFolderPath + string.Format("\\{0}", yearOfPic); string extendedMonthPath = extendedYearPath + string.Format("\\{0}", monthOfPic); //--------------------- // check if such a year exist in the new folder if (Directory.Exists(extendedYearPath)) { //check if such a month exist in the new folder if (Directory.Exists(extendedMonthPath)) { // Copy the file string fileToCopy = item; string destinationDirectory = extendedMonthPath + "\\"; CopyMethods instanceCopy = new CopyMethods(); instanceCopy.Copy_FileNameExistsMethod(fileToCopy, destinationDirectory); //File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy)); } else { Directory.CreateDirectory(extendedMonthPath); string fileToCopy = item; string destinationDirectory = extendedMonthPath + "\\"; CopyMethods instanceCopy = new CopyMethods(); instanceCopy.Copy_FileNameExistsMethod(fileToCopy, destinationDirectory); //File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy)); } } else { Directory.CreateDirectory(extendedYearPath); Directory.CreateDirectory(extendedMonthPath); string fileToCopy = item; string destinationDirectory = extendedMonthPath + "\\"; CopyMethods instanceCopy = new CopyMethods(); instanceCopy.Copy_FileNameExistsMethod(fileToCopy, destinationDirectory); //File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy)); } Thread.Sleep(2); } } else { // nothing } } } catch (Exception e) // this comes if exif has no INFO { string messageToWriteFailed = "Exception happen" + e.ToString(); LoggingTxtIva ll2 = new LoggingTxtIva(messageToWriteFailed); // here i need to create directory in case Exif Data not exist messageToWriteFailed = "No Exif data in the file"; LoggingTxtIva ll5 = new LoggingTxtIva(messageToWriteFailed); string extendedNoExif = StaticProp.CreateFolderPath + "\\No_Date"; Directory.CreateDirectory(extendedNoExif); // Copy the file string fileToCopy = item; string destinationDirectory = extendedNoExif + "\\"; CopyMethods instanceCopy = new CopyMethods(); instanceCopy.Copy_FileNameExistsMethod(fileToCopy, destinationDirectory); //File.Copy(fileToCopy, destinationDirectory + Path.GetFileName("\\" + fileToCopy)); } } // Change TextBoxStatus TextBoxStatus = "Process Finished!"; } else { //MessageBox.Show("You have to choose SCAN folder and NEW folder", "Help", MessageBoxButtons.OK); // Change TextBoxStatus TextBoxStatus = "Folders not determined"; } #endregion } } // Stop button make hidden again VisibilityStopButton = Visibility.Hidden; // enable exit button when process is finished IsEnabledExitButton = true; }