/// <summary> /// 序列化 /// </summary> /// <returns></returns> public byte[] Serialize() { ClSet cs = new ClSet(); ClTable ct = new ClTable("System"); ct.AddColumn("INFO", typeof(int)); cs.Tables.Add(ct); ClRow _cr = ct.NewRow(); _cr[0] = sysstate; ct.Rows.Add(_cr); int idna = 0, idsna = 1, idsp = 2, idlo = 3, idst = 4; ct = new ClTable("Locoms"); ct.AddColumn("NAME", typeof(string)); ct.AddColumn("SECTIONNA", typeof(string)); ct.AddColumn("SPEED", typeof(short)); ct.AddColumn("LOCATION", typeof(byte)); ct.AddColumn("STATE", typeof(byte)); cs.Tables.Add(ct); foreach (Locom l in this) { ClRow cr = ct.NewRow(); cr[idna] = l.name; cr[idsna] = l.sectionname; cr[idsp] = l.speed; cr[idlo] = l.location; cr[idst] = l.state; ct.Rows.Add(cr); } return(cs.Serialize(2)); }
/// <summary> /// 序列化 /// </summary> /// <param name="wnds">车次窗</param> /// <param name="color">颜色</param> /// <returns>字节流</returns> public static byte[] Serialize(TrainWnd[] wnds, byte color) { ClSet cs = new ClSet(); ClTable ct1 = new ClTable("Infomations"); ct1.AddColumn("I_LINE_ID", typeof(short)); ct1.AddColumn("C_TRA_NUM", typeof(string)); ct1.AddColumn("F_WEGH", typeof(float)); ct1.AddColumn("F_LEN", typeof(short)); ct1.AddColumn("I_CAR_CNT", typeof(short)); ct1.AddColumn("B_FLAG", typeof(byte)); ct1.AddColumn("C_NOTE", typeof(string)); ct1.AddColumn("B_LOCOM_TYPE", typeof(byte)); ClTable ct2 = new ClTable("CarStream"); ct2.AddColumn("I_LINE_ID", typeof(short)); ct2.AddColumn("I_GRO_ID", typeof(short)); ct2.AddColumn("I_CAR_CNT", typeof(short)); foreach (TrainWnd w in wnds) { ClRow cr = ct1.NewRow(); cr["I_LINE_ID"] = w.lineID; cr["F_WEGH"] = w.weight; cr["F_LEN"] = (short)(w.length * 10 + .5); cr["I_CAR_CNT"] = w.cnt; cr["C_TRA_NUM"] = w.trainnum; cr["B_FLAG"] = w.flag; cr["C_NOTE"] = w.infomation; cr["B_LOCOM_TYPE"] = w.LocomType; ct1.Rows.Add(cr); foreach (CarInfomation inf in w.infomations) { if (inf.cnt > 0) { cr = ct2.NewRow(); cr["I_LINE_ID"] = w.lineID; cr["I_GRO_ID"] = inf.dir; cr["I_CAR_CNT"] = inf.cnt; ct2.Rows.Add(cr); } } } cs.Tables.Add(ct1); cs.Tables.Add(ct2); if (color != 0) { ct2 = new ClTable("SYSCOLOR"); ct2.AddColumn("COLOR", typeof(byte)); ClRow _cr = ct2.NewRow(); _cr[0] = color; ct2.Rows.Add(_cr); cs.Tables.Add(ct2); } byte[] b = cs.Serialize(2); b[0] = 0x33; return(b); }
/// <summary> /// 序列化 /// </summary> /// <param name="cs">数据集</param> /// <returns>字节流</returns> protected byte[] Serialize(ClSet cs) { string s; s = typeof(CIPS.ClientCommand).FullName + "\n" + GetType().FullName + "\0"; ToClTable(cs); byte[] head = System.Text.Encoding.Unicode.GetBytes(s); byte[] b = cs.Serialize(head.Length); head.CopyTo(b, 0); return(b); }