Exemplo n.º 1
0
        public void Init(Post post)
        {
            try
            {
                var img = new BitmapImage();
                var scale = new ScaleTransform(150 / post.preview_width, 125 / post.preview_height);

                img.BeginInit();
                img.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
                img.UriSource = new Uri(post.preview_url, UriKind.RelativeOrAbsolute);
                img.EndInit();

                Width = 150;
                Height = 125;
                Source = new TransformedBitmap(img, scale);
                ImageData = post;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
        }
Exemplo n.º 2
0
        private void getImages()
        {
            if (!Directory.Exists("cache"))
                Directory.CreateDirectory("cache");

            Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        ProgressBar.Visibility = Visibility.Hidden;
                        ProgressbarText.Text = "Contacting konachan...";
                        ProgressbarText.Visibility = Visibility.Visible;
                    }));

            var downloadString = "";
            var xml = "";
            using (var client = new WebClient())
            {
                try
                {
                    downloadString = "http://konachan.com/post.xml?limit=100&page=" + Page;
                    if (TagsManager.GetInstance().HasTags())
                        downloadString += "&tags=" + TagsManager.GetInstance().GetTagsAsString();
                    xml = client.DownloadString(downloadString);
                }
                catch (Exception)
                {
                    Logger.Log("Failed to download posts from " + downloadString, "ERROR");
                    return;
                }
            }

            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(xml);

            XmlNodeList elements = xmlDocument.GetElementsByTagName("post");

            Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        if (elements.Count > 0)
                        {
                            ProgressbarText.Text = "";
                            ProgressbarText.Visibility = Visibility.Hidden;
                            ProgressBar.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            ProgressbarText.Text = "No images found.";
                            return;
                        }
                    }));

            foreach (XmlElement element in elements)
            {
                Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            var post = new Post(element.Attributes);
                            var img = new CachedImage();

                            img.Init(post);
                            img.MouseDown += img_MouseDown;
                            Imgs.Add(post);
                            ImgListView.Items.Add(img);

                            ProgressBar.Value = (double)Imgs.Count - ((Page - 1) * 100.0);
                        }));
            }
            Page++;
            Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
                    {
                        ProgressBar.Visibility = Visibility.Hidden;
                        ProgressBar.Value = 0;
                        SearchButton.IsEnabled = true;
                    }));
        }