Beispiel #1
0
        /*
         * Tries to apply a setting otherwise applies settings based on a default structure
         */
        public static void applySetting(SectionObject section)
        {
            bool hasSetting = false;

            foreach (SettingsHolder setting in settings)
            {
                if (setting.notebook.Equals(section.notebook) &&
                    setting.sectionGroup.Equals(section.sectionGroup) &&
                    setting.section.Equals(section.section))
                {
                    section.fileName = setting.filename;
                    section.export   = setting.export;
                    hasSetting       = true;
                    setting.used     = true;
                }
            }
            if (!hasSetting)
            {
                if (section.sectionGroup != "")
                {
                    section.fileName = section.sectionGroup + "-" + section.section;
                }
                else
                {
                    section.fileName = section.section;
                }
                section.export = false;
                SettingsHolder settingsHolder = new SettingsHolder(section.notebook, section.sectionGroup, section.section, section.fileName, "0");
                settingsHolder.used = true;
                settings.Add(settingsHolder);
            }
        }
Beispiel #2
0
 public void adaptToItem(SectionObject item)
 {
     if (this.notebook.Equals(item.notebook) && this.sectionGroup.Equals(item.sectionGroup) && this.section.Equals(item.section))
     {
         this.filename = item.fileName;
         this.export   = item.export;
     }
 }
Beispiel #3
0
            public SettingsHolder(SectionObject section)
            {
                this.sectionGroup = section.sectionGroup;
                this.section      = section.section;
                this.notebook     = section.notebook;
                this.filename     = section.fileName;

                this.export = section.export;
            }
 /*
  * Adds the section object to this notebook object if the sections notebook
  * has the same name as this notebook object
  */
 public bool addSectionTry(SectionObject section)
 {
     if (section.notebook.Equals(this.name))
     {
         sections.Add(section);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #5
0
        public static void updateSetting(SectionObject section)
        {
            bool flag = false;

            foreach (SettingsHolder holder in settings)
            {
                if (holder.notebook.Equals(section.notebook) &&
                    holder.sectionGroup.Equals(section.sectionGroup) &&
                    holder.section.Equals(section.section))
                {
                    holder.filename = section.fileName;
                    holder.export   = section.export;
                    flag            = true;
                }
            }
            if (!flag)
            {
                settings.Add(new SettingsHolder(section));
            }
        }
        /*
         * 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());
        }