/// <summary> /// Creates an instance of InheritDocCopyComponent class. /// </summary> /// <param name="configuration">Configuration section to be parsed.</param> /// <param name="data">A dictionary object with string as key and object as value.</param> public InheritDocCopyComponent(XPathNavigator configuration, Dictionary <string, object> data) : base(configuration, data) { // get the copy commands XPathNodeIterator copy_nodes = configuration.Select("copy"); foreach (XPathNavigator copy_node in copy_nodes) { // get the comments info string source_name = copy_node.GetAttribute("name", string.Empty); if (String.IsNullOrEmpty(source_name)) { throw new ConfigurationErrorsException("Each copy command must specify an index to copy from."); } // get the reflection info string reflection_name = copy_node.GetAttribute("use", String.Empty); if (String.IsNullOrEmpty(reflection_name)) { throw new ConfigurationErrorsException("Each copy command must specify an index to get reflection information from."); } IndexedDocumentController indexController = (IndexedDocumentController)data[source_name]; this.index = indexController[source_name]; IndexedDocumentController reflectController = (IndexedDocumentController)data[reflection_name]; this.reflectionIndex = reflectController[reflection_name]; } this.WriteMessage(MessageLevel.Info, "Initialized."); }
protected CopyComponentEx(XPathNavigator configuration, Dictionary <string, object> data) : base(configuration, data) { IndexedDocumentController cached = null; foreach (KeyValuePair <string, object> item in data) { cached = item.Value as IndexedDocumentController; if (cached != null) { break; } } if (cached != null) { BuildComponent copyComponent = cached.Component; if (copyComponent != null) { BuildAssembler assembler = copyComponent.BuildAssembler; if (assembler != null) { _messageWriter = assembler.MessageWriter; } } } _thisType = this.GetType(); }
protected override void Dispose(bool disposing) { if (_documentController != null) { _documentController.Dispose(); _documentController = null; } }
public CopyFromIndexComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { _copyComponents = new List <CopyComponent>(); _copyCommands = new List <CopyFromIndexCommand>(); _context = new CustomContext(); // set up the context XPathNodeIterator contextNodes = configuration.Select("context"); foreach (XPathNavigator contextNode in contextNodes) { string prefix = contextNode.GetAttribute("prefix", String.Empty); string name = contextNode.GetAttribute("name", String.Empty); _context.AddNamespace(prefix, name); } // set up the indices _documentController = new IndexedDocumentController(this, configuration, _context, Data); // get the copy commands XPathNodeIterator copyNodes = configuration.Select("copy"); foreach (XPathNavigator copyNode in copyNodes) { string sourceName = copyNode.GetAttribute("name", String.Empty); if (String.IsNullOrEmpty(sourceName)) { throw new BuildComponentException( "Each copy command must specify an index to copy from."); } string keyXPath = copyNode.GetAttribute("key", String.Empty); string sourceXPath = copyNode.GetAttribute("source", String.Empty); if (String.IsNullOrEmpty(sourceXPath)) { throw new BuildComponentException( "When instantiating a CopyFromDirectory component, you must specify a source xpath format using the source attribute."); } string targetXPath = copyNode.GetAttribute("target", String.Empty); if (String.IsNullOrEmpty(targetXPath)) { throw new BuildComponentException( "When instantiating a CopyFromDirectory component, you must specify a target xpath format using the target attribute."); } string attributeValue = copyNode.GetAttribute("attribute", String.Empty); string ignoreCaseValue = copyNode.GetAttribute("ignoreCase", String.Empty); string missingEntryValue = copyNode.GetAttribute("missing-entry", String.Empty); string missingSourceValue = copyNode.GetAttribute("missing-source", String.Empty); string missingTargetValue = copyNode.GetAttribute("missing-target", String.Empty); // Note that sourceController != _documentController IndexedDocumentController sourceController = (IndexedDocumentController)Data[sourceName]; CopyFromIndexCommand copyCommand = new CopyFromIndexCommand( sourceController[sourceName], keyXPath, sourceXPath, targetXPath, attributeValue, ignoreCaseValue); if (!String.IsNullOrEmpty(missingEntryValue)) { try { copyCommand.MissingEntry = (MessageLevel)Enum.Parse( typeof(MessageLevel), missingEntryValue, true); } catch (ArgumentException) { WriteMessage(MessageLevel.Error, String.Format("'{0}' is not a message level.", missingEntryValue)); } } if (!String.IsNullOrEmpty(missingSourceValue)) { try { copyCommand.MissingSource = (MessageLevel)Enum.Parse( typeof(MessageLevel), missingSourceValue, true); } catch (ArgumentException) { WriteMessage(MessageLevel.Error, String.Format( "'{0}' is not a message level.", missingSourceValue)); } } if (!String.IsNullOrEmpty(missingTargetValue)) { try { copyCommand.MissingTarget = (MessageLevel)Enum.Parse( typeof(MessageLevel), missingTargetValue, true); } catch (ArgumentException) { WriteMessage(MessageLevel.Error, String.Format( "'{0}' is not a message level.", missingTargetValue)); } } _copyCommands.Add(copyCommand); } XPathNodeIterator componentNodes = configuration.Select("components/component"); foreach (XPathNavigator componentNode in componentNodes) { // get the data to load the component string assemblyPath = componentNode.GetAttribute( "assembly", String.Empty); if (String.IsNullOrEmpty(assemblyPath)) { WriteMessage(MessageLevel.Error, "Each component element must have an assembly attribute."); } string typeName = componentNode.GetAttribute("type", String.Empty); if (String.IsNullOrEmpty(typeName)) { WriteMessage(MessageLevel.Error, "Each component element must have a type attribute."); } // expand environment variables in the path assemblyPath = Environment.ExpandEnvironmentVariables(assemblyPath); try { Assembly assembly = Assembly.LoadFrom(assemblyPath); CopyComponent component = (CopyComponent)assembly.CreateInstance(typeName, false, BindingFlags.Public | BindingFlags.Instance, null, new Object[2] { componentNode.Clone(), Data }, null, null); if (component == null) { WriteMessage(MessageLevel.Error, String.Format( "The type '{0}' does not exist in the assembly '{1}'.", typeName, assemblyPath)); } else { _copyComponents.Add(component); } } catch (IOException e) { WriteMessage(MessageLevel.Error, String.Format( "A file access error occurred while attempting to load the build component '{0}'. The error message is: {1}", assemblyPath, e.Message)); } catch (BadImageFormatException e) { WriteMessage(MessageLevel.Error, String.Format( "A syntax generator assembly '{0}' is invalid. The error message is: {1}.", assemblyPath, e.Message)); } catch (TypeLoadException e) { WriteMessage(MessageLevel.Error, String.Format( "The type '{0}' does not exist in the assembly '{1}'. The error message is: {2}", typeName, assemblyPath, e.Message)); } catch (MissingMethodException e) { WriteMessage(MessageLevel.Error, String.Format( "The type '{0}' in the assembly '{1}' does not have an appropriate constructor. The error message is: {2}", typeName, assemblyPath, e.Message)); } catch (TargetInvocationException e) { WriteMessage(MessageLevel.Error, String.Format( "An error occurred while attempting to instantiate the type '{0}' in the assembly '{1}'. The error message is: {2}", typeName, assemblyPath, e.InnerException.Message)); } catch (InvalidCastException) { WriteMessage(MessageLevel.Error, String.Format( "The type '{0}' in the assembly '{1}' is not a SyntaxGenerator.", typeName, assemblyPath)); } } WriteMessage(MessageLevel.Info, String.Format( "Loaded {0} copy components.", _copyComponents.Count)); }