Ejemplo n.º 1
0
        protected override XElement ExportNewTOC()
        {
            List<XElement> list = new List<XElement>();

            foreach (Node item in Model.Nodes)
            {
                XElement navPoint = ConvertToXElement(item);
                if (navPoint != null)
                {
                    list.Add(navPoint);
                }
            }
            IEnumerable<XAttribute> spine = TOC.Attributes();
            XElement navMap = null;

            if (spine.Count()>0)
            {
                navMap = new XElement(ns + "spine", spine, list);
            } else
            {
                //There is no spine elements
                OpfDocument doc = new OpfDocument();
                XAttribute TocRef = new XAttribute("toc", doc.GetNCXid());

                navMap = new XElement(ns + "spine", TocRef, list);
            }

            OnSave(new ExportTocEventArgs(navMap));

            //_NewTOC = navMap;
            return navMap;
        }
Ejemplo n.º 2
0
        protected override XElement ExportNewTOC()
        {
            List <XElement> list = new List <XElement>();

            foreach (Node item in Model.Nodes)
            {
                XElement navPoint = ConvertToXElement(item);
                if (navPoint != null)
                {
                    list.Add(navPoint);
                }
            }
            IEnumerable <XAttribute> spine = TOC.Attributes();
            XElement navMap = null;

            if (spine.Count() > 0)
            {
                navMap = new XElement(ns + "spine", spine, list);
            }
            else
            {
                //There is no spine elements
                OpfDocument doc    = new OpfDocument();
                XAttribute  TocRef = new XAttribute("toc", doc.GetNCXid());

                navMap = new XElement(ns + "spine", TocRef, list);
            }


            OnSave(new ExportTocEventArgs(navMap));

            //_NewTOC = navMap;
            return(navMap);
        }
Ejemplo n.º 3
0
        private void ReplaceSpine()
        {
            OpfDocument     doc      = new OpfDocument();
            XElement        oldSpine = doc.GetXmlElement("spine");
            XNamespace      ns       = oldSpine.Name.Namespace;
            List <XElement> newItems = new List <XElement>();

            foreach (XElement item in oldSpine.Elements())
            {
                string id = item.Attribute("idref").Value;
                if (Ids.Values.Contains(id))
                {
                    List <string> IdsToAdd = (from i in Ids
                                              where i.Value == id
                                              select i.Key).ToList();


                    foreach (string ids in IdsToAdd)
                    {
                        XElement newEl =
                            new XElement(ns + "itemref",
                                         new XAttribute("idref", ids));

                        newItems.Add(newEl);
                    }
                }
                else
                {
                    newItems.Add(item);
                }
            }

            IEnumerable <XAttribute> spine = oldSpine.Attributes();
            XElement newSpine = null;

            if (spine.Count() > 0)
            {
                newSpine = new XElement(ns + "spine", spine, newItems);
            }
            else
            {
                //There is no spine elements
                XAttribute TocRef = new XAttribute("toc", doc.GetNCXid());

                newSpine = new XElement(ns + "spine", TocRef, newItems);
            }

            doc.ReplaceSpine(newSpine);
        }
Ejemplo n.º 4
0
        public static void DeleteFromSpine(IEnumerable <string> FilesTodelete)
        {
            OpfDocument     doc      = new OpfDocument();
            XElement        oldSpine = doc.GetXmlElement("spine");
            XNamespace      ns       = oldSpine.Name.Namespace;
            List <XElement> newItems = new List <XElement>();

            foreach (XElement item in oldSpine.Elements())
            {
                string id = item.Attribute("idref").Value;
                if (!FilesTodelete.Contains(GetSrc(id)))
                {
                    newItems.Add(item);
                }
            }

            IEnumerable <XAttribute> spine = oldSpine.Attributes();
            XElement newSpine = null;

            if (spine.Count() > 0)
            {
                newSpine = new XElement(ns + "spine", spine, newItems);
            }
            else
            {
                //There is no spine elements
                XAttribute TocRef = new XAttribute("toc", doc.GetNCXid());

                newSpine = new XElement(ns + "spine", TocRef, newItems);
            }

            doc.ReplaceSpine(newSpine);

            if (doc.SaveMessage.StartsWith("Error"))
            {
                MessageBox.Show(doc.SaveMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
0
        private void ReplaceSpine()
        {
            OpfDocument doc = new OpfDocument();
            XElement oldSpine = doc.GetXmlElement("spine");
            XNamespace ns = oldSpine.Name.Namespace;
            List<XElement> newItems = new List<XElement>();

            foreach (XElement item in oldSpine.Elements())
            {
                string id = item.Attribute("idref").Value;
                if (Ids.Values.Contains(id))
                {
                    List<string> IdsToAdd = (from i in Ids
                                             where i.Value == id
                                             select i.Key).ToList();

                    foreach (string ids in IdsToAdd)
                    {
                        XElement newEl =
                            new XElement(ns + "itemref",
                                new XAttribute("idref", ids));

                        newItems.Add(newEl);
                    }

                } else
                {
                    newItems.Add(item);
                }
            }

            IEnumerable<XAttribute> spine = oldSpine.Attributes();
            XElement newSpine = null;

            if (spine.Count() > 0)
            {
                newSpine = new XElement(ns + "spine", spine, newItems);
            } else
            {
                //There is no spine elements
                XAttribute TocRef = new XAttribute("toc", doc.GetNCXid());

                newSpine = new XElement(ns + "spine", TocRef, newItems);
            }

            doc.ReplaceSpine(newSpine);
        }
Ejemplo n.º 6
0
        public static void DeleteFromSpine(IEnumerable<string> FilesTodelete)
        {
            OpfDocument doc = new OpfDocument();
            XElement oldSpine = doc.GetXmlElement("spine");
            XNamespace ns = oldSpine.Name.Namespace;
            List<XElement> newItems = new List<XElement>();

            foreach (XElement item in oldSpine.Elements())
            {
                string id = item.Attribute("idref").Value;
                if (!FilesTodelete.Contains(GetSrc(id)))
                {
                    newItems.Add(item);
                }
            }

            IEnumerable<XAttribute> spine = oldSpine.Attributes();
            XElement newSpine = null;

            if (spine.Count() > 0)
            {
                newSpine = new XElement(ns + "spine", spine, newItems);
            } else
            {
                //There is no spine elements
                XAttribute TocRef = new XAttribute("toc", doc.GetNCXid());

                newSpine = new XElement(ns + "spine", TocRef, newItems);
            }

            doc.ReplaceSpine(newSpine);

            if (doc.SaveMessage.StartsWith("Error"))
                MessageBox.Show(doc.SaveMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }