Exemplo n.º 1
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // Load the transforms
            XPathNodeIterator transformNodes = configuration.Select("transform");

            foreach(XPathNavigator transformNode in transformNodes)
            {
                // Load the transform
                string file = transformNode.GetAttribute("file", String.Empty);

                if(String.IsNullOrEmpty(file))
                    this.WriteMessage(MessageLevel.Error, "Each transform element must specify a file attribute.");

                file = Environment.ExpandEnvironmentVariables(file);

                Transform transform = null;

                try
                {
                    transform = new Transform(file);
                }
                catch(IOException e)
                {
                    this.WriteMessage(MessageLevel.Error, "The transform file '{0}' could not be loaded. The " +
                        "error message is: {1}", file, e.GetExceptionMessage());
                }
                catch(XmlException e)
                {
                    this.WriteMessage(MessageLevel.Error, "The transform file '{0}' is not a valid XML file. " +
                        "The error message is: {1}", file, e.GetExceptionMessage());
                }
                catch(XsltException e)
                {
                    this.WriteMessage(MessageLevel.Error, "The XSL transform '{0}' contains an error. The " +
                        "error message is: {1}", file, e.GetExceptionMessage());
                }

                transforms.Add(transform);

                // Load any arguments
                XPathNodeIterator argumentNodes = transformNode.Select("argument");

                foreach(XPathNavigator argumentNode in argumentNodes)
                {
                    string key = argumentNode.GetAttribute("key", String.Empty);

                    if(String.IsNullOrWhiteSpace(key))
                        this.WriteMessage(MessageLevel.Error, "When creating a transform argument, you must " +
                            "specify a key using the key attribute");

                    // Don't allow "key" as a key name.  That's reserved for the build process.
                    if(key == "key")
                        this.WriteMessage(MessageLevel.Error, "The key name 'key' is reserved for use by " +
                            "the build process.  Choose another key name.");

                    // Set "expand-value" attribute to true to expand environment variables embedded in "value".
                    string expandAttr = argumentNode.GetAttribute("expand-value", String.Empty);
                    bool expandValue = String.IsNullOrEmpty(expandAttr) ? false :
                        Convert.ToBoolean(expandAttr, CultureInfo.InvariantCulture);

                    // If a value attribute is supplied, use that.  If not, use the argument node itself
                    string value = argumentNode.GetAttribute("value", String.Empty);

                    if(!String.IsNullOrEmpty(value))
                        transform.Arguments[key] =  expandValue ? Environment.ExpandEnvironmentVariables(value) : value;
                    else
                        transform.Arguments[key] = argumentNode.Clone();
                }
            }
        }
Exemplo n.º 2
0
        //=====================================================================

        /// <inheritdoc />
        public override void Initialize(XPathNavigator configuration)
        {
            // load the transforms
            XPathNodeIterator transform_nodes = configuration.Select("transform");

            foreach(XPathNavigator transform_node in transform_nodes)
            {
                // load the transform
                string file = transform_node.GetAttribute("file", String.Empty);

                if(String.IsNullOrEmpty(file))
                    base.WriteMessage(MessageLevel.Error, "Each transform element must specify a file attribute.");

                file = Environment.ExpandEnvironmentVariables(file);

                Transform transform = null;

                try
                {
                    transform = new Transform(file);
                }
                catch(IOException e)
                {
                    base.WriteMessage(MessageLevel.Error, "The transform file '{0}' could not be loaded. The " +
                        "error message is: {1}", file, e.GetExceptionMessage());
                }
                catch(XmlException e)
                {
                    base.WriteMessage(MessageLevel.Error, "The transform file '{0}' is not a valid XML file. " +
                        "The error message is: {1}", file, e.GetExceptionMessage());
                }
                catch(XsltException e)
                {
                    base.WriteMessage(MessageLevel.Error, "The XSL transform '{0}' contains an error. The " +
                        "error message is: {1}", file, e.GetExceptionMessage());
                }

                transforms.Add(transform);

                // load any arguments
                XPathNodeIterator argument_nodes = transform_node.Select("argument");

                foreach(XPathNavigator argument_node in argument_nodes)
                {
                    string key = argument_node.GetAttribute("key", String.Empty);

                    if((key == null) || (key.Length == 0))
                        base.WriteMessage(MessageLevel.Error, "When creating a transform argument, you must " +
                            "specify a key using the key attribute");

                    // set "expand-value" attribute to true to expand environment variables embedded in "value".
                    string expand_attr = argument_node.GetAttribute("expand-value", String.Empty);
                    bool expand_value = String.IsNullOrEmpty(expand_attr) ? false :
                        Convert.ToBoolean(expand_attr, CultureInfo.InvariantCulture);

                    string value = argument_node.GetAttribute("value", String.Empty);

                    if((value != null) && (value.Length > 0))
                        transform.Arguments.AddParam(key, String.Empty, expand_value ? Environment.ExpandEnvironmentVariables(value) : value);
                    else
                        transform.Arguments.AddParam(key, String.Empty, argument_node.Clone());
                }
            }
        }