Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
        void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            var tabItemHeaer = ((TabItem)(this.tabControl.SelectedItem)).Header as string;

            switch (tabItemHeaer)
            {
            case "_Books":
                if (this.lbBooks.SelectedIndex >= 0)
                {
                    var mycontent = this.lbBooks.SelectedItem as MyContentControl;
                    chosenPdfMetaData = mycontent.pdfMetaDataItem;
                }
                else
                {
                    // nothing is selected. we'll terminate dialog anyway, but allow nothing to be selected
                }
                var oldChooseSortby = Properties.Settings.Default.ChooseBooksSort;
                var newChooseSortBy = rbtnByDate.IsChecked == true ? "ByDate" : (rbtnByFolder.IsChecked == true ? "ByFolder" : "ByNumPages");
                if (newChooseSortBy != oldChooseSortby)
                {
                    Properties.Settings.Default.ChooseBooksSort = newChooseSortBy;
                    Properties.Settings.Default.Save();
                }
                break;

            case "Fa_vorites":
                if (_TreeView.SelectedItem != null)
                {
                    if (_TreeView.SelectedItem is MyTreeViewItem myTreeViewItem)
                    {
                        chosenPdfMetaData            = myTreeViewItem.pdfMetaData;
                        chosenPdfMetaData.LastPageNo = myTreeViewItem.favEntry.Pageno;
                    }
                }
                break;

            case "_Query":
                var br      = (BrowsePanel)this.dpQuery.Children[0];
                var selitem = br.BrowseList.SelectedItem;
                if (selitem != null)
                {
                    var tdescitem = TypeDescriptor.GetProperties(selitem)["_Tup"];
                    Tuple <PdfMetaData, TOCEntry> tup = (Tuple <PdfMetaData, TOCEntry>)tdescitem.GetValue(selitem);
                    chosenPdfMetaData            = tup.Item1;
                    chosenPdfMetaData.LastPageNo = tup.Item2.PageNo;
                }
                break;

            case "_Playlists":
                break;
            }
            Properties.Settings.Default.ChooseQueryTab = ((TabItem)(this.tabControl.SelectedItem)).Header as string;
            this.DialogResult = true; // chosenPdfMetaData  can be null
            this.Close();
            e.Handled = true;
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
            public async Task <PdfMetaData> CreateAndSaveBmkAsync()
            {
                (var lstPdfMetaFileData, var _) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(pdfViewerWindow._RootMusicFolder);

                var curmetadata = lstPdfMetaFileData[0];

                test.AddLogEntry($"metadata cnt = {lstPdfMetaFileData.Count}= {curmetadata}");
                Assert.AreEqual(1, lstPdfMetaFileData.Count);
                //                curmetadata.ToggleFavorite(PageNo: 2, IsFavorite: true);
                curmetadata.SaveIfDirty(ForceDirty: true);
                //                test.AddLogEntry(File.ReadAllText(curmetadata.PdfBmkMetadataFileName));
                foreach (var vol in curmetadata.lstVolInfo)
                {
                    test.AddLogEntry($" vol = {vol}");
                }
                return(curmetadata);
            }
Exemplo n.º 5
0
 void DumpVolAndToc(string description, PdfMetaData curMetaData)
 {
     AddLogEntry($"{description}");
     foreach (var vol in curMetaData.lstVolInfo)
     {
         AddLogEntry($"  Vol {vol}");
     }
     foreach (var toc in curMetaData.lstTocEntries)
     {
         AddLogEntry($"  TOC {toc}");
     }
     if (curMetaData.dictFav.Count != curMetaData.Favorites.Count)
     {
         AddLogEntry($"dictFav != Fav {curMetaData.dictFav.Count}  {curMetaData.Favorites.Count}");
     }
     foreach (var fav in curMetaData.dictFav)
     {
         AddLogEntry($"  Fav {fav}");
     }
 }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        public async Task TestSingles()
        {
            var testdir       = Path.Combine(Environment.CurrentDirectory, "testdir");
            var singlesFolder = Path.Combine(testdir, "singles");

            for (int i = 0; i < 20; i++)
            {
                AddLogEntry($"Iter {i}");
                if (!Directory.Exists(testdir))
                {
                    Directory.CreateDirectory(testdir);
                }
                foreach (var file in Directory.EnumerateFiles(testdir))
                {
                    AddLogEntry($"Del {file}");
                    File.Delete(file);
                }
                if (Directory.Exists(singlesFolder))
                {
                    foreach (var file in Directory.EnumerateFiles(singlesFolder))
                    {
                        AddLogEntry($"Del {file}");
                        File.Delete(file);
                    }
                    Directory.Delete(singlesFolder, recursive: true);
                }
                Directory.CreateDirectory(singlesFolder);
                var sourceFiles = Directory.GetFiles(Path.Combine(root1, @"ragtime\singles"), "*.pdf").OrderBy(p => p);
                foreach (var file in sourceFiles.Take(2))
                {
                    File.Copy(file, Path.Combine(singlesFolder, Path.GetFileName(file)));
                }

                foreach (var testfile in Directory.EnumerateFiles(singlesFolder))
                {
                    var pdfdoc = await PdfMetaData.GetPdfDocumentForFileAsync(testfile);
                }
            }
        }
Exemplo n.º 8
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;
                //    }
                //}
            }
        }
Exemplo n.º 9
0
 public MyTreeViewItem(PdfMetaData pdfMetaData, Favorite favEntry)
 {
     this.pdfMetaData = pdfMetaData;
     this.favEntry    = favEntry;
 }
Exemplo n.º 10
0
 public MyContentControl(PdfMetaData pdfMetaDataItem)
 {
     this.pdfMetaDataItem = pdfMetaDataItem;
 }
Exemplo n.º 11
0
        private async Task ChangeRootFolderAsync(string selectedPath)
        {
            var col = new StringCollection
            {
                selectedPath
            };

            foreach (ComboBoxItem itm in this.cboRootFolder.Items)
            {
                var str = (string)itm.Content;
                if (!col.Contains(str) && str != NewFolderDialogString)
                {
                    col.Add((string)itm.Content);
                }
            }
            Properties.Settings.Default.RootFolderMRU = col;
            Properties.Settings.Default.Save();
            // now that we have the col in MRU order, we want to rearrange the cbo.items in same order
            CboEnableCboSelectionChange = false;
            this.cboRootFolder.Items.Clear();
            foreach (var itm in col)
            {
                this.cboRootFolder.Items.Add(new ComboBoxItem()
                {
                    Content = itm
                });
            }
            this.cboRootFolder.Items.Add(new ComboBoxItem()
            {
                Content = NewFolderDialogString
            });
            this.cboRootFolder.SelectedIndex = 0;
            CboEnableCboSelectionChange      = true;


            if (Directory.Exists(selectedPath))
            {
                _pdfViewerWindow._RootMusicFolder = selectedPath;
            }
            //            this.cboRootFolder.Text = _pdfViewerWindow._RootMusicFolder;
            this.tabControl.SelectedIndex = 0;
            _pdfViewerWindow.CloseCurrentPdfFile();
            _pdfViewerWindow.lstPdfMetaFileData.Clear(); // release mem
            (_pdfViewerWindow.lstPdfMetaFileData, _pdfViewerWindow.lstFolders) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(selectedPath);

            this.lbBooks.ItemsSource = null;
            this.dpTview.Children.Clear();
            this.dpQuery.Children.Clear();
            this.dpPlaylists.Children.Clear();
            ActivateTab(string.Empty);
        }
Exemplo n.º 12
0
        //        [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;
        }
Exemplo n.º 13
0
        public async Task TestSinglesPreserveFavAndInk()
        {
            var failMessage  = string.Empty;
            var ev           = new ManualResetEventSlim();
            var tcsStaThread = new TaskCompletionSource <int>();
            var c            = CreateExecutionContext(tcsStaThread);
            await c.Dispatcher.InvokeAsync(async() =>
            {
                try
                {
                    foreach (var fileToAdd in new[] { "12th Street", "Black Cat", "Freckles" }) // insert before, between and after 14,40
                    {
                        AddLogEntry($"Doing = {fileToAdd}");
                        int num = 0;
                        using (var helper = new SinglesTesthelper(this, (str) =>
                        {
                            var include = false;
                            if (str.Contains("Crazy Bone") || str.Contains("Banana Peel"))
                            {
                                include = true;
                            }
                            num++;
                            return(include);
                        }))
                        {
                            var strComposer = "Charles L Johnson GREAT COMPOSER GREAT COMPOSER GREAT COMPOSER";
                            {
                                var curmetadata = await helper.CreateAndSaveBmkAsync();

                                Assert.AreEqual(2, curmetadata.lstVolInfo.Count);
                                Assert.AreEqual(2, curmetadata.lstTocEntries.Count);
                                for (int i = 0; i < curmetadata.MaxPageNum; i += 2)
                                {
                                    var volno = curmetadata.GetVolNumFromPageNum(i);
                                    curmetadata.ToggleFavorite(i, IsFavorite: true, FavoriteName: curmetadata.lstVolInfo[volno].FileNameVolume);
                                }
                                DumpVolAndToc("Start", curmetadata);
                                curmetadata.lstTocEntries.Where(t => t.SongName.Substring(0, 5) == "Crazy").First().Composer = strComposer;
                                curmetadata.SaveIfDirty(ForceDirty: true);
                                var fileToAddFullPath = helper.sourceFiles.Where(f => f.Contains(fileToAdd)).First();
                                AddLogEntry($"Adding file  = {fileToAddFullPath}");
                                File.Copy(fileToAddFullPath,
                                          Path.Combine(helper.singlesFolder, Path.GetFileName(fileToAddFullPath))
                                          );
                            }
                            {
                                (var lstPdfMetaFileData, var lstFolders) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(helper.pdfViewerWindow._RootMusicFolder);
                                Assert.AreEqual(1, lstPdfMetaFileData.Count);
                                var curmetadata = lstPdfMetaFileData[0];
                                DumpVolAndToc("Done", curmetadata);
                                Assert.AreEqual(3, curmetadata.lstVolInfo.Count);
                                Assert.AreEqual(3, curmetadata.lstTocEntries.Count);
                                Assert.AreEqual(strComposer, curmetadata.lstTocEntries.Where(t => t.SongName.Substring(0, 5) == "Crazy").First().Composer);
                                var lastone = string.Empty;
                                foreach (var vol in curmetadata.lstVolInfo)
                                {
                                    Assert.IsTrue(string.Compare(lastone, vol.FileNameVolume) < 0, $"sequence {lastone} {vol}");
                                    lastone = vol.FileNameVolume;
                                }
                                Assert.AreEqual("Crazy Bone Rag.pdf", curmetadata.dictFav.Values.ToList()[2].FavoriteName);
                                curmetadata.SaveIfDirty(ForceDirty: true);
                                AddLogEntry(File.ReadAllText(curmetadata.PdfBmkMetadataFileName));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    failMessage = ex.ToString();
                }
                AddLogEntry("set event");
                ev.Set();
            });

            ev.Wait();
            AddLogEntry("Done wait event");
            Assert.IsTrue(string.IsNullOrEmpty(failMessage), failMessage);
        }
Exemplo n.º 14
0
        public async Task TestSinglesInsert1File()
        {
            var failMessage  = string.Empty;
            var ev           = new ManualResetEventSlim();
            var tcsStaThread = new TaskCompletionSource <int>();
            var c            = CreateExecutionContext(tcsStaThread);
            await c.Dispatcher.InvokeAsync(async() =>
            {
                try
                {
                    foreach (var fileToAdd in new[] { "12th Street", "Black Cat", "Freckles" }) // insert before, between and after 14,40
                    {
                        AddLogEntry($"Doing = {fileToAdd}");
                        int num = 0;
                        using (var helper = new SinglesTesthelper(this, (str) =>
                        {
                            var include = false;
                            if (str.Contains("Crazy Bone") || str.Contains("Banana Peel"))
                            {
                                include = true;
                            }
                            num++;
                            return(include);
                        }))
                        {
                            var curmetadata = await helper.CreateAndSaveBmkAsync();
                            DumpVolAndToc("Start", curmetadata);
                            Assert.AreEqual(2, curmetadata.lstVolInfo.Count, $"{fileToAdd}");
                            Assert.AreEqual(2, curmetadata.lstTocEntries.Count, $"{fileToAdd}");
                            if (fileToAdd == "12th Street")
                            {
                                Assert.AreEqual("Crazy Bone Rag", curmetadata.lstTocEntries[1].SongName, $"{fileToAdd}");
                                Assert.AreEqual(3, curmetadata.lstTocEntries[1].PageNo, $"{fileToAdd}");
                            }

                            var fileToAddFullPath = helper.sourceFiles.Where(f => f.Contains(fileToAdd)).First();
                            AddLogEntry($"Adding file  = {fileToAddFullPath}");
                            File.Copy(fileToAddFullPath,
                                      Path.Combine(helper.singlesFolder, Path.GetFileName(fileToAddFullPath))
                                      );
                            (var lstPdfMetaFileData, var lstFolders) = await PdfMetaData.LoadAllPdfMetaDataFromDiskAsync(helper.pdfViewerWindow._RootMusicFolder);
                            Assert.AreEqual(1, lstPdfMetaFileData.Count, $"{fileToAdd}");
                            curmetadata = lstPdfMetaFileData[0];
                            DumpVolAndToc("Done", curmetadata);
                            Assert.AreEqual(3, curmetadata.lstVolInfo.Count, $"{fileToAdd}");
                            Assert.AreEqual(3, curmetadata.lstTocEntries.Count, $"{fileToAdd}");
                            var lastone = string.Empty;
                            foreach (var vol in curmetadata.lstVolInfo)
                            {
                                Assert.IsTrue(string.Compare(lastone, vol.FileNameVolume) < 0, $" nskip {fileToAdd} sequence {lastone} {vol}");
                                lastone = vol.FileNameVolume;
                            }
                            if (fileToAdd == "12th Street" || fileToAdd == "Black Cat")
                            {
                                Assert.AreEqual("Crazy Bone Rag", curmetadata.lstTocEntries[2].SongName, $"{fileToAdd}");
                                Assert.AreEqual(6, curmetadata.lstTocEntries[2].PageNo, $"{fileToAdd}");
                            }
                            else
                            {
                                Assert.AreEqual("Freckles Rag", curmetadata.lstTocEntries[2].SongName, $"{fileToAdd}");
                                Assert.AreEqual(6, curmetadata.lstTocEntries[2].PageNo, $"{fileToAdd}");
                            }
                            curmetadata.SaveIfDirty(ForceDirty: true);
                            AddLogEntry(File.ReadAllText(curmetadata.PdfBmkMetadataFileName));
                        }
                    }
                }
                catch (Exception ex)
                {
                    failMessage = ex.ToString();
                }
                AddLogEntry("set event");
                ev.Set();
            });

            ev.Wait();
            AddLogEntry("Done wait event");
            Assert.IsTrue(string.IsNullOrEmpty(failMessage), failMessage);
        }