public static string SerializeNode(INodeProxy[] nodeProxies) { XmlSerializer serializer = new XmlSerializer(typeof(Nodes)); Encoding utf8 = new UTF8Encoding(false); MemoryStream ms = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(ms, new XmlWriterSettings() { Indent = false, NewLineHandling = NewLineHandling.None, CloseOutput = true, Encoding = utf8 }); Nodes nodes = new Nodes(); List <NodesNode> nodesList = new List <NodesNode>(); foreach (INodeProxy nodeProxy in nodeProxies) { NodesNode node = new NodesNode() { NodeUid = nodeProxy.Id, NodeType = new NodesNodeNodeType() { NodeTypeName = nodeProxy.NodeType.Name, NodeTypeUid = nodeProxy.NodeType.Id }, DomainUid = nodeProxy.Domain }; List <NodesNodeMetadata> metadatam = new List <NodesNodeMetadata>(); foreach (MetadataContext key in nodeProxy.Metadata.Keys) { NodesNodeMetadata metaData = new NodesNodeMetadata() { Name = key.MetadataName.Replace(".", "_"), Value = nodeProxy.Metadata[key].MetadataValue }; metadatam.Add(metaData); } node.Metadatum = metadatam.ToArray(); nodesList.Add(node); } nodes.Node = nodesList.ToArray(); serializer.Serialize(xmlWriter, nodes); byte[] bytes = ms.ToArray(); ms.Close(); string xmlString = Encoding.UTF8.GetString(bytes, 0, bytes.Length); return(xmlString); }
public static string SerializeNode(INodeProxy[] nodeProxies) { XmlSerializer serializer = new XmlSerializer(typeof(Nodes)); Encoding utf8 = new UTF8Encoding(false); MemoryStream ms = new MemoryStream(); XmlWriter xmlWriter = XmlWriter.Create(ms, new XmlWriterSettings() { Indent = false, NewLineHandling = NewLineHandling.None, CloseOutput = true, Encoding = utf8 }); Nodes nodes = new Nodes(); List<NodesNode> nodesList = new List<NodesNode>(); foreach (INodeProxy nodeProxy in nodeProxies) { NodesNode node = new NodesNode() { NodeUid = nodeProxy.Id, NodeType = new NodesNodeNodeType() { NodeTypeName = nodeProxy.NodeType.Name, NodeTypeUid = nodeProxy.NodeType.Id }, DomainUid = nodeProxy.Domain }; List<NodesNodeMetadata> metadatam = new List<NodesNodeMetadata>(); foreach (MetadataContext key in nodeProxy.Metadata.Keys) { NodesNodeMetadata metaData = new NodesNodeMetadata() { Name = key.MetadataName.Replace(".", "_"), Value = nodeProxy.Metadata[key].MetadataValue }; metadatam.Add(metaData); } node.Metadatum = metadatam.ToArray(); nodesList.Add(node); } nodes.Node = nodesList.ToArray(); serializer.Serialize(xmlWriter, nodes); byte[] bytes = ms.ToArray(); ms.Close(); string xmlString = Encoding.UTF8.GetString(bytes, 0, bytes.Length); return xmlString; }