private async Task EnsureData(CancellationToken cancellationToken) { if (_items == null) { try { using (var stream = await _provider.GetFile(GetRemotePath(), _target, new Progress <double>(), cancellationToken)) { _items = _json.DeserializeFromStream <List <LocalItem> >(stream); } } catch (FileNotFoundException) { _items = new List <LocalItem>(); } catch (DirectoryNotFoundException) { _items = new List <LocalItem>(); } using (var memoryStream = new MemoryStream()) { _json.SerializeToStream(_items, memoryStream); // Now cache it memoryStream.Position = 0; await CacheData(memoryStream).ConfigureAwait(false); } } }
private async Task <List <LocalItem> > RetrieveItems(CancellationToken cancellationToken) { _logger.Debug("Getting {0} from {1}", string.Join(MediaSync.PathSeparatorString, GetRemotePath().ToArray()), _provider.Name); await _remoteDataLock.WaitAsync(cancellationToken).ConfigureAwait(false); try { var fileResult = await _provider.GetFiles(GetRemotePath().ToArray(), _target, cancellationToken).ConfigureAwait(false); if (fileResult.Items.Length > 0) { using (var stream = await _provider.GetFile(fileResult.Items[0].FullName, _target, new Progress <double>(), cancellationToken)) { return(_json.DeserializeFromStream <List <LocalItem> >(stream)); } } } finally { _remoteDataLock.Release(); } return(new List <LocalItem>()); }
private async Task EnsureData(CancellationToken cancellationToken) { if (_items == null) { _logger.Debug("Getting {0} from {1}", string.Join(MediaSync.PathSeparatorString, GetRemotePath().ToArray()), _provider.Name); var fileResult = await _provider.GetFiles(new FileQuery { FullPath = GetRemotePath().ToArray() }, _target, cancellationToken).ConfigureAwait(false); if (fileResult.Items.Length > 0) { using (var stream = await _provider.GetFile(fileResult.Items[0].Id, _target, new Progress<double>(), cancellationToken)) { _items = _json.DeserializeFromStream<List<LocalItem>>(stream); } } else { _items = new List<LocalItem>(); } } }