예제 #1
0
 /// <summary>
 /// 清除点集数据
 /// </summary>
 public void Flush()
 {
     _list.Clear();
     _list        = new List <PointF>();
     _grouplist   = null;
     _ylimitvalue = new PointF(0, 0);
     _DataUnit    = null;
 }
예제 #2
0
 /// <summary"反序列化">
 /// 给定的序列化的字符串进行反序列化为object对象
 /// </summary>
 /// <param name="val">序列化过的字符串</param>
 /// <returns>返回的反序列化的对象</returns>
 public static DataUnitDescription Deserialize(string val)
 {
     try
     {
         if (!val.StartsWith(c_Name))
         {
             return(null);
         }
         string   rs    = val.Substring(c_Name.Length, val.Length - c_Name.Length);
         string[] pinfs = rs.Split(new string[] { "\r" }, StringSplitOptions.RemoveEmptyEntries);
         if (pinfs == null || pinfs.GetLength(0) == 0)
         {
             return(null);
         }
         string[]                       values = null;
         DataUnitDescription            dud    = new DataUnitDescription();
         System.Reflection.PropertyInfo pinf   = null;
         object vs = null;
         foreach (string prop in pinfs)
         {
             if (prop == null)
             {
                 continue;
             }
             values = prop.Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
             if (values == null || values.GetLength(0) != 2)
             {
                 continue;
             }
             pinf = dud.GetType().GetProperty(values[0]);
             if (pinf == null)
             {
                 continue;
             }
             vs = Convert.ChangeType(values[1], pinf.PropertyType);
             pinf.SetValue(dud, vs, null);
         }
         return(dud);
     }
     catch
     {
         return(null);
     }
 }
예제 #3
0
        /// <summary "序列化">
        /// 给定的object对象进行序列化为字符串
        /// </summary>
        /// <param name="obj"> 序列化的目标源</param>
        /// <returns>序列化过的字符串</returns>
        public static string Serialize(DataUnitDescription dud)
        {
            if (dud == null)
            {
                return("");
            }
            string rs    = c_Name;
            string value = "";

            System.Reflection.PropertyInfo[] pinfs = dud.GetType().GetProperties();
            foreach (System.Reflection.PropertyInfo pinf in pinfs)
            {
                //if (pinf.Attributes.ToString() != "SerializePropertyAttribute") continue;
                value = pinf.GetValue(dud, null).ToString();
                value = value.Replace("=", "");
                value = value.Replace("\r", "");
                rs   += "\r" + pinf.Name + "=" + value;
            }
            return(rs);
        }
예제 #4
0
        /// <summary>
        /// 对象反序列化
        /// </summary>
        /// <param name="stream">从流对象反序列化</param>
        public void Deserialize(MemoryStream stream)
        {
            try
            {
                BinaryFormatter format = new BinaryFormatter();
                try
                {
                    stream.Position = 0;
                    StringBuilder value = (StringBuilder)format.Deserialize(stream);
                    string[]      pts   = value.ToString().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    string[]      pt    = new string[2];
                    int           count = pts.GetLength(0);

                    DataUnitDescription dud = DataUnitDescription.Deserialize(pts[count - 1]);
                    if (dud != null)
                    {
                        DataUnit = dud;
                        count--;
                    }

                    for (int i = 0; i < count; i++)
                    {
                        pt = pts[i].Split(',');
                        _list.Add(new PointF(float.Parse(pt[0]), float.Parse(pt[1])));
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteError(ex);
                    stream.Position = 0;
                    _list           = (List <PointF>)format.Deserialize(stream);
                }
                _ylimitvalue = _list[_list.Count - 1];
                _list.RemoveAt(_list.Count - 1);
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex);
            }
        }
예제 #5
0
        /// <summary>
        /// 对象序列化
        /// </summary>
        /// <param name="stream">序列化到流对象</param>
        /// <param name="format"></param>
        public void Serialize(ref MemoryStream stream)
        {
            BinaryFormatter format = new BinaryFormatter();

            _list.Add(YLimitValue);
            StringBuilder value = new StringBuilder();

            for (int i = 0; i < _list.Count; i++)
            {
                value.Append(_list[i].X.ToString() + "," + _list[i].Y.ToString() + ";");
            }

            if (DataUnit != null)
            {
                string dunit = DataUnitDescription.Serialize(DataUnit);
                value.Append(dunit + ";");
            }

            format.Serialize(stream, value);
            //format.Serialize(stream, _list);
            _list.RemoveAt(_list.Count - 1);
        }