private ViewModelBase()
        {
            // read all lines from txt file and put it to List<string>
            List <string> EmptyList = new List <string> {
            };
            LoggingTxtIva ll0       = new LoggingTxtIva(EmptyList);


            TextBoxGenShow            = "No Pictures choosen";
            TextBoxNewFolder          = StaticProp.initTextBoxNewFolder;
            TextBoxScanFolder         = StaticProp.initTextBoxScanFolder;
            ProgressBarStatusVisible  = Visibility.Hidden;
            IsEnabledOpenFolderButton = false;
            IsEnabledExitButton       = true;
            VisibilityStopButton      = Visibility.Hidden;
        }
        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;
        }
Exemple #3
0
        public void MethodCopyVideoFiles(string[] filesVideoCollected)
        {
            // in case check box Video As Well to separate Folder is true
            if (StaticProp.CheckBoxVideoSeparateFolder == true)
            {
                // in case check box Delete files after copy is true
                if (StaticProp.PropCheckBoxDelete)
                {
                    foreach (string item in filesVideoCollected)
                    {
                        // to increase ProgressStatusBarValue
                        ProgressBarStatusValue++;

                        try
                        {
                            // making extended Pathes
                            string extendedFolderForVideo = StaticProp.CreateFolderPath + string.Format("\\{0}", "Video_Files");
                            //---------------------
                            // check if such a folder exist
                            if (File.Exists(extendedFolderForVideo))
                            {
                                // Copy the file
                                string fileToCopy           = item;
                                string destinationDirectory = extendedFolderForVideo + "\\";

                                // method to movefiles but also to check if such a file already exist
                                Move_FileNameExistsMethod(fileToCopy, destinationDirectory);
                            }
                            else
                            {
                                Directory.CreateDirectory(extendedFolderForVideo);
                                string fileToCopy           = item;
                                string destinationDirectory = extendedFolderForVideo + "\\";

                                // method to movefiles but also to check if such a file already exist
                                Move_FileNameExistsMethod(fileToCopy, destinationDirectory);

                                //File.Move(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy));
                                //Thread.Sleep(200);
                            }
                        }
                        catch (Exception e)
                        {
                            string        messageToWriteFailed = "Exception happen" + e.ToString();
                            LoggingTxtIva ll6 = new LoggingTxtIva(messageToWriteFailed);
                        }
                    }
                }
                else
                {
                    // in case check box Delete files after copy is False
                    foreach (string item in filesVideoCollected)
                    {
                        // to increase ProgressBarStatusValue

                        ProgressBarStatusValue++;
                        try
                        {
                            // making extended Pathes
                            string extendedFolderForVideo = StaticProp.CreateFolderPath + string.Format("\\{0}", "Video_Files");
                            //---------------------
                            // check if such a folder exist
                            if (File.Exists(extendedFolderForVideo))
                            {
                                // Copy the file
                                string fileToCopy           = item;
                                string destinationDirectory = extendedFolderForVideo + "\\";

                                // method to copy files but also to check if such a file already exist
                                Copy_FileNameExistsMethod(fileToCopy, destinationDirectory);

                                //File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy));
                            }
                            else
                            {
                                // Copy the file
                                Directory.CreateDirectory(extendedFolderForVideo);
                                string fileToCopy           = item;
                                string destinationDirectory = extendedFolderForVideo + "\\";
                                // method to copy files but also to check if such a file already exist
                                Copy_FileNameExistsMethod(fileToCopy, destinationDirectory);

                                //File.Copy(fileToCopy, destinationDirectory + Path.GetFileName(fileToCopy));
                            }
                        }
                        catch (Exception e)
                        {
                            string        messageToWriteFailed = "Exception happen" + e.ToString();
                            LoggingTxtIva ll6 = new LoggingTxtIva(messageToWriteFailed);
                        }
                    }
                }
            }
            else
            {
                // in case check box Move Video Files to separate Folder is False
                LoggingTxtIva ll6 = new LoggingTxtIva("check box Move Video Files to separate Folder is False");
            }
        }