예제 #1
0
        private async Task SyncFoldersAsync(IDictionary <string, CipherResponse> serverFolders)
        {
            if (!_authService.IsAuthenticated)
            {
                return;
            }

            var localFolders = (await _folderRepository.GetAllByUserIdAsync(_authService.UserId).ConfigureAwait(false))
                               .ToDictionary(f => f.Id);

            foreach (var serverFolder in serverFolders)
            {
                if (!_authService.IsAuthenticated)
                {
                    return;
                }

                try
                {
                    var data = new FolderData(serverFolder.Value, _authService.UserId);
                    await _folderRepository.UpsertAsync(data).ConfigureAwait(false);
                }
                catch (SQLite.SQLiteException) { }
            }

            foreach (var folder in localFolders.Where(localFolder => !serverFolders.ContainsKey(localFolder.Key)))
            {
                try
                {
                    await _folderRepository.DeleteAsync(folder.Value.Id).ConfigureAwait(false);
                }
                catch (SQLite.SQLiteException) { }
            }
        }
예제 #2
0
        public async Task <IEnumerable <Folder> > GetAllAsync()
        {
            var data = await _folderRepository.GetAllByUserIdAsync(_authService.UserId);

            var folders = data.Select(f => new Folder(f));

            return(folders);
        }
예제 #3
0
        private async Task SyncFoldersAsync(IDictionary <string, CipherResponse> serverFolders, bool deleteMissing)
        {
            if (!_authService.IsAuthenticated)
            {
                return;
            }

            var localFolders = (await _folderRepository.GetAllByUserIdAsync(_authService.UserId).ConfigureAwait(false))
                               .ToDictionary(f => f.Id);

            foreach (var serverFolder in serverFolders)
            {
                if (!_authService.IsAuthenticated)
                {
                    return;
                }

                var existingLocalFolder = localFolders.ContainsKey(serverFolder.Key) ? localFolders[serverFolder.Key] : null;
                if (existingLocalFolder == null)
                {
                    var data = new FolderData(serverFolder.Value, _authService.UserId);
                    await _folderRepository.InsertAsync(data).ConfigureAwait(false);
                }
                else if (existingLocalFolder.RevisionDateTime != serverFolder.Value.RevisionDate)
                {
                    var data = new FolderData(serverFolder.Value, _authService.UserId);
                    await _folderRepository.UpdateAsync(data).ConfigureAwait(false);
                }
            }

            if (!deleteMissing)
            {
                return;
            }

            foreach (var folder in localFolders.Where(localFolder => !serverFolders.ContainsKey(localFolder.Key)))
            {
                await _folderRepository.DeleteAsync(folder.Value.Id).ConfigureAwait(false);
            }
        }