Esempio n. 1
0
        public bool RefreshList()
        {
            listView.ItemsSource = "";
            bool               isThrow    = false;
            List <Contr>       controller = new List <Contr>();
            MyDirectory        dirs       = new MyDirectory(mainPath.Text);
            List <DiscElement> elements   = null;

            try
            {
                elements = dirs.GetSubElements();
            }
            catch
            {
                MessageBox.Show("Нет доступа");
                elements = dirs.GetSubElements();
                isThrow  = true;
            }

            foreach (var item in elements)
            {
                controller.Add(new Contr(item));
            }
            listView.ItemsSource = controller;

            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listView.ItemsSource);

            view.Filter = UserFilter;
            return(isThrow);
        }
Esempio n. 2
0
        private void DisplayFiles(string path)
        {
            //Clear the listbox first
            FileList.Items.Clear();

            //Set the current path
            currentPath      = path;
            CurrentPath.Text = path;

            try
            {
                //Initialize FileWatcher
                FileSystemWatcher watcher = new FileSystemWatcher();
                watcher.Path     = currentPath;
                watcher.Changed += new FileSystemEventHandler(OnChanged);
                watcher.Created += new FileSystemEventHandler(OnChanged);
                watcher.Deleted += new FileSystemEventHandler(OnChanged);
                watcher.Renamed += new RenamedEventHandler(OnRenamed);

                watcher.EnableRaisingEvents = true;
            } catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            //Create an DirectoryInfo object to extract child files from it
            DirectoryInfo d         = new DirectoryInfo(path);
            MyDirectory   directory = new MyDirectory(d.Name, d.FullName);

            currentList = directory.GetSubElements();

            Iterate(directory.GetSubElements());
        }
Esempio n. 3
0
        private void SearchFiles(string path, string filename)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            FileInfo[]      fileInfos      = directoryInfo.GetFiles("*" + filename + "*");
            DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories("*" + filename + "*");
            listBox.Items.Clear();
            MyDirectory        myDir      = new MyDirectory(path);
            List <DiscElement> myElements = myDir.GetSubElements();

            foreach (DirectoryInfo directory in directoryInfos)
            {
                foreach (DiscElement myElement in myElements)
                {
                    if (directory.Name == myElement.GetName())
                    {
                        DirectoryView newFolderView = new DirectoryView((MyDirectory)myElement);
                        newFolderView.DirectoryChanged += OnDirectoryChanged;
                        listBox.Items.Add(newFolderView);
                    }
                }
            }
            foreach (FileInfo file in fileInfos)
            {
                foreach (DiscElement myElement in myElements)
                {
                    if (file.Name == myElement.GetName())
                    {
                        FileView newElementView = new FileView((MyFile)myElement);
                        listBox.Items.Add(newElementView);
                    }
                }
            }
        }
Esempio n. 4
0
        public void LoadFiles(string path, bool sort)
        {
            if (!Directory.Exists(path))
            {
                MessageBox.Show("Błąd Ścieżki!");
                listBox.Items.Clear();
                return;
            }
            MyDirectory        myDir      = new MyDirectory(path);
            List <DiscElement> myElements = myDir.GetSubElements();

            listBox.Items.Clear();
            if (sort == true)
            {
                myElements = myElements.OrderBy(o => o.GetCreationTime()).ToList();
                List <DiscElement> myDirSorted  = new List <DiscElement>();
                List <DiscElement> myFileSorted = new List <DiscElement>();
                foreach (DiscElement orderingElement in myElements)
                {
                    if (orderingElement is MyDirectory)
                    {
                        myDirSorted.Add(orderingElement);
                    }
                    else
                    {
                        myFileSorted.Add(orderingElement);
                    }
                }
                myElements.Clear();
                foreach (DiscElement myDirectory in myDirSorted)
                {
                    myElements.Add(myDirectory);
                }
                foreach (DiscElement myFile in myFileSorted)
                {
                    myElements.Add(myFile);
                }
            }
            foreach (DiscElement myElement in myElements)
            {
                if (myElement is MyDirectory)
                {
                    DirectoryView newFolderView = new DirectoryView((MyDirectory)myElement);
                    newFolderView.DirectoryChanged += OnDirectoryChanged;
                    newFolderView.DirectoryDelete  += OnDeleteDirectory;
                    listBox.Items.Add(newFolderView);
                }
                else
                {
                    FileView newElementView = new FileView((MyFile)myElement);
                    newElementView.filedelete += OnDeleteClick;
                    listBox.Items.Add(newElementView);
                }
            }
        }
Esempio n. 5
0
        //public List<DiscElement> elements;
        public void RefreshList()
        {
            listView.ItemsSource = "";

            List <Contr> controller = new List <Contr>();
            MyDirectory  dirs       = new MyDirectory(mainPath.Text);

            List <DiscElement> elements = dirs.GetSubElements();

            foreach (var item in elements)
            {
                controller.Add(new Contr(item));
            }
            listView.ItemsSource = controller;

            CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(listView.ItemsSource);

            view.Filter = UserFilter;
        }