/// <summary> /// Reads an XML config document. /// </summary> /// <param name="document">The document to read.</param> /// <param name="errorProcesser">The error processer to use (can be null).</param> /// <returns>The loaded configuration.</returns> public IConfiguration Read(XmlDocument document, IConfigurationErrorProcesser errorProcesser) { Configuration configuration = new Configuration(); string conflictingXmlNode = string.Empty; List <string> projectNames = new List <string>(); // Validate the document element var actualErrorProcesser = errorProcesser ?? new DefaultErrorProcesser(); VerifyDocumentHasValidRootElement(document, actualErrorProcesser); InvalidNodeEventHandler invalidNodeHandler = (args) => { if (!actualErrorProcesser.ProcessUnhandledNode(args.Node)) { actualErrorProcesser.ProcessError(args.Message); } }; typeTable.InvalidNode += invalidNodeHandler; try { var sha = new SHA1CryptoServiceProvider(); foreach (XmlNode node in document.DocumentElement) { conflictingXmlNode = string.Empty; if (!(node.NodeType == XmlNodeType.Comment || node.NodeType == XmlNodeType.Text)) { conflictingXmlNode = "Conflicting project data : " + node.OuterXml; // Load the item and generate the hash if required var loadedItem = this.ParseElement(node); var hashStore = loadedItem as IHashStore; if (hashStore != null) { var data = Encoding.Unicode.GetBytes(node.OuterXml); var hash = sha.ComputeHash(data); hashStore.Hash = hash; } // Add the item to the configuration if (loadedItem is IProject) { this.LoadAndValidateProject(actualErrorProcesser, projectNames, configuration, loadedItem); } else if (loadedItem is IQueueConfiguration) { this.LoadAndValidateQueue(configuration, loadedItem); } else if (loadedItem is ISecurityManager) { this.LoadAndValidateSecurityManager(configuration, loadedItem); } else { actualErrorProcesser.ProcessError( new ConfigurationException( "\nUnknown configuration item found\n" + node.OuterXml)); } } } // Do a validation check to ensure internal configuration consistency ValidateConfiguration(configuration, actualErrorProcesser); } catch (NetReflectorException ex) { actualErrorProcesser.ProcessError(new ConfigurationException("\nUnable to instantiate CruiseControl projects from configuration document." + "\nConfiguration document is likely missing Xml nodes required for properly populating CruiseControl configuration.\n" + ex.Message + "\n " + conflictingXmlNode, ex)); } finally { typeTable.InvalidNode -= invalidNodeHandler; } return(configuration); }
public NetReflectorTypeTable(IInstantiator instantiator) { this.instantiator = instantiator; InvalidNode = new InvalidNodeEventHandler(NullHandler); }