Example #1
0
        private static LogLevel ParseLevel(string levelString)
        {
            string   level = StringUtils.StrTok(levelString, "|");
            LogLevel log   = LogLevel.NONE;

            while (level != null)
            {
                log  |= EnumUtils.StringToEnum <LogLevel>(level.Trim().ToUpper());
                level = StringUtils.StrTok(null, "|");
            }
            return(log);
        }
Example #2
0
        public static object ToObject(string str, Type type)
        {
            if (type.IsGenericType)
            {
                if (type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    Type[]        types  = type.GetGenericArguments();
                    Type          t      = types[0];
                    List <string> list   = ToListObject(str);
                    var           result = type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    foreach (var item in list)
                    {
                        var v = ToObject(item, t);
                        ListAddMethodInfo.Invoke(result, new object[] { v });
                    }
                    return(result);
                }
                else if (type.GetGenericTypeDefinition() == typeof(Dictionary <,>))
                {
                    Type[] types = type.GetGenericArguments();
                    Dictionary <string, string> map = ToMapObject(str);
                    var result = type.GetConstructor(Type.EmptyTypes).Invoke(null);
                    foreach (var item in map)
                    {
                        var key = ToObject(item.Key, types[0]);
                        var v   = ToObject(item.Value, types[1]);
                        DictionaryAddMethodInfo.Invoke(result, new object[] { key, v });
                    }
                    return(result);
                }
                DebugUtils.Assert(false, "ToObject Not Found Type: " + type.FullName);
                return(null);
            }
            else if (type.BaseType == typeof(Enum))
            {
                return(EnumUtils.StringToEnum(str, type));
            }
            MethodInfo method = GetToObjectMethodInfoFromCache(type);

            GenericParametersObjectTwo[0] = str;
            GenericParametersObjectTwo[1] = GetDefault(type);
            bool res = (bool)method.Invoke(null, GenericParametersObjectTwo);

            DebugUtils.Assert(res, string.Format("Data {0} Not Right Type {1}", str, type.FullName));
            return(GenericParametersObjectTwo[1]);
        }
Example #3
0
        private string GetDataManager()
        {
            GameDataManagerType type = GameDataManagerType.LIST;

            if (Manager != null)
            {
                type = EnumUtils.StringToEnum <GameDataManagerType>(Manager.ToUpper());
            }
            switch (type)
            {
            case GameDataManagerType.LIST:
                return("GameDataList");

            case GameDataManagerType.MAP:
                return("GameDataMap");

            case GameDataManagerType.GROUP:
                return("GameDataGroup");
            }
            return("GameDataList");
        }
Example #4
0
        private string MakeClassDefine()
        {
            GameDataManagerType type = GameDataManagerType.LIST;

            if (Manager != null)
            {
                type = EnumUtils.StringToEnum <GameDataManagerType>(Manager.ToUpper());
            }
            string baseName = GetDataManager();

            if (type == GameDataManagerType.LIST)
            {
                return(string.Format("public class {0} : {1}<{2}>", SheetName, baseName, SheetName));
            }
            DebugUtils.Assert(!string.IsNullOrEmpty(Keys), "Wrong Keys");
            List <string> keys           = new List <string>(Keys.Split(','));
            string        dataTypeString = null;
            string        readString     = null;
            string        writeString    = null;
            string        generic        = string.Format("public class {0} : {1}<", SheetName, baseName);

            for (int j = 0; j < keys.Count; ++j)
            {
                string key = keys[j];
                int    i   = 0;
                for (i = 0; i < mVariableNames.Count; ++i)
                {
                    if (mVariableNames[i] == key)
                    {
                        break;
                    }
                }
                DebugUtils.Assert(i < mVariableNames.Count, string.Format("{0} KeyName Not Found", key));
                GetType(mVariableTypes[i], ref dataTypeString, ref readString, ref writeString);
                generic += dataTypeString + ", ";
            }
            generic += SheetName + ">";
            return(generic);
        }
Example #5
0
        private static List <XlsxRow> CleanRowAndCols(ExcelWorksheet tDS, XlsxSheet sheet, out string managerName, out string keys, out List <string> variableNames, out List <DataTypeEnum> variableTypes, out List <DataSideEnum> variableSides)
        {
            variableNames = new List <string>();
            variableTypes = new List <DataTypeEnum>();
            variableSides = new List <DataSideEnum>();
            managerName   = null;
            keys          = null;
            ExcelRange range = tDS.Cells;

            object[,] values = (object[, ])range.Value;
            int           rows     = values.GetLength(0);
            int           cols     = values.GetLength(1);
            HashSet <int> skipCols = new HashSet <int>();
            HashSet <int> skipRows = new HashSet <int>();

            if (rows > 0 && cols > 0)
            {
                // List,Group<ColName>,Map<ColName>,Map<ColName1, ColName2>
                string value = (string)values[SHEET_DATA_MANAGER, 0];
                if (value == null)
                {
                    MainEntry.Log(string.Format("****************SheetName: {0} Wrong At [0, 0] End", tDS.Name));
                    return(null);
                }
                ParseManagerType(value, ref managerName, ref keys);
                if (managerName == null)
                {
                    MainEntry.Log(string.Format("****************SheetName: {0} Wrong ManagerName {1} End", tDS.Name, value));
                    return(null);
                }
            }
            for (int i = 0; i < cols; ++i)
            {
                if (values[VARIABLE_SIDE_ROW, i] == null)
                {
                    MainEntry.Log(string.Format("skip null col: [{0}, {1}], maybe last col", VARIABLE_SIDE_ROW, i));
                    skipCols.Add(i);
                    continue;
                }
                string       v    = values[VARIABLE_SIDE_ROW, i].ToString().Trim().ToUpper();
                DataSideEnum side = EnumUtils.StringToEnum <DataSideEnum>(v);
                if (side == DataSideEnum.SKIP)
                {
                    MainEntry.Log(string.Format("skip flag col: [{0}, {1}]", VARIABLE_SIDE_ROW, i));
                    skipCols.Add(i);
                    continue;
                }
                if (values[VARIABLE_NAME_ROW, i] == null)
                {
                    // log
                    MainEntry.Log(string.Format("Not Define Variable Name: [{0}, {1}]", VARIABLE_NAME_ROW, i));
                    return(null);
                }
                if (values[VARIABLE_TYPE_ROW, i] == null)
                {
                    // log
                    MainEntry.Log(string.Format("Not Define Variable Type: [{0}, {1}]", VARIABLE_TYPE_ROW, i));
                    return(null);
                }
                variableSides.Add(side);
                v = values[VARIABLE_NAME_ROW, i].ToString().Trim();
                variableNames.Add(v);
                v = values[VARIABLE_TYPE_ROW, i].ToString().Trim();
                try
                {
                    DataTypeEnum dataType = EnumUtils.StringToEnum <DataTypeEnum>(v.ToUpper());
                    variableTypes.Add(dataType);
                }
                catch (Exception e)
                {
                    MainEntry.Log(string.Format("Not Define Variable Side: [{0}, {1}] = {2}, Error: {3}", VARIABLE_TYPE_ROW, i, v, e.Message));
                    return(null);
                }
            }
            for (int i = VALUE_START_ROW; i < rows; ++i)
            {
                if (values[i, 0] != null)
                {
                    string v = values[i, 0].ToString().Trim();
                    if (v.StartsWith(SKIP_ROW))
                    {
                        MainEntry.Log(string.Format("skip flag row: [{0}, 0]", i));
                        skipRows.Add(i);
                    }
                }
                else
                {
                    MainEntry.Log(string.Format("skip null row: [{0}, 0], maybe last row", i));
                    skipRows.Add(i);
                }
            }
            List <XlsxRow> originalDatas = new List <XlsxRow>();
            int            rowIndex      = 0;

            for (int i = VALUE_START_ROW; i < rows; ++i)
            {
                if (skipRows.Contains(i))
                {
                    continue;
                }
                List <string> rowData = new List <string>();
                XlsxRow       row     = new XlsxRow(rowIndex++, rowData, sheet);
                originalDatas.Add(row);
                for (int j = 0; j < cols; ++j)
                {
                    if (skipCols.Contains(j))
                    {
                        continue;
                    }
                    rowData.Add(values[i, j] != null ? values[i, j].ToString() : null);
                }
            }
            return(originalDatas);
        }