Пример #1
0
        public Task ScanForLocalRepositoriesAsync()
        {
            Scanning = true;
            OnScanStateChanged?.Invoke(this, Scanning);

            int scannedPaths = 0;

            var paths = _pathProvider.GetPaths();

            var tasks = paths.Select(path =>
            {
                return(Task.Run(() => _pathCrawlerFactory.Create().Find(path, "HEAD", OnFoundNewRepository, null))
                       .ContinueWith(t => scannedPaths++)
                       .ContinueWith(t =>
                {
                    bool newScanningState = (scannedPaths < paths.Length);
                    bool didChange = newScanningState != Scanning;
                    Scanning = newScanningState;

                    if (didChange)
                    {
                        OnScanStateChanged?.Invoke(this, Scanning);
                    }
                }));
            });

            return(Task.WhenAll(tasks));
        }