Beispiel #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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
        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);
        }