Ejemplo n.º 1
0
        public static void DeleteFromManifest(IEnumerable <string> FilesTodelete)
        {
            OpfDocument     doc         = new OpfDocument();
            XElement        oldManifest = doc.GetXmlElement("manifest");
            XNamespace      ns          = oldManifest.Name.Namespace;
            List <XElement> newItems    = new List <XElement>();

            foreach (XElement item in oldManifest.Elements())
            {
                string href      = item.Attribute("href").Value;
                string id        = item.Attribute("id").Value;
                string mediaType = item.Attribute("media-type").Value;
                if (!FilesTodelete.Contains(href))
                {
                    newItems.Add(item);
                }
            }

            XElement newManifest = new XElement(ns + "manifest", newItems);

            doc.ReplaceManifest(newManifest);

            //if (doc.SaveMessage.StartsWith("Error"))
            //    MessageBox.Show(doc.SaveMessage, "Manifest Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Ejemplo n.º 2
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.º 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
        private void ReplaceManifest()
        {
            OpfDocument     doc         = new OpfDocument();
            XElement        oldManifest = doc.GetXmlElement("manifest");
            XNamespace      ns          = oldManifest.Name.Namespace;
            List <XElement> newItems    = new List <XElement>();

            Ids = new Dictionary <string, string>();

            foreach (XElement item in oldManifest.Elements())
            {
                string href      = Utils.VerifyFilenameEncoding(item.Attribute("href").Value);
                string id        = item.Attribute("id").Value;
                string mediaType = item.Attribute("media-type").Value;
                if (FilesTodelete.Contains(href))
                {
                    List <string> filesToAdd = (from i in list
                                                where i.Key.Split('#')[0] == href
                                                select i.Value).ToList();


                    foreach (string files in filesToAdd)
                    {
                        string newID = id + "-" + filesToAdd.IndexOf(files);
                        if (!Ids.ContainsKey(newID))
                        {
                            Ids.Add(newID, id);

                            XElement newEl =
                                new XElement(ns + "item",
                                             new XAttribute("href", files),
                                             new XAttribute("id", newID),
                                             new XAttribute("media-type", mediaType));

                            newItems.Add(newEl);
                        }
                    }
                }
                else
                {
                    Ids.Add(id, id);
                    newItems.Add(item);
                }
            }

            XElement newManifest = new XElement(ns + "manifest", newItems);

            doc.ReplaceManifest(newManifest);
        }
Ejemplo n.º 5
0
        protected void SaveOpfFixToFile()
        {
            List <string> list = new List <string>()
            {
                "metadata", "manifest", "spine", "guide"
            };
            OpfDocument doc = new OpfDocument();

            foreach (string item in list)
            {
                XElement meta = doc.GetXmlElement(item);
                if (meta != null)
                {
                    doc.ReplaceSection(meta, item);
                }
            }
        }
Ejemplo n.º 6
0
        public static void DeleteFromGuide(IEnumerable<string> FilesToDelete)
        {
            OpfDocument doc = new OpfDocument();
            XElement oldManifest = doc.GetXmlElement("guide");
            XNamespace ns = oldManifest.Name.Namespace;
            List<XElement> newItems = new List<XElement>();

            foreach (XElement item in oldManifest.Elements())
            {
                string href = item.Attribute("href").Value;
                if (!FilesToDelete.Contains(href))
                {
                    newItems.Add(item);
                }
            }

            XElement newManifest = new XElement(ns + "guide", newItems);
            doc.ReplaceSection(newManifest, "guide");
        }
Ejemplo n.º 7
0
        public static void DeleteFromGuide(IEnumerable <string> FilesToDelete)
        {
            OpfDocument     doc         = new OpfDocument();
            XElement        oldManifest = doc.GetXmlElement("guide");
            XNamespace      ns          = oldManifest.Name.Namespace;
            List <XElement> newItems    = new List <XElement>();

            foreach (XElement item in oldManifest.Elements())
            {
                string href = item.Attribute("href").Value;
                if (!FilesToDelete.Contains(href))
                {
                    newItems.Add(item);
                }
            }

            XElement newManifest = new XElement(ns + "guide", newItems);

            doc.ReplaceSection(newManifest, "guide");
        }
Ejemplo n.º 8
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.º 9
0
        public static void DeleteFromManifest(IEnumerable<string> FilesTodelete)
        {
            OpfDocument doc = new OpfDocument();
            XElement oldManifest = doc.GetXmlElement("manifest");
            XNamespace ns = oldManifest.Name.Namespace;
            List<XElement> newItems = new List<XElement>();

            foreach (XElement item in oldManifest.Elements())
            {
                string href = item.Attribute("href").Value;
                string id = item.Attribute("id").Value;
                string mediaType = item.Attribute("media-type").Value;
                if (!FilesTodelete.Contains(href))
                {
                    newItems.Add(item);
                }
            }

            XElement newManifest = new XElement(ns + "manifest", newItems);
            doc.ReplaceManifest(newManifest);

            //if (doc.SaveMessage.StartsWith("Error"))
            //    MessageBox.Show(doc.SaveMessage, "Manifest Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Ejemplo n.º 10
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.º 11
0
        private void ReplaceManifest()
        {
            OpfDocument doc = new OpfDocument();
            XElement oldManifest = doc.GetXmlElement("manifest");
            XNamespace ns = oldManifest.Name.Namespace;
            List<XElement> newItems = new List<XElement>();
            Ids = new Dictionary<string, string>();

            foreach (XElement item in oldManifest.Elements())
            {
                string href = Utils.VerifyFilenameEncoding(item.Attribute("href").Value);
                string id = item.Attribute("id").Value;
                string mediaType = item.Attribute("media-type").Value;
                if (FilesTodelete.Contains(href))
                {
                    List<string> filesToAdd = (from i in list
                                               where i.Key.Split('#')[0] == href
                                               select i.Value).ToList();

                    foreach (string files in filesToAdd)
                    {
                        string newID = id + "-" + filesToAdd.IndexOf(files);
                        if (!Ids.ContainsKey(newID))
                        {
                            Ids.Add(newID, id);

                            XElement newEl =
                                new XElement(ns + "item",
                                    new XAttribute("href", files),
                                    new XAttribute("id", newID),
                                    new XAttribute("media-type", mediaType));

                            newItems.Add(newEl);
                        }
                    }

                } else
                {
                    Ids.Add(id, id);
                    newItems.Add(item);
                }
            }

            XElement newManifest = new XElement(ns + "manifest", newItems);
            doc.ReplaceManifest(newManifest);
        }
Ejemplo n.º 12
0
 protected void SaveOpfFixToFile()
 {
     List<string> list = new List<string>() { "metadata", "manifest", "spine", "guide" };
     OpfDocument doc = new OpfDocument();
     foreach (string item in list)
     {
         XElement meta = doc.GetXmlElement(item);
         if (meta != null)
         {
             doc.ReplaceSection(meta, item);
         }
     }
 }