コード例 #1
0
ファイル: Synchronize.cs プロジェクト: qdraw/starsky
        public async Task <List <FileIndexItem> > Sync(string subPath, bool recursive = true,
                                                       ISynchronize.SocketUpdateDelegate updateDelegate = null)
        {
            // Prefix / for database
            subPath = PathHelper.PrefixDbSlash(subPath);
            if (subPath != "/")
            {
                subPath = PathHelper.RemoveLatestSlash(subPath);
            }

            if (FilterCommonTempFiles.Filter(subPath) || _syncIgnoreCheck.Filter(subPath))
            {
                return(FilterCommonTempFiles.DefaultOperationNotSupported(subPath));
            }

            _console.WriteLine($"[Synchronize] Sync {subPath} {DateTimeDebug()}");

            // ReSharper disable once ConvertSwitchStatementToSwitchExpression
            switch (_subPathStorage.IsFolderOrFile(subPath))
            {
            case FolderOrFileModel.FolderOrFileTypeList.Folder:
                return(await _syncFolder.Folder(subPath, updateDelegate));

            case FolderOrFileModel.FolderOrFileTypeList.File:
                var item = await _syncSingleFile.SingleFile(subPath, updateDelegate);

                return(new List <FileIndexItem> {
                    item
                });

            case FolderOrFileModel.FolderOrFileTypeList.Deleted:
                return(await _syncRemove.Remove(subPath));

            default:
                throw new AggregateException("enum is not valid");
            }
        }
コード例 #2
0
        internal async Task CompareFolderListAndFixMissingFolders(List <string> subPaths, List <FileIndexItem> folderList)
        {
            if (subPaths.Count == folderList.Count)
            {
                return;
            }

            foreach (var path in subPaths.Where(path => folderList.All(p => p.FilePath != path) &&
                                                _subPathStorage.ExistFolder(path) && !_syncIgnoreCheck.Filter(path)))
            {
                await _query.AddItemAsync(new FileIndexItem(path)
                {
                    IsDirectory   = true,
                    AddToDatabase = DateTime.UtcNow,
                    ColorClass    = ColorClassParser.Color.None
                });
            }
        }