예제 #1
0
        protected async Task <bool> DeleteCacheFile()
        {
            using (var releaser = await _Lock.LockAsync())
            {
                if (NowPlaying && IsCached)
                {
                    _DeleteRequestedOnPlaying = true;
                    return(false);
                }
            }

            var result = await VideoDownloadManager.RemoveCacheRequest(NicoVideo.RawVideoId, Quality);

            var file = await GetCacheFile();

            if (file != null)
            {
                await file.DeleteAsync();
            }

            using (var releaser = await _Lock.LockAsync())
            {
                CacheState         = NicoVideoCacheState.NotCacheRequested;
                CacheFilePath      = null;
                VideoFileCreatedAt = default(DateTime);
                IsCacheRequested   = false;

                return(result);
            }
        }
예제 #2
0
        public async Task RequestCache(bool forceUpdate = false)
        {
            if (!CanDownload)
            {
                return;
            }

            var isCacheFileExist = false;

            using (var releaser = await _Lock.LockAsync())
            {
                isCacheFileExist = !forceUpdate && (IsCached || NowCacheDonwloading);
            }

            if (isCacheFileExist)
            {
                // update cached time
                await GetCacheFile();

                return;
            }

            using (var releaser = await _Lock.LockAsync())
            {
                VideoDownloadManager.DownloadStarted += VideoDownloadManager_DownloadStarted;
                IsCacheRequested = true;
                CacheState       = NicoVideoCacheState.Pending;

                VideoFileCreatedAt = DateTime.Now;

                await VideoDownloadManager.AddCacheRequest(NicoVideo.RawVideoId, Quality, forceUpdate);

                await NicoVideo.OnCacheRequested();
            }
        }
예제 #3
0
        private async Task Initialize()
        {
            // キャッシュ完了したアイテムを検索
            await RetrieveCacheCompletedVideos();

            // ダウンロード中の情報を復元
            await VideoDownloadManager.Initialize();

            IsInitialized = true;

            Completed?.Invoke(this);
        }
예제 #4
0
        private NiconicoMediaManager(HohoemaApp app)
        {
            _HohoemaApp                             = app;
            VideoDownloadManager                    = new VideoDownloadManager(_HohoemaApp, this);
            VideoDownloadManager.Requested         += VideoDownloadManager_Requested;
            VideoDownloadManager.RequestCanceled   += VideoDownloadManager_RequestCanceled;
            VideoDownloadManager.DownloadStarted   += VideoDownloadManager_DownloadStarted;
            VideoDownloadManager.DownloadCompleted += VideoDownloadManager_DownloadCompleted;
            VideoDownloadManager.DownloadCanceled  += VideoDownloadManager_DownloadCanceled;

            _VideoIdToNicoVideo = new Dictionary <string, NicoVideo>();

            _CacheVideos = new ObservableCollection <NicoVideo>();
            CacheVideos  = new ReadOnlyObservableCollection <NicoVideo>(_CacheVideos);

            _HohoemaApp.OnSignin += _HohoemaApp_OnSignin;
        }
예제 #5
0
        public async Task <StorageFile> GetCacheFile()
        {
            using (var releaser = await _Lock.LockAsync())
            {
                if (IsCached)
                {
                    if (string.IsNullOrEmpty(CacheFilePath))
                    {
                        throw new Exception();
                    }

                    var file = await StorageFile.GetFileFromPathAsync(CacheFilePath);

                    VideoFileCreatedAt = file.DateCreated.DateTime;

                    return(file);
                }
                else if (NowCacheDonwloading)
                {
                    var downloadOp = await VideoDownloadManager.GetDownloadingVideoOperation(this.RawVideoId, this.Quality);

                    if (downloadOp != null)
                    {
                        VideoFileCreatedAt = downloadOp.ResultFile.DateCreated.DateTime;
                        return(downloadOp.ResultFile as StorageFile);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }