Exemplo n.º 1
0
    public WDBData GetData()
    {
        BinaryFormatter formatter           = new BinaryFormatter();
        MemoryStream    serializationStream = new MemoryStream(this.m_Stream);
        WDBData         data = formatter.Deserialize(serializationStream) as WDBData;

        if (data != null)
        {
            data.Init();
        }
        return(data);
    }
Exemplo n.º 2
0
    public static WDBData Analyze(string text)
    {
        if (string.IsNullOrEmpty(text))
        {
            return(null);
        }
        WDBData             data      = new WDBData();
        List <WDBSheetLine> sheetList = new List <WDBSheetLine>();

        data.m_Type = new List <TYPE>();
        Dictionary <int, TYPE> _type = new Dictionary <int, TYPE>();

        string[] lineData = text.Split('\n');

        int keyLine  = -1;
        int typeLine = -1;

        for (int nLine = 0; nLine < lineData.Length; ++nLine)
        {
            string[] datas = lineData[nLine].Split('\r');
            datas = datas[0].Split('\t');

            if (datas.Length == 0 || datas[0].IndexOf("#") == 0)
            {
                continue;//判断有错误,如果未找到该字符串,则为 -1。 如果 value 为 String.Empty,则返回值为 0
            }
            if (datas.Length == 1 && datas[0] == "")
            {
                continue;
            }
            if (keyLine < 0)
            {
                keyLine = nLine;
            }
            else
            {
                if (nLine == keyLine + 1)
                {
                    typeLine = nLine;
                }
            }


            WDBSheetLine sheetLine = new WDBSheetLine();
            sheetLine.m_Line = new object[datas.Length];

            for (int col = 0; col < datas.Length; ++col)
            {
                //								if (nLine == keyLine)
                //										data.m_FieldName.Add (datas [col], col);
                if (nLine == typeLine)
                {
                    TYPE strType = nameToType(datas[col]);
                    if (strType == TYPE.TYPE_INVALID)
                    {
                        throw new Exception("failed to parse type: " + datas[col]);
                    }
                    _type.Add(col, strType);
                    data.m_Type.Add(strType);
                    continue;
                }
                if (nLine == keyLine)
                {
                    sheetLine.m_Line[col] = datas[col];
                }
                else
                {
                    sheetLine.m_Line[col] = ConvertValue(datas[col], _type[col]);
                }
            }
            if (nLine != typeLine)
            {
                sheetList.Add(sheetLine);
            }
        }

        if (sheetList.Count > 0)
        {
            data.m_Data = new WDBSheetLine[sheetList.Count];
            for (int n = 0; n < sheetList.Count; ++n)
            {
                data.m_Data[n] = sheetList[n];
            }
            sheetList.Clear();
            data.Init();
        }

        return(data);
    }