Esempio n. 1
0
 public static void AddItemToCollection(ObservableCollection<DirectoryModel> collection, DirectoryModel item)
 {
     if (collection != null)
         GUIDispatcher.Invoke((Action)(() => { collection.Add(item); }));
 }
Esempio n. 2
0
 public ForegroundOrganiser(DirectoryModel rootDirectory)
     : base()
 {
     base._rootDirectory = rootDirectory;
 }
Esempio n. 3
0
        /// <summary>
        /// Iterates through all files, in all chosen directories, and calls
        /// method to create FilesInfo object for each, which is then added to
        /// //_filesToMove list.
        /// </summary>
        /// <param name="totalFileSize">Value used to calculate total size
        ///  of all files, this value is then used to calculate progress of
        ///  organistion and state of progress bar passed from GUI.</param>
        void GetFileObjects(DirectoryModel directory, ref long totalFileSize)
        {
            if (directory.IsChecked)
            {
                try
                {
                    string[] fileArray = Directory.GetFiles(directory.Path);

                    foreach (string file in fileArray)
                    {
                        string fileType = Path.GetExtension(file);

                        /// Check that current file has filetype, if it does not
                        /// file it under "FILE" for the purposes of organisation.
                        if (fileType.Length > 0)
                        {
                            fileType = fileType.Substring(1);
                        }
                        else
                        {
                            fileType = "FILE";
                        }

                        foreach (string s in _selectedFileTypes)
                        {
                            Console.WriteLine(fileType + " - " + s);
                        }

                        /// Check that user has selected any filetypes to filter to
                        /// and that the current file is of one of these types.
                        /// If there are no filters chosen, or the previous two states
                        /// evaluate as true, create a FilesInfo object for the file.
                        if (_selectedFileTypes.Count > 0)
                        {
                            if (_selectedFileTypes.Contains(fileType))
                            {
                                CreateFileObject(file, fileType, ref totalFileSize);
                            }
                        }
                        else
                        {
                            CreateFileObject(file, fileType, ref totalFileSize);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //TO DO
                }
            }

            if (_organiseSubDirectories && directory.Subdirectories.Count > 0)
            {
                foreach (DirectoryModel subdirectory in directory.Subdirectories)
                {
                    GetFileObjects(subdirectory, ref totalFileSize);
                }
            }
        }
Esempio n. 4
0
        public DirectoryModel CreateAndAddSubdirectory(string path)
        {
            DirectoryModel subdirectory = new DirectoryModel();
            subdirectory.Path = path;
            GUIDispatcherUpdates.AddItemToCollection(Subdirectories, subdirectory);

            return subdirectory;
        }
Esempio n. 5
0
        /// <summary>
        /// Traverse root directory's subdirectories to ascertain directory tree structure,
        /// also gather available filetype data.
        /// </summary>
        /// <param name="directory"> Directory to be traversed.</param>
        /// <param name="availableFileTypes"> List to be populated with all filetypes in directories</param>
        /// <param name="directory"> Directory to be traversed.</param>
        public static void TraverseDirectories(DirectoryModel directory, ObservableCollection<string> availableFileTypes = null)
        {
            directory.Name = System.IO.Path.GetFileName(directory.Path);

            try
            {
                // List of subdirectories and filetypes in the current directory.
                string[] dirs = Directory.GetDirectories(directory.Path, "*", SearchOption.TopDirectoryOnly);

                if (availableFileTypes != null)
                {
                    string[] files = Directory.GetFiles(directory.Path);

                    OrganiserBase.PopulateFileTypes(files, availableFileTypes);
                }

                if (dirs.Count() > 0)
                {
                    foreach (string dir in dirs)
                    {
                        // Traverse each subdirectory contained in current directory then
                        // add to directories subdirectory list

                        DirectoryModel childDirectory = directory.CreateAndAddSubdirectory(dir);

                        OrganiserBase.TraverseDirectories(childDirectory, availableFileTypes);
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }