Exemple #1
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var w = new SheetMusicViewer.PdfViewerWindow();

            w.ShowDialog();
            Environment.Exit(0);
        }
        public async Task TestReadBmkData()
        {
            var //rootfolder = @"C:\Bak\SheetMusic\Poptest";
            //rootfolder = @"C:\SheetMusic\Classical";
                rootfolder = @"C:\SheetMusic";
            //rootfolder = @"c:\temp";
            //for (int i = 0;i <10000; i++)
            //{
            //    TestContext.WriteLine($"adfadf {i}");
            //}
            var w = new SheetMusicViewer.PdfViewerWindow
            {
                _RootMusicFolder = rootfolder
            };

            (var lstMetaData, var _) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(w._RootMusicFolder);

            foreach (var pm in lstMetaData)
            {
                if (pm.dictInkStrokes.Count > 0)
                {
                    //foreach (var kvp in pm.dictInkStrokes)
                    //{
                    //    kvp.Value.Pageno = kvp.Value.Pageno;
                    //}
                    //pm.SaveIfDirty(ForceDirty: true);
                    //pm.IsDirty = true;
                    //PdfMetaData.SavePdfMetaFileData(pm);
                }
            }
        }
        public async Task TestCreateBmpCache()
        {
            var w = new SheetMusicViewer.PdfViewerWindow
            {
                _RootMusicFolder = Rootfolder
            };
            await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(w._RootMusicFolder);

            for (int i = 0; i < 11; i++)
            {
                GetBMPs(w);
            }
        }
 void GetBMPs(SheetMusicViewer.PdfViewerWindow w)
 {
     AddLogEntry($"Got PDFMetaDataCnt={w.lstPdfMetaFileData.Count}");
     foreach (var pdfMetaData in w.lstPdfMetaFileData)
     {
         _ = pdfMetaData.GetBitmapImageThumbnailAsync();
         pdfMetaData.bitmapImageCache = null;
         //                AddLogEntry($" {pdfMetaData} {bmi.PixelWidth} {bmi.PixelHeight}");
     }
     //var classicalPdf = w.lstPdfMetaFileData[0];
     // with no renderoptions,wh=(794,1122), pixelHeight= (1589, 2245 )
     // with renderops = 150,225 wh= (225,150), pixelhw = (300, 450), dpix = dpiy = 192
     //            var bmi = classicalPdf.GetBitmapImageThumbnail();
 }
        public async Task TestUpdaateBmkWriteTime()
        {
            var tcsStaThread = new TaskCompletionSource <int>();
            var c            = CreateExecutionContext(tcsStaThread);
            await c.Dispatcher.InvokeAsync(async() =>
            {
                var w = new SheetMusicViewer.PdfViewerWindow
                {
                    _RootMusicFolder = Rootfolder
                };
                (var lstMetaData, var _) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(w._RootMusicFolder);
                foreach (var itm in lstMetaData)
                {
//                        itm.SaveIfDirty(ForceDirty: true);
                }
                c.Dispatcher.InvokeShutdown();
                AddLogEntry("Done all");
            });

            await tcsStaThread.Task;
        }
Exemple #6
0
        private async void MainWindow_Loadedtry(object sender, RoutedEventArgs e)
        {
            var w = new SheetMusicViewer.PdfViewerWindow
            {
                //                    _RootMusicFolder = Path.Combine(Rootfolder, "FakeBooks")
                _RootMusicFolder = Rootfolder
            };

            (var lstMetaData, var _) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(w._RootMusicFolder);

            foreach (var currentPdfMetaData in lstMetaData.Where(p => p.GetFullPathFileFromVolno(volNo: 0).Contains("Classical Fake")))
            {
                var sw = Stopwatch.StartNew();
                //                    var currentPdfMetaData = lstMetaData.Where(m => m.GetFullPathFile(volNo: 0).Contains("Fake")).First();
                w.currentPdfMetaData = currentPdfMetaData;
                w.currentPdfMetaData.InitializeListPdfDocuments();
                w.ShowDialog();
                //for (int iter = 0; iter < 100; iter++)
                //{
                //    //var cacheEntry = PdfViewerWindow.CacheEntry.TryAddCacheEntry(mpdf.PageNumberOffset);
                //    //await cacheEntry.task;
                //    //// calling thread must be STA, UIThread
                //    //var res = cacheEntry.task.Result;
                //    var pageNo = 0;
                //    for (pageNo = currentPdfMetaData.PageNumberOffset; pageNo < currentPdfMetaData.NumPagesInSet + currentPdfMetaData.PageNumberOffset - 1; pageNo++)
                //    {
                //        var cacheEntry = w._pageCache.TryAddCacheEntry(pageNo);
                //        await cacheEntry.task;
                //        var bmi = cacheEntry.task.Result;
                //        this.Content = new Image() { Source = bmi };
                //        this.Title = $"{cnt++} {pageNo,8}   bmi={bmi.Width:n0}, {bmi.Height:n0}  {sw.Elapsed.TotalSeconds,8:n4} {currentPdfMetaData} ";
                //        //break;
                //    }
                //}
            }
        }
        //        [Ignore]
        public async Task TestStress()
        {
            var tcsStaThread = new TaskCompletionSource <int>();
            var c            = CreateExecutionContext(tcsStaThread);
            await c.Dispatcher.InvokeAsync(async() =>
            {
                var w = new SheetMusicViewer.PdfViewerWindow
                {
                    _RootMusicFolder = Rootfolder
                };
                (var lstMetaData, var _) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(w._RootMusicFolder);
                var testw     = new Window();
                var ctsDone   = new CancellationTokenSource();
                testw.Closed += (o, e) =>
                {
                    ctsDone.Cancel();
                };
                testw.Show();
                foreach (var currentPdfMetaData in lstMetaData)
                {
                    AddLogEntry($"Starting {currentPdfMetaData}");
                    w.Title = currentPdfMetaData.ToString();
                    w.currentPdfMetaData = currentPdfMetaData;
                    w.currentPdfMetaData.InitializeListPdfDocuments();
                    //var cacheEntry = PdfViewerWindow.CacheEntry.TryAddCacheEntry(mpdf.PageNumberOffset);
                    //await cacheEntry.task;
                    //// calling thread must be STA, UIThread
                    //var res = cacheEntry.task.Result;
                    try
                    {
                        for (var iter = 0; iter < 1; iter++)
                        {
                            for (var pageNo = currentPdfMetaData.PageNumberOffset; pageNo < currentPdfMetaData.MaxPageNum; pageNo++)
                            {
                                ctsDone.Token.ThrowIfCancellationRequested();
                                var(pdfDoc, pdfPgno) = await currentPdfMetaData.GetPdfDocumentForPageno(pageNo);
                                //                    var pdfPgNo = currentPdfMetaData.GetPdfVolPageNo(pageNo + i);
                                if (pdfDoc != null && pdfPgno >= 0 && pdfPgno < pdfDoc.PageCount)
                                {
                                    using (var pdfPage = pdfDoc.GetPage((uint)(pdfPgno)))
                                    {
                                        using (var strm = new InMemoryRandomAccessStream())
                                        {
                                            var rect       = pdfPage.Dimensions.ArtBox;
                                            var renderOpts = new PdfPageRenderOptions()
                                            {
                                                DestinationWidth  = (uint)rect.Width,
                                                DestinationHeight = (uint)rect.Height,
                                            };
                                            if (pdfPage.Rotation != PdfPageRotation.Normal)
                                            {
                                                renderOpts.DestinationHeight = (uint)rect.Width;
                                                renderOpts.DestinationWidth  = (uint)rect.Height;
                                            }

                                            await pdfPage.RenderToStreamAsync(strm, renderOpts);
                                            var bmi = new BitmapImage();
                                            bmi.BeginInit();
                                            bmi.StreamSource = strm.AsStream();
                                            bmi.Rotation     = (Rotation)currentPdfMetaData.GetRotation(pageNo);
                                            bmi.CacheOption  = BitmapCacheOption.OnLoad;
                                            bmi.EndInit();
                                            testw.Content = new Image()
                                            {
                                                Source = bmi
                                            };
                                            if (pdfPage.Rotation != PdfPageRotation.Rotate270 && pdfPage.Rotation != PdfPageRotation.Rotate90)
                                            {
                                                AddLogEntry($"got page {pageNo,5}   strms={strm.Size,10:n0} {pdfPage.Rotation,10} {rect}  {currentPdfMetaData} ");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (OperationCanceledException)
                    {
                    }
                }
                c.Dispatcher.InvokeShutdown();
                AddLogEntry("Done all");
            });

            await tcsStaThread.Task;
        }