Exemple #1
0
        /// <summary>
        /// Generates a clone of this security settings configuration.
        /// </summary>
        /// <returns></returns>
        public virtual object Clone()
        {
            ServerSecurity newValue = new ServerSecurity();

            CopyTo(newValue);
            return(newValue);
        }
Exemple #2
0
        /// <summary>
        /// Deserializes the specified <see cref="System.Xml.XmlDocument">XmlDocument</see>.
        /// </summary>
        /// <param name="ccnetConfig">The ccnet config.</param>
        /// <exception cref="CCNetConfig.Core.Exceptions.DuplicateProjectNameException">DuplicateProjectNameException</exception>
        public void Deserialize(XmlDocument ccnetConfig)
        {
            this.Projects.Clear();
            Queues.Clear();
            Version v = Util.GetConfigFileVersion(ccnetConfig);

            if (v != null)
            {
                this.Version = v;
            }
            if (ccnetConfig.DocumentElement != null && string.Compare(ccnetConfig.DocumentElement.Name, "cruisecontrol", false) == 0)
            {
                /*this.Entities = ccnetConfig.DocumentType.Entities;
                 * foreach ( XmlEntity entity in this.Entities ) {
                 *      Console.WriteLine ( entity.ToString () );
                 * }*/

                ItemSerialiserFactory factory = new ItemSerialiserFactory();

                // Attempt to deserialise each item in the configuration
                foreach (XmlElement item in ccnetConfig.DocumentElement.SelectNodes("*"))
                {
                    IItemSerialiser serialiser = factory.Retrieve(item.Name);
                    if (serialiser != null)
                    {
                        // The serialiser factory knows the item type, so it can be deserialised and
                        // added to the correct collection
                        object output = serialiser.Deserialize(item);
                        if (output is Project)
                        {
                            Project p = output as Project;
                            if (!this.Projects.Contains(p.Name))
                            {
                                this.Projects.Add(p);
                            }
                            else
                            {
                                throw new DuplicateProjectNameException(p.Name);
                            }
                        }
                        else if (output is Queue)
                        {
                            Queue q = output as Queue;
                            if (!Queues.Contains(q.Name))
                            {
                                Queues.Add(q);
                            }
                            else
                            {
                                throw new Exception(string.Format("Duplicate queue definition: '{0}'", q.Name));
                            }
                        }
                        else if (output is ServerSecurity)
                        {
                            Security = output as ServerSecurity;
                        }
                    }
                    else
                    {
                        // Currently throwing an exception if an unhandled item is found
                        // This should be changed to something a bit nicer
                        throw new Exception(
                                  string.Format("Unhandled item found: '{0}'",
                                                item.Name));
                    }
                }

                if (Util.UserSettings.SortProject)
                {
                    this.Projects.Sort(new ProjectList.ProjectComparer());
                }

                // Check all the projects and add any explicit queues that don't have their own configuration
                foreach (Project p in Projects)
                {
                    if (!string.IsNullOrEmpty(p.Queue))
                    {
                        if (!Queues.Contains(p.Queue))
                        {
                            Queue queue = new Queue();
                            queue.Name = p.Queue;
                            Queues.Add(queue);
                        }
                        Queues[p.Queue].Projects.Add(p);
                    }
                }
            }
            else
            {
                throw new InvalidCastException(string.Format("Can not convert {0} to a cruisecontrol", ccnetConfig.DocumentElement != null ? ccnetConfig.DocumentElement.Name : "UNKNOWN"));
            }
        }
Exemple #3
0
 /// <summary>
 /// Copies the values of this instance to another.
 /// </summary>
 /// <param name="value">The target instance.</param>
 protected void CopyTo(ServerSecurity value)
 {
     value.type = Type;
 }