Example #1
0
        internal string ConstructParentPath(string parentPath, XmlElementContext context, string argumentString) {
            Debug.Assert(this.parentPath == null && this.context == null && this.argumentString == null,
                "Do not call ConstructPath recursively");

            string resultPath = String.Empty;

            if (this.parentPath == null && this.context == null && this.argumentString == null) {
                try {
                    this.parentPath = parentPath;
                    this.context = context;
                    this.argumentString = argumentString;

                    resultPath = ParentPath;
                }
                finally {
                    this.parentPath = null;
                    this.context = null;
                    this.argumentString = null;
                    this.arguments = null;

                    ReleaseLogger();
                }
            }

            return resultPath;
        }
        private void HandleElement(XmlElementContext context) {
            string argumentString;
            Transform transform = context.ConstructTransform(out argumentString);
            if (transform != null) {

                bool fOriginalSupressWarning = logger.SupressWarnings;

                XmlAttribute SupressWarningsAttribute = context.Element.Attributes.GetNamedItem(XmlTransformation.SupressWarnings, XmlTransformation.TransformNamespace) as XmlAttribute;
                if (SupressWarningsAttribute != null)
                {
                    bool fSupressWarning = System.Convert.ToBoolean(SupressWarningsAttribute.Value, System.Globalization.CultureInfo.InvariantCulture);
                    logger.SupressWarnings = fSupressWarning;
                }

                try
                {
                    OnApplyingTransform();

                    transform.Execute(context, argumentString);

                    OnAppliedTransform();
                }
                catch (Exception ex)
                {
                    HandleException(ex, context);
                }
                finally
                {
                    // reset back the SupressWarnings back per node
                    logger.SupressWarnings = fOriginalSupressWarning;
                }
            }

            // process children
            TransformLoop(context);
        }
        private void PreprocessImportElement(XmlElementContext context) {
            string assemblyName = null;
            string nameSpace = null;
            string path = null;

            foreach (XmlAttribute attribute in context.Element.Attributes) {
                if (attribute.NamespaceURI.Length == 0) {
                    switch (attribute.Name) {
                        case "assembly":
                            assemblyName = attribute.Value;
                            continue;
                        case "namespace":
                            nameSpace = attribute.Value;
                            continue;
                        case "path":
                            path = attribute.Value;
                            continue;
                    }
                }

                throw new XmlNodeException(string.Format(System.Globalization.CultureInfo.CurrentCulture,SR.XMLTRANSFORMATION_ImportUnknownAttribute, attribute.Name), attribute);
            }

            if (assemblyName != null && path != null) {
                throw new XmlNodeException(string.Format(System.Globalization.CultureInfo.CurrentCulture,SR.XMLTRANSFORMATION_ImportAttributeConflict), context.Element);
            }
            else if (assemblyName == null && path == null) {
                throw new XmlNodeException(string.Format(System.Globalization.CultureInfo.CurrentCulture,SR.XMLTRANSFORMATION_ImportMissingAssembly), context.Element);
            }
            else if (nameSpace == null) {
                throw new XmlNodeException(string.Format(System.Globalization.CultureInfo.CurrentCulture,SR.XMLTRANSFORMATION_ImportMissingNamespace), context.Element);
            }
            else {
                if (assemblyName != null) {
                    namedTypeFactory.AddAssemblyRegistration(assemblyName, nameSpace);
                }
                else {
                    namedTypeFactory.AddPathRegistration(path, nameSpace);
                }
            }
        }
 private XmlElementContext CreateElementContext(XmlElementContext parentContext, XmlElement element) {
     return new XmlElementContext(parentContext, element, xmlTarget, this);
 }
Example #5
0
 internal string ConstructParentPath(string parentPath, XmlElementContext context, string argumentString)
 {
     string str = string.Empty;
     if (this.parentPath == null && this.context == null)
     {
         if (this.argumentString == null)
         {
             try
             {
                 this.parentPath = parentPath;
                 this.context = context;
                 this.argumentString = argumentString;
                 str = this.ParentPath;
             }
             finally
             {
                 this.parentPath = (string)null;
                 this.context = (XmlElementContext)null;
                 this.argumentString = (string)null;
                 this.arguments = (IList<string>)null;
                 this.ReleaseLogger();
             }
         }
     }
     return str;
 }
 private void PreprocessImportElement(XmlElementContext context)
 {
     string assemblyName = (string)null;
     string nameSpace = (string)null;
     string path = (string)null;
     foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap)context.Element.Attributes)
     {
         if (xmlAttribute.NamespaceURI.Length == 0)
         {
             switch (xmlAttribute.Name)
             {
                 case "assembly":
                     assemblyName = xmlAttribute.Value;
                     continue;
                 case "namespace":
                     nameSpace = xmlAttribute.Value;
                     continue;
                 case "path":
                     path = xmlAttribute.Value;
                     continue;
             }
         }
         throw new XmlNodeException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Import tag does not support '{0}' attribute", new object[1] { (object) xmlAttribute.Name }), (XmlNode)xmlAttribute);
     }
     if (assemblyName != null && path != null)
         throw new XmlNodeException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Import tag cannot have both a 'path' and an 'assembly'", new object[0]), (XmlNode)context.Element);
     if (assemblyName == null && path == null)
         throw new XmlNodeException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Import tag must have a 'path' or an 'assembly'", new object[0]), (XmlNode)context.Element);
     if (nameSpace == null)
         throw new XmlNodeException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, "Import tag must have a 'namespace'", new object[0]), (XmlNode)context.Element);
     if (assemblyName != null)
         this.namedTypeFactory.AddAssemblyRegistration(assemblyName, nameSpace);
     else
         this.namedTypeFactory.AddPathRegistration(path, nameSpace);
 }
 private void HandleElement(XmlElementContext context)
 {
     string argumentString;
     Transform transform = context.ConstructTransform(out argumentString);
     if (transform != null)
     {
         bool supressWarnings = this.logger.SupressWarnings;
         XmlAttribute xmlAttribute = context.Element.Attributes.GetNamedItem(XmlTransformation.SupressWarnings, XmlTransformation.TransformNamespace) as XmlAttribute;
         if (xmlAttribute != null)
             this.logger.SupressWarnings = Convert.ToBoolean(xmlAttribute.Value, (IFormatProvider)CultureInfo.InvariantCulture);
         try
         {
             this.OnApplyingTransform();
             transform.Execute(context, argumentString);
             this.OnAppliedTransform();
         }
         catch (Exception ex)
         {
             this.HandleException(ex, (XmlNodeContext)context);
         }
         finally
         {
             this.logger.SupressWarnings = supressWarnings;
         }
     }
     this.TransformLoop((XmlNodeContext)context);
 }
 private XmlElementContext CreateElementContext(XmlElementContext parentContext, XmlElement element)
 {
     return new XmlElementContext(parentContext, element, this.xmlTarget, (IServiceProvider)this);
 }