Example #1
0
 public void FilterFiles()
 {
     FilesTree.BeginUpdate();
     try
     {
         ICollection <FileContainer> data = MappedData.Data.OfType <FileContainer>().ToArray();
         try
         {
             var expr = string.IsNullOrWhiteSpace(ActiveFilter) ? null : new Regex(ActiveFilter, _CaseInsensitiveFileSearch ? RegexOptions.IgnoreCase : RegexOptions.None, new TimeSpan(0, 0, 1));
             foreach (var f in data)
             {
                 f.Visible = (!_MappedOnly || f.IsMapped) &&
                             (!_CyrilicOnly || f.CyrilicCount > 0) &&
                             (!LetterOnly || f.ContainsLiteral()) &&
                             (expr == null || expr.IsMatch(f.Name));
             }
         }
         catch (Exception e)
         {
             Helpers.ConsoleWrite(e.ToString(), ConsoleColor.Blue);
         }
     }
     finally
     {
         FilesTree.EndUpdate();
     }
 }
Example #2
0
        void AddFiles(ICollection <string> files, Action <string, int> callback = null)
        {
            EditingEnabled = false;
            var cts = new CancellationTokenSource();

            FilesTree.BeginUpdate();
            try
            {
                callback?.Invoke(null, files.Count);
                int    cnt         = 0;
                string currentFile = string.Empty;
                Task.Run(() => {
                    while (!cts.IsCancellationRequested)
                    {
                        Task.Delay(1000);
                        callback?.Invoke(currentFile, cnt);
                    }
                });
                //System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
                //w.Start();
                foreach (var f in files)
                {
                    currentFile = f;
                    ++cnt;
                    FilesTree.AddFile(f);
                }
                //w.Stop();
            }
            finally
            {
                cts.Cancel();
                FilesTree.EndUpdate();
                EditingEnabled = true;
                FilterFiles();
                GC.Collect();
            }
        }