Ejemplo n.º 1
0
        /*
         * Returns an array of all sections found,where every string is a single section. Structure of string:
         * notebook name,SPLITTER,section name,SPLITTER,ID,SPLITTER, exported file creation time,SPLITTER,FileName,
         */
        SectionObject[] GetAllSections(string section)
        {
            updateNotebookData();
            var ns = XDocument.Parse(strXML).Root.Name.Namespace;

            List <SectionObject> returnlist = new List <SectionObject>();

            //List<NotebookObject> notebooks = new List<NotebookObject>();

            notebooks = new NotebookObject[XDocument.Parse(strXML).Descendants(ns + "Notebook").Count()];

            int index = 0;

            XDocument sd = XDocument.Parse(strXML);

            foreach (var nodeBook in XDocument.Parse(strXML).Descendants(ns + "Notebook"))
            {
                NotebookObject currentNotebook = new NotebookObject(nodeBook.Attribute("name").Value);


                foreach (XElement element in nodeBook.Elements())
                {
                    string type             = element.Name.ToString().Split('}')[1];
                    String sectionGroupName = "";
                    Console.WriteLine(element.Attribute("name").Value);
                    SectionObject toAdd = new SectionObject();
                    if (type == "SectionGroup")
                    {
                        if (!element.Attribute("name").Value.ToString().Equals("OneNote_RecycleBin"))
                        {
                            sectionGroupName = element.Attribute("name").Value;
                            foreach (var nodeSection in element.Descendants(ns + "Section"))
                            {
                                if (nodeSection.Attribute("name").ToString().Contains(section) || section.Equals("") || section.Equals(String.Empty))
                                {
                                    toAdd = new SectionObject(nodeBook.Attribute("name").Value, sectionGroupName, nodeSection.Attribute("name").Value, nodeSection.Attribute("ID").Value);
                                    if (!nodeSection.Parent.Attribute("name").Value.ToString().Equals(toAdd.sectionGroup))
                                    {
                                        toAdd = new SectionObject(nodeBook.Attribute("name").Value, sectionGroupName, nodeSection.Parent.Attribute("name").Value.ToString() + "-" + toAdd.section, nodeSection.Attribute("ID").Value);
                                    }
                                    if (!returnlist.Contains(toAdd))
                                    {
                                        currentNotebook.addSectionTry(toAdd);
                                        returnlist.Add(toAdd);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (element.Attribute("name").ToString().Contains(section) || section.Equals("") || section.Equals(String.Empty))
                        {
                            toAdd = new SectionObject(nodeBook.Attribute("name").Value, sectionGroupName, element.Attribute("name").Value, element.Attribute("ID").Value);
                            if (!returnlist.Contains(toAdd))
                            {
                                currentNotebook.addSectionTry(toAdd);
                                returnlist.Add(toAdd);
                            }
                        }
                    }
                }
                notebooks[index] = currentNotebook;
                index++;
            }
            currentNotebook = notebooks[0];
            allSections     = returnlist.ToArray();
            SettingsManager.checkForUnusedSetting();
            return(returnlist.ToArray());
        }