Example #1
0
        private void SetIncludeOnlySection(ONNotebook notebook)
        {
            if (notebook == null)
            {
                throw new ArgumentNullException("notebook");
            }

            ONSection section = notebook.GetSection(Config.Current.ExportOnly);

            if (section == null)
            {
                // dont find any section to process
                return;
            }
            notebook.SetNotebookExcludeFlag(true);
            notebook.SetSectionExcludeFlag(section, false);

            // propagate settings
            ONBasedType b = section;

            while (b != notebook)
            {
                if (b is ONSection)
                {
                    (b as ONSection).Exclude = false;
                }
                b = b.Parent;
            }

            Log.Information(string.Format("Export only section [{0}]", section.Name));
            //foreach
        }
Example #2
0
        public void PDFCombineAllTest()
        {
            Export2PDF_Accessor target = new Export2PDF_Accessor();
            string     basedName       = string.Empty;
            ONNotebook notebook        = null;

            target.PDFCombineAll(basedName, notebook);
        }
Example #3
0
        public void GetSectionTest1()
        {
            ONNotebook target      = notebookListing.GetNotebook("Shared Reference");
            string     sectionName = "learning/programing";
            ONSection  expected    = null;
            ONSection  actual;

            actual = target.GetSection(sectionName);
            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void GetSectionTest3()
        {
            ONNotebook target      = notebookListing.GetNotebook("Code Notebook");
            string     sectionName = "Cá nhân/Thông tin không được xâm phạm";
            string     expected    = "{22A89DC3-B809-4FAE-BDF1-B34AF08A0580}{1}{B0}";
            ONSection  actual;

            actual = target.GetSection(sectionName);
            Assert.AreEqual(expected, actual.ID);
        }
Example #5
0
        public void GetSectionTest2()
        {
            ONNotebook target      = notebookListing.GetNotebook("Code Notebook");
            string     sectionName = "Cá nhân";
            string     expected    = "Cá nhân";
            ONSection  actual;

            actual = target.GetSection(sectionName);
            Assert.AreEqual(expected, actual.Name);
        }
Example #6
0
 private void SetExcludeSection(ONNotebook notebook)
 {
     // set sections to exclude
     foreach (string s in Config.Current.ExcludeSections)
     {
         Data.ONSection exSec = notebook.GetSection(s);
         if (exSec != null)
         {
             Log.Information(string.Format("Exclude section [{0}] from exporting", exSec.Name));
             exSec.Exclude = true;
         }
     }
 }
        public void ONNotebookListingConstructor2Test()
        {
            string notebooksXml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<one:Notebooks xmlns:one=""http://schemas.microsoft.com/office/onenote/2007/onenote"">
  <one:Notebook name=""Code Notebook"" ID=""{B4B9B6D8-C298-4CF1-A191-C30C5BF0B69D}{1}{B0}"" lastModifiedTime=""2007-12-07T10:15:56.000Z"">
    <one:Section name=""TODO"" ID=""{928433B9-7EE1-0C1D-38FB-21B387CEFA94}{1}{B0}"" lastModifiedTime=""2007-08-31T14:53:10.000Z"">
        <one:Page name=""Test"" ID=""{928433B9-7EE1-0C1D-38FB-21B387CEFA94}{1}{B0}"" lastModifiedTime=""2007-08-31T14:53:10.000Z"" />
        </one:Section>
    </one:Notebook>
</one:Notebooks>";

            ONNotebookListing target = new ONNotebookListing(notebooksXml);
            string            expect = "Code Notebook";
            ONNotebook        actual = target.GetNotebook("Code Notebook");

            Assert.AreEqual(expect, actual.Name);
        }
        public void GetNotebookTest()
        {
            string            notebooksXml = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<one:Notebooks xmlns:one=""http://schemas.microsoft.com/office/onenote/2007/onenote"">
  <one:Notebook name=""Code Notebook"" ID=""{B4B9B6D8-C298-4CF1-A191-C30C5BF0B69D}{1}{B0}"" lastModifiedTime=""2007-12-07T10:15:56.000Z"">
    <one:Section name=""TODO"" ID=""{928433B9-7EE1-0C1D-38FB-21B387CEFA94}{1}{B0}"" lastModifiedTime=""2007-08-31T14:53:10.000Z"">
        <one:Page name=""Test"" ID=""{928433B9-7EE1-0C1D-38FB-21B387CEFA94}{1}{B0}"" lastModifiedTime=""2007-08-31T14:53:10.000Z"" />
        </one:Section>
    </one:Notebook>
</one:Notebooks>";
            ONNotebookListing target       = new ONNotebookListing(notebooksXml); // TODO: Initialize to an appropriate value
            string            notebookName = string.Empty;                        // TODO: Initialize to an appropriate value
            ONNotebook        expected     = null;                                // TODO: Initialize to an appropriate value
            ONNotebook        actual;

            actual = target.GetNotebook(notebookName);
            Assert.AreEqual(expected, actual);
        }
Example #9
0
        static void Main(string[] args)
        {
            OneNote.Application oneApp;
            // Obtain reference to OneNote application
            try
            {
                oneApp = new OneNote.Application();
            }
            catch (Exception e)
            {
                Log.Error(string.Format("Could not obtain reference to OneNote ({0})", e.Message));
                return;
            }

            // get till page level
            oneApp.GetHierarchy(null, OneNote.HierarchyScope.hsPages, out string outputXML);
            ONNotebookListing onListing = new ONNotebookListing(outputXML);

            if (Config.Current.ShowHelp || Config.Current.Arguments.Count == 0)
            {
                HelpHandler hh = new HelpHandler();
                Log.Information(hh.Print());
                return;
            }

            if (Config.Current.ListAllNotebook)
            {
                string[] notebookNames = onListing.ListAllNotebook();
                foreach (var nb in notebookNames)
                {
                    Console.WriteLine(nb);
                }
                return;
            }

            if (!string.IsNullOrEmpty(Config.Current.NotebookName))
            {
                Log.Information("Query notebook information");
                ONNotebook notebook = onListing.GetNotebook(Config.Current.NotebookName);
                if (notebook == null)
                {
                    Log.Error("Cannot get desired notebook");
                    return;
                }
                Log.Information(string.Format("Notebook name: {0}", notebook.Name));
                Log.Information(string.Format("Notebook ID: {0}", notebook.ID));
                Log.Information(string.Format("Number section: {0}", notebook.Sections.Count));

                Log.Information("Begin exporting ...");

                Export2PDF export2PDF = new Export2PDF();
                export2PDF.BasedPath          = Config.Current.CacheFolder;
                export2PDF.OneNoteApplication = oneApp;

                export2PDF.CreateCacheFolder(notebook);

                if (Config.Current.ExportNotebook)
                {
                    Log.Information(string.Format("Exporting entire notebook [{0}]", notebook.Name));
                    export2PDF.Export(Config.Current.OutputPath, notebook);
                }
                if (!string.IsNullOrEmpty(Config.Current.ExportSection))
                {
                    OneNote2PDF.Library.Data.ONSection section = notebook.GetSection(Config.Current.ExportSection);
                    if (section == null)
                    {
                        Log.Error("Cannot find the specified section");
                    }
                    else
                    {
                        Log.Information(string.Format("Exporting section [{0}] ...", section.Name));
                        export2PDF.Export(Config.Current.OutputPath, section);
                    }
                }
                return;
            }
        }