コード例 #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
        public static async Task SetAsBitmap(byte[] data, ImageDataSource target, CoreDispatcher Dispatcher = null)
        {
            using (var stream = new InMemoryRandomAccessStream())
            {
                await stream.WriteAsync(data.AsBuffer());

                stream.Seek(0);
                if (Dispatcher == null)
                {
                    Dispatcher = SystemUtil.GetCurrentDispatcher();
                }
                if (Dispatcher == null)
                {
                    return;
                }

                await Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                {
                    var image = new BitmapImage();
                    image.SetSource(stream);
                    target.Image = image;
                });
            }
        }
コード例 #3
0
ファイル: MediaDownloader.cs プロジェクト: zmrzli/locana
        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;
        }