コード例 #1
0
        public override void OnLoadItem(CatalogPage item, int index)
        {
            var    path = string.Format("Catalogs/{0}/view/{1}.jpg", CatalogId, index + 1);
            string uri  = CatalogPageHelper.GetPageUri(CatalogId, (index + 1).ToString(), ImageResolution.View);

            isoCache.FetchResource(path, new Uri(uri), isoPath => item.PageUri = isoPath);
            base.OnLoadItem(item, index);
        }
コード例 #2
0
        private void LoadZoomPage(string id, string page)
        {
            var path = string.Format("Catalogs/{0}/zoom/{1}.jpg", id, page);

            //var path = string.Format("Catalogs/{0}/{1}.jpg", id, page);
            if (isoStore.FileExists(path))
            {
                this.DataContext = new CatalogPageViewModel {
                    ImagePath = path
                };

                return;
            }

            ThreadPool.QueueUserWorkItem(state =>
            {
                WebClient client = new WebClient();

                string uri = CatalogPageHelper.GetPageUri(id, page, ImageResolution.Zoom);
                client.OpenReadAsync(new Uri(uri));
                client.OpenReadCompleted += (sender, e) =>
                {
                    string temp = uri;
                    if (e.Error != null || e.Cancelled)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            MessageBox.Show("Ups, kunne ikke hente zoom siden");
                        });
                        return;
                    }
                    using (var stream = e.Result)
                    {
                        if (isoStore.FileExists(path))
                        {
                            this.DataContext = path;
                            return;
                        }

                        using (IsolatedStorageFileStream fileStream = isoStore.CreateFile(path))
                        {
                            stream.CopyTo(fileStream);
                            fileStream.Close();
                        }
                    }

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        this.DataContext = new CatalogPageViewModel {
                            ImagePath = path
                        };
                    });

                    return;
                };
            });
        }
        private void LoadZoomPage(string id, int pageZeroBase)
        {
            int page = pageZeroBase + 1;
            var path = string.Format("Catalogs/{0}/zoom/{1}.jpg", id, page);
            IsoStorageHelper isoStore = new IsoStorageHelper();

            //var path = string.Format("Catalogs/{0}/{1}.jpg", id, page);
            if (isoStore.FileExists(path))
            {
                zoomImage.Source     = new ImageHelper().ConvertIsoFileStreamToBitmapImage(path);
                zoomImage.Visibility = System.Windows.Visibility.Visible;
                slideView.Visibility = System.Windows.Visibility.Collapsed;
                return;
            }

            ThreadPool.QueueUserWorkItem(state =>
            {
                WebClient client = new WebClient();

                string uri = CatalogPageHelper.GetPageUri(id, page.ToString(), ImageResolution.Zoom);
                client.OpenReadAsync(new Uri(uri));
                client.OpenReadCompleted += (sender, e) =>
                {
                    string temp = uri;
                    if (e.Error != null || e.Cancelled)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            MessageBox.Show("Ups, kunne ikke hente zoom siden");
                            zoomImage.Source     = null;
                            zoomImage.Visibility = System.Windows.Visibility.Collapsed;
                            slideView.Visibility = System.Windows.Visibility.Visible;
                        });
                        return;
                    }
                    using (var stream = e.Result)
                    {
                        if (isoStore.FileExists(path))
                        {
                            zoomImage.Source     = new ImageHelper().ConvertIsoFileStreamToBitmapImage(path);
                            zoomImage.Visibility = System.Windows.Visibility.Visible;
                            slideView.Visibility = System.Windows.Visibility.Collapsed;
                            return;
                        }

                        using (IsolatedStorageFileStream fileStream = isoStore.CreateFile(path))
                        {
                            stream.CopyTo(fileStream);
                            fileStream.Close();
                        }
                    }

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        zoomImage.Source     = new ImageHelper().ConvertIsoFileStreamToBitmapImage(path);
                        zoomImage.Visibility = System.Windows.Visibility.Visible;
                        slideView.Visibility = System.Windows.Visibility.Collapsed;
                    });

                    return;
                };
            });
        }