Example #1
0
 public SearchForm(MainForm MyParent, MyFolder folderToSearch, string mask)
 {
     InitializeComponent();
     this.folderToSearch = folderToSearch;
     this.vs             = MyParent.vs;
     this.startMask      = mask;
 }
Example #2
0
 void FillQueuesDeep(MyFolder folder)
 {
     try
     {
         if (includeDirectoryNames)
         {
             AddSingleFile(folder);
         }
         var files = folder.DirectoryGetFiles;
         var dirs  = folder.DirectoryGetFolders;
         int i     = GetIndex();
         foreach (var file in files)
         {
             Queues[i].Enqueue(file);
             i++;
             if (i == count)
             {
                 i = 0;
             }
         }
         foreach (var dir in dirs)
         {
             FillQueuesDeep(dir);
         }
     }
     catch (Exception)
     {
     }
 }
Example #3
0
        private void buttonGo_Click(object sender, EventArgs e)
        {
            string   newDir    = textBoxCurrentDir.Text;
            MyFolder newFolder = new MyFolder(newDir);

            ModelChangeDirectory(newFolder);
        }
Example #4
0
        private void explorer_ItemActivate(object sender, EventArgs e)
        {
            var items = explorer.SelectedItems;

            foreach (var item in items)
            {
                ListViewItem listItem = item as ListViewItem;
                if (listItem != null)
                {
                    if (listItem.Group.Name == "folder")
                    {
                        MyFolder folder = listItem.Tag as MyFolder;
                        ModelChangeDirectory(folder);
                    }
                    else if (listItem.Group.Name == "file")
                    {
                        try
                        {
                            MyFile file = listItem.Tag as MyFile;
                            AskModelExecuteFile(file);
                        }
                        catch (Exception exc)
                        {
                            MessageBox.Show(exc.Message + " while exectuing a file");
                        }
                    }
                    else if (listItem.Group.Name == "up")
                    {
                        ModelGoUp();
                    }
                }
            }
        }
Example #5
0
 private void AddItemToExplorer(Entry entry)
 {
     if (entry.Type == EntryType.File)
     {
         MyFile       entryAsFile = entry as MyFile;
         ListViewItem lvitem      = new ListViewItem(entryAsFile.Name, fileGroup);
         long         size        = entryAsFile.Length;
         string       sizeText    = size.ToString() + " B";
         if (size > 1024)
         {
             sizeText = size / 1024 + " KB";
         }
         lvitem.SubItems.Add(entryAsFile.FullPath);
         lvitem.SubItems.Add(sizeText);
         explorer.Items.Add(lvitem);
     }
     else if (entry.Type == EntryType.Folder)
     {
         MyFolder     entryAsFolder = entry as MyFolder;
         ListViewItem lvitem        = new ListViewItem(entryAsFolder.Name, dirGroup);
         lvitem.BackColor = vs.DirColor;
         lvitem.SubItems.Add(entryAsFolder.FullPath);
         explorer.Items.Add(lvitem);
     }
 }
 protected void FillSingleQueue(IEnumerable <string> items) //заполнение очереди
 {
     foreach (var path in items)
     {
         try
         {
             MyFile file = new MyFile(path);
             if (file.Exists)
             {
                 singleQueue.Enqueue(path);
             }
             else
             {
                 MyFolder folder = new MyFolder(path);
                 if (folder.Exists)
                 {
                     var fileList = folder.DirectoryGetFiles;
                     foreach (var f in fileList)
                     {
                         singleQueue.Enqueue(f.FullPath);
                     }
                 }
             }
         }
         catch (Exception exc)
         {
             MessageBox.Show(exc.Message);
         }
     }
     singleQueueSize = singleQueue.Count;
 }
Example #7
0
 public Model(IView view, MyFolder folder = null)
 {
     if (folder == null)
     {
         folder = Factory.GetSpecialFolder(Environment.SpecialFolder.MyDocuments);
     }
     if (!folder.Exists)
     {
         throw new MyDirectoryNotFoundException(folder.FullPath);
     }
     directoryViewerSource = new DirectoryViewerSource(folder);
     InitializateView(view);
     myWatcher = new MyWatcher(folder, false);
     myWatcher.OnFileDelete += (sender, e, path) =>
     {
         directoryViewerSource.Refresh();
         ModelChange(GetArgs());
     }; //myWatcherChange;
     myWatcher.OnFileCreate += (sender, e, path) =>
     {
         directoryViewerSource.Refresh();
         ModelChange(GetArgs());
     };
     myWatcher.OnFileModify += (sender, e, path) =>
     {
         directoryViewerSource.Refresh();
         ModelChange(GetArgs());
     };
     myWatcher.EnableRaisingEvents = true;
 }
Example #8
0
 public static void Copy(List <Entry> sourceEntries, MyFolder destDirectory)
 {
     foreach (var entry in sourceEntries)
     {
         Copy(entry, destDirectory);
     }
 }
Example #9
0
        private static void StructureView(SPFolder root, MyFolder folder, SPWeb web)
        {
            if (folder.name.Equals("Forms"))
            {
                return;
            }
            //todo files
            foreach (SPFile file in root.Files)
            {
                //name
                //parent folder name
                MyFile myFile = new MyFile(file.Name, file.ParentFolder.Name);
                folder.files.Add(myFile);
                bar.progress++;
                //bar.drawTextProgressBar(file.Name);
                bar.drawProgress(file.Name);

                if (!DownloadFile(web, file, myFile))
                {
                    notDowloaded.Add(myFile.name);
                }
            }

            foreach (SPFolder subfolder in root.SubFolders)
            {
                if (!subfolder.Name.Equals("Forms"))
                {
                    bar.progress++;
                }
                MyFolder newFolder = new MyFolder(subfolder.Name);
                folder.subFolders.Add(newFolder);
                StructureView(subfolder, newFolder, web);
            }
        }
Example #10
0
 public void ChangeDirectory(MyFolder newFolder)
 {
     try
     {
         if (newFolder.Exists)
         {
             currentDrive     = newFolder.RootDirectory;
             currentDirectory = newFolder;
             Refresh();
         }
         else
         {
             throw new MyDirectoryNotFoundException(newFolder.FullPath);
         }
     }
     catch (FileNotFoundException inner)
     {
         throw new MyFileNotFoundException(inner.Message, inner);
     }
     catch (DirectoryNotFoundException inner)
     {
         throw new MyDirectoryNotFoundException(inner.Message, inner);
     }
     catch (DriveNotFoundException inner)
     {
         throw new MyDriveNotFoundException(inner.Message, inner);
     }
     catch (UnauthorizedAccessException inner)
     {
         throw new UnauthorizedAccessException(inner.Message, inner);
     }
 }
 public override void Visit(MyFolder folder)
 {
     if (predicate(folder))
     {
         folders.Add(folder);
     }
 }
        private static void TraverseDirDFS(DirectoryInfo directory, MyFolder folder)
        {
            try
            {
                var files = directory.GetFiles();
                foreach (var file in files)
                {
                    var myFile = new MyFile(file.Name, file.Length);

                    folder.Files.Add(myFile);
                }

                var directories = directory.GetDirectories();
                foreach (var dir in directories)
                {
                    var newFolder = new MyFolder(dir.Name);

                    TraverseDirDFS(dir, newFolder);

                    folder.SubFolders.Add(newFolder);
                }
            }
            catch (UnauthorizedAccessException)
            {
                return;
            }
        }
Example #13
0
 public FindResultsViewer(MyFolder searchFolder, SearchNewElementHandler NewElementHandler, Action MaskChangeHandler, Action SearchingCompletedHandler)
 {
     this.searchFolder               = searchFolder;
     this.NewElementHandler         += NewElementHandler;
     this.MaskChangeHandler         += MaskChangeHandler;
     this.SearchingCompletedHandler += SearchingCompletedHandler;
 }
Example #14
0
 public ASyncDelegateFinding(MyFolder folder, string target = null)
 {
     this.folder = folder;
     if (target != null)
     {
         this.target = target;
     }
 }
Example #15
0
 public ParallelForEachFinding(MyFolder folder, string target = null)
 {
     this.folder = folder;
     if (target != null)
     {
         this.target = target;
     }
 }
Example #16
0
 private void OnError()
 {
     Stop();
     isWorking      = false;
     directory      = null;
     isDirectorySet = false;
     currentData    = new Dictionary <MyFile, MyFileInfo>();
 }
Example #17
0
        private MyFolder DirectoryChange()
        {
            MyFolder directorySafe = directory;

            currentData = new Dictionary <MyFile, MyFileInfo>();
            FillData(directory, currentData, deep);
            needToChangeDirectory = false;
            return(directorySafe);
        }
Example #18
0
 public ModelChangeEventArgs(MyFolder currentDirectory, MyFolder currentDrive, List <MyFolder> driveList,
                             List <MyFolder> directoryList, List <MyFile> fileList)
 {
     this.currentDirectory = currentDirectory;
     this.currentDrive     = currentDrive;
     this.driveList        = driveList;
     this.directoryList    = directoryList;
     this.fileList         = fileList;
 }
Example #19
0
 public static void Move(Entry sourceEntry, MyFolder destDirectory)
 {
     if (destDirectory.Exists)
     {
         sourceEntry.MoveToDirectory(destDirectory);
     }
     else
     {
         throw new ArgumentException("Папка назначения отсутсвует или недоступна.");
     }
 }
Example #20
0
 public AsyncAwaitFinding(IProgress <int> progress, System.Threading.CancellationTokenSource cts, Action OnCTSCancel, MyFolder folder, string target = null)
 {
     if (target != null)
     {
         this.target = target;
     }
     this.progress    = progress;
     this.cts         = cts;
     this.OnCTSCancel = OnCTSCancel;
     this.folder      = folder;
 }
Example #21
0
        //查询文件夹
        public List <MyFolder> findFolder()
        {
            string          sql    = "select distinct FolderName from db_Folder ";
            List <MyFolder> list   = new List <MyFolder>();
            SqlDataReader   reader = Util.ExecuteReader(sql);

            while (reader.Read())
            {
                folder            = new MyFolder();
                folder.Foldername = reader["FolderName"].ToString();
                list.Add(folder);
            }
            return(list);
        }
Example #22
0
 private void TV_Show_AfterSelect(object sender, TreeViewEventArgs e)
 {
     if (isFirst)
     {
         isFirst = false;
     }
     else
     {
         listView.Items.Clear();
         //MessageBox.Show("after select");
         MyFolder folder = e.Node.Tag as MyFolder;
         ShowSons(folder);
     }
 }
Example #23
0
        public void ChangeDrive(MyFolder newDrive)
        {
            DriveInfo di = new DriveInfo(newDrive.FullPath);

            if (di.IsReady)
            {
                currentDrive = newDrive;
                ChangeDirectory(newDrive);
            }
            else
            {
                throw new MyDriveNotFoundException();
            }
        }
Example #24
0
        public void ZipArchiveAddFiles()
        {
            // arrange
            MyZipArchive zipArchive = Factory.CreateZipArchive(Path.Combine
                                                                   (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".zip"));
            MyFolder folder = Factory.CreateFolder(Path.Combine
                                                       (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), Path.GetFileNameWithoutExtension(Path.GetRandomFileName())));
            string           content = "S);PFE_NWaf9fAk";
            MyFile           file1   = Factory.CreateFile(folder.FullPath + "\\document.doc"); file1.FileAppendAllText(content);
            MyFile           file2   = Factory.CreateFile(folder.FullPath + "\\documentx.docx"); file2.FileAppendAllText(content);
            MyFile           file3   = Factory.CreateFile(folder.FullPath + "\\document.html"); file3.FileAppendAllText(content);
            MyFile           file4   = Factory.CreateFile(folder.FullPath + "\\document.dot"); file4.FileAppendAllText(content);
            MyFile           file5   = Factory.CreateFile(folder.FullPath + "\\page.doc"); file5.FileAppendAllText(content);
            MyFile           file6   = Factory.CreateFile(folder.FullPath + "\\image.jpg"); file6.FileAppendAllText(content);
            HashSet <string> paths   = new HashSet <string>();

            paths.Add(file1.Name); paths.Add(file2.Name); paths.Add(file3.Name);
            paths.Add(file4.Name); paths.Add(file5.Name); paths.Add(file6.Name);

            // act
            folder.CopyToDirectory(zipArchive);
            var dirs = zipArchive.DirectoryGetFolders;

            if (dirs.Count != 1)
            {
                Assert.Fail("There is " + dirs.Count + " folders. Expected 1.");
            }
            var files = dirs[0].DirectoryGetFiles;

            if (files.Count != 6)
            {
                Assert.Fail("There is " + files.Count + " files in " + dirs[0].FullPath + ". Expected 6.");
            }
            foreach (var file in files)
            {
                if (!paths.Contains(file.Name))
                {
                    Assert.Fail(dirs[0].FullPath + "does not contain " + file.Name + ".");
                }
                else
                {
                    paths.Remove(file.Name);
                }
            }
            // удаляем используемые entry
            folder.Delete();
            zipArchive.Delete();
            // assert
            Assert.IsTrue(paths.Count == 0);
        }
Example #25
0
 public MultiQueues(int count, MyFolder folder, bool deep = false, bool includeDirectoryNames = false)
 {
     this.includeDirectoryNames = includeDirectoryNames;
     Initialize(count);
     if (deep)
     {
         FillQueuesDeep(folder);
     }
     else
     {
         FillQueues(folder);
     }
     SetCapacity();
 }
Example #26
0
 public DirectoryViewerSource(MyFolder folder = null)
 {
     if (folder == null)
     {
         folder = Factory.GetSpecialFolder(Environment.SpecialFolder.MyDocuments);
     }
     if (!folder.Exists)
     {
         throw new MyDirectoryNotFoundException(folder.FullPath);
     }
     RefreshDrives();
     currentDrive     = folder.RootDirectory;
     currentDirectory = folder;
     Refresh();
 }
Example #27
0
 public MyWatcher(MyFolder folder, bool deep = true)
 {
     if (folder.Exists)
     {
         directory = folder;
     }
     else
     {
         throw new ArgumentException("Directory " + folder.FullPath + " does not exist!");
     }
     this.deep      = deep;
     isWorking      = false;
     isDirectorySet = true;
     //Initialization();
 }
        private static void TraverseMyFolderDFS(MyFolder folder)
        {
            var folders = folder.SubFolders;
            foreach (var item in folders)
            {
                Console.WriteLine("Folder name: " + item.Name);
                TraverseMyFolderDFS(item);
            }

            var files = folder.Files;
            foreach (var item in files)
            {
                Console.WriteLine("File name: " + item.Name);
            }
        }
Example #29
0
 private void ShowSons(MyFolder folder)
 {
     foreach (MyFolder f in folder.Folders)
     {
         ListViewItem item = new ListViewItem(f.Name);
         item.Tag = f;
         listView.Items.Add(item);
     }
     foreach (MyFile file in folder.Files)
     {
         ListViewItem item = new ListViewItem(file.FileInfo.Name);
         item.Tag = file;
         listView.Items.Add(item);
     }
 }
Example #30
0
        public void ChangeDirectory(string newDir)
        {
            MyFolder newFolder = new MyFolder(newDir);

            if (newFolder.Exists)
            {
                currentDrive     = Path.GetPathRoot(newDir);
                currentDirectory = newDir;
                Refresh();
            }
            else
            {
                throw new DirectoryNotFoundException();
            }
        }
Example #31
0
        private void MergeFolders(string path1, string path2)
        {
            MyFolder folder1 = new MyFolder(path1);

            if (!folder1.Exists)
            {
                folder1.DirectoryCreate();
            }
            MyFolder folder2 = new MyFolder(path2);

            if (!folder2.Exists)
            {
                folder2.DirectoryCreate();
            }
            var files1 = folder1.DirectoryGetFiles;
            var files2 = folder2.DirectoryGetFiles;

            foreach (var file in files1) //copying path1's files to path2
            {
                var fullPath = Path.Combine(path1, file.FullPath);
                FileManager.Copy(fullPath, path2);
            }
            foreach (var file in files2) //copying path2's files to path1
            {
                var fullPath = Path.Combine(path2, file.FullPath);
                FileManager.Copy(fullPath, path1);
            }
            var dirs1 = folder1.DirectoryGetFolders;
            var dirs2 = folder2.DirectoryGetFolders;

            foreach (var dir in dirs2) // creating folders from path2 in path1
            {
                var      dirFullPath1 = Path.Combine(path1, dir.Name);
                MyFolder dir1         = new MyFolder(dirFullPath1);
                dir1.DirectoryCreate();
                var dirFullPath2 = Path.Combine(path2, dir.FullPath);
                MergeFolders(dirFullPath1, dirFullPath2);
            }
            foreach (var dir in dirs1) // creating folders from path1 in path2
            {
                var      dirFullPath2 = Path.Combine(path1, dir.Name);
                MyFolder dir2         = new MyFolder(dirFullPath2);
                dir2.DirectoryCreate();
                var dirFullPath1 = Path.Combine(path2, dir.Name);
                MergeFolders(dirFullPath2, dirFullPath1);
            }
        }
Example #32
0
        public SearchResults(string rootPath, string nameMask, ref TreeView tree, EventHandler startSearch, EventHandler <ReadFileEventArgs> finishSearch)
        {
            _findTime = new Stopwatch();
            _findTime.Start();

            _files    = new List <MyFile>();
            _root     = new MyFolder(rootPath, nameMask, ref _files, ref tree);
            _lookFor  = true;
            _stopFind = false;


            foreach (var i in _files)
            {
                i.ReadStart  += startSearch;
                i.ReadFinish += finishSearch;
            }
        }