예제 #1
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;
                };
            });
        }
예제 #2
0
        public void FetchResource(string isolatedStoragePath, Uri networkUri, Action <string> callback)
        {
            ThreadPool.QueueUserWorkItem(state =>
            {
                if (isoStore.FileExists(isolatedStoragePath))
                {
                    callback(isolatedStoragePath);
                    return;
                }

                WebClient client = new WebClient();
                client.OpenReadAsync(networkUri);

                client.OpenReadCompleted += (sender, e) =>
                {
                    if (e.Cancelled || e.Error != null)
                    {
                        callback(null);
                        return;
                    }
                    using (var stream = e.Result)
                    {
                        lock (syncContext)
                        {
                            if (isoStore.FileExists(isolatedStoragePath))
                            {
                                callback(isolatedStoragePath);
                                return;
                            }

                            using (IsolatedStorageFileStream fileStream = isoStore.CreateFile(isolatedStoragePath))
                            {
                                stream.CopyTo(fileStream);
                                fileStream.Close();
                            }
                            Debug.WriteLine("Downloaded uri: " + networkUri.ToString() + " -->" + isolatedStoragePath);
                        }
                    }

                    callback(isolatedStoragePath);
                    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;
                };
            });
        }