コード例 #1
0
        private static CustomContext GetContext(XPathNavigator configuration)
        {
            CustomContext context = new CustomContext();

            XPathNodeIterator context_nodes = configuration.Select("context");

            foreach (XPathNavigator context_node in context_nodes)
            {
                string prefix = context_node.GetAttribute("prefix", String.Empty);
                string name   = context_node.GetAttribute("name", String.Empty);
                context.AddNamespace(prefix, name);
            }

            return(context);
        }
コード例 #2
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // set up the context
            XPathNodeIterator context_nodes = configuration.Select("context");

            foreach (XPathNavigator context_node in context_nodes)
            {
                string prefix = context_node.GetAttribute("prefix", String.Empty);
                string name   = context_node.GetAttribute("name", String.Empty);
                context.AddNamespace(prefix, name);
            }

            // load the expression format
            XPathNavigator variable_node = configuration.SelectSingleNode("variable");

            if (variable_node == null)
            {
                throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " +
                                                       "specify a variable using the <variable> element.");
            }

            string xpath_format = variable_node.GetAttribute("expression", String.Empty);

            if ((xpath_format == null) || (xpath_format.Length == 0))
            {
                throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " +
                                                       "specify a variable expression using the expression attribute");
            }

            xpath = XPathExpression.Compile(xpath_format);

            // load the subcomponents
            WriteMessage(MessageLevel.Info, "Loading subcomponents.");
            XPathNavigator components_node = configuration.SelectSingleNode("components");

            if (components_node == null)
            {
                throw new ConfigurationErrorsException("When instantiating a ForEach component, you must " +
                                                       "specify subcomponents using the <components> element.");
            }

            components = BuildAssembler.LoadComponents(components_node);

            WriteMessage(MessageLevel.Info, "Loaded {0} subcomponents.", components.Count());
        }
コード例 #3
0
        public CopyFromIndexComponent(BuildAssembler assembler, XPathNavigator configuration)
            : base(assembler, configuration)
        {
            // set up the context
            XPathNodeIterator context_nodes = configuration.Select("context");

            foreach (XPathNavigator context_node in context_nodes)
            {
                string prefix = context_node.GetAttribute("prefix", String.Empty);
                string name   = context_node.GetAttribute("name", String.Empty);
                context.AddNamespace(prefix, name);
            }

            // set up the indices
            XPathNodeIterator index_nodes = configuration.Select("index");

            foreach (XPathNavigator index_node in index_nodes)
            {
                // get the name of the index
                string name = index_node.GetAttribute("name", String.Empty);
                if (String.IsNullOrEmpty(name))
                {
                    throw new ConfigurationErrorsException("Each index must have a unique name.");
                }

                // get the xpath for value nodes
                string value_xpath = index_node.GetAttribute("value", String.Empty);
                if (String.IsNullOrEmpty(value_xpath))
                {
                    WriteMessage(MessageLevel.Error, "Each index element must have a value attribute containing an XPath that describes index entries.");
                }

                // get the xpath for keys (relative to value nodes)
                string key_xpath = index_node.GetAttribute("key", String.Empty);
                if (String.IsNullOrEmpty(key_xpath))
                {
                    WriteMessage(MessageLevel.Error, "Each index element must have a key attribute containing an XPath (relative to the value XPath) that evaluates to the entry key.");
                }

                // get the cache size
                int    cache       = 10;
                string cache_value = index_node.GetAttribute("cache", String.Empty);
                if (!String.IsNullOrEmpty(cache_value))
                {
                    cache = Convert.ToInt32(cache_value);
                }

                // create the index
                IndexedDocumentCache index = new IndexedDocumentCache(this, key_xpath, value_xpath, context, cache);

                // search the data directories for entries
                XPathNodeIterator data_nodes = index_node.Select("data");
                foreach (XPathNavigator data_node in data_nodes)
                {
                    string base_value = data_node.GetAttribute("base", String.Empty);
                    if (!String.IsNullOrEmpty(base_value))
                    {
                        base_value = Environment.ExpandEnvironmentVariables(base_value);
                    }

                    bool   recurse       = false;
                    string recurse_value = data_node.GetAttribute("recurse", String.Empty);
                    if (!String.IsNullOrEmpty(recurse_value))
                    {
                        recurse = (bool)Convert.ToBoolean(recurse_value);
                    }

                    // get the files
                    string files = data_node.GetAttribute("files", String.Empty);
                    if (String.IsNullOrEmpty(files))
                    {
                        WriteMessage(MessageLevel.Error, "Each data element must have a files attribute specifying which files to index.");
                    }
                    // if ((files == null) || (files.Length == 0)) throw new ConfigurationErrorsException("When instantiating a CopyFromDirectory component, you must specify a directory path using the files attribute.");
                    files = Environment.ExpandEnvironmentVariables(files);

                    WriteMessage(MessageLevel.Info, String.Format("Searching for files that match '{0}'.", files));
                    index.AddDocuments(base_value, files, recurse);
                }
                WriteMessage(MessageLevel.Info, String.Format("Indexed {0} elements in {1} files.", index.Count, index.DocumentCount));

                Data.Add(name, index);
            }

            // get the copy commands
            XPathNodeIterator copy_nodes = configuration.Select("copy");

            foreach (XPathNavigator copy_node in copy_nodes)
            {
                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.");
                }

                string key_xpath = copy_node.GetAttribute("key", String.Empty);

                string source_xpath = copy_node.GetAttribute("source", String.Empty);
                if (String.IsNullOrEmpty(source_xpath))
                {
                    throw new ConfigurationErrorsException("When instantiating a CopyFromDirectory component, you must specify a source xpath format using the source attribute.");
                }

                string target_xpath = copy_node.GetAttribute("target", String.Empty);
                if (String.IsNullOrEmpty(target_xpath))
                {
                    throw new ConfigurationErrorsException("When instantiating a CopyFromDirectory component, you must specify a target xpath format using the target attribute.");
                }

                string attribute_value = copy_node.GetAttribute("attribute", String.Empty);

                string ignoreCase_value = copy_node.GetAttribute("ignoreCase", String.Empty);

                string missingEntryValue  = copy_node.GetAttribute("missing-entry", String.Empty);
                string missingSourceValue = copy_node.GetAttribute("missing-source", String.Empty);
                string missingTargetValue = copy_node.GetAttribute("missing-target", String.Empty);

                IndexedDocumentCache index = (IndexedDocumentCache)Data[source_name];

                CopyCommand copyCommand = new CopyCommand(index, key_xpath, source_xpath, target_xpath, attribute_value, ignoreCase_value);
                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));
                    }
                }

                copy_commands.Add(copyCommand);
            }

            XPathNodeIterator component_nodes = configuration.Select("components/component");

            foreach (XPathNavigator component_node in component_nodes)
            {
                // get the data to load the component
                string assembly_path = component_node.GetAttribute("assembly", String.Empty);
                if (String.IsNullOrEmpty(assembly_path))
                {
                    WriteMessage(MessageLevel.Error, "Each component element must have an assembly attribute.");
                }
                string type_name = component_node.GetAttribute("type", String.Empty);
                if (String.IsNullOrEmpty(type_name))
                {
                    WriteMessage(MessageLevel.Error, "Each component element must have a type attribute.");
                }

                // expand environment variables in the path
                assembly_path = Environment.ExpandEnvironmentVariables(assembly_path);

                //Console.WriteLine("loading {0} from {1}", type_name, assembly_path);
                try
                {
                    Assembly      assembly  = Assembly.LoadFrom(assembly_path);
                    CopyComponent component = (CopyComponent)assembly.CreateInstance(type_name, false, BindingFlags.Public | BindingFlags.Instance, null, new Object[2] {
                        component_node.Clone(), Data
                    }, null, null);

                    if (component == null)
                    {
                        WriteMessage(MessageLevel.Error, String.Format("The type '{0}' does not exist in the assembly '{1}'.", type_name, assembly_path));
                    }
                    else
                    {
                        components.Add(component);
                    }
                }
                catch (IOException e)
                {
                    WriteMessage(MessageLevel.Error, String.Format("A file access error occured while attempting to load the build component '{0}'. The error message is: {1}", assembly_path, e.Message));
                }
                catch (BadImageFormatException e)
                {
                    WriteMessage(MessageLevel.Error, String.Format("A syntax generator assembly '{0}' is invalid. The error message is: {1}.", assembly_path, 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}", type_name, assembly_path, 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}", type_name, assembly_path, e.Message));
                }
                catch (TargetInvocationException e)
                {
                    WriteMessage(MessageLevel.Error, String.Format("An error occured while attempting to instantiate the type '{0}' in the assembly '{1}'. The error message is: {2}", type_name, assembly_path, e.InnerException.Message));
                }
                catch (InvalidCastException)
                {
                    WriteMessage(MessageLevel.Error, String.Format("The type '{0}' in the assembly '{1}' is not a SyntaxGenerator.", type_name, assembly_path));
                }
            }

            WriteMessage(MessageLevel.Info, String.Format("Loaded {0} copy components.", components.Count));
        }
コード例 #4
0
		private static CustomContext GetContext (XPathNavigator configuration) {

			CustomContext context = new CustomContext();

			XPathNodeIterator context_nodes = configuration.Select("context");
			foreach (XPathNavigator context_node in context_nodes) {
				string prefix = context_node.GetAttribute("prefix", String.Empty);
				string name = context_node.GetAttribute("name", String.Empty);
				context.AddNamespace(prefix, name);
			}

			return(context);			

		}
コード例 #5
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // Get the context.  This will contain namespaces that prefix the elements to find.
            context = new CustomContext();

            XPathNodeIterator contextNodes = configuration.Select("context");

            foreach (XPathNavigator cn in contextNodes)
            {
                context.AddNamespace(cn.GetAttribute("prefix", String.Empty),
                                     cn.GetAttribute("name", String.Empty));
            }

            // Item keys are compared case-insensitively
            content = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            elements = new List <SharedContentElement>();

            // Get the elements to be resolved
            XPathNodeIterator resolve_nodes = configuration.Select("replace");

            foreach (XPathNavigator resolve_node in resolve_nodes)
            {
                // Get the XPath expression used to find the elements to replace
                string path = resolve_node.GetAttribute("elements", String.Empty);

                // If not defined, assume include and includeAttribute are to be replaced
                if (String.IsNullOrEmpty(path))
                {
                    path = "//include | //includeAttribute";
                }

                try
                {
                    XPathExpression path_expresion = XPathExpression.Compile(path, context);
                }
                catch (XPathException)
                {
                    base.WriteMessage(MessageLevel.Error, "The elements expression '{0}' is not a valid XPath",
                                      path);
                }

                // Get the XPath expression used to get the item name to insert
                string item = resolve_node.GetAttribute("item", String.Empty);

                if (String.IsNullOrEmpty(item))
                {
                    item = "string(@item)";
                }
                try
                {
                    XPathExpression item_expression = XPathExpression.Compile(item, context);
                }
                catch (XPathException)
                {
                    base.WriteMessage(MessageLevel.Error, "The item expression '{0}' is not a valid XPath", item);
                }

                // Get the XPath expression used to find parameter elements
                string parameters = resolve_node.GetAttribute("parameters", String.Empty);

                if (String.IsNullOrEmpty(parameters))
                {
                    parameters = "parameter";
                }

                // Get the XPath expression used to get the attribute name for attribute items
                string attribute = resolve_node.GetAttribute("attribute", String.Empty);

                if (String.IsNullOrEmpty(attribute))
                {
                    attribute = "string(@name)";
                }

                elements.Add(new SharedContentElement(path, item, parameters, attribute, context));
            }

            // If not defined, assume include and includeAttribute are to be replaced using the default names
            if (elements.Count == 0)
            {
                elements.Add(new SharedContentElement("//include | //includeAttribute", "string(@item)",
                                                      "parameter", "string(@name)", context));
            }

            // Load the content item files
            XPathNodeIterator content_nodes = configuration.Select("content");

            foreach (XPathNavigator content_node in content_nodes)
            {
                string sharedContentFiles = content_node.GetAttribute("file", String.Empty);

                if (String.IsNullOrEmpty(sharedContentFiles))
                {
                    base.WriteMessage(MessageLevel.Error, "The content/@file attribute must specify a path.");
                }

                this.ParseDocuments(sharedContentFiles);
            }

            base.WriteMessage(MessageLevel.Info, "Loaded {0} shared content items.", content.Count);
        }
コード例 #6
0
        // Namespace control

        public void AddNamespace(string prefix, string uri)
        {
            context.AddNamespace(prefix, uri);
        }