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("\
\
\
\
\
\
");
*/
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 coordinates)
{
yzgraph yz = new yzgraph();
yz.tag = tag;
yz.coordinates = new List();
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 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; }
}
}