Esempio n. 1
0
        /// <summary>
        /// Deserializes the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        public void Deserialize(XmlElement element)
        {
            Version versionInfo = Util.GetTypeDescriptionProviderVersion(this.GetType());

            this.ArtifactDirectory        = string.Empty;
            this._externalLinks           = new CloneableList <ExternalLink> ();
            this.Labeller                 = null;
            this.ModificationDelaySeconds = null;
            this._name = string.Empty;
            this.Publishers.Clear();
            this.PublishExceptions = null;
            this.SourceControl     = null;
            this.State             = null;
            this.Tasks.Clear();
            this.Triggers.Clear();
            this.PreBuild.Clear();
            this.WebUrl           = null;
            this.WorkingDirectory = string.Empty;
            this._extensions      = new CloneableList <ProjectExtension> ();
            this.QueuePriority    = null;
            this.Queue            = string.Empty;
            this.Category         = string.Empty;

            if (string.Compare(element.Name, "project", false) != 0)
            {
                throw new InvalidCastException(string.Format("Unable to deserialize a project from a {0} element.", element.Name));
            }

            this.Name = Util.GetElementOrAttributeValue("name", element);

            if (versionInfo.CompareTo(new Version("1.3")) >= 0)
            {
                this.Queue = Util.GetElementOrAttributeValue("queue", element);
                int qp = 0;
                if (int.TryParse(Util.GetElementOrAttributeValue("queuePriority", element), out qp))
                {
                    this.QueuePriority = qp;
                }
                this.Category = Util.GetElementOrAttributeValue("category", element);
            }

            string s = Util.GetElementOrAttributeValue("workingDirectory", element);

            if (!string.IsNullOrEmpty(s))
            {
                this.WorkingDirectory = s;
            }

            s = Util.GetElementOrAttributeValue("artifactDirectory", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.ArtifactDirectory = s;
            }

            s = Util.GetElementOrAttributeValue("webURL", element);
            if (!string.IsNullOrEmpty(s))
            {
                this.WebUrl = new Uri(s);
            }

            s = Util.GetElementOrAttributeValue("modificationDelaySeconds", element);
            if (!string.IsNullOrEmpty(s))
            {
                int mds = 0;
                if (int.TryParse(s, out mds))
                {
                    this.ModificationDelaySeconds = mds;
                }
            }

            if (Util.IsInVersionRange(null, new Version("1.2.1"), versionInfo))
            {
                s = Util.GetElementOrAttributeValue("publishExceptions", element);
                if (!string.IsNullOrEmpty(s))
                {
                    this.PublishExceptions = string.Compare(s, bool.TrueString, true) == 0;
                }
            }

            XmlElement ele = element.SelectSingleNode("triggers") as XmlElement;

            if (ele != null)
            {
                foreach (XmlElement trig in ele.SelectNodes("./*"))
                {
                    Trigger trigger = Util.GetTriggerFromElement(trig);
                    if (trigger != null)
                    {
                        this.Triggers.Add(trigger);
                    }
                }
            }

            ele = element.SelectSingleNode("sourcecontrol") as XmlElement;
            if (ele != null)
            {
                SourceControl sc = Util.GetSourceControlFromElement(ele);
                if (sc != null)
                {
                    this.SourceControl = sc;
                }
            }

            ele = element.SelectSingleNode("labeller") as XmlElement;
            if (ele != null)
            {
                Labeller labeller = Util.GetLabellerFromElement(ele);
                if (labeller != null)
                {
                    this.Labeller = labeller;
                }
            }

            ele = element.SelectSingleNode("state") as XmlElement;
            if (ele != null)
            {
                State state = Util.GetStateFromElement(ele);
                this.State = state;
            }

            ele = element.SelectSingleNode("tasks") as XmlElement;
            if (ele != null)
            {
                foreach (XmlElement t in ele.SelectNodes("./*"))
                {
                    PublisherTask task = Util.GetPublisherTaskFromElement(t);
                    if (task != null)
                    {
                        this.Tasks.Add(task);
                    }
                }
            }

            ele = element.SelectSingleNode("publishers") as XmlElement;
            if (ele != null)
            {
                foreach (XmlElement t in ele.SelectNodes("./*"))
                {
                    PublisherTask pub = Util.GetPublisherTaskFromElement(t);
                    if (pub != null)
                    {
                        this.Publishers.Add(pub);
                    }
                }
            }

            ele = element.SelectSingleNode("preBuild") as XmlElement;
            if (ele == null) // reported that either are acceptable.
            {
                ele = element.SelectSingleNode("prebuild") as XmlElement;
            }

            if (ele != null)
            {
                foreach (XmlElement t in ele.SelectNodes("./*"))
                {
                    PublisherTask task = Util.GetPublisherTaskFromElement(t);
                    if (task != null)
                    {
                        this.PreBuild.Add(task);
                    }
                }
            }

            ele = element.SelectSingleNode("externalLinks") as XmlElement;
            if (ele != null)
            {
                foreach (XmlElement eleUrl in ele.SelectNodes("externalLink"))
                {
                    ExternalLink el = new ExternalLink();
                    el.Deserialize(eleUrl);
                    this.ExternalLinks.Add(el);
                }
            }

            foreach (Type type in Util.ProjectExtensions)
            {
                this.ProjectExtensions.Add((ProjectExtension)Util.CreateInstanceOfType(type));
            }

            XmlElement securityEl = element.SelectSingleNode("security") as XmlElement;

            if (securityEl != null)
            {
                string          xmlName  = securityEl.GetAttribute("type");
                ProjectSecurity security = Util.CreateInstanceFromXmlName <ProjectSecurity>(xmlName);
                if (security != null)
                {
                    security.Deserialize(securityEl);
                    Security = security;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Serializes this instance.
        /// </summary>
        /// <returns></returns>
        public XmlElement Serialize()
        {
            Version versionInfo = Util.GetTypeDescriptionProviderVersion(this.GetType());

            XmlDocument doc  = new XmlDocument();
            XmlElement  root = doc.CreateElement("project");

            root.SetAttribute("name", Util.CheckRequired(this, "name", this.Name));

            // 1.3 introduced the queue and queue priority
            if (versionInfo.CompareTo(new Version("1.3")) >= 0)
            {
                if (!string.IsNullOrEmpty(this.Queue))
                {
                    root.SetAttribute("queue", this.Queue);
                }
                if (this.QueuePriority.HasValue)
                {
                    root.SetAttribute("queuePriority", this.QueuePriority.Value.ToString( ));
                }
                XmlElement tele = doc.CreateElement("category");
                tele.InnerText = this.Category;
            }

            if (!string.IsNullOrEmpty(this.WorkingDirectory))
            {
                XmlElement ele = doc.CreateElement("workingDirectory");
                ele.InnerText = this.WorkingDirectory;
                root.AppendChild(ele);
            }

            if (!string.IsNullOrEmpty(this.ArtifactDirectory))
            {
                XmlElement ele = doc.CreateElement("artifactDirectory");
                ele.InnerText = this.ArtifactDirectory;
                root.AppendChild(ele);
            }

            if (this.WebUrl != null)
            {
                XmlElement ele = doc.CreateElement("webURL");
                ele.InnerText = this.WebUrl.ToString();
                root.AppendChild(ele);
            }

            if (this.ModificationDelaySeconds.HasValue)
            {
                XmlElement ele = doc.CreateElement("modificationDelaySeconds");
                ele.InnerText = this.ModificationDelaySeconds.Value.ToString();
                root.AppendChild(ele);
            }


            if (Util.IsInVersionRange(null, new Version("1.2.1"), versionInfo))
            {
                if (this.PublishExceptions.HasValue)
                {
                    XmlElement ele = doc.CreateElement("publishExceptions");
                    ele.InnerText = this.PublishExceptions.Value.ToString( );
                    root.AppendChild(ele);
                }
            }

            if (SourceControl != null)
            {
                root.AppendChild(doc.ImportNode(SourceControl.Serialize(), true));
            }

            XmlElement triggersEle = this.Triggers.Serialize( );

            root.AppendChild(doc.ImportNode(triggersEle, true));

            if (this.Tasks.Count > 0)
            {
                XmlElement ele = this.Tasks.Serialize( );
                if (ele != null)
                {
                    root.AppendChild(doc.ImportNode(ele, true));
                }
            }

            if (this.Publishers.Count > 0)
            {
                XmlElement ele = this.Publishers.Serialize( );
                if (ele != null)
                {
                    root.AppendChild(doc.ImportNode(ele, true));
                }
            }

            if (versionInfo.CompareTo(new Version("1.1")) >= 0)
            {
                if (this.PreBuild.Count > 0)
                {
                    XmlElement ele = this.PreBuild.Serialize( );
                    if (ele != null)
                    {
                        root.AppendChild(doc.ImportNode(ele, true));
                    }
                }
            }

            if (this.State != null)
            {
                root.AppendChild(doc.ImportNode(this.State.Serialize(), true));
            }

            if (this.Labeller != null)
            {
                root.AppendChild(doc.ImportNode(this.Labeller.Serialize(), true));
            }

            if (this.ExternalLinks.Count > 0)
            {
                XmlElement ele = doc.CreateElement("externalLinks");
                foreach (ExternalLink lnk in this.ExternalLinks)
                {
                    ele.AppendChild(doc.ImportNode(lnk.Serialize(), true));
                }
                root.AppendChild(ele);
            }

            // Extended items
            foreach (ProjectExtension ipe in this._extensions)
            {
                XmlElement ele = ipe.Serialize();
                if (ele != null)
                {
                    root.AppendChild(doc.ImportNode(ele, true));
                }
            }

            if (Security != null)
            {
                XmlElement securityEl = Security.Serialize();
                if (securityEl != null)
                {
                    root.AppendChild(doc.ImportNode(securityEl, true));
                }
            }

            return(root);
        }