Exemple #1
0
        private async Task <IEnumerable <Folder> > FetchFoldersAsync(Config config, string tilde, CancellationToken cancellationToken)
        {
            // If the folder is invalid for any reason, we'll ignore it.
            // Again, there's the potential for duplicate folder IDs (if the user's been fiddling their config).
            // In this case, there's nothing really sensible we can do. Just pick one of them :)
            var folderConstructionTasks = config.Folders
                                          .Where(x => String.IsNullOrWhiteSpace(x.Invalid))
                                          .DistinctBy(x => x.ID)
                                          .Select(async folder =>
            {
                var status    = await this.FetchFolderStatusAsync(folder.ID, cancellationToken);
                var syncState = FolderStateTransformer.SyncStateFromString(status.State);

                var path = folder.Path;
                // Strip off UNC prefix, if they're put it on
                if (path.StartsWith(uncPrefix))
                {
                    path = path.Substring(uncPrefix.Length);
                }
                if (path.StartsWith("~"))
                {
                    path = Path.Combine(tilde, path.Substring(1).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
                }

                return(new Folder(folder.ID, folder.Label, path, folder.IsFsWatcherEnabled, syncState, status));
            });

            cancellationToken.ThrowIfCancellationRequested();

            var folders = await Task.WhenAll(folderConstructionTasks);

            var actualFolders = folders.Where(x => x != null);

            return(actualFolders);
        }
Exemple #2
0
        private void FolderSyncStateChanged(SyncStateChangedEventArgs e)
        {
            if (!this.folders.TryGetValue(e.FolderId, out var folder))
            {
                return; // We don't know about this folder
            }
            var syncState = FolderStateTransformer.SyncStateFromString(e.SyncState);

            folder.SyncState = syncState;

            if (syncState == FolderSyncState.Syncing)
            {
                folder.ClearFolderErrors();
                this.OnFolderErrorsChanged(folder, new List <FolderError>());
            }

            this.OnSyncStateChanged(folder, FolderStateTransformer.SyncStateFromString(e.PrevSyncState), syncState);
        }