/// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            var app = Application.Current as App;
            if (app.needToDownload == false) { needtoGoBack = true; return; }

            app.needToDownload = false;

            var item = navigationParameter as DownloadMagazine;

            if (item != null)
            {
                statusText.Text = "Download in progress";

                manager = item.manager;
                var url = item.url;

                magList.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                downloadView.Visibility = Windows.UI.Xaml.Visibility.Visible;

                try
                {
                    var folder = await manager.AddMagazineFolderStructure(url);
                    Windows.UI.Xaml.Media.Imaging.BitmapSource bitmap = null;
                    try
                    {
                        bitmap = await manager.DownloadThumbnailAsync(url, folder);
                    }
                    catch { }
                    if (bitmap == null) return;
                    pdfThumbnail.Width = bitmap.PixelWidth * pdfThumbnail.Height / bitmap.PixelHeight;
                    pdfThumbnail.Source = bitmap;

                    pRing.IsActive = false;

                    var progressIndicator = new Progress<int>((value) =>
                    {
                        if (statusText.Text != manager.StatusText)
                            statusText.Text = manager.StatusText;
                        progressBar.Value = value;
                    });
                    cts = new CancellationTokenSource();

                    IRandomAccessStream stream = null;
                    if (item.redirectUrl == null) {

                        stream = await manager.DownloadMagazineAsync(url, folder, progressIndicator, cts.Token);

                    } else {

                        stream = await manager.DownloadMagazineAsync(url, item.redirectUrl, folder, progressIndicator, cts.Token);
                    }
                    statusText.Text = "Done.";
                    await manager.MarkAsDownloaded(url, folder);
                    await Task.Delay(1000);

                    var mag = DownloadManager.GetLocalUrl(manager.MagazineLocalUrl, url.FullName);
                    this.Frame.Navigate(typeof(PdfViewPage), new MagazineData() { stream = stream, folderUrl = mag.FolderPath });
                }
                catch (Exception ex)
                {
                    statusText.Text = "Error";
                    if (ex.Message == "Response status code does not indicate success: 403 (Forbidden).")
                    {
                        var messageDialog = new MessageDialog("This is a paid app. You need to purchase it first");
                        var task = messageDialog.ShowAsync().AsTask();
                        return;
                    }
                    else if (ex.Message == "The operation was canceled.")
                    {
                        int x = 0;
                    }
                    else
                    {
                        var messageDialog = new MessageDialog("Unexpected error");
                        var task = messageDialog.ShowAsync().AsTask();
                        return;
                    }
                }
            }
            else
            {
                string s = navigationParameter as string;
                if (s == "test")
                {
                    testView.Visibility = Windows.UI.Xaml.Visibility.Visible;
                }
                else
                {
                    needtoGoBack = true;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            
            if (rootFrame == null)
            {
                var licenseInformation = CurrentAppSimulator.LicenseInformation;

                //await LibrelioApplication.Utils.Utils.prepareTestData();

                var fileHandle =
                    await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"CustomizationAssets\application_.xml");

                var xml = await XmlDocument.LoadFromFileAsync(fileHandle);
                var appName = xml.SelectSingleNode("/resources/string[@name='app_name']");
                ClientName = xml.SelectSingleNode("/resources/string[@name='client_name']").InnerText;
                MagazineName = xml.SelectSingleNode("/resources/string[@name='magazine_name']").InnerText;

                Application.Current.Resources["AppName"] = appName.InnerText;

                Manager = new MagazineManager("http://librelio-europe.s3.amazonaws.com/" + ClientName + "/" + MagazineName + "/", "Magazines");

                await DiscoverActiveDownloadsAsync(); 
 
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();
                //Associate the frame with a SuspensionManager key                                
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }
            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(LibrelioApplication.ItemsPage), "AllGroups"))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            testView.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            magList.Visibility = Windows.UI.Xaml.Visibility.Visible;
            try
            {
                manager = new MagazineManager("http://librelio-europe.s3.amazonaws.com/niveales/wind/", "Magazines");

                await manager.LoadPLISTAsync();

                var mag = new List<Item>();
                foreach (var url in manager.MagazineUrl)
                {
                    mag.Add(new Item { Title = url.Title, Subtitle = url.Subtitle, FullName = url.FullName });
                }
                itemListView.ItemsSource = mag;
            }
            catch
            {
            }
        }