当前位置: 首页>>代码示例>>C#>>正文


C# StringBuilder.ToXElement方法代码示例

本文整理汇总了C#中StringBuilder.ToXElement方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuilder.ToXElement方法的具体用法?C# StringBuilder.ToXElement怎么用?C# StringBuilder.ToXElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringBuilder的用法示例。


在下文中一共展示了StringBuilder.ToXElement方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExtractDataList

        /// <summary>
        /// Extracts the data list.
        /// </summary>
        /// <param name="serviceDef">The service def.</param>
        /// <returns></returns>
        public static string ExtractDataList(StringBuilder serviceDef)
        {
            string result = string.Empty;

            var xe = serviceDef.ToXElement();

            var dl = xe.Elements().FirstOrDefault(c => c.Name == GlobalConstants.DataListRootTag);

            if (dl != null)
            {
                result = dl.ToString(SaveOptions.DisableFormatting);
            }
            
            return result;
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:20,代码来源:ServiceUtils.cs

示例2: ExtensionMethods_ToStreamForXmlLoad_WhenLoadingXElement_ExpectValidXElement

        public void ExtensionMethods_ToStreamForXmlLoad_WhenLoadingXElement_ExpectValidXElement()
        {
            //------------Setup for test--------------------------
            const string val = "<x><y>1</y></x>";
            StringBuilder value = new StringBuilder(val);

            //------------Execute Test---------------------------
            var xe = value.ToXElement();

            string result = xe.ToString(SaveOptions.DisableFormatting);

            //------------Assert Results-------------------------
            Assert.AreEqual(val, result);
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:14,代码来源:ExtensionMethodsTest.cs

示例3: ExtensionMethods_ToStreamForXmlLoad_WhenLoadingXElement_ExpectException

        public void ExtensionMethods_ToStreamForXmlLoad_WhenLoadingXElement_ExpectException()
        {
            //------------Setup for test--------------------------
            const string val = "<x><y>1</y>.</</x>";
            StringBuilder value = new StringBuilder(val);

            //------------Execute Test---------------------------
            value.ToXElement();
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:9,代码来源:ExtensionMethodsTest.cs

示例4: ExtensionMethods_CleanEncodingHeaderForXmlSave_WhenSavingXElement_ExpectEncodingHeaderRemoved

        public void ExtensionMethods_CleanEncodingHeaderForXmlSave_WhenSavingXElement_ExpectEncodingHeaderRemoved()
        {
            //------------Setup for test--------------------------
            StringBuilder value = new StringBuilder("<x><y>1</y></x>");

            //------------Execute Test---------------------------
            var xe = value.ToXElement();

            var sb = new StringBuilder();
            using(var sw = new StringWriter(sb))
            {
                xe.Save(sw, SaveOptions.DisableFormatting);
            }

            var res = sb.CleanEncodingHeaderForXmlSave();

            //------------Assert Results-------------------------
            var result = res.Contains("encoding=");

            Assert.IsFalse(result, "Encoding Header Not Removed");
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:21,代码来源:ExtensionMethodsTest.cs

示例5: ExtensionMethods_AttributeSafe_WhenAttributeDoesNotExist_ExpectEmptyString

        public void ExtensionMethods_AttributeSafe_WhenAttributeDoesNotExist_ExpectEmptyString()
        {
            //------------Setup for test--------------------------
            const string msg = "<x foo=\"bar\">test message</x>";
            var sb = new StringBuilder(msg);

            //------------Execute Test---------------------------

            var xe = sb.ToXElement();
            var result = xe.AttributeSafe("foo2");

            //------------Assert Results-------------------------
            Assert.AreEqual(result, string.Empty);
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:14,代码来源:ExtensionMethodsTest.cs

示例6: ExtensionMethods_AttributeSafe_WhenAttributeExist_ExpectAttributeValue

        public void ExtensionMethods_AttributeSafe_WhenAttributeExist_ExpectAttributeValue()
        {
            //------------Setup for test--------------------------
            const string msg = "<x foo=\"bar\">test message</x>";
            var sb = new StringBuilder(msg);

            //------------Execute Test---------------------------

            var xe = sb.ToXElement();
            var result = xe.AttributeSafe("foo");

            //------------Assert Results-------------------------
            StringAssert.Contains(result, "bar");
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:14,代码来源:ExtensionMethodsTest.cs

示例7: ExtensionMethods_ElementSafe_WhenElementDoesNotExist_ExpectEmptyString

        public void ExtensionMethods_ElementSafe_WhenElementDoesNotExist_ExpectEmptyString()
        {
            //------------Setup for test--------------------------
            const string msg = "<x><y>y value</y></x>";
            var sb = new StringBuilder(msg);

            //------------Execute Test---------------------------

            var xe = sb.ToXElement();
            var result = xe.ElementSafe("q");

            //------------Assert Results-------------------------
            Assert.AreEqual(result, string.Empty);
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:14,代码来源:ExtensionMethodsTest.cs

示例8: ExtensionMethods_ElementSafe_WhenElementExist_ExpectElement

        public void ExtensionMethods_ElementSafe_WhenElementExist_ExpectElement()
        {
            //------------Setup for test--------------------------
            const string msg = "<x><y>y value</y></x>";
            var sb = new StringBuilder(msg);

            //------------Execute Test---------------------------

            var xe = sb.ToXElement();
            var result = xe.ElementSafe("y");

            //------------Assert Results-------------------------
            StringAssert.Contains(result, "y");
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:14,代码来源:ExtensionMethodsTest.cs

示例9: AppServer_Update_Resource_Correctly

        public void AppServer_Update_Resource_Correctly()
        {
            CommunicationController coms = new CommunicationController { ServiceName = "SaveResourceService" };

            var tmp = new StringBuilder(TestResource.Service_Update_Request_String);
            var xe = tmp.ToXElement();
            var xml = xe.Element("ResourceXml");

            var wtf = xml.ToStringBuilder().Unescape();
            wtf = wtf.Replace("<XmlData>", "").Replace("</XmlData>", "").Replace("<ResourceXml>", "").Replace("</ResourceXml>", "");

            coms.AddPayloadArgument("ResourceXml", wtf);
            coms.AddPayloadArgument("WorkspaceID", Guid.Empty.ToString());

            const string expected = @"Updated WorkflowService 'ServiceToBindFrom'";

            var result = coms.ExecuteCommand<ExecuteMessage>(_connection, Guid.Empty);

            StringAssert.Contains(result.Message.ToString(), expected);

        }
开发者ID:Robin--,项目名称:Warewolf,代码行数:21,代码来源:ApplicationServerBuildTests.cs

示例10: ExtractOutputMapping

        public static string ExtractOutputMapping(StringBuilder serviceDef)
        {
            string result = string.Empty;

            var xe = serviceDef.ToXElement();

            // could have service as its root ;(
            var tmpB = xe.Elements().FirstOrDefault(c => c.Name == GlobalConstants.ActionsRootTag);

            var tmpA = xe.Elements().FirstOrDefault(c => c.Name == GlobalConstants.ActionRootTag);

            if (tmpB != null)
            {
                tmpA = tmpB.Elements().FirstOrDefault(c => c.Name == GlobalConstants.ActionRootTag);
            }


            if (tmpA != null)
            {
                var dl = tmpA.Elements().FirstOrDefault(c => c.Name == GlobalConstants.OutputRootTag);

                if (dl != null)
                {
                    result = dl.ToString();
                }
            }


            return result;
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:30,代码来源:ServiceUtils.cs

示例11: GenerateServiceGraph

        public List<DynamicServiceObjectBase> GenerateServiceGraph(StringBuilder serviceData)
        {
            if(serviceData == null || serviceData.Length == 0)
            {
                throw new ArgumentException("serviceData");
            }

            List<DynamicServiceObjectBase> result = new List<DynamicServiceObjectBase>();
            var xe = serviceData.ToXElement();

            if(IsSource(serviceData))
            {
                Source src = new Source();
                var tmp = src as DynamicServiceObjectBase;
                ServiceMetaData.ExtractMetaData(xe, ref tmp);

                var typeOf = xe.AttributeSafe("ResourceType");

                enSourceType sourceType;
                src.Type = !Enum.TryParse(typeOf, out sourceType) ? enSourceType.Unknown : sourceType;

                src.ConnectionString = xe.AttributeSafe("ConnectionString");
                var tmpUri = xe.AttributeSafe("Uri");
                if(!string.IsNullOrEmpty(tmpUri))
                {
                    src.WebServiceUri = new Uri(tmpUri);
                }

                src.AssemblyName = xe.AttributeSafe("AssemblyName");
                src.AssemblyLocation = xe.AttributeSafe("AssemblyLocation");

                // PBI 6597: TWR - added source ID check
                var id = ServiceMetaData.SetID(ref xe);
                src.ID = id;
                src.ResourceDefinition = serviceData;

                result.Add(src);

            }
            else
            {
                DynamicService ds = new DynamicService();
                var tmp = ds as DynamicServiceObjectBase;
                ServiceMetaData.ExtractMetaData(xe, ref tmp);

                // set the resource def ;)
                ds.ResourceDefinition = serviceData;

                var actions = xe.Element("Actions");
                XElement action = actions != null ? actions.Element("Action") : xe.Element("Action");

                if(action != null)
                {
                    ServiceAction sa = new ServiceAction { Name = action.AttributeSafe("Name"), ResourceDefinition = serviceData };

                    // Set service action ;)
                    enActionType actionType;
                    var typeOf = action.AttributeSafe("Type");
                    if(Enum.TryParse(typeOf, out actionType))
                    {
                        sa.ActionType = actionType;
                    }

                    var element = action.Element("Outputs");
                    if(element != null)
                    {
                        sa.OutputSpecification = element.Value;
                    }

                    // set name and id ;)
                    sa.ServiceName = ds.Name;
                    var id = ServiceMetaData.SetID(ref xe);
                    ds.ID = id;

                    if(IsWorkflow(serviceData))
                    {
                        // Convert to StringBuilder
                        var xElement = action.Element("XamlDefinition");
                        if(xElement != null)
                        {
                            var def = xElement.ToStringBuilder();
                            def = def.Replace("<XamlDefinition>", "").Replace("</XamlDefinition>", "");
                            sa.XamlDefinition = def.Unescape();
                        }

                        var dataList = xe.Element("DataList");
                        if(dataList != null)
                        {
                            ds.DataListSpecification = dataList.ToStringBuilder();
                        }
                    }
                    else
                    {
                        if(sa.ActionType == enActionType.InvokeStoredProc)
                        {
                            int timeout;
                            Int32.TryParse(action.AttributeSafe("CommandTimeout"), out timeout);
                            sa.CommandTimeout = timeout;
                        }

//.........这里部分代码省略.........
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:101,代码来源:ServiceDefinitionLoader.cs

示例12: BuildGraph

        /// <summary>
        /// Builds the graph.
        /// </summary>
        /// <param name="xmlData">The XML data.</param>
        /// <param name="modelName">Name of the model.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns></returns>
        public Graph BuildGraph(StringBuilder xmlData, string modelName, double width, double height)
        {

            if(xmlData == null || xmlData.Length == 0)
            {
                return new Graph("Dependency information could not be retrieved");
            }

            XElement xe = xmlData.ToXElement();

            // Create a graph.
            var graphElem = xe.AncestorsAndSelf("graph").FirstOrDefault();
            if(graphElem == null)
            {
                return new Graph("Dependency information is malformed");
            }

            try
            {
                string title = graphElem.Attribute("title").Value;
                var graph = new Graph(title);
                double count = 0;

                var nodeElems = graphElem.Elements("node").ToList();

                // Create all of the nodes and add them to the graph.
                foreach(XElement nodeElem in nodeElems)
                {
                    // build the graph position data
                    string id = nodeElem.Attribute("id").Value;
                    var node = CreateNode(nodeElem, modelName, width, height, ref count);

                    bool alreadyAdded = false;
                    foreach(Node n in graph.Nodes)
                    {
                        if(n.ID == id)
                        {
                            alreadyAdded = true;
                        }
                    }

                    if(!alreadyAdded)
                    {
                        graph.Nodes.Add(node);
                    }
                }

                // Associate each node with its dependencies.
                foreach(Node node in graph.Nodes)
                {
                    var nodeElem = nodeElems.First(elem => elem.Attribute("id").Value == node.ID);
                    var dependencyElems = nodeElem.Elements("dependency");
                    foreach(XElement dependencyElem in dependencyElems)
                    {
                        string depID = dependencyElem.Attribute("id").Value;

                        var dependency = graph.Nodes.FirstOrDefault(n => n.ID == depID);
                        if(dependency != null)
                            node.NodeDependencies.Add(dependency);
                    }

                    //Now adjust position according to nodesize
                    node.LocationX = node.LocationX - node.NodeWidth;
                    node.LocationY = node.LocationY - node.NodeHeight / 2;
                }

                // Tell the graph to inspect itself for circular dependencies.
                graph.CheckForCircularDependencies();

                return graph;
            }
            catch
            {
                return new Graph("Dependency information is malformed");
            }
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:84,代码来源:DependencyGraphGenerator.cs


注:本文中的StringBuilder.ToXElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。