|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Xml;
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
/*
|
|
|
//CString sXML = _T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
|
|
|
<yz-graph tag=\"rect\" min=\"\" max=\"\" avg=\"\">\
|
|
|
<G id=\"1\" x=\"0\" y=\"0\"/>\
|
|
|
<G id=\"2\" x=\"37\" y=\"25\"/>\
|
|
|
<G id=\"3\" x=\"38\" y=\"25\"/>\
|
|
|
<G id=\"4\" x=\"39\" y=\"25\"/>\
|
|
|
</yz-graph>");
|
|
|
*/
|
|
|
namespace GummingCommon
|
|
|
{
|
|
|
public class ComInterface
|
|
|
{
|
|
|
//tag 值域: "dot", "line" , "rect", "ellipse", "polygon", 分别是点,直线,矩形,椭圆, 多边形
|
|
|
public const string Dot = "dot";
|
|
|
public const string Line = "line";
|
|
|
public const string Rectangle = "rect";
|
|
|
public const string Circle = "ellipse";
|
|
|
public const string Polygon = "polygon";
|
|
|
|
|
|
public static string Transfer(string tag, List<coordinate> coordinates)
|
|
|
{
|
|
|
yzgraph yz = new yzgraph();
|
|
|
yz.tag = tag;
|
|
|
yz.coordinates = new List<coordinate>();
|
|
|
yz.coordinates = coordinates;
|
|
|
|
|
|
XmlSerializer serializer = new XmlSerializer(typeof(yzgraph));
|
|
|
MemoryStream ms = new MemoryStream();
|
|
|
StreamWriter sw = new StreamWriter(ms, Encoding.UTF8);
|
|
|
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
|
|
|
ns.Add("", "");//remove default namespace
|
|
|
serializer.Serialize(sw, yz, ns);
|
|
|
string xml = Encoding.UTF8.GetString(ms.ToArray());
|
|
|
ms.Close();
|
|
|
|
|
|
return xml.Replace("<?", "<?").Replace("?>", " ?>");
|
|
|
}
|
|
|
|
|
|
public static yzgraph Read(string xml)
|
|
|
{
|
|
|
XmlDocument xdoc = new XmlDocument();
|
|
|
try
|
|
|
{
|
|
|
xdoc.LoadXml(xml);
|
|
|
XmlNodeReader reader = new XmlNodeReader(xdoc.DocumentElement);
|
|
|
XmlSerializer ser = new XmlSerializer(typeof(yzgraph));
|
|
|
object obj = ser.Deserialize(reader);
|
|
|
return (yzgraph)obj;
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
return default(yzgraph);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
[Serializable]
|
|
|
[XmlRoot("yz-graph")]
|
|
|
public class yzgraph
|
|
|
{
|
|
|
[XmlAttribute]
|
|
|
public string tag { get; set; }
|
|
|
|
|
|
[XmlAttribute]
|
|
|
public string min { get; set; }
|
|
|
[XmlAttribute]
|
|
|
public string max { get; set; }
|
|
|
[XmlAttribute]
|
|
|
public string avg { get; set; }
|
|
|
|
|
|
[XmlElementAttribute(ElementName = "G")]
|
|
|
public List<coordinate> coordinates { get; set; }
|
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
|
public class coordinate
|
|
|
{
|
|
|
[XmlAttribute]
|
|
|
public string id { get; set; }
|
|
|
|
|
|
[XmlAttribute]
|
|
|
public string x { get; set; }
|
|
|
[XmlAttribute]
|
|
|
public string y { get; set; }
|
|
|
}
|
|
|
}
|