Exemplo n.º 1
0
 internal async Task FilesDropAsync(DragEventArgs e)
 {
     try
     {
         main.Dispatcher.Invoke(() =>
         {
             main.lblInfo.Content     = "Поиск файлов";
             main.btnBrowse.IsEnabled = false;
             main.btnStart.IsEnabled  = false;
             main.btnCancel.IsEnabled = true;
         });
         cts = new CancellationTokenSource();
         string[] paths = (string[])e.Data.GetData(DataFormats.FileDrop, true);
         await SearchOps.FilterFilesAsync(files, paths, searchPattern, cts.Token)
         .ContinueWith(n => SearchComplete());
     }
     catch (OperationCanceledException ex)
     {
     }
 }
Exemplo n.º 2
0
        //internal async Task FileBrowseAsync()
        //{
        //    try
        //    {
        //        var vfbd = new VistaFolderBrowserDialog { SelectedPath = path, Description = "Выберите папку", ShowNewFolderButton = false };
        //        if (vfbd.ShowDialog() == true)
        //        {
        //            main.Dispatcher.Invoke(() =>
        //                                   {
        //                                       main.lblInfo.Content = "Поиск файлов";
        //                                       main.btnBrowse.IsEnabled = false;
        //                                       main.btnStart.IsEnabled = false;
        //                                       main.btnCancel.IsEnabled = true;
        //                                   });
        //            cts = new CancellationTokenSource();
        //            path = vfbd.SelectedPath;
        //            main.lblInfo.Content = path;
        //            di = new DirectoryInfo(path);
        //            await SearchOps.FilterFilesAsync(files, new[] { path }, searchPattern, cts.Token).ContinueWith(n => SearchComplete());
        //        }

        //    }
        //    catch (OperationCanceledException ex){}
        //}

        internal async Task FileBrowseAsync()
        {
            try
            {
                var dlg = new CommonOpenFileDialog
                {
                    Title                     = "Выберите папку",
                    IsFolderPicker            = true,
                    InitialDirectory          = di.FullName,
                    AddToMostRecentlyUsedList = false,
                    AllowNonFileSystemItems   = false,
                    DefaultDirectory          = di.FullName,
                    EnsureFileExists          = true,
                    EnsurePathExists          = true,
                    EnsureReadOnly            = false,
                    EnsureValidNames          = true,
                    Multiselect               = false,
                    ShowPlacesList            = true
                };
                if (dlg.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    main.Dispatcher.Invoke(() =>
                    {
                        main.lblInfo.Content     = "Поиск файлов";
                        main.btnBrowse.IsEnabled = false;
                        main.btnStart.IsEnabled  = false;
                        main.btnCancel.IsEnabled = true;
                    });
                    cts  = new CancellationTokenSource();
                    path = dlg.FileName;
                    main.lblInfo.Content = path;
                    di = new DirectoryInfo(path);
                    await SearchOps.FilterFilesAsync(files, new[] { path }, searchPattern, cts.Token)
                    .ContinueWith(n => SearchComplete());
                }
            }
            catch (OperationCanceledException ex)
            {
            }
        }