private void ReloadDriveInfos()
        {
            var usbDrives = UsbDriveListProvider.GetAllRemovableDrives();

            Application.Current.Dispatcher.Invoke(() =>
            {
                DriveInfos.Clear();

                foreach (var usbDrive in usbDrives)
                {
                    DriveInfos.Add(usbDrive);
                }
                UsbDriveCount = DriveInfos.Count;
                RaisePropertyChanged("UsbDriveCount");
                RaisePropertyChanged("DriveInfos");
            });
        }
Ejemplo n.º 2
0
        //private readonly System.Threading.Timer timer = null;
        //private int periodTimer = 1000;

        //void TimerCallback(object state)
        //{
        //    Application.Current.Dispatcher.Invoke(() =>
        //    {
        //        int count = Swatches.Count;
        //        SelectedSwatchPrimaryColor = Swatches[new Random().Next(0, count)];
        //    });

        //}



        public MainWindowViewModel()
        {
            //timer = new System.Threading.Timer(new TimerCallback(TimerCallback), null, Timeout.Infinite, periodTimer);

            OpenFileCommand                   = new ActionCommand(OpenFileCommandExecute, OpenFileCommandCanExecute);
            OpenFolderCommand                 = new ActionCommand(OpenFolderCommandExecute, OpenFolderCommandCanExecute);
            DropDownDisksOpenedCommand        = new ActionCommand(DropDownDisksOpenedCommandExecute);
            StartSearchCommand                = new ActionCommand(StartSearchCommandExecute, StartSearchCommandCanExecute);
            StopSearchCommand                 = new ActionCommand(StopSearchCommandExecute, StopSearchCommandCanExecute);
            ShowHelpTypeMultithreadingCommand = new ActionCommand(ShowHelpTypeMultithreadingCommandExecute);
            ClosingWindowCommand              = new ActionCommand(ClosingWindowCommandExecute);

            //разрешает доступ к коллекции из разных потоков
            BindingOperations.EnableCollectionSynchronization(FilesCollection, lockerCollection);

            TypesMultiThreading.Add(new SearchManagerThread());
            TypesMultiThreading.Add(new SearchManagerThreadPool());
            TypesMultiThreading.Add(new SearchManagerTask());

            for (var i = 0; i < TypesMultiThreading.Count; ++i)
            {
                var s = TypesMultiThreading[i];

                s.eventNewFileFinded         += SearchTechnology_eventNewFileFinded;
                s.eventWorkingThreadsChanged += SearchTechnology_eventWorkingThreadsChanged;
                typesMultiThreadingStrings[i] = s.Name;
            }
            SearchTechnology = TypesMultiThreading.Last();

            MaxCountThreadsStr  = "100";
            CurrentState        = "Настройте поиск и нажмите Найти";
            CountWorkingThreads = 0;



            //определение расширений разных типов файлов
            FileExtensionAssociation textFiles = new FileExtensionAssociation()
            {
                Name       = "Текстовые файлы",
                Extensions = ".txt .docx .doc .rtf .pdf .cpp .h .cs .log .ini .cfg .lst .xml .html .text .yml .utf8"
            };
            FileExtensionAssociation audioFiles = new FileExtensionAssociation()
            {
                Name       = "Аудиофайлы",
                Extensions = ".mp3 .wav .aac .ogg .mp2 .mp1 "
            };
            FileExtensionAssociation videoFiles = new FileExtensionAssociation()
            {
                Name       = "Видеофайлы",
                Extensions = ".mp4 .mp2 .mpg .wmv .mpeg .avi .mpeg4 .mkv .flv .mov .webm .mpeg1 .3gp .3gpp .3gpp2 .h264 .swf"
            };
            FileExtensionAssociation pictureFiles = new FileExtensionAssociation()
            {
                Name       = "Изображения",
                Extensions = ".jpg .jpeg .png .gif .bmp .tiff .webp .psd .nrw"
            };
            FileExtensionAssociation applicationFiles = new FileExtensionAssociation()
            {
                Name       = "Приложения",
                Extensions = ".exe .msi .bat .cmd .ps1 .vbe .vbs"
            };
            FileExtensionAssociation archiveFiles = new FileExtensionAssociation()
            {
                Name       = "Архивы",
                Extensions = ".rar .zip .7z .zip .gzip .tar .tgz .xz .bz2 .z"
            };

            //добавление расширений в коллекцию
            FileExtensionAssociations.Add(textFiles);
            FileExtensionAssociations.Add(audioFiles);
            FileExtensionAssociations.Add(videoFiles);
            FileExtensionAssociations.Add(pictureFiles);
            FileExtensionAssociations.Add(applicationFiles);
            FileExtensionAssociations.Add(archiveFiles);


            //получение и добавление разделов дисков
            foreach (var disk in DriveInfo.GetDrives())
            {
                DriveInfos.Add(disk);
            }
            if (DriveInfos.Count > 0)
            {
                SelectedDrive = DriveInfos[0];
            }


            Swatches = new ObservableCollection <Swatch>(new SwatchesProvider().Swatches);

            LoadOptions();


            //SelectedSwatchPrimaryColor = Swatches.Where(s => s.Name == "blue").Single();
        }