Пример #1
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);
        }
Пример #2
0
 public XmlElementContext(XmlElementContext parent, XmlElement element, XmlDocument xmlTargetDoc, IServiceProvider serviceProvider)
     : base((XmlNode)element)
 {
     this.parentContext   = parent;
     this.xmlTargetDoc    = xmlTargetDoc;
     this.serviceProvider = serviceProvider;
 }
Пример #3
0
        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);
        }
Пример #4
0
        private void PreprocessTransformDocument()
        {
            this.hasTransformNamespace = false;
            foreach (XmlNode xmlNode in this.xmlTransformation.SelectNodes("//namespace::*"))
            {
                if (xmlNode.Value.Equals(XmlTransformation.TransformNamespace, StringComparison.Ordinal))
                {
                    this.hasTransformNamespace = true;
                    break;
                }
            }
            if (!this.hasTransformNamespace)
            {
                return;
            }
            XmlNamespaceManager nsmgr = new XmlNamespaceManager((XmlNameTable) new NameTable());

            nsmgr.AddNamespace("xdt", XmlTransformation.TransformNamespace);
            foreach (XmlNode xmlNode in this.xmlTransformation.SelectNodes("//xdt:*", nsmgr))
            {
                XmlElement element = xmlNode as XmlElement;
                if (element != null)
                {
                    XmlElementContext context = (XmlElementContext)null;
                    try
                    {
                        switch (element.LocalName)
                        {
                        case "Import":
                            context = this.CreateElementContext((XmlElementContext)null, element);
                            this.PreprocessImportElement(context);
                            continue;

                        default:
                            this.logger.LogWarning((XmlNode)element, "Unknown tag '{0}'", new object[1] {
                                (object)element.Name
                            });
                            continue;
                        }
                    }
                    catch (Exception ex)
                    {
                        Exception exception = ex;
                        if (context != null)
                        {
                            exception = this.WrapException(exception, (XmlNodeContext)context);
                        }
                        this.logger.LogErrorFromException(exception);
                        throw new XmlTransformationException("Fatal syntax error", exception);
                    }
                    finally
                    {
                    }
                }
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
 internal bool HasTargetParent(out XmlElementContext failedContext, out bool existedInOriginal)
 {
     failedContext     = (XmlElementContext)null;
     existedInOriginal = false;
     if (this.TargetParents.Count != 0)
     {
         return(true);
     }
     failedContext = this;
     while (failedContext.parentContext != null && !string.IsNullOrEmpty(failedContext.parentContext.ParentXPath) && failedContext.parentContext.TargetParents.Count == 0)
     {
         failedContext = failedContext.parentContext;
     }
     existedInOriginal = this.ExistedInOriginal(failedContext.XPath);
     return(false);
 }
Пример #7
0
 private void TransformLoop(XmlNodeContext parentContext)
 {
     foreach (XmlNode xmlNode in parentContext.Node.ChildNodes)
     {
         XmlElement element = xmlNode as XmlElement;
         if (element != null)
         {
             XmlElementContext elementContext = this.CreateElementContext(parentContext as XmlElementContext, element);
             try
             {
                 this.HandleElement(elementContext);
             }
             catch (Exception ex)
             {
                 this.HandleException(ex, (XmlNodeContext)elementContext);
             }
         }
     }
 }
Пример #8
0
        private void HandleMissingTarget(XmlElementContext matchFailureContext, bool existedInOriginal)
        {
            string message = string.Format((IFormatProvider)CultureInfo.CurrentCulture, existedInOriginal ? "'{0}' did not find a match, because matching nodes in the source document were modified or removed by a previous transform" : "No element in the source document matches '{0}'", new object[1] {
                (object)matchFailureContext.XPath
            });

            switch (this.MissingTargetMessage)
            {
            case MissingTargetMessage.None:
                this.Log.LogMessage(MessageType.Verbose, message, new object[0]);
                break;

            case MissingTargetMessage.Information:
                this.Log.LogMessage(MessageType.Normal, message, new object[0]);
                break;

            case MissingTargetMessage.Warning:
                this.Log.LogWarning(matchFailureContext.Node, message, new object[0]);
                break;

            case MissingTargetMessage.Error:
                throw new XmlNodeException(message, matchFailureContext.Node);
            }
        }
Пример #9
0
 private XmlElementContext CreateElementContext(XmlElementContext parentContext, XmlElement element)
 {
     return(new XmlElementContext(parentContext, element, this.xmlTarget, (IServiceProvider)this));
 }
Пример #10
0
        internal void Execute(XmlElementContext context, string argumentString)
        {
            if (this.context != null || this.argumentString != null)
            {
                return;
            }
            bool flag1 = false;
            bool flag2 = false;

            try
            {
                this.context        = context;
                this.argumentString = argumentString;
                this.arguments      = (IList <string>)null;
                if (!this.ShouldExecuteTransform())
                {
                    return;
                }
                flag2 = true;
                this.Log.StartSection(MessageType.Verbose, "Executing {0}", new object[1] {
                    (object)this.TransformNameLong
                });
                this.Log.LogMessage(MessageType.Verbose, "on {0}", new object[1] {
                    (object)context.XPath
                });
                if (this.ApplyTransformToAllTargetNodes)
                {
                    this.ApplyOnAllTargetNodes();
                }
                else
                {
                    this.ApplyOnce();
                }
            }
            catch (Exception ex)
            {
                flag1 = true;
                if (context.TransformAttribute != null)
                {
                    this.Log.LogErrorFromException(XmlNodeException.Wrap(ex, (XmlNode)context.TransformAttribute));
                }
                else
                {
                    this.Log.LogErrorFromException(ex);
                }
            }
            finally
            {
                if (flag2)
                {
                    if (flag1)
                    {
                        this.Log.EndSection(MessageType.Verbose, "Error during {0}", new object[1] {
                            (object)this.TransformNameShort
                        });
                    }
                    else
                    {
                        this.Log.EndSection(MessageType.Verbose, "Done executing {0}", new object[1] {
                            (object)this.TransformNameShort
                        });
                    }
                }
                else
                {
                    this.Log.LogMessage(MessageType.Normal, "Not executing {0}", new object[1] {
                        (object)this.TransformNameLong
                    });
                }
                this.context        = (XmlElementContext)null;
                this.argumentString = (string)null;
                this.arguments      = (IList <string>)null;
                this.ReleaseLogger();
            }
        }