Exemplo n.º 1
0
        public IAwaitableTransfer LoadFile(Uri remoteUri)
        {
            var progress = new OngoingReactiveProgress1();
            var transfer = _downloader.Load(remoteUri, progress, CancellationToken.None);
            //TODO: FileCache.TryGetFileModel
            var fileModel = await _fileCache.CachedFiles.FirstOrDefaultAsync();

            if (fileModel != null || cacheInfo.Downloaded < cacheInfo.FinalSize)
            {
                //if (not downloaded OR download not finished)
                var progress = new OngoingReactiveProgress1();
                target.SetRealReactiveProgress(progress);
                //TODO: progress.Subscribe( { save CacheInfo as progress goes} );
                var transfer = await _downloader.Load(_item.PodcastUri, progress, CancellationToken.None);
                //TODO: think how to implement via Move (should atomically call Move and Save info into cache)
                CachedUri = await _storage.MoveFromTransferTempStorage(transfer.DownloadLocation, _item);
                var newCacheInfo = new CacheInfo()
                {
                    FileUri = CachedUri,
                    FinalSize = progress.FinalState.Total,
                    Downloaded = progress.FinalState.Total
                };
                await Cache.Local.InsertObject(_item.OriginalUri.OriginalString, newCacheInfo);
            }
            else
            {
                CachedUri = cacheInfo.FileUri;
                var progress = new FinishedReactiveProgress<ProgressValue>(new ProgressValue(cacheInfo.Downloaded, cacheInfo.FinalSize));
                target.SetRealReactiveProgress(progress);
            }
        }
Exemplo n.º 2
0
        public async Task UpdateOrCreateCacheEntry(PodcastId id, CacheInfo entry)
        {
            FileModel existingEnry;
            if (!_memCache.TryGetValue(id, out existingEnry))
            {
                var fileModel = new FileModel(id, entry);
                _memCache.Add(id, fileModel);
                _cachedFiles.OnNext(fileModel);
            }
            else
            {
                existingEnry.UpdateCachingState(entry);
            }

            await Cache.Local.InsertObject(id.Url, entry);
        }
Exemplo n.º 3
0
 public void UpdateCachingState(CacheInfo entry)
 {
     State
 }