GetAttributeNode() public method

public GetAttributeNode ( string name ) : XmlAttribute
name string
return XmlAttribute
		public override void Load (XmlElement filenode, FilePath baseDirectory)
		{
			var extAtt = filenode.GetAttributeNode ("extension");
			if (extAtt != null)
				extension = extAtt.Value ?? "";

			propertyInnerText = filenode.InnerText;
			if (propertyInnerText == null)
				throw new InvalidOperationException ("Property is missing its inner text");

			typeAtt = filenode.GetAttributeNode ("type");
			if (typeAtt == null)
				throw new InvalidOperationException ("Property is missing the type attribute");

			if (String.IsNullOrEmpty (typeAtt.Value))
				throw new InvalidOperationException ("Property's type attribute is empty");

			if (String.IsNullOrEmpty (filenode.InnerText))
				throw new InvalidOperationException ("Property is empty");
		}
        public static IAssertion assert_throttle(XmlElement config)
        {
            var delay = new TimeSpan();

            XmlAttribute attribute = config.GetAttributeNode("delayTimeSpan");

            if (attribute != null)
            {
                delay = TimeSpan.Parse(attribute.Value);
            }

            bool trace = false;

            attribute = config.GetAttributeNode("traceThrottledExceptions");

            if (attribute != null)
            {
                trace = bool.Parse(attribute.Value);
            }

            return new ThrottleAssertion(delay, trace);
        }
        public SequentialInitializer(System.Xml.XmlElement config)
        {
            XmlAttribute attribute = config.GetAttributeNode("startFrom");

            if (null != attribute)
            {
                _value = long.Parse(attribute.Value);
            }
            else
            {
                _value = 1;
            }
        }
        /// <summary>
        /// Extracts the data from the DOM tree below the indicated context
        /// <see cref="XmlElement"/> and create a suitable <see crel="Release"/>
        /// structure to add to the indicated <see cref="Specification"/>.
        /// </summary>
        /// <param name="specification">The owning <see cref="Specification"/>.</param>
        /// <param name="context">The context <see cref="XmlElement"/> containing data</param>
        /// <param name="loadedSchemas">A dictionary of all ready loaded schemas.</param>
        public virtual void LoadData(Specification specification, XmlElement context,
            Dictionary<string, SchemaRelease> loadedSchemas)
        {
            XmlAttribute	id 		= context.GetAttributeNode ("id");

            SchemaRelease release = new SchemaRelease (specification,
                    GetVersion (context), GetNamespaceUri (context),
                    GetSchemaLocation (context), GetPreferredPrefix (context),
                    GetAlternatePrefix (context), GetRootElements (context));

            HandleImports (release, context, loadedSchemas);

            if (id != null) loadedSchemas.Add (id.Value, release);
        }
Beispiel #5
0
 private void SortAttributesAttributes(XmlElement el)
 {
     ArrayList al = new ArrayList();
     foreach (XmlAttribute a in el.Attributes)
         al.Add(a.Name);
     al.Sort();
     string[] names = (string[])al.ToArray(typeof(string));
     al.Clear();
     foreach (string name in names)
         al.Add(el.RemoveAttributeNode(
             el.GetAttributeNode(name)));
     foreach (XmlAttribute a in al)
         // Exclude xmlns="" here.
         if (a.Name != "xmlns")// || a.Value != String.Empty)
             el.SetAttributeNode(a);
 }
        /// <summary>
        /// Extracts the data from the DOM tree below the indicated context
        /// <see cref="XmlElement"/> and create a suitable <see cref="HandCoded.Meta.Release"/>
        /// structure to add to the indicated <see cref="HandCoded.Meta.Specification"/>.
        /// </summary>
        /// <param name="specification">The owning <see cref="HandCoded.Meta.Specification"/>.</param>
        /// <param name="context">The context <see cref="XmlElement"/> containing data</param>
        /// <param name="loadedSchemas">A dictionary of all ready loaded schemas.</param>
        public override void LoadData(HandCoded.Meta.Specification specification, XmlElement context,
            Dictionary<string, HandCoded.Meta.SchemaRelease> loadedSchemas)
        {
            XmlAttribute    id 		= context.GetAttributeNode ("id");

            SchemaRelease release = new SchemaRelease (specification,
                    GetVersion (context), GetNamespaceUri (context),
                    GetSchemaLocation (context), GetPreferredPrefix (context),
                    GetAlternatePrefix (context),
                    new FpMLInstanceInitialiser (),
                    new FpMLSchemaRecogniser (), GetRootElements (context),
                    GetSchemeDefaults (context), GetSchemeCollection (context));

            HandleImports (release, context, loadedSchemas);

            if (id != null) loadedSchemas.Add (id.Value, release);
        }
Beispiel #7
0
        /// <summary>
        /// Inspects a ProgressText element.
        /// </summary>
        /// <param name="element">The ProgressText element to inspect.</param>
        private void InspectProgressTextElement(XmlElement element)
        {
            XmlAttribute template = element.GetAttributeNode("Template");

            if (null != template && String.Empty == template.Value)
            {
                this.OnError(InspectorTestType.ProgressTextTemplateEmpty, element, "The ProgressText/@Template attribute's value cannot be the empty string.");
                element.Attributes.Remove(template);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Inspects a Media element.
        /// </summary>
        /// <param name="element">The Media element to inspect.</param>
        private void InspectMediaElement(XmlElement element)
        {
            XmlAttribute src = element.GetAttributeNode("src");

            if (null != src)
            {
                this.OnError(InspectorTestType.SrcIsDeprecated, src, "The Media/@src attribute has been deprecated.  Use the Layout attribute instead.");

                XmlAttribute layout = element.OwnerDocument.CreateAttribute("Layout");
                layout.Value = src.Value;
                element.Attributes.InsertAfter(layout, src);

                element.Attributes.Remove(src);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Inspects a FileSearch element.
        /// </summary>
        /// <param name="element">The FileSearch element to inspect.</param>
        private void InspectFileSearchElement(XmlElement element)
        {
            XmlAttribute name = element.GetAttributeNode("Name");
            XmlAttribute longName = element.GetAttributeNode("LongName");

            // check for a short/long filename separator in the Name attribute
            if (null != name && 0 <= name.Value.IndexOf('|'))
            {
                if (null == longName) // long name is not present, split the Name if possible
                {
                    string[] names = name.Value.Split("|".ToCharArray());

                    // this appears to be splittable
                    if (2 == names.Length)
                    {
                        this.OnError(InspectorTestType.FileSearchNamesCombined, element, "The FileSearch/@Name attribute appears to contain both a short and long file name.  It may only contain an 8.3 file name.  Also use the LongName attribute to specify a longer name.");

                        // fix the short name
                        name.Value = names[0];

                        // insert the new LongName attribute after the previous Name attribute
                        longName = element.OwnerDocument.CreateAttribute("LongName");
                        longName.Value = names[1];
                        element.Attributes.InsertAfter(longName, name);
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Inspects a Control element.
        /// </summary>
        /// <param name="element">The Control element to inspect.</param>
        private void InspectControlElement(XmlElement element)
        {
            XmlAttribute checkBoxValue = element.GetAttributeNode("CheckBoxValue");

            if (null != checkBoxValue && String.Empty == checkBoxValue.Value)
            {
                this.OnError(InspectorTestType.IniFileValueEmpty, element, "The Control/@CheckBoxValue attribute's value cannot be the empty string.");
                element.Attributes.Remove(checkBoxValue);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Inspects a Class element.
        /// </summary>
        /// <param name="element">The Class element to inspect.</param>
        private void InspectClassElement(XmlElement element)
        {
            bool advertised = false;
            XmlAttribute description = element.GetAttributeNode("Description");
            XmlAttribute relativePath = element.GetAttributeNode("RelativePath");

            if (null != description && String.Empty == description.Value)
            {
                this.OnError(InspectorTestType.ClassDescriptionEmpty, element, "The Class/@Description attribute's value cannot be an empty string.");
                element.Attributes.Remove(description);
            }

            if (null != relativePath)
            {
                // check if this element or any of its parents is advertised
                for (XmlNode node = element; null != node; node = node.ParentNode)
                {
                    if (node.Attributes != null)
                    {
                        XmlNode advertise = node.Attributes.GetNamedItem("Advertise");

                        if (null != advertise && "yes" == advertise.Value)
                        {
                            advertised = true;
                        }
                    }
                }

                if (advertised) // if advertised, then RelativePath="no" is unnecessary since its the default value
                {
                    if ("no" == relativePath.Value)
                    {
                        this.OnVerbose(element, "The Class/@RelativePath attribute with value 'no' is not necessary since this element is advertised.");
                        element.Attributes.Remove(relativePath);
                    }
                }
                else // if there is no advertising, then the RelativePath attribute is not allowed
                {
                    this.OnError(InspectorTestType.ClassRelativePathMustBeAdvertised, element, "The Class/@RelativePath attribute is not supported for non-advertised Class elements.");
                    element.Attributes.Remove(relativePath);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Inspects a WebApplicationExtension element.
        /// </summary>
        /// <param name="element">The WebApplicationExtension element to inspect.</param>
        private void InspectWebApplicationExtensionElement(XmlElement element)
        {
            XmlAttribute extension = element.GetAttributeNode("Extension");
            XmlAttribute id = element.GetAttributeNode("Id");

            if (null != id)
            {
                // an empty Id attribute value should be replaced with "*"
                if (String.Empty == id.Value)
                {
                    this.OnError(InspectorTestType.WebApplicationExtensionIdEmpty, element, "The WebApplicationExtension/@Id attribute's value cannot be an empty string.  Use '*' for the value instead.");
                    id.Value = "*";
                }

                // Id has been deprecated, use Extension instead
                if (null == extension)
                {
                    this.OnError(InspectorTestType.WebApplicationExtensionIdDeprecated, element, "The WebApplicationExtension/@Id attribute has been deprecated.  Use the Extension attribute instead.");
                    extension = element.OwnerDocument.CreateAttribute("Extension");
                    extension.Value = id.Value;
                    element.Attributes.InsertAfter(extension, id);
                    element.Attributes.Remove(id);
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Inspects a TypeLib element.
        /// </summary>
        /// <param name="element">The TypeLib element to inspect.</param>
        private void InspectTypeLibElement(XmlElement element)
        {
            XmlAttribute description = element.GetAttributeNode("Description");

            if (null != description && string.Empty == description.Value)
            {
                this.OnError(InspectorTestType.TypeLibDescriptionEmpty, element, "The TypeLib/@Description attribute's value cannot be an empty string.  If you want the value to be null or empty, simply drop the entire attribute.");
                element.Attributes.Remove(description);
            }
        }
 private string GetAttributeFromElement(XmlElement elem, string name, string ns)
 {
     XmlAttribute attributeNode = elem.GetAttributeNode(name, ns);
     if (attributeNode != null)
     {
         return attributeNode.Value;
     }
     return null;
 }
 private bool PathHasDuplicateNamespace(XmlElement top, XmlElement bottom, string localName)
 {
     string strReservedXmlns = this.document.strReservedXmlns;
     while ((bottom != null) && (bottom != top))
     {
         if (bottom.GetAttributeNode(localName, strReservedXmlns) != null)
         {
             return true;
         }
         bottom = bottom.ParentNode as XmlElement;
     }
     return false;
 }
 private bool MoveToAttributeFromElement(XmlElement elem, string name, string ns)
 {
     XmlAttribute node = null;
     if (ns.Length == 0)
     {
         node = elem.GetAttributeNode(name);
     }
     else
     {
         node = elem.GetAttributeNode(name, ns);
     }
     if (node != null)
     {
         this.bOnAttrVal = false;
         this.elemNode = elem;
         this.curNode = node;
         this.attrIndex = elem.Attributes.FindNodeOffsetNS(node);
         if (this.attrIndex != -1)
         {
             return true;
         }
     }
     return false;
 }
Beispiel #17
0
        /// <summary>
        /// Inspects a Shortcut element.
        /// </summary>
        /// <param name="element">The Shortcut element to inspect.</param>
        private void InspectShortcutElement(XmlElement element)
        {
            XmlAttribute workingDirectory = element.GetAttributeNode("WorkingDirectory");

            if (null != workingDirectory && String.Empty == workingDirectory.Value)
            {
                this.OnError(InspectorTestType.ShortcutWorkingDirectoryEmpty, element, "The Shortcut/@WorkingDirectory attribute's value cannot be the empty string.");
                element.Attributes.Remove(workingDirectory);
            }
        }
        private static object ParseArgument(ParameterInfo parameter, XmlElement config)
        {
            Debug.Assert(parameter != null);
            Debug.Assert(config != null);

            var name = parameter.Name;
            var type = parameter.ParameterType;
            string text;

            var attribute = config.GetAttributeNode(name);
            if (attribute != null)
            {
                text = attribute.Value;
            }
            else
            {
                var element = config[name];
                if (element == null)
                    return null;

                text = element.InnerText;
            }

            if (type == typeof(IContextExpression))
                return new WebDataBindingExpression(text);

            if (type == typeof(Type))
                return TypeResolution.GetType(text);

            if (type == typeof(bool))
            {
                text = text.Trim().ToLowerInvariant();
                return Boolean.TrueString.Equals(StringTranslation.Translate(Boolean.TrueString, text, _truths));
            }

            var converter = TypeDescriptor.GetConverter(type);
            return converter.ConvertFromInvariantString(text);
        }
Beispiel #19
0
        /// <summary>
        /// Inspects an UpgradeVersion element.
        /// </summary>
        /// <param name="element">The UpgradeVersion element to inspect.</param>
        private void InspectUpgradeVersionElement(XmlElement element)
        {
            XmlAttribute removeFeatures = element.GetAttributeNode("RemoveFeatures");

            if (null != removeFeatures && string.Empty == removeFeatures.Value)
            {
                this.OnError(InspectorTestType.TypeLibDescriptionEmpty, element, "The UpgradeVersion/@RemoveFeatures attribute's value cannot be an empty string.  If you want the value to be null or empty, simply drop the entire attribute.");
                element.Attributes.Remove(removeFeatures);
            }
        }
 private String GetAttributeFromElement( XmlElement elem, String name, String ns ) {
     XmlAttribute attr = elem.GetAttributeNode( name, ns );
     if ( attr != null )
         return attr.Value;
     return null;
 }
Beispiel #21
0
        /// <summary>
        /// Inspects a Wix element.
        /// </summary>
        /// <param name="element">The Wix element to inspect.</param>
        private void InspectWixElement(XmlElement element)
        {
            XmlAttribute xmlns = element.GetAttributeNode("xmlns");

            if (null == xmlns)
            {
                this.OnError(InspectorTestType.XmlnsMissing, element, "The xmlns attribute is missing.  It must be present with a value of '{0}'.", WixNamespaceURI);
                element.SetAttribute("xmlns", WixNamespaceURI);
            }
            else if (WixNamespaceURI != xmlns.Value)
            {
                this.OnError(InspectorTestType.XmlnsValueWrong, xmlns, "The xmlns attribute's value is wrong.  It must be '{0}'.", WixNamespaceURI);
                element.SetAttribute("xmlns", WixNamespaceURI);
            }
        }
 private bool MoveToAttributeFromElement( XmlElement elem, String name, String ns ) {
     XmlAttribute attr = null;
     if( ns.Length == 0 )
         attr = elem.GetAttributeNode( name );
     else
         attr = elem.GetAttributeNode( name, ns );
     if ( attr != null ) {
         this.bOnAttrVal = false;
         elemNode = elem;
         curNode = attr;
         attrIndex = elem.Attributes.FindNodeOffsetNS(attr);
         if (attrIndex != -1) {
             return true;
         }
     }
     return false;
 }
Beispiel #23
0
        /// <summary>
        /// Inspects a Component element.
        /// </summary>
        /// <param name="element">The Component element to inspect.</param>
        private void InspectComponentElement(XmlElement element)
        {
            XmlAttribute guid = element.GetAttributeNode("Guid");

            if (null == guid)
            {
                this.OnError(InspectorTestType.RequireComponentGuid, guid, "The Component/@Guid attribute is required.  Setting this attribute's value to empty now enables the functionality previously represented by omitting the attribute.  This creates an unmanaged component.  Please note that unmanaged components can be a security vulnerability and should be carefully reviewed.");
                element.SetAttribute("Guid", String.Empty);
            }
        }
		/// <summary>
		/// Sets a parameter on an object.
		/// </summary>
		/// <param name="element">The parameter element.</param>
		/// <param name="target">The object to set the parameter on.</param>
		/// <remarks>
		/// The parameter name must correspond to a writable property
		/// on the object. The value of the parameter is a string,
		/// therefore this function will attempt to set a string
		/// property first. If unable to set a string property it
		/// will inspect the property and its argument type. It will
		/// attempt to call a static method called <c>Parse</c> on the
		/// type of the property. This method will take a single
		/// string argument and return a value that can be used to
		/// set the property.
		/// </remarks>
		protected void SetParameter(XmlElement element, object target) 
		{
			// Get the property name
			string name = element.GetAttribute(NAME_ATTR);

			// If the name attribute does not exist then use the name of the element
			if (element.LocalName != PARAM_TAG || name == null || name.Length == 0)
			{
				name = element.LocalName;
			}

			// Look for the property on the target object
			Type targetType = target.GetType();
			Type propertyType = null;

			PropertyInfo propInfo = null;
			MethodInfo methInfo = null;

			// Try to find a writable property
			propInfo = targetType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
			if (propInfo != null && propInfo.CanWrite)
			{
				// found a property
				propertyType = propInfo.PropertyType;
			}
			else
			{
				propInfo = null;

				// look for a method with the signature Add<property>(type)
				methInfo = FindMethodInfo(targetType, name);

				if (methInfo != null)
				{
					propertyType = methInfo.GetParameters()[0].ParameterType;
				}
			}

			if (propertyType == null)
			{
				LogLog.Error(declaringType, "XmlHierarchyConfigurator: Cannot find Property [" + name + "] to set object on [" + target.ToString() + "]");
			}
			else
			{
				string propertyValue = null;

				if (element.GetAttributeNode(VALUE_ATTR) != null)
				{
					propertyValue = element.GetAttribute(VALUE_ATTR);
				}
				else if (element.HasChildNodes)
				{
					// Concatenate the CDATA and Text nodes together
					foreach(XmlNode childNode in element.ChildNodes)
					{
						if (childNode.NodeType == XmlNodeType.CDATA || childNode.NodeType == XmlNodeType.Text)
						{
							if (propertyValue == null)
							{
								propertyValue = childNode.InnerText;
							}
							else
							{
								propertyValue += childNode.InnerText;
							}
						}
					}
				}

				if(propertyValue != null)
				{
#if !NETCF	
					try
					{
						// Expand environment variables in the string.
					    IDictionary environmentVariables = Environment.GetEnvironmentVariables();
					    if (HasCaseInsensitiveEnvironment) {
						environmentVariables = CreateCaseInsensitiveWrapper(environmentVariables);
					    }
						propertyValue = OptionConverter.SubstituteVariables(propertyValue, environmentVariables);
					}
					catch(System.Security.SecurityException)
					{
						// This security exception will occur if the caller does not have 
						// unrestricted environment permission. If this occurs the expansion 
						// will be skipped with the following warning message.
						LogLog.Debug(declaringType, "Security exception while trying to expand environment variables. Error Ignored. No Expansion.");
					}
#endif

					Type parsedObjectConversionTargetType = null;

					// Check if a specific subtype is specified on the element using the 'type' attribute
					string subTypeString = element.GetAttribute(TYPE_ATTR);
					if (subTypeString != null && subTypeString.Length > 0)
					{
						// Read the explicit subtype
						try
						{
							Type subType = SystemInfo.GetTypeFromString(subTypeString, true, true);

							LogLog.Debug(declaringType, "Parameter ["+name+"] specified subtype ["+subType.FullName+"]");

							if (!propertyType.IsAssignableFrom(subType))
							{
								// Check if there is an appropriate type converter
								if (OptionConverter.CanConvertTypeTo(subType, propertyType))
								{
									// Must re-convert to the real property type
									parsedObjectConversionTargetType = propertyType;

									// Use sub type as intermediary type
									propertyType = subType;
								}
								else
								{
									LogLog.Error(declaringType, "subtype ["+subType.FullName+"] set on ["+name+"] is not a subclass of property type ["+propertyType.FullName+"] and there are no acceptable type conversions.");
								}
							}
							else
							{
								// The subtype specified is found and is actually a subtype of the property
								// type, therefore we can switch to using this type.
								propertyType = subType;
							}
						}
						catch(Exception ex)
						{
							LogLog.Error(declaringType, "Failed to find type ["+subTypeString+"] set on ["+name+"]", ex);
						}
					}

					// Now try to convert the string value to an acceptable type
					// to pass to this property.

					object convertedValue = ConvertStringTo(propertyType, propertyValue);
					
					// Check if we need to do an additional conversion
					if (convertedValue != null && parsedObjectConversionTargetType != null)
					{
						LogLog.Debug(declaringType, "Performing additional conversion of value from [" + convertedValue.GetType().Name + "] to [" + parsedObjectConversionTargetType.Name + "]");
						convertedValue = OptionConverter.ConvertTypeTo(convertedValue, parsedObjectConversionTargetType);
					}

					if (convertedValue != null)
					{
						if (propInfo != null)
						{
							// Got a converted result
							LogLog.Debug(declaringType, "Setting Property [" + propInfo.Name + "] to " + convertedValue.GetType().Name + " value [" + convertedValue.ToString() + "]");

							try
							{
								// Pass to the property
								propInfo.SetValue(target, convertedValue, BindingFlags.SetProperty, null, null, CultureInfo.InvariantCulture);
							}
							catch(TargetInvocationException targetInvocationEx)
							{
								LogLog.Error(declaringType, "Failed to set parameter [" + propInfo.Name + "] on object [" + target + "] using value [" + convertedValue + "]", targetInvocationEx.InnerException);
							}
						}
						else if (methInfo != null)
						{
							// Got a converted result
							LogLog.Debug(declaringType, "Setting Collection Property [" + methInfo.Name + "] to " + convertedValue.GetType().Name + " value [" + convertedValue.ToString() + "]");

							try
							{
								// Pass to the property
								methInfo.Invoke(target, BindingFlags.InvokeMethod, null, new object[] {convertedValue}, CultureInfo.InvariantCulture);
							}
							catch(TargetInvocationException targetInvocationEx)
							{
								LogLog.Error(declaringType, "Failed to set parameter [" + name + "] on object [" + target + "] using value [" + convertedValue + "]", targetInvocationEx.InnerException);
							}
						}
					}
					else
					{
						LogLog.Warn(declaringType, "Unable to set property [" + name + "] on object [" + target + "] using value [" + propertyValue + "] (with acceptable conversion types)");
					}
				}
				else
				{
					object createdObject = null;

					if (propertyType == typeof(string) && !HasAttributesOrElements(element))
					{
						// If the property is a string and the element is empty (no attributes
						// or child elements) then we special case the object value to an empty string.
						// This is necessary because while the String is a class it does not have
						// a default constructor that creates an empty string, which is the behavior
						// we are trying to simulate and would be expected from CreateObjectFromXml
						createdObject = "";
					}
					else
					{
						// No value specified
						Type defaultObjectType = null;
						if (IsTypeConstructible(propertyType))
						{
							defaultObjectType = propertyType;
						}

						createdObject = CreateObjectFromXml(element, defaultObjectType, propertyType);
					}

					if (createdObject == null)
					{
						LogLog.Error(declaringType, "Failed to create object to set param: "+name);
					}
					else
					{
						if (propInfo != null)
						{
							// Got a converted result
							LogLog.Debug(declaringType, "Setting Property ["+ propInfo.Name +"] to object ["+ createdObject +"]");

							try
							{
								// Pass to the property
								propInfo.SetValue(target, createdObject, BindingFlags.SetProperty, null, null, CultureInfo.InvariantCulture);
							}
							catch(TargetInvocationException targetInvocationEx)
							{
								LogLog.Error(declaringType, "Failed to set parameter [" + propInfo.Name + "] on object [" + target + "] using value [" + createdObject + "]", targetInvocationEx.InnerException);
							}
						}
						else if (methInfo != null)
						{
							// Got a converted result
							LogLog.Debug(declaringType, "Setting Collection Property ["+ methInfo.Name +"] to object ["+ createdObject +"]");

							try
							{
								// Pass to the property
								methInfo.Invoke(target, BindingFlags.InvokeMethod, null, new object[] {createdObject}, CultureInfo.InvariantCulture);
							}
							catch(TargetInvocationException targetInvocationEx)
							{
								LogLog.Error(declaringType, "Failed to set parameter [" + methInfo.Name + "] on object [" + target + "] using value [" + createdObject + "]", targetInvocationEx.InnerException);
							}
						}
					}
				}
			}
		}
Beispiel #25
0
        /// <summary>
        /// Inspects a Feature element.
        /// </summary>
        /// <param name="element">The Feature element to inspect.</param>
        private void InspectFeatureElement(XmlElement element)
        {
            XmlAttribute followParent = element.GetAttributeNode("FollowParent");
            XmlAttribute installDefault = element.GetAttributeNode("InstallDefault");

            if (null != followParent)
            {
                this.OnError(InspectorTestType.FeatureFollowParentDeprecated, followParent, "The Feature/@FollowParent attribute has been deprecated.  Value of 'yes' should now be represented with InstallDefault='followParent'.");

                // if InstallDefault is present, candle with display an error
                if ("yes" == followParent.Value && null == installDefault)
                {
                    installDefault = element.OwnerDocument.CreateAttribute("InstallDefault");
                    installDefault.Value = "followParent";
                    element.Attributes.Append(installDefault);
                }

                element.Attributes.Remove(followParent);
            }
        }
        private static InlineDescription GetInlineDescription(XmlElement element)
        {
            InlineType type;
            var elementName = element.Name.ToLower();
            switch (elementName)
            {
                case "run":
                    type = InlineType.Run;
                    break;

                case "linebreak":
                    type = InlineType.LineBreak;
                    break;

                case "span":
                    type = InlineType.Span;
                    break;

                case "bold":
                    type = InlineType.Bold;
                    break;

                case "italic":
                    type = InlineType.Italic;
                    break;

                case "hyperlink":
                    type = InlineType.Hyperlink;
                    break;

                case "underline":
                    type = InlineType.Underline;
                    break;

                default:
                    return null;
            }

            string styleName = null;
            var attribute = element.GetAttributeNode("style");
            if (attribute != null)
                styleName = attribute.Value;

            string text = null;
            var childDescriptions = new List<InlineDescription>();

            if (type == InlineType.Run || type == InlineType.LineBreak)
            {
                text = element.InnerText;
            }
            else
            {
                childDescriptions.AddRange(
                    element.ChildNodes.Cast<XmlNode>()
                        .Select(GetInlineDescription)
                        .Where(childDescription => childDescription != null));
            }

            var inlineDescription = new InlineDescription
            {
                Type = type,
                StyleName = styleName,
                Text = text,
                Inlines = childDescriptions.ToArray()
            };

            return inlineDescription;
        }
Beispiel #27
0
        /// <summary>
        /// Inspects an IniFile element.
        /// </summary>
        /// <param name="element">The IniFile element to inspect.</param>
        private void InspectIniFileElement(XmlElement element)
        {
            XmlAttribute value = element.GetAttributeNode("Value");

            if (null != value && String.Empty == value.Value)
            {
                this.OnError(InspectorTestType.IniFileValueEmpty, element, "The IniFile/@Value attribute's value cannot be the empty string.");
                element.Attributes.Remove(value);
            }
        }
Beispiel #28
0
        /// <summary>
        /// Inspects a RegistrySearch element.
        /// </summary>
        /// <param name="element">The RegistrySearch element to inspect.</param>
        private void InspectRegistrySearchElement(XmlElement element)
        {
            XmlAttribute type = element.GetAttributeNode("Type");

            if (null != type && "registry" == type.Value)
            {
                this.OnError(InspectorTestType.RegistrySearchTypeRegistryDeprecated, element, "The RegistrySearch/@Type attribute's value 'registry' has been deprecated.  Please use the value 'raw' instead.");
                element.SetAttribute("Type", "raw");
            }
        }
Beispiel #29
0
        /// <summary>
        /// Inspects a Merge element.
        /// </summary>
        /// <param name="element">The Merge element to inspect.</param>
        private void InspectMergeElement(XmlElement element)
        {
            XmlAttribute src = element.GetAttributeNode("src");

            if (null != src)
            {
                this.OnError(InspectorTestType.SrcIsDeprecated, src, "The Merge/@src attribute has been deprecated.  Use the SourceFile attribute instead.");

                XmlAttribute sourceFile = element.OwnerDocument.CreateAttribute("SourceFile");
                sourceFile.Value = src.Value;
                element.Attributes.InsertAfter(sourceFile, src);

                element.Attributes.Remove(src);
            }
        }
Beispiel #30
0
        /// <summary>
        /// Inspects a ServiceInstall element.
        /// </summary>
        /// <param name="element">The ServiceInstall element to inspect.</param>
        private void InspectServiceInstallElement(XmlElement element)
        {
            XmlAttribute localGroup = element.GetAttributeNode("LocalGroup");
            XmlAttribute password = element.GetAttributeNode("Password");

            if (null != localGroup && String.Empty == localGroup.Value)
            {
                this.OnError(InspectorTestType.ServiceInstallLocalGroupEmpty, element, "The ServiceInstall/@LocalGroup attribute's value cannot be the empty string.");
                element.Attributes.Remove(localGroup);
            }

            if (null != password && String.Empty == password.Value)
            {
                this.OnError(InspectorTestType.ServiceInstallPasswordEmpty, element, "The ServiceInstall/@Password attribute's value cannot be the empty string.");
                element.Attributes.Remove(password);
            }
        }
 private bool PathHasDuplicateNamespace(XmlElement top, XmlElement bottom, string localName)
 {
     string namespaceUri = XmlConst.ReservedNsXmlNs;
     while (bottom != null
            && bottom != top)
     {
         XmlAttribute attribute = bottom.GetAttributeNode(localName, namespaceUri);
         if (attribute != null)
         {
             return true;
         }
         bottom = bottom.ParentNode as XmlElement;
     }
     return false;
 }
Beispiel #32
0
        /// <summary>
        /// 移除属性
        /// </summary>
        public static void RemoveAttribute(this XmlNode node, string attributeName)
        {
            XmlElement element = node as XmlElement;

            node.Attributes.Remove(element.GetAttributeNode(attributeName));
        }