public void Recycle()
        {
            waitingDocumentConfigurator = null;
            animationManager.StopAll();
            dragPinchManager.Disable();
            // Stop tasks
            if (RenderingHandler != null)
            {
                RenderingHandler.Stop();
                RenderingHandler.RemoveMessages(RenderingHandler.MsgRenderTask);
            }

            decodingAsyncTask?.Cancel();

            // Clear caches
            CacheManager.Recycle();

            if (ScrollHandle != null && isScrollHandleInit)
            {
                ScrollHandle.DestroyLayout();
            }

            if (PdfFile != null)
            {
                PdfFile.Dispose();
                PdfFile = null;
            }

            RenderingHandler   = null;
            ScrollHandle       = null;
            isScrollHandleInit = false;
            CurrentXOffset     = CurrentYOffset = 0;
            Zoom       = 1f;
            IsRecycled = true;
            Callbacks  = new Callbacks();
            state      = State.Default;
        }
예제 #2
0
        private async void Navigator_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
        {
            try
            {
                if (args.SelectedItem is NavigationViewItem navigationViewItem)
                {
                    var tag = navigationViewItem.Tag;
                    if (tag is string typeName)
                    {
                        if (!string.IsNullOrEmpty(typeName))
                        {
                            if (_pages.TryGetValue(typeName, out Type type))
                            {
                                if (type == typeof(PdfViewerPageContent))
                                {
                                    var file = await PickFile();

                                    if (file != null)
                                    {
                                        if (IsFileOpen(file.Path))
                                        {
                                            Navigator.SelectedItem = null;
                                            return;
                                        }

                                        var token = StorageApplicationPermissions.FutureAccessList.Add(file);

                                        //var tempFile = await CopyFileToDevice(file);
                                        var pdfFileExists = PdfFiles.Find(x => x.FullFilePath == file.Path);
                                        var tempFile      = pdfFileExists != null ? await OpenFile(Mapper.Map <PdfFileModel>(pdfFileExists)) : await CopyFileToDevice(file);

                                        if (tempFile != null)
                                        {
                                            if (ContentFrame.Content is PdfViewerPageContent content)
                                            {
                                                PdfFile pdfFile = null;
                                                pdfFile = PdfFiles.Find(x => x.FullFilePath == file.Path);
                                                if (pdfFile == null)
                                                {
                                                    pdfFile = new PdfFile()
                                                    {
                                                        FullFilePath = file.Path, IsFavorite = false, LastTimeOpened = DateTime.Now, FileToken = token
                                                    };
                                                }
                                                var pdfFileModel = Mapper.Map <PdfFileModel>(pdfFile);
                                                if (!PdfFiles.Exists(x => x.FullFilePath == pdfFile.FullFilePath))
                                                {
                                                    await RemovePdfFileLastUsedAsync();

                                                    PdfFiles.Add(pdfFile);
                                                    await SaveSettings(PdfFiles);
                                                }


                                                content.LoadPdfViewer(tempFile, pdfFileModel);
                                            }
                                        }
                                    }
                                    Navigator.SelectedItem = null;
                                }
                            }
                            else if (typeName == "FavoriteDialog")
                            {
                                await OpenFavoriteFileDialog();

                                Navigator.SelectedItem = null;
                            }
                            else if (typeName == "LastTimeUsedDialog")
                            {
                                await OpenLastTimeUsedFilesDialog();

                                Navigator.SelectedItem = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog(ex.Message, "Fehler");
                await dialog.ShowAsync();
            }
        }