Example #1
0
        //解析一个网络协议
        // public static ScriptTable Deserialize(Script script, byte[] data, string layoutTableName) {
        //     return Read(script, new ScorpioReader(data), null, "", layoutTableName, true);
        // }

        /// <summary>
        /// 脚本 读取excel文件数据内容
        /// </summary>
        /// <param name="script"></param>
        /// <param name="fileName"></param>
        /// <param name="reader"></param>
        /// <param name="dataArray"></param>
        /// <param name="layoutTableName"></param>
        /// <param name="keyName"></param>
        /// <param name="MD5"></param>
        /// <returns></returns>
        public static ScriptTable ReadDatas(Script script, string fileName, IScorpioReader reader, ScriptTable dataArray, string layoutTableName, string keyName, string MD5)
        {
            var iRow = TableUtil.ReadHead(reader, fileName, MD5);

            for (var i = 0; i < iRow; ++i)
            {
                var data = Read(script, reader, layoutTableName, false);
                data.SetValue("ID", data.GetValue(keyName));
                var key = data.GetValue(keyName).ObjectValue;
                if (dataArray.HasValue(key))
                {
                    var value = dataArray.GetValue(key) as ScriptTable;
                    var itor  = data.GetIterator();
                    while (itor.MoveNext())
                    {
                        value.SetValue(itor.Current.Key, itor.Current.Value);
                    }
                }
                else
                {
                    dataArray.SetValue(key, data);
                }
            }
            return(dataArray);
        }
Example #2
0
        const string Language  = "Language";    //该字段是否有多国语言



        //解析一个网络协议
        // public static ScriptTable Deserialize(Script script, byte[] data, string layoutTableName) {
        //     return Read(script, new ScorpioReader(data), null, "", layoutTableName, true);
        // }

        /// <summary>
        /// 脚本 读取excel文件数据内容
        /// </summary>
        /// <param name="script">脚本引擎</param>
        /// <param name="fileName">文件名字</param>
        /// <param name="reader">文件读取</param>
        /// <param name="dataArray">数据集合</param>
        /// <param name="layoutTableName">布局</param>
        /// <param name="keyName">主key名字</param>
        /// <param name="MD5">文件结构MD5</param>
        /// <returns></returns>
        public static ScriptMap ReadDatas(string fileName, IScorpioReader reader, ScriptMap dataArray, string layoutTableName, string keyName, string MD5)
        {
            using (reader) {
                var script = dataArray.getScript();
                var iRow   = TableUtil.ReadHead(reader, fileName, MD5);                     //数据行数
                var layout = script.Global.GetValue(layoutTableName).Get <ScriptArray>();   //数据结构
                for (var i = 0; i < iRow; ++i)
                {
                    var data     = Read(script, reader, layout); //读取一行数据
                    var keyValue = data.GetValue(keyName);       //获取key值
                    data.SetValue("ID", keyValue);
                    var key = keyValue.Value;
                    if (dataArray.ContainsKey(key))
                    {
                        var value = dataArray.GetValue(key).Get <ScriptMap>();
                        foreach (var pair in data)
                        {
                            value.SetValue(pair.Key, pair.Value);
                        }
                    }
                    else
                    {
                        dataArray.SetValue(key, new ScriptValue(data));
                    }
                }
                return(dataArray);
            }
        }
Example #3
0
        public TableTest Initialize(string fileName, IScorpioReader reader)
        {
            var iRow = TableUtil.ReadHead(reader, fileName, FILE_MD5_CODE);

            for (var i = 0; i < iRow; ++i)
            {
                var pData = DataTest.Read(fileName, reader);
                if (m_dataArray.ContainsKey(pData.ID()))
                {
                    m_dataArray[pData.ID()].Set(pData);
                }
                else
                {
                    m_dataArray.Add(pData.ID(), pData);
                }
            }
            m_count = m_dataArray.Count;
            return(this);
        }
Example #4
0
        public TableTest Initialize(TableManager tableManager, string fileName)
        {
            m_dataArray.Clear();
            ScorpioReader reader = new ScorpioReader(TableUtil.GetBuffer(fileName));
            int           iRow   = TableUtil.ReadHead(reader, fileName, FILE_MD5_CODE);

            for (int i = 0; i < iRow; ++i)
            {
                DataTest pData = DataTest.Read(tableManager, fileName, reader);
                if (Contains(pData.ID()))
                {
                    throw new System.Exception("文件[" + fileName + "]有重复项 ID : " + pData.ID());
                }
                m_dataArray.Add(pData.ID(), pData);
            }
            m_count = m_dataArray.Count;
            reader.Close();
            return(this);
        }
Example #5
0
        //读取excel文件数据内容
        public static ScriptTable ReadDatas(Script script, ScriptTable tableManager, string fileName, string layoutTableName, string keyName, string MD5)
        {
            ScriptTable   ret    = script.CreateTable();
            ScorpioReader reader = new ScorpioReader(TableUtil.GetBuffer(fileName));
            int           iRow   = TableUtil.ReadHead(reader, fileName, MD5);
            ScriptTable   data   = null;
            double        key    = 0;

            for (int i = 0; i < iRow; ++i)
            {
                data = ScorpioSerializer.Read(script, reader, tableManager, fileName, layoutTableName, false);
                key  = ScorpioUtil.ToDouble(data.GetValue(keyName).ObjectValue);
                if (ret.HasValue(key))
                {
                    throw new System.Exception("文件[" + fileName + "]有重复项 ID : " + key);
                }
                ret.SetValue(key, data);
                data.SetValue("ID", script.CreateDouble(key));
            }
            return(ret);
        }