Пример #1
0
        private void ChangeDocumentStatus(Fb2FixStatus status)
        {
            XmlNode statusInfoNode = document.SelectSingleNode("//FictionBook/description/custom-info[@info-type='fb2fix-status']");

            if (statusInfoNode != null && statusInfoNode.NodeType == XmlNodeType.Element)
            {
                statusInfoNode.InnerText = Enum.GetName(typeof(Fb2FixStatus), status);
            }
            else
            {
                XmlElement xmlStatusNode = document.CreateElement("custom-info");
                xmlStatusNode.InnerText = Enum.GetName(typeof(Fb2FixStatus), Fb2FixStatus.Passed);

                XmlAttribute statusAttr = document.CreateAttribute("info-type");
                statusAttr.Value = "fb2fix-status";

                xmlStatusNode.Attributes.Append(statusAttr);

                this.descriptionNode.AppendChild(xmlStatusNode);
            }
        }
Пример #2
0
        public FictionBook(XmlDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            this.document = document;

            this.documentStatus = Fb2FixStatus.None;

            XmlNode statusInfoNode = document.SelectSingleNode("//FictionBook/description/custom-info[@info-type='fb2fix-status']");
            if (statusInfoNode != null && statusInfoNode.NodeType == XmlNodeType.Element)
            {
                if (String.IsNullOrEmpty(statusInfoNode.InnerText))
                {
                    try
                    {
                        this.documentStatus = (Fb2FixStatus)Enum.Parse(typeof(Fb2FixStatus), statusInfoNode.InnerText, true);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
            }

            this.documentInfoNode = document.SelectSingleNode("//FictionBook/description/document-info");
            if (this.documentInfoNode != null && this.documentInfoNode.NodeType == XmlNodeType.Element)
            {
                documentInfo = new DocumentInfoNode();
                documentInfo.Load(this.documentInfoNode as XmlElement);
            }

            this.titleInfoNode = document.SelectSingleNode("//FictionBook/description/title-info");
            if (this.titleInfoNode != null && this.titleInfoNode.NodeType == XmlNodeType.Element)
            {
                titleInfo = new TitleInfoNode();
                titleInfo.Load(this.titleInfoNode as XmlElement);
            }

            if (titleInfo == null)
            {
                throw new Exception("InvalidFictionBookFormatException");
            }

            this.srcTitleInfoNode = document.SelectSingleNode("//FictionBook/description/src-title-info");
            if (this.srcTitleInfoNode != null && this.srcTitleInfoNode.NodeType == XmlNodeType.Element)
            {
                srcTitleInfo = new TitleInfoNode();
                srcTitleInfo.Load(this.srcTitleInfoNode as XmlElement);
            }

            this.publishInfoNode = document.SelectSingleNode("//FictionBook/description/publish-info");
            if (this.publishInfoNode != null && this.publishInfoNode.NodeType == XmlNodeType.Element)
            {
                publishInfo = new PublishInfoNode();
                publishInfo.Load(this.publishInfoNode as XmlElement);
            }

            this.descriptionNode = document.SelectSingleNode("//FictionBook/description");

            if (this.descriptionNode == null)
            {
                throw new Exception("InvalidFictionBookFormatException");
            }

            XmlNodeList nodes = document.SelectNodes("//FictionBook/description/custom-info");

            customInfos = new List<CustomInfoNode>(nodes.Count);

            foreach (XmlNode node in nodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    CustomInfoNode item = new CustomInfoNode();
                    item.Load((XmlElement)node);

                    if (!String.IsNullOrEmpty(item.InfoType))
                    {
                        switch (item.InfoType)
                        {
                            case "fb2fix-status":
                            case "librusec-id":
                            case "previous-id":
                                continue;
                        }
                    }

                    item.XmlNode = node;
                    customInfos.Add(item);
                }
            }

            this.modificationType = ModificationType.None;
            this.containerDateTime = DateTime.Now;
        }
Пример #3
0
        private void ChangeDocumentStatus(Fb2FixStatus status)
        {
            XmlNode statusInfoNode = document.SelectSingleNode("//FictionBook/description/custom-info[@info-type='fb2fix-status']");
            if (statusInfoNode != null && statusInfoNode.NodeType == XmlNodeType.Element)
            {
                statusInfoNode.InnerText = Enum.GetName(typeof(Fb2FixStatus), status);
            }
            else
            {
                XmlElement xmlStatusNode = document.CreateElement("custom-info");
                xmlStatusNode.InnerText = Enum.GetName(typeof(Fb2FixStatus), Fb2FixStatus.Passed);

                XmlAttribute statusAttr = document.CreateAttribute("info-type");
                statusAttr.Value = "fb2fix-status";

                xmlStatusNode.Attributes.Append(statusAttr);

                this.descriptionNode.AppendChild(xmlStatusNode);
            }
        }
Пример #4
0
        public FictionBook(XmlDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }

            this.document = document;

            this.documentStatus = Fb2FixStatus.None;

            XmlNode statusInfoNode = document.SelectSingleNode("//FictionBook/description/custom-info[@info-type='fb2fix-status']");

            if (statusInfoNode != null && statusInfoNode.NodeType == XmlNodeType.Element)
            {
                if (String.IsNullOrEmpty(statusInfoNode.InnerText))
                {
                    try
                    {
                        this.documentStatus = (Fb2FixStatus)Enum.Parse(typeof(Fb2FixStatus), statusInfoNode.InnerText, true);
                    }
                    catch (ArgumentException)
                    {
                    }
                }
            }

            this.documentInfoNode = document.SelectSingleNode("//FictionBook/description/document-info");
            if (this.documentInfoNode != null && this.documentInfoNode.NodeType == XmlNodeType.Element)
            {
                documentInfo = new DocumentInfoNode();
                documentInfo.Load(this.documentInfoNode as XmlElement);
            }

            this.titleInfoNode = document.SelectSingleNode("//FictionBook/description/title-info");
            if (this.titleInfoNode != null && this.titleInfoNode.NodeType == XmlNodeType.Element)
            {
                titleInfo = new TitleInfoNode();
                titleInfo.Load(this.titleInfoNode as XmlElement);
            }

            if (titleInfo == null)
            {
                throw new Exception("InvalidFictionBookFormatException");
            }

            this.srcTitleInfoNode = document.SelectSingleNode("//FictionBook/description/src-title-info");
            if (this.srcTitleInfoNode != null && this.srcTitleInfoNode.NodeType == XmlNodeType.Element)
            {
                srcTitleInfo = new TitleInfoNode();
                srcTitleInfo.Load(this.srcTitleInfoNode as XmlElement);
            }

            this.publishInfoNode = document.SelectSingleNode("//FictionBook/description/publish-info");
            if (this.publishInfoNode != null && this.publishInfoNode.NodeType == XmlNodeType.Element)
            {
                publishInfo = new PublishInfoNode();
                publishInfo.Load(this.publishInfoNode as XmlElement);
            }

            this.descriptionNode = document.SelectSingleNode("//FictionBook/description");

            if (this.descriptionNode == null)
            {
                throw new Exception("InvalidFictionBookFormatException");
            }

            XmlNodeList nodes = document.SelectNodes("//FictionBook/description/custom-info");

            customInfos = new List <CustomInfoNode>(nodes.Count);

            foreach (XmlNode node in nodes)
            {
                if (node.NodeType == XmlNodeType.Element)
                {
                    CustomInfoNode item = new CustomInfoNode();
                    item.Load((XmlElement)node);

                    if (!String.IsNullOrEmpty(item.InfoType))
                    {
                        switch (item.InfoType)
                        {
                        case "fb2fix-status":
                        case "librusec-id":
                        case "previous-id":
                            continue;
                        }
                    }

                    item.XmlNode = node;
                    customInfos.Add(item);
                }
            }

            this.modificationType  = ModificationType.None;
            this.containerDateTime = DateTime.Now;
        }