Ejemplo n.º 1
0
 public String getShortDesc(KonfigurationOneNote onenoteConf)
 {
     foreach (Paragraph paragraph in paragraphs)
     {
         if (paragraph.firstContentIsText())
         {
             String renderedText = paragraph.render(onenoteConf);
             try
             {
                 HtmlDocument doc = new HtmlDocument();
                 doc.LoadHtml(renderedText);
                 var           text   = doc.DocumentNode.SelectNodes("text()").Select(node => node.InnerText);
                 StringBuilder output = new StringBuilder();
                 foreach (string line in text)
                 {
                     output.AppendLine(line);
                 }
                 string textOnly = HttpUtility.HtmlDecode(output.ToString());
                 textOnly = textOnly.Replace("\r\n", "");
                 textOnly = textOnly.Replace("\n", "");
                 return(textOnly);
             }
             catch (Exception ex)
             {
                 Debug.WriteLine(ex.Message);
             }
         }
     }
     return("");
 }
Ejemplo n.º 2
0
        public String getPageJsonConfig(KonfigurationOneNote onenoteConf)
        {
            String itemsCfg = "{"
                              + "\"name\": \"" + JSONHelpers.EscapeStringValue(this.getCfgId()) + "\","
                              + "\"url\": \"" + JSONHelpers.EscapeStringValue(this.getRenderPagePath()) + "\","
                              + "\"title\": \"" + JSONHelpers.EscapeStringValue(this.name) + "\","
                              + "\"description\": \"" + JSONHelpers.EscapeStringValue(this.getShortDesc(onenoteConf)) + "\""
                              + "}";

            if (childPages.Count > 0)
            {
                foreach (Page page in childPages)
                {
                    itemsCfg = itemsCfg + "," + page.getPageJsonConfig(onenoteConf);
                }
                bool expanded = false;
                if (this.tags.Contains(onenoteConf.onenoteTags.expandedTag))
                {
                    expanded = true;
                }
                return("{"
                       + "\"title\": \"" + JSONHelpers.EscapeStringValue(this.name) + "\","
                       + (expanded ? "\"expanded\": true," : "")
                       + "\"items\": [" + itemsCfg + "]"
                       + "}");
            }
            else
            {
                return(itemsCfg);
            }
        }
Ejemplo n.º 3
0
        public override String render(KonfigurationOneNote onenoteConf)
        {
            XmlNode firstChild = node.FirstChild;

            if (firstChild.Name == "one:Bullet" &&
                firstChild.Attributes["bullet"] != null)
            {
                /**
                 * List Templates:
                 * -   List Item
                 * *   List Item
                 */
                switch (firstChild.Attributes["bullet"].InnerText)
                {
                case "25":
                    return("-   ");

                default:
                    return("*   ");
                }
            }
            else if (firstChild.Name == "one:Number" &&
                     firstChild.Attributes["text"] != null)
            {
                /**
                 * Numeric List Templates:
                 * 1.   List Item
                 * 2.   List Item
                 */
                return(firstChild.Attributes["text"].InnerText + "   ");
            }
            return("");
        }
        public static void StartExportOneNotePages(string profilename, KonfigurationOneNote onenoteConf)
        {
            oneNote = new Application();
            String      oneNoteBooksC;
            Application onApplication = new Application();

            onApplication.GetHierarchy(null,
                                       HierarchyScope.hsPages, out oneNoteBooksC);

            XmlDocument oneNoteBooksXml = new XmlDocument();

            oneNoteBooksXml.LoadXml(oneNoteBooksC);
            string strNamespace       = "http://schemas.microsoft.com/office/onenote/2013/onenote";
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(oneNoteBooksXml.NameTable);

            nsmgr.AddNamespace("one", strNamespace);
            XmlNode xmlOneNoteBook = oneNoteBooksXml.SelectSingleNode("//one:Notebook[@name='" + onenoteConf.notebook + "']", nsmgr);

            OneNoteBook book = new OneNoteBook(xmlOneNoteBook, onenoteConf);

            book.saveOneNoteBook(onenoteConf);
            book.saveOneNoteBookCfg(onenoteConf);

            Debug.WriteLine("Done.");
        }
Ejemplo n.º 5
0
        public ContentTable(XmlNode node, Page page, KonfigurationOneNote onenoteConf)
        {
            this.node = node;
            this.page = page;

            this.createTableStructure(onenoteConf);
        }
 public KonfigurationParameter()
 {
     this._ixConf                 = new KonfigurationIx();
     this._onenoteConf            = new KonfigurationOneNote();
     this._cmdGitPullAllConf      = new KonfigurationCmd();
     this._cmdEloPullUnittestConf = new KonfigurationCmd();
     this._cmdEloPrepareConf      = new KonfigurationCmd();
     this._cmdEloPullPackageConf  = new KonfigurationCmd();
 }
 public KonfigurationParameter(KonfigurationIx ixConf, KonfigurationOneNote onenoteConf, KonfigurationCmd cmdGitPullAllConf, KonfigurationCmd cmdEloPullUnittestConf, KonfigurationCmd cmdEloPrepareConf, KonfigurationCmd cmdEloPullPackageConf)
 {
     this._ixConf                 = ixConf;
     this._onenoteConf            = onenoteConf;
     this._cmdGitPullAllConf      = cmdGitPullAllConf;
     this._cmdEloPullUnittestConf = cmdEloPullUnittestConf;
     this._cmdEloPrepareConf      = cmdEloPrepareConf;
     this._cmdEloPullPackageConf  = cmdEloPullPackageConf;
 }
Ejemplo n.º 8
0
        public void savePages(KonfigurationOneNote onenoteConf)
        {
            foreach (Page page in pages)
            {
                page.saveMDFile(onenoteConf);
            }

            Debug.WriteLine("Finished page");
        }
Ejemplo n.º 9
0
        public void saveOneNoteBook(KonfigurationOneNote onenoteConf)
        {
            foreach (Section section in sections)
            {
                section.savePages(onenoteConf);
            }

            Debug.WriteLine("Finished section");
        }
Ejemplo n.º 10
0
        public override String render(KonfigurationOneNote onenoteConf)
        {
            String filePath = this.page.getRenderPagePath();

            if (altText.Trim().Equals(""))
            {
                return("{@img " + filename + "}");
            }
            return("{@img " + filename + " " + altText + "}"); // alt-text aus xml-Knoten
        }
Ejemplo n.º 11
0
 public Paragraph(Page page, XmlNode node, KonfigurationOneNote onenoteConf)
 {
     this.page = page;
     this.node = node;
     if (node.Attributes["quickStyleIndex"] != null)
     {
         this.quickStyleIndex = page.getQuickStyleNameForId(node.Attributes["quickStyleIndex"].InnerText);
     }
     readTagsForParagraph();
     addAllChildNodesAsContent(onenoteConf);
 }
Ejemplo n.º 12
0
        public void saveImage(KonfigurationOneNote onenoteConf)
        {
            String filePath = this.page.getPagePath(onenoteConf);
            String fn       = this.filename;

            if (this.requiresConversion)
            {
                fn = this.originFilename;
            }
            File.WriteAllBytes(filePath + @"\" + fn, Convert.FromBase64String(data.InnerText));
        }
        public KonfigurationParameter(XmlNode profileNode)
        {
            this._ixConf                 = new KonfigurationIx();
            this._onenoteConf            = new KonfigurationOneNote();
            this._cmdGitPullAllConf      = new KonfigurationCmd();
            this._cmdEloPullUnittestConf = new KonfigurationCmd();
            this._cmdEloPrepareConf      = new KonfigurationCmd();
            this._cmdEloPullPackageConf  = new KonfigurationCmd();

            foreach (XmlNode subNode in profileNode.ChildNodes)
            {
                string cmdName = "";

                switch (subNode.Name)
                {
                case "ixConf":
                    _ixConf = new KonfigurationIx(subNode);
                    break;

                case "onenoteConf":
                    _onenoteConf = new KonfigurationOneNote(subNode);
                    break;

                case "cmdConf":
                    foreach (XmlNode subSubNode in subNode.ChildNodes)
                    {
                        if (subSubNode.Name == "#text")
                        {
                            cmdName = subSubNode.InnerText;
                        }
                    }

                    switch (cmdName)
                    {
                    case "gitPullAll":
                        _cmdGitPullAllConf = new KonfigurationCmd(subNode);
                        break;

                    case "eloPullUnittest":
                        _cmdEloPullUnittestConf = new KonfigurationCmd(subNode);
                        break;

                    case "eloPrepare":
                        _cmdEloPrepareConf = new KonfigurationCmd(subNode);
                        break;

                    case "eloPullPackage":
                        _cmdEloPullPackageConf = new KonfigurationCmd(subNode);
                        break;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 14
0
        public bool ignore(KonfigurationOneNote onenoteConf)
        {
            IEnumerator <String> enumerator = this.tags.GetEnumerator();

            while (enumerator.MoveNext())
            {
                if (onenoteConf.ignoreTags.Contains(enumerator.Current))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 15
0
        private String getLang(KonfigurationOneNote onenoteConf)
        {
            String lang = "DE";

            try
            {
                lang = onenoteConf.lang;
            }
            catch (Exception)
            {
            }
            return(lang);
        }
Ejemplo n.º 16
0
        public void saveOneNoteBookCfg(KonfigurationOneNote onenoteConf)
        {
            System.IO.Directory.CreateDirectory(ExportOneNotePages.GetOutPutDir(onenoteConf.notebook));
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(ExportOneNotePages.GetOutPutDir(onenoteConf.notebook) + @"\guides.json"))
            {
                file.Write(getBookCfg(onenoteConf));

                file.Flush();
                file.Close();
            }

            Debug.WriteLine("Finished Config");
        }
Ejemplo n.º 17
0
        public void saveMDFile(KonfigurationOneNote onenoteConf)
        {
            System.IO.Directory.CreateDirectory(this.getPagePath(onenoteConf));
            using (System.IO.StreamWriter file = new System.IO.StreamWriter(this.getPagePath(onenoteConf) + @"README.md"))
            {
                file.WriteLine("# " + this.name);
                file.WriteLine("");
                foreach (Paragraph paragraph in paragraphs)
                {
                    String renderedText = paragraph.render(onenoteConf);

                    renderedText = this.RenderInternalLinks(renderedText);

                    file.WriteLine(renderedText);
                }

                file.Flush();
                file.Close();
            }

            foreach (Page page in childPages)
            {
                page.saveMDFile(onenoteConf);
            }

            foreach (ContentImage image in images)
            {
                image.saveImage(onenoteConf);
            }

            // rename thumbnail image as "icon.png"
            if (thumbnail != null)
            {
                thumbnail.renameToIcon();
                thumbnail.saveImage(onenoteConf);
            }

            try
            {
                this.readImages(onenoteConf);
            }
            catch (Exception e)
            {
                Debug.WriteLine("ERROR: reading images failed " + e.Message);
            }


            Debug.WriteLine("Finished page");
        }
Ejemplo n.º 18
0
        public void readImages(KonfigurationOneNote onenoteConf)
        {
            if (onenoteConf.renderImages == false)
            {
                return;
            }

            // read images from word export file since emf conversion does not handle antialiasing
            if (images.Count == 0)
            {
                return;
            }

            string zipPath = ExportOneNotePages.GetTempDir(onenoteConf.notebook) + @"\" + this.getCfgId() + this.getCfgId() + ".docx";

            if (File.Exists(zipPath))
            {
                return;
            }
            ExportOneNotePages.oneNote.Publish(this.id, zipPath, Microsoft.Office.Interop.OneNote.PublishFormat.pfWord);
            string extractPath = ExportOneNotePages.GetTempDir(onenoteConf.notebook) + @"\" + this.getCfgId() + @"\";

            if (Directory.Exists(extractPath))
            {
                Directory.Delete(extractPath, true);
            }

            System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);

            try
            {
                String   temp      = ExportOneNotePages.GetTempDir(onenoteConf.notebook) + @"\" + this.getCfgId() + @"\word\media\";
                String[] filePaths = Directory.GetFiles(temp);
                int      idx       = 0;
                foreach (String file in filePaths)
                {
                    if (file.StartsWith(temp + "image"))
                    {
                        File.Move(file, getPagePath(onenoteConf) + images[idx].filename);
                    }
                    idx++;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ERROR: Saving Images from Word failed. " + ex.Message);
            }
        }
Ejemplo n.º 19
0
        public Section(XmlNode node, OneNoteBook book, KonfigurationOneNote onenoteConf)
        {
            this.book = book;
            this.node = node;

            if (node.Attributes != null && node.Attributes["ID"] != null)
            {
                id = node.Attributes["ID"].InnerText;
            }
            if (node.Attributes != null && node.Attributes["name"] != null)
            {
                name = node.Attributes["name"].InnerText;
            }

            addPages(onenoteConf);
        }
Ejemplo n.º 20
0
        private Page getPage(XmlNode node, KonfigurationOneNote onenoteConf)
        {
            if (node.Attributes["ID"] != null)
            {
                String pageContentXml;
                ExportOneNotePages.oneNote.GetPageContent(node.Attributes["ID"].InnerText, out pageContentXml, PageInfo.piAll);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(pageContentXml);

                Page page = new Page(xmlDoc, node.Attributes["ID"].InnerText, this.book, onenoteConf);
                return(page);
            }

            return(null);
        }
Ejemplo n.º 21
0
        private void addAllChildNodesAsContent(KonfigurationOneNote onenoteConf)
        {
            foreach (XmlNode childNode in node.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "one:Table":
                    contents.Add(new ContentTable(childNode, page, onenoteConf));
                    break;

                case "one:T":
                    contents.Add(new ContentText(childNode, page));
                    break;

                case "one:List":
                    contents.Add(new ContentList(childNode, page));
                    break;

                case "one:Image":
                    // Check, if thumbnail tag is set
                    if (tags.Contains(onenoteConf.onenoteTags.thumbnailTag))
                    {
                        Debug.WriteLine("thumbnailTag");
                        // Set image as thumbnail to page and set paragraph to home
                        ContentImage img = new ContentImage(childNode, page);
                        page.setThumbnail(img);
                        this.isHome = true;
                    }
                    else
                    {
                        // check for locale tag
                        if (checkLocationTag(onenoteConf))
                        {
                            ContentImage img = new ContentImage(childNode, page);
                            contents.Add(img);
                            page.addImage(img);
                        }
                    }
                    break;

                default:
                    Debug.WriteLine("ERROR: Unknown type for paragraph: " + childNode.Name);
                    // ignore type
                    break;
                }
            }
        }
Ejemplo n.º 22
0
        public void createTableStructure(KonfigurationOneNote onenoteConf)
        {
            foreach (XmlNode childNode in node.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "one:Row":
                    table.Add(createTableRow(childNode, onenoteConf));
                    break;

                default:
                    Debug.WriteLine("ERROR: Unknown type for table: " + childNode.Name);
                    // ignore type
                    break;
                }
            }
        }
Ejemplo n.º 23
0
        public String getBookCfg(KonfigurationOneNote onenoteConf)
        {
            String itemsCfg = "";

            foreach (Section section in sections)
            {
                if (!itemsCfg.Equals(""))
                {
                    itemsCfg += ",";
                }
                itemsCfg += section.getPagesCfg(onenoteConf);
            }

            return("["
                   + itemsCfg
                   + "]");
        }
Ejemplo n.º 24
0
        private void addSections(KonfigurationOneNote onenoteConf)
        {
            foreach (XmlNode childNode in node.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "one:Section":
                    // if not deleted
                    // if (childNode.Attributes[""])
                    sections.Add(new Section(childNode, this, onenoteConf));
                    break;

                default:
                    Debug.WriteLine("ERROR: Unknown type for section element: " + childNode.Name);
                    // ignore type
                    break;
                }
            }
        }
Ejemplo n.º 25
0
        private Boolean checkLocationTag(KonfigurationOneNote onenoteConf)
        {
            // Check location, if selected
            String        lang       = getLang(onenoteConf);
            Boolean       addImage   = false;
            List <string> localeTags = new List <string>();
            String        textTag    = "";
            int           i;

            if (tags.Count == 0)
            {
                addImage = true;
            }
            else
            {
                for (i = 0; i < tags.Count; i++)
                {
                    textTag = tags[i];
                    if (textTag.StartsWith(preLocaleTag))
                    {
                        localeTags.Add(textTag);
                    }
                }
                if (localeTags.Count == 0)
                {
                    addImage = true;
                }
                else
                {
                    for (i = 0; i < localeTags.Count; i++)
                    {
                        textTag = localeTags[i];
                        if (textTag.EndsWith(lang))
                        {
                            addImage = true;
                        }
                    }
                }
            }
            return(addImage);
        }
Ejemplo n.º 26
0
        public List <List <Paragraph> > createTableRow(XmlNode node, KonfigurationOneNote onenoteConf)
        {
            List <List <Paragraph> > row = new List <List <Paragraph> >();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "one:Cell":
                    if (childNode.FirstChild != null)
                    {
                        List <Paragraph> column  = new List <Paragraph>();
                        XmlNodeList      oeNodes = childNode.FirstChild.ChildNodes;
                        foreach (XmlNode oeNode in oeNodes)
                        {
                            switch (oeNode.Name)
                            {
                            case "one:OE":
                                Paragraph paragraph = new Paragraph(this.page, oeNode, onenoteConf);
                                column.Add(paragraph);
                                break;

                            default:
                                break;
                            }
                        }

                        row.Add(column);
                    }
                    break;

                default:
                    Debug.WriteLine("ERROR: Unknown type for table: " + childNode.Name);
                    // ignore type
                    break;
                }
            }
            return(row);
        }
Ejemplo n.º 27
0
        public String render(KonfigurationOneNote onenoteConf)
        {
            // ignore paragraph if home
            if (this.isHome)
            {
                return("");
            }

            String paragraph = "";

            foreach (Content content in contents)
            {
                paragraph += content.render(onenoteConf);
            }

            // apply styles to paragraph
            paragraph = renderStyles(paragraph);

            // apply message types to content
            paragraph = renderMessageTypes(paragraph, tags, onenoteConf);

            return(paragraph);
        }
Ejemplo n.º 28
0
        public override String render(KonfigurationOneNote onenoteConf)
        {
            String tableOutput = "";

            foreach (List <List <Paragraph> > row in this.table)
            {
                Boolean isHeader           = tableOutput.Equals("");
                String  rowOutput          = "<tr>";
                String  headingOutputPre   = "";
                String  headingOutputAfter = "";
                foreach (List <Paragraph> cell in row)
                {
                    String content = "";
                    foreach (Paragraph paragraph in cell)
                    {
                        if (!content.Equals(""))
                        {
                            content += "<br />";
                        }
                        content += paragraph.render(onenoteConf);
                    }
                    rowOutput += "<td>" + content + "</td>";
                }
                rowOutput += "</tr>";
                if (isHeader)
                {
                    headingOutputPre   = "<table><thead>";
                    headingOutputAfter = "</thead><tbody>";
                }
                tableOutput += headingOutputPre + rowOutput + headingOutputAfter;
            }

            tableOutput += "</tbody></table>";

            return(tableOutput);
        }
Ejemplo n.º 29
0
        public String getPagesCfg(KonfigurationOneNote onenoteConf)
        {
            String itemsCfg = "";
            bool   expanded = false;

            foreach (Page page in pages)
            {
                if (page.tags.Contains(onenoteConf.onenoteTags.expandedTag))
                {
                    expanded = true;
                }
                if (!itemsCfg.Equals(""))
                {
                    itemsCfg += ",";
                }
                itemsCfg += page.getPageJsonConfig(onenoteConf);
            }

            return("{"
                   + "\"title\": \"" + JSONHelpers.EscapeStringValue(this.name) + "\","
                   + (expanded ? "\"expanded\": true," : "")
                   + "\"items\": [" + itemsCfg + "]"
                   + "}");
        }
Ejemplo n.º 30
0
        ContentImage thumbnail = null; // thumbnail image

        public Page(XmlDocument node, String id, OneNoteBook book, KonfigurationOneNote onenoteConf)
        {
            this.book = book;
            this.node = node;
            this.id   = id;

            // generate Page link
            String link;

            ExportOneNotePages.oneNote.GetHyperlinkToObject(this.id, null, out link);
            this.linkPageId = getLinkPageId(link);

            string strNamespace       = "http://schemas.microsoft.com/office/onenote/2013/onenote";
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(node.NameTable);

            nsmgr.AddNamespace("one", strNamespace);

            XmlNode pageNode = node.SelectSingleNode("//one:Page", nsmgr);

            if (pageNode.Attributes != null && pageNode.Attributes["name"] != null)
            {
                name = pageNode.Attributes["name"].InnerText;
            }

            // read quickstyle definitions
            XmlNodeList quickStyleNodes = node.SelectNodes("//one:QuickStyleDef", nsmgr);

            foreach (XmlNode quickStyleNode in quickStyleNodes)
            {
                if (quickStyleNode.Attributes["index"] != null && quickStyleNode.Attributes["name"] != null)
                {
                    styles.Add(quickStyleNode.Attributes["index"].InnerText, quickStyleNode.Attributes["name"].InnerText);
                }
            }

            // read tag definitions
            XmlNodeList tagDefNodes = node.SelectNodes("//one:TagDef", nsmgr);

            foreach (XmlNode tagDefNode in tagDefNodes)
            {
                if (tagDefNode.Attributes["index"] != null && tagDefNode.Attributes["name"] != null)
                {
                    tagDef.Add(tagDefNode.Attributes["index"].InnerText, tagDefNode.Attributes["name"].InnerText);
                }
            }

            // read tags
            XmlNodeList tagNodes = node.SelectNodes("//one:Tag", nsmgr);

            foreach (XmlNode tagNode in tagNodes)
            {
                if (tagNode.Attributes["index"] != null)
                {
                    String name = tagDef[tagNode.Attributes["index"].InnerText];
                    if (name != null)
                    {
                        tags.Add(name);
                    }
                }
            }

            // read paragraphs
            XmlNodeList oeNodes = node.SelectNodes("//one:OE", nsmgr);

            foreach (XmlNode oeNode in oeNodes)
            {
                if (!this.ignoreNodeIfNameInParents(oeNode, "one:Table") &&
                    !this.ignoreNodeIfNameInParents(oeNode, "one:Title"))
                {
                    paragraphs.Add(new Paragraph(this, oeNode, onenoteConf));
                }
            }
        }