Пример #1
0
        private async void Enqueue(Uri uri, string namebase, Mediatype type, string extension = null)
        {
            DebugUtil.Log(() => "ContentsDownloader: Enqueue " + uri.AbsolutePath);

            if (extension == null)
            {
                var split = uri.AbsolutePath.Split('.');
                if (split.Length > 0)
                {
                    extension = "." + split[split.Length - 1].ToLower();
                    DebugUtil.Log(() => "detected file extension: " + extension);
                }
            }

            await SystemUtil.GetCurrentDispatcher().RunAsync(CoreDispatcherPriority.Low, () =>
            {
                var req = new DownloadRequest
                {
                    Uri       = uri,
                    NameBase  = namebase,
                    Completed = OnFetched,
                    Error     = OnFailed,
                    Mediatype = type,
                    extension = extension
                };
                DownloadQueue.Enqueue(req);
                QueueStatusUpdated?.Invoke(DownloadQueue.Count);
                ProcessQueueSequentially();
            });
        }
Пример #2
0
        private async Task Enqueue(Uri uri, string namebase, Mediatype type, CancellationTokenSource cts, string extension = null)
        {
            DebugUtil.LogSensitive(() => "ContentsDownloader: Enqueue {0}", uri.AbsolutePath);

            if (extension == null)
            {
                var split = uri.AbsolutePath.Split('.');
                if (split.Length > 0)
                {
                    extension = "." + split[split.Length - 1].ToLower();
                    DebugUtil.Log(() => "detected file extension: " + extension);
                }
            }

            var tcs = new TaskCompletionSource <bool>();

            await SystemUtil.GetCurrentDispatcher().RunAsync(CoreDispatcherPriority.Low, () =>
            {
                var req = new DownloadRequest
                {
                    Uri                     = uri,
                    NameBase                = namebase,
                    Completed               = OnFetched,
                    Error                   = OnFailed,
                    Mediatype               = type,
                    FileExtension           = extension,
                    CompletionSource        = tcs,
                    CancellationTokenSource = cts,
                };
                DownloadQueue.Enqueue(req);
                QueueStatusUpdated?.Invoke(DownloadQueue.Count);
                ProcessQueueSequentially();
            });

            await tcs.Task;
        }