private async Task InitializeAsync(FileSystemStorageFile PdfFile) { LoadingControl.IsLoading = true; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } NumIndicator.Text = Convert.ToString(Pdf.PageCount); TextBoxControl.Text = "1"; for (uint i = 0; i < Pdf.PageCount; i++) { PdfCollection.Add(new BitmapImage()); LoadTable.Add(i); } Flip.ItemsSource = PdfCollection; await JumpToPageIndexAsync(0); } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync(); Frame.GoBack(); } finally { await Task.Delay(500); LoadingControl.IsLoading = false; } }
private async Task Initialize(FileSystemStorageItemBase PdfFile) { LoadingControl.IsLoading = true; MainPage.ThisPage.IsAnyTaskRunning = true; PdfCollection = new ObservableCollection <BitmapImage>(); LoadQueue = new Queue <int>(); ExitLocker = new ManualResetEvent(false); Cancellation = new CancellationTokenSource(); Flip.ItemsSource = PdfCollection; MaxLoad = 0; LastPageIndex = 0; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read).ConfigureAwait(true)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync().ConfigureAwait(true)) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } for (uint i = 0; i < 10 && i < Pdf.PageCount && !Cancellation.IsCancellationRequested; i++) { using (PdfPage Page = Pdf.GetPage(i)) using (InMemoryRandomAccessStream PageStream = new InMemoryRandomAccessStream()) { await Page.RenderToStreamAsync(PageStream); BitmapImage DisplayImage = new BitmapImage(); PdfCollection.Add(DisplayImage); await DisplayImage.SetSourceAsync(PageStream); } } } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync().ConfigureAwait(true); Frame.GoBack(); } finally { ExitLocker.Set(); if (!Cancellation.IsCancellationRequested) { Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; } await Task.Delay(1000).ConfigureAwait(true); LoadingControl.IsLoading = false; MainPage.ThisPage.IsAnyTaskRunning = false; } }
private async Task Initialize(FileSystemStorageFile PdfFile) { LoadingControl.IsLoading = true; PdfCollection.Clear(); LoadQueue.Clear(); Cancellation = new CancellationTokenSource(); MaxLoad = 0; LastPageIndex = 0; try { using (IRandomAccessStream PdfStream = await PdfFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read)) { try { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream); } catch (Exception) { PdfPasswordDialog Dialog = new PdfPasswordDialog(); if ((await Dialog.ShowAsync()) == ContentDialogResult.Primary) { Pdf = await PdfDocument.LoadFromStreamAsync(PdfStream, Dialog.Password); } else { Frame.GoBack(); return; } } } for (uint i = 0; i < 10 && i < Pdf.PageCount && !Cancellation.IsCancellationRequested; i++) { using (PdfPage Page = Pdf.GetPage(i)) using (InMemoryRandomAccessStream PageStream = new InMemoryRandomAccessStream()) { await Page.RenderToStreamAsync(PageStream, new PdfPageRenderOptions { DestinationHeight = Convert.ToUInt32(Page.Size.Height * 1.5), DestinationWidth = Convert.ToUInt32(Page.Size.Width * 1.5) }); BitmapImage DisplayImage = new BitmapImage(); PdfCollection.Add(DisplayImage); await DisplayImage.SetSourceAsync(PageStream); } } } catch (Exception) { QueueContentDialog Dialog = new QueueContentDialog { Title = Globalization.GetString("Common_Dialog_ErrorTitle"), Content = Globalization.GetString("QueueDialog_PDFOpenFailure"), CloseButtonText = Globalization.GetString("Common_Dialog_GoBack") }; _ = await Dialog.ShowAsync(); Frame.GoBack(); } finally { if (!Cancellation.IsCancellationRequested) { Flip.SelectionChanged += Flip_SelectionChanged; Flip.SelectionChanged += Flip_SelectionChanged1; } await Task.Delay(1000); LoadingControl.IsLoading = false; } }