Example #1
0
        private void ThumbnailItem_Loaded(object sender, RoutedEventArgs e)
        {
            if (loaded)
            {
                return;
            }
            loaded = true;

            switch (Article.type)
            {
            case "icon_recomimg":
            case "icon_pic":
                Icon.Kind = MaterialDesignThemes.Wpf.PackIconKind.Image;
                break;

            default:
                Icon.Kind = MaterialDesignThemes.Wpf.PackIconKind.Pen;
                break;
            }

            if (Article.type == "icon_pic" || Article.type == "icon_recomimg")
            {
                Task.Run(() =>
                {
                    var html = NetTools.DownloadString(URL);
                    if (html == null || html == "")
                    {
                        Extends.Post(() =>
                        {
                            Icon.Kind = MaterialDesignThemes.Wpf.PackIconKind.TrashCanOutline;
                        });
                        return;
                    }
                    downloaded_article = DCInsideUtils.ParseBoardView(html);
                    if (downloaded_article.ImagesLink.Count == 0)
                    {
                        return;
                    }
                    temp_file = TemporaryFiles.UseNew();
                    NetTools.DownloadFile(downloaded_article.ImagesLink[0], temp_file);

                    Extends.Post(() => AnimationBehavior.SetSourceUri(Image, new Uri(temp_file)));
                });
            }
        }
Example #2
0
        //bool opened = false;
        private void UserControl_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (downloaded_article == null || downloaded_article.ImagesLink.Count == 1)
            {
                return;
            }
            image_index = (image_index + 1) % downloaded_article.ImagesLink.Count;

            Task.Run(() =>
            {
                temp_file = TemporaryFiles.UseNew();
                NetTools.DownloadFile(downloaded_article.ImagesLink[image_index], temp_file);

                Extends.Post(() => AnimationBehavior.SetSourceUri(Image, new Uri(temp_file)));
            });

            //if (!opened)
            //{
            //    //opened = true;
            //    //if (Icon.Kind == PackIconKind.TrashCanOutline)
            //    //{
            //    //    opened = false;
            //    //    return;
            //    //}
            //    //if (downloaded_article == null)
            //    //{
            //    //    var html = NetTools.DownloadString(URL);
            //    //    if (html == null || html == "")
            //    //    {
            //    //        opened = false;
            //    //        return;
            //    //    }
            //    //    downloaded_article = DCInsideUtils.ParseBoardView(html);
            //    //}
            //    ////var bv = new BodyView(downloaded_article);
            //    ////await DialogHost.Show(bv, "RootDialog");
            //    //opened = false;
            //}
            //else
            //    DialogHost.CloseDialogCommand.Execute(null, null);
        }
Example #3
0
        static void download_data(string url, string filename)
        {
            Logs.Instance.Push($"Download {filename}...");
            var task = NetTask.MakeDefault(url);

            SingleFileProgressBar pb = null;
            long tsz = 0;

            task.SizeCallback = (sz) =>
            {
                Console.Write("Downloading ... ");
                pb = new SingleFileProgressBar();
                pb.Report(sz, 0);
                tsz = sz;
            };
            task.Filename         = filename;
            task.DownloadCallback = (sz) => pb.Report(tsz, sz);
            NetTools.DownloadFile(task);
            pb.Dispose();
            Console.WriteLine("Complete!");
        }