public static XmlElement SetColumnProperty(this XmlElement element, string name, string value)
        {
            XmlElement columnElement = element["column"] ?? element.AddElement("column");
            columnElement.WithAtt(name, value);

            return element;
        }
Example #2
0
        public static void WriteSection(this XmlElement parent, Section section)
        {
            var sectionElement = parent.AddElement(XmlConvert.EncodeName(section.Key));
            sectionElement.SetAttribute(XmlConstants.Id, section.id);

            if (section.ActiveCells.Count > 0)
            {
                var activeCellString = section.ActiveCells.Select(x => "{0}={1}".ToFormat(x.Key, x.Value)).Join(",");
                sectionElement.SetAttribute(XmlConstants.ActiveCells, activeCellString);
            }


            section.Children.Each(child =>
            {
                if (child is Comment)
                {
                    sectionElement.WriteComment(child.As<Comment>());
                }

                if (child is Step)
                {
                    sectionElement.WriteStep(child.As<Step>());
                }
            });
        }
        public static void WriteStep(this XmlElement parent, Step step)
        {
            var element = parent.AddElement(step.Key);
            step.Values.Each(pair => element.SetAttribute(pair.Key, pair.Value));

            step.Collections.Each(element.WriteSection);
        }
        public static VA.Text.Markup.TextElement AddElementEx(this VA.Text.Markup.TextElement p, string text,
                                                              int? font, double? size, int? color,
                                                              VA.Drawing.AlignmentHorizontal? halign,
                                                              VA.Text.CharStyle? cs)
        {
            var el = p.AddElement(text);
            if (font != null)
            {
                el.CharacterCells.Font = font.Value;
            }
            if (size.HasValue)
            {
                el.CharacterCells.Size = string.Format("{0}pt",size.Value);
            }
            if (color.HasValue)
            {
                var c = new VA.Drawing.ColorRGB(color.Value);
                el.CharacterCells.Color = c.ToFormula();
            }
            if (halign.HasValue)
            {
                el.ParagraphCells.HorizontalAlign = (int) halign.Value;
            }

            if (cs.HasValue)
            {
                el.CharacterCells.Style = (int) cs;
            }

            return el;
        }
Example #5
0
    public static IHtmlElement Add(this IHtmlContainer container, XElement element )
    {
      var result = container.AddElement( element.Name.LocalName );
      foreach ( var attribute in element.Attributes() )
        result.SetAttribute( attribute.Name.LocalName, attribute.Value );

      return result;
    }
        public static void SetAttributeOnChild(this XmlElement element, string childName, string attName, string attValue)
        {
            XmlElement childElement = element[childName];
            if (childElement == null)
            {
                childElement = element.AddElement(childName);
            }

            childElement.SetAttribute(attName, attValue);
        }
Example #7
0
        public static EdmEntityContainer EnsureEntityContainer(this EdmModel model, Type apiType)
        {
            var container = (EdmEntityContainer)model.EntityContainer;
            if (container == null)
            {
                container = new EdmEntityContainer(apiType.Namespace, DefaultEntityContainerName);
                model.AddElement(container);
            }

            return container;
        }
Example #8
0
        /// <summary>
        /// Add a new <see cref="IPostDataElement"/> that represents the specified file
        /// </summary>
        /// <param name="postData">post data instance</param>
        /// <param name="fileName">file name</param>
        public static void AddFile(this IPostData postData, string fileName)
        {
            if(string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            var element = postData.CreatePostDataElement();
            element.File = fileName;

            postData.AddElement(element);
        }
        /// <summary>
        /// 在容器末尾增加一个元素
        /// </summary>
        /// <param name="modifier">DOM 结构修改器</param>
        /// <param name="container">要添加元素的容器</param>
        /// <param name="elementName">元素名</param>
        /// <returns>添加的元素</returns>
        public static IHtmlElement AddElement( this IHtmlDomModifier modifier, IHtmlContainer container, string elementName )
        {
            if ( modifier == null )
            throw new ArgumentNullException( "modifier" );

              if ( container == null )
            throw new ArgumentNullException( "container" );

              if ( elementName == null )
            throw new ArgumentNullException( "elementName" );

              lock ( container.SyncRoot )
              {
            return modifier.AddElement( container, container.Nodes().Count(), elementName );
              }
        }
Example #10
0
        /// <summary>
        /// Add a new <see cref="IPostDataElement"/> that represents the key and value
        /// The data is encoded using
        /// </summary>
        /// <param name="postData">Post Data</param>
        /// <param name="data">Data to be encoded for the post data element</param>
        /// <param name="encoding">Specified Encoding. If null then <see cref="Encoding.Default"/> will be used</param>
        public static void AddData(this IPostData postData, string data, Encoding encoding = null)
        {
            if (string.IsNullOrEmpty(data))
            {
                throw new ArgumentNullException("data");
            }

            if(encoding == null)
            {
                encoding = Encoding.Default;
            }

            var element = postData.CreatePostDataElement();

            element.Bytes = encoding.GetBytes(data);

            postData.AddElement(element);
        }
Example #11
0
 private static void AddReasonElement(this XmlNode parent, TestResult result)
 {
     parent.AddElement("reason").AddElementWithCDataSection("message", result.Message);
 }
Example #12
0
        private static void AddFailureElement(this XmlNode parent, TestResult result)
        {
            var thisNode = parent.AddElement("failure");

            if (result.Message != null)
                thisNode.AddElementWithCDataSection("message", result.Message);

            if (result.StackTrace != null)
                thisNode.AddElementWithCDataSection("stack-trace", result.StackTrace);
        }
Example #13
0
 // Adds a property element and its contents
 private static void AddProperty(this XmlNode parent, string key, object val)
 {
     if (parent == null)
         throw new ArgumentNullException("parent");
     if (val == null)
         throw new ArgumentNullException("val");
     var node = parent.AddElement("property");
     node.AddAttribute("name", key);
     node.AddAttribute("value", val.ToString());
 }
Example #14
0
        //Adds a properties element and its contents
        private static void AddProperties(this XmlNode parent, ITest test)
        {
            var properties = parent.AddElement("properties");

            foreach (string key in test.Properties.Keys)
            {
                object propValue = test.Properties[key];

                // NOTE: This depends on categories being the only multi-valued 
                // property. We can count on this because NUnit V2 is not 
                // being developed any further.
                if (key == "_CATEGORIES")
                    foreach (string category in (IList)propValue)
                        properties.AddProperty(key, category);
                else
                    properties.AddProperty(key, propValue);
            }

            // Special handling for empty _CATEGORIES prop
            // which is sometimes created by NUnit V2
            if (properties.ChildNodes.Count == 0)
                parent.RemoveChild(properties);
        }
Example #15
0
 /// <summary>
 /// Adds the a new element as a child of an existing node and returns it.
 /// A CDataSection is added to the new element using the data provided.
 /// </summary>
 /// <param name="node">The node to which the element should be added.</param>
 /// <param name="name">The element name.</param>
 /// <param name="data">The data for the CDataSection.</param>
 /// <returns></returns>
 private static XmlNode AddElementWithCDataSection(this XmlNode node, string name, string data)
 {
     XmlNode childNode = node.AddElement(name);
     foreach (var section in EscapeCDataString(data))
         childNode.AppendChild(node.OwnerDocument.CreateCDataSection(section));
     return childNode;
 }
 private static void AddType(this EdmModel model, IEdmType type)
 {
     if (type.TypeKind == EdmTypeKind.Complex)
     {
         model.AddElement(type as IEdmComplexType);
     }
     else if (type.TypeKind == EdmTypeKind.Entity)
     {
         model.AddElement(type as IEdmEntityType);
     }
     else if (type.TypeKind == EdmTypeKind.Enum)
     {
         model.AddElement(type as IEdmEnumType);
     }
     else
     {
         Contract.Assert(false, "Only ComplexTypes, EntityTypes and EnumTypes are supported.");
     }
 }
Example #17
0
 /// <summary>
 /// Adds the a new element as a child of an existing node and returns it.
 /// A CDataSection is added to the new element using the data provided.
 /// </summary>
 /// <param name="node">The node to which the element should be added.</param>
 /// <param name="name">The element name.</param>
 /// <param name="data">The data for the CDataSection.</param>
 /// <returns></returns>
 public static XmlNode AddElementWithCDataSection(this XmlNode node, string name, string data)
 {
     XmlNode childNode = node.AddElement(name);
     childNode.AppendChild(node.OwnerDocument.CreateCDataSection(data));
     return childNode;
 }
Example #18
0
 public static void WriteLink(this XmlElement element, string title, string url)
 {
     element.AddElement("a").WithAtt("href", url.Url()).WithInnerText(title);
 }
Example #19
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="element"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public static XElement AddElement(this XElement element, XName name)
 {
     return element.AddElement(new XElement(name));
 }
Example #20
0
 public static void WriteComment(this XmlElement parent, Comment comment)
 {
     parent.AddElement(XmlConstants.Comment).WithAtt(XmlConstants.Id, comment.id)
         .InnerText = comment.Text;
 }
 public static XElement AddElement( this XElement element, string name )
 {
     return element.AddElement( name, null );
 }
Example #22
0
        // Adds a test-suite or test-case element, without result info
        private static XmlNode AddTest(this XmlNode parent, ITest test, bool recursive)
        {
            var thisNode = parent.AddElement(test.IsSuite ? "test-suite" : "test-case");

            if (test.IsSuite)
                thisNode.AddAttribute("type", test.TestType);

            var tn = test.TestName;
            thisNode.AddAttribute("id", string.Format("{0}-{1}", tn.RunnerID, tn.TestID));
            thisNode.AddAttribute("name", tn.Name);
            thisNode.AddAttribute("fullname", tn.FullName);
            thisNode.AddAttribute("runstate", test.RunState.ToString());

            if (test.IsSuite)
                thisNode.AddAttribute("testcasecount", test.TestCount.ToString());

            if (test.Properties.Keys.Count > 0)
                thisNode.AddProperties(test);

            if (recursive && test.IsSuite)
                foreach (ITest child in test.Tests)
                    thisNode.AddTest(child, recursive);

            return thisNode;
        }
        private static void AddProcedures(this EdmEntityContainer container, IEnumerable<ProcedureConfiguration> configurations, Dictionary<string, IEdmStructuredType> edmTypeMap, Dictionary<string, EdmEntitySet> edmEntitySetMap)
        {
            foreach (ProcedureConfiguration procedure in configurations)
            {
                switch (procedure.Kind)
                {
                    case ProcedureKind.Action:
                        ActionConfiguration action = procedure as ActionConfiguration;
                        IEdmTypeReference returnReference = GetEdmTypeReference(edmTypeMap, action.ReturnType, nullable: true);
                        IEdmExpression expression = GetEdmEntitySetExpression(edmEntitySetMap, action);

                        EdmFunctionImport functionImport = new EdmFunctionImport(container, action.Name, returnReference, expression, action.IsSideEffecting, action.IsComposable, action.IsBindable);
                        foreach (ParameterConfiguration parameter in action.Parameters)
                        {
                            // TODO: http://aspnetwebstack.codeplex.com/workitem/417
                            IEdmTypeReference parameterTypeReference = GetEdmTypeReference(edmTypeMap, parameter.TypeConfiguration, nullable: true);
                            EdmFunctionParameter functionParameter = new EdmFunctionParameter(functionImport, parameter.Name, parameterTypeReference, EdmFunctionParameterMode.In);
                            functionImport.AddParameter(functionParameter);
                        }
                        container.AddElement(functionImport);
                        break;

                    case ProcedureKind.Function:
                        Contract.Assert(false, "Functions are not supported.");
                        break;

                    case ProcedureKind.ServiceOperation:
                        Contract.Assert(false, "ServiceOperations are not supported.");
                        break;
                }
            }
        }
Example #24
0
 /// <summary>
 /// Sets multiple values of a specified child element.
 /// </summary>
 /// 
 /// <param name="parent">The element that contains the child element.</param>
 /// <param name="name">The name of the child element whose value you want to change.</param>
 /// <param name="values">The new values of the child element.</param>
 /// 
 /// <returns>The child element.</returns>
 public static XElement SetChildValue(this XElement parent, string name, params object[] values)
 {
     XElement element = parent.Element(name);
     if (element == null) element = parent.AddElement(name, values);
     else element.SetValue(values);
     return element;
 }
        private static void AddProcedures(this EdmModel model, IEnumerable<ProcedureConfiguration> configurations, EdmEntityContainer container,
            Dictionary<Type, IEdmType> edmTypeMap, IDictionary<string, EdmNavigationSource> edmNavigationSourceMap)
        {
            Contract.Assert(model != null, "Model can't be null");

            ValidateActionOverload(configurations.OfType<ActionConfiguration>());

            foreach (ProcedureConfiguration procedure in configurations)
            {
                IEdmTypeReference returnReference = GetEdmTypeReference(edmTypeMap,
                    procedure.ReturnType,
                    procedure.ReturnType != null && procedure.OptionalReturn);
                IEdmExpression expression = GetEdmEntitySetExpression(edmNavigationSourceMap, procedure);
                IEdmPathExpression pathExpression = procedure.EntitySetPath != null
                    ? new EdmPathExpression(procedure.EntitySetPath)
                    : null;

                EdmOperationImport operationImport;

                switch (procedure.Kind)
                {
                    case ProcedureKind.Action:
                        operationImport = CreateActionImport(procedure, container, returnReference, expression, pathExpression);
                        break;
                    case ProcedureKind.Function:
                        operationImport = CreateFunctionImport((FunctionConfiguration)procedure, container, returnReference, expression, pathExpression);
                        break;
                    case ProcedureKind.ServiceOperation:
                        Contract.Assert(false, "ServiceOperations are not supported.");
                        goto default;
                    default:
                        Contract.Assert(false, "Unsupported ProcedureKind");
                        return;
                }

                EdmOperation operation = (EdmOperation)operationImport.Operation;
                if (procedure.IsBindable && procedure.Title != null & procedure.Title != procedure.Name)
                {
                    model.SetOperationTitleAnnotation(operation, new OperationTitleAnnotation(procedure.Title));
                }

                if (procedure.IsBindable &&
                    procedure.NavigationSource != null &&
                    edmNavigationSourceMap.ContainsKey(procedure.NavigationSource.Name))
                {
                    model.SetAnnotationValue(operation, new ReturnedEntitySetAnnotation(procedure.NavigationSource.Name));
                }

                AddProcedureParameters(operation, procedure, edmTypeMap);

                if (procedure.IsBindable)
                {
                    AddProcedureLinkBuilder(model, operation, procedure);
                    ValidateProcedureEntitySetPath(model, operationImport, procedure);
                }
                else
                {
                    container.AddElement(operationImport);
                }

                model.AddElement(operation);
            }
        }
Example #26
0
		/// <summary>
		/// Adds a node to the XML tree
		/// </summary>
		/// <param name="xmlDocument"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		public static XmlNode AddElement(this XmlDocument xmlDocument, string name)
		{
			return xmlDocument.AddElement(name, null);
		}
Example #27
0
 /// <summary>
 /// Gets an element with the specified name, creating it if it does not exist.
 /// </summary>
 /// 
 /// <param name="parent">The element that contains the child element.</param>
 /// <param name="name">The name of the child element to find.</param>
 /// 
 /// <returns>The element, if found; otherwise, a new empty element.</returns>
 public static XElement TryGetElement(this XElement parent, string name)
 {
     XElement element = parent.Element(name) ?? parent.AddElement(name);
     return element;
 }
Example #28
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="element"></param>
 /// <param name="name"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public static XElement AddElement(this XElement element, XName name, object value)
 {
     return element.AddElement(new XElement(name, value));
 }
 /// <summary>
 /// Adds the element with a specifed name.
 /// </summary>
 /// <param name="me">Me.</param>
 /// <param name="name">The name.</param>
 /// <returns>Newly created element</returns>
 public static XElement AddElement(this XElement me, XName name)
 {
     return me.AddElement(name, null);
 }
Example #30
0
		/// <summary>
		/// Adds a node to the XML tree
		/// </summary>
		/// <param name="element"></param>
		/// <param name="name"></param>
		/// <returns></returns>
		public static XmlNode AddElement(this XmlElement element, string name)
		{
			return element.AddElement(name, null);
		}