Example #1
0
 public MultiSetTableValue(string colstring, List <string> lstDataRow)
 {
     schema       = new TextTableSchema();
     _LstDataRows = lstDataRow;
     _Cols        = schema.StringToColumns(colstring);
 }
Example #2
0
        /// <summary>
        /// 以最简单的方式系列化为Bytes 的格式。
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        public DataTable DeSerializer(byte[] datas)
        {
            TextTableSchema schema = new TextTableSchema();

            byte[]        bytes_c = MB.Util.Compression.Instance.UnZip(datas);
            string        dstr    = _Encoding.GetString(bytes_c);
            string        colString;
            string        header;
            List <string> dataRows = new List <string>();

            using (StringReader reader = new StringReader(dstr)) {
                //先取Flag  第一行的标志行 为构造DataTable
                string[] flag = reader.ReadLine().Split(';');
                if (flag.Length < 2)
                {
                    throw new MB.Util.APPException("反系列化时出错,不是有效的系列化文件", MB.Util.APPMessageType.SysErrInfo);
                }

                colString = flag[1].Substring(SE_COLUMNS.Length - 3, flag[1].Length - SE_COLUMNS.Length + 3);

                //先读取表头
                header = reader.ReadLine();
                string[] colFields = System.Text.RegularExpressions.Regex.Split(header, "\t");
                while (true)
                {
                    string dataRow = reader.ReadLine();
                    if (string.IsNullOrEmpty(dataRow))
                    {
                        break;
                    }
                    dataRows.Add(dataRow);
                }
            }
            int       all  = computeCount(dataRows.Count);
            var       cols = schema.StringToColumns(colString);
            DataTable dt   = schema.CreateDataTable(cols);
            List <MultiSetTableValue> lst = new List <MultiSetTableValue>();

            for (int i = 0; i < all; i++)
            {
                int           l        = (i + 1) * SINGLE_L > dataRows.Count ? dataRows.Count - i * SINGLE_L : SINGLE_L;
                List <string> childLst = dataRows.GetRange(i * SINGLE_L, l);
                lst.Add(new MultiSetTableValue(colString, childLst));
                Thread t = new Thread(new ThreadStart(lst[i].SetValue));
                t.Priority = ThreadPriority.Highest;
                t.Start();
            }
            ArrayList lstData = new ArrayList();

            for (int i = 0; i < lst.Count; i++)
            {
                if (lst[i].Done)      //保证按系列化前的顺序加载到集合中。
                {
                    dt.Merge(lst[i].CreateDataTable);
                }
                else
                {
                    i--;
                    Thread.Sleep(100);
                }
            }
            return(dt);
        }