Esempio n. 1
0
        //public delegate void DoSomething(int a); ==Action<int>
        //public delegate int DoSomething(int a); ==Func<int, int>

        //FileSystemVisitor(FileSystemBlaBla fs)
        //{
        //    this.fs = fs;
        //}

        public List <string> GetFiles(Func <FileSystemInfo, bool> condition, FileSystemInfo dirFiles)
        {
            var result = new List <string>();

            //logic for looping through files
            try
            {
                OnSearchStart?.Invoke("Search has started");
                foreach (string d in Directory.GetDirectories(dirFiles.ToString()))
                {
                    if (Stop)
                    {
                        return(result);
                    }
                    var dir = new DirectoryInfo(d);
                    if (condition(dir))
                    {
                        if (!Exclude)
                        {
                            result.Add(d);
                        }
                        Exclude = false;
                        OnDirectoryFound?.Invoke(dir);
                    }
                    var r = GetFiles(d => condition(d), dir);
                    result.AddRange(r);
                }
                foreach (string f in Directory.GetFiles(dirFiles.ToString()))
                {
                    if (Stop)
                    {
                        return(result);
                    }
                    var fi = new FileInfo(f);
                    if (condition(fi))
                    {
                        if (!Exclude)
                        {
                            result.Add(f);
                        }
                        OnFileFound?.Invoke(fi);
                    }
                }
            }
            catch (System.Exception excpt)
            {
                Console.WriteLine(excpt.Message);
            }
            OnSearchFinish?.Invoke("Search has finished");
            return(result);
        }
Esempio n. 2
0
        protected override void OnQueryChanged(string oldValue, string newValue)
        {
            base.OnQueryChanged(oldValue, newValue);

            if (string.IsNullOrWhiteSpace(newValue))
            {
                ItemsSource = null;
            }
            else
            {
                if (newValue.Trim().Length >= 3)
                {
                    // Cancels the current execution
                    if (cancellationTokenSource != null)
                    {
                        cancellationTokenSource.Cancel();
                    }

                    cancellationTokenSource = new CancellationTokenSource();

                    Task.Run(async() =>
                    {
                        var token = cancellationTokenSource.Token;
                        await Task.Delay(SearchDelay);

                        if (!token.IsCancellationRequested)
                        {
                            OnSearchStart?.Invoke();
                            ItemsSource = await LynxDependencyService.Get <ITasqR>()
                                          .UsingAsHandler <GetBillPaymentStepsTemplatesQrHandler_API>()
                                          .RunAsync(new GetBillPaymentStepsTemplatesQr(3, newValue.Trim()), token);
                            OnSearchEnd?.Invoke();
                        }
                    }, cancellationTokenSource.Token);
                }
            }
        }