Exemple #1
0
        /**
         * @brief 从Xml节点中读取字符串
         *
         * @param node xml节点
         * @param nodeName 节点名字
         * @param defualtVal 默认值
         * @param isMust 是否强制不能为空
         *
         * @return
         */
        public static string ExtractString(DBC_Row node, string nodeName, string defualtVal, bool isMust)
        {
            string result = defualtVal;

            if (node == null || !node.HasFields || node.SelectFieldByName(nodeName) == null)
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtactString Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }

                return(result);
            }

            string nodeText = node.SelectFieldByName(nodeName);

            if (Helper.StringIsNullOrEmpty(nodeText))
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtactString Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }
            }
            else
            {
                result = nodeText;
            }

            return(result);
        }
Exemple #2
0
        /**
         * @brief 从Xml节点中读取字符串数组
         *
         * @param node xml节点
         * @param nodeName 节点名字
         * @param defualtVal 默认值
         * @param isMust 是否强制不能为空
         *
         * @return
         */
        public static List <string> ExtractStringList(DBC_Row node, string nodeName, string defualtVal, bool isMust)
        {
            List <string> result = new List <string>();

            if (node == null || !node.HasFields)
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractStringList Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }

                return(result);
            }

            string nodeText = node.SelectFieldByName(nodeName);

            if (Helper.StringIsNullOrEmpty(nodeText))
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractStringList Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }
            }
            else
            {
                result = Converter.ConvertStringList(nodeText);
            }

            return(result);
        }
        /**
         * @brief 读取数据
         *
         * @param node
         *
         * @return
         */
        public bool CollectData(SkillConfigType type, string file, string rootLabel)
        {
            bool result = false;

            switch (type)
            {
            case SkillConfigType.SCT_SKILL: {
                result = skillLogicDataMgr.CollectDataFromDBC(file, rootLabel);
            } break;

            case SkillConfigType.SCT_IMPACT: {
                result = impactLogicDataMgr.CollectDataFromDBC(file, rootLabel);
            } break;

            case SkillConfigType.SCT_SOUND: {
                result = soundLogicDataMgr.CollectDataFromDBC(file, rootLabel);
            } break;

            default: {
                LogSystem.Assert(false, "SkillConfigProvider.CollectData type error!");
            } break;
            }

            return(result);
        }
Exemple #4
0
        /**
         * @brief 提取数据
         *
         * @param file 文件路径
         *
         * @return
         */
        public bool CollectDataFromDBC(string file, string rootLabel)
        {
            bool result = true;

            DBC document = new DBC();

            document.Load(HomePath.GetAbsolutePath(file));

            for (int index = 0; index < document.RowNum; index++)
            {
                DBC_Row node = document.GetRowByIndex(index);
                if (node != null)
                {
                    TData  data = new TData();
                    bool   ret  = data.CollectDataFromDBC(node);
                    string info = string.Format("DataTempalteMgr.CollectDataFromXml collectData Row:{0} failed!", index);
                    LogSystem.Assert(ret, info);
                    if (ret)
                    {
                        m_DataContainer.Add(data.GetId(), data);
                    }
                    else
                    {
                        result = false;
                    }
                }
            }

            return(result);
        }
Exemple #5
0
        /**
         * @brief 从Xml节点中读取字符串数组
         *
         * @param node xml节点
         * @param nodeName 节点名字
         * @param defualtVal 默认值
         * @param isMust 是否强制不能为空
         *
         * @return
         */
        public static List <string> ExtractStringList(XmlNode node, string nodeName, string defualtVal, bool isMust)
        {
            List <string> result = new List <string>();

            if (node == null || !node.HasChildNodes)
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractStringList Error node:{0} nodeName:{1}", node.Name, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }

                return(result);
            }

            XmlNode childNode = node.SelectSingleNode(nodeName);

            string nodeText = childNode.InnerText;

            if (Helper.StringIsNullOrEmpty(nodeText))
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractStringList Error node:{0} nodeName:{1}", node.Name, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }
            }
            else
            {
                result = Converter.ConvertStringList(nodeText);
            }

            return(result);
        }
Exemple #6
0
        public static T LoadClassByName <T>(string assemblyPath, string assemblyName, string className, object [] args)
        {
            Assembly assembly = GetAssembly(assemblyPath, assemblyName, className);

            if (assembly == null)
            {
                LogSystem.Assert(false, "KernelUtil.LoadClassByName Assembly load failed!");
                return(default(T));
            }

            T obj = (T)(assembly.CreateInstance(className));

            return(obj);
        }
Exemple #7
0
        /**
         * @brief 从Xml节点中读取数值类型,使用时,必须在函数中指明数值类型
         *          如: int id = ExtractNumeric<int>(xmlNode, "Id", -1, true);
         *
         * @param node xml节点
         * @param nodeName 节点名字
         * @param defualtVal 默认值
         * @param isMust 是否强制不能为空
         *
         * @return
         */
        public static T ExtractNumeric <T>(XmlNode node, string nodeName, T defualtVal, bool isMust)
        {
            T result = defualtVal;

            if (node == null || !node.HasChildNodes || node.SelectSingleNode(nodeName) == null)
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractNumeric Error node:{0} nodeName:{1}", node.Name, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }

                return(result);
            }

            XmlNode childNode = node.SelectSingleNode(nodeName);

            string nodeText = childNode.InnerText;

            if (Helper.StringIsNullOrEmpty(nodeText))
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractNumeric Error node:{0} nodeName:{1}", node.Name, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }
            }
            else
            {
                try
                {
                    result = (T)Convert.ChangeType(nodeText, typeof(T));
                }
                catch (System.Exception ex)
                {
                    string info = string.Format("ExtractNumeric Error node:{0} nodeName:{1} ex:{2} stacktrace:{3}",
                                                node.Name, nodeName, ex.Message, ex.StackTrace);
                    LogSystem.Debug(info);
                }
            }

            return(result);
        }
Exemple #8
0
        /**
         * @brief 从Xml节点中读取数值类型,使用时,必须在函数中指明数值类型
         *          如: int id = ExtractNumeric<int>(xmlNode, "Id", -1, true);
         *
         * @param node xml节点
         * @param nodeName 节点名字
         * @param defualtVal 默认值
         * @param isMust 是否强制不能为空
         *
         * @return
         */
        public static T ExtractNumeric <T>(DBC_Row node, string nodeName, T defualtVal, bool isMust)
        {
            T result = defualtVal;

            if (node == null || !node.HasFields || node.SelectFieldByName(nodeName) == null)
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractNumeric Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }

                return(result);
            }

            string nodeText = node.SelectFieldByName(nodeName);

            if (Helper.StringIsNullOrEmpty(nodeText))
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractNumeric Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }
            }
            else
            {
                try
                {
                    result = (T)Convert.ChangeType(nodeText, typeof(T));
                }
                catch (System.Exception ex)
                {
                    string info = string.Format("ExtractNumeric Error node:{0} nodeName:{1} ex:{2} stacktrace:{3}",
                                                node.RowIndex, nodeName, ex.Message, ex.StackTrace);
                    LogSystem.Debug(info);
                    Helper.LogCallStack();
                }
            }

            return(result);
        }
Exemple #9
0
        /**
         * @brief 从Xml节点中读取布尔值
         *
         * @param node xml节点
         * @param nodeName 节点名字
         * @param defualtVal 默认值
         * @param isMust 是否强制不能为空
         *
         * @return
         */
        public static bool ExtractBool(XmlNode node, string nodeName, bool defualtVal, bool isMust)
        {
            bool result = defualtVal;

            if (node == null || !node.HasChildNodes || node.SelectSingleNode(nodeName) == null)
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractBool Error node:{0} nodeName:{1}", node.Name, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }

                return(result);
            }

            XmlNode childNode = node.SelectSingleNode(nodeName);

            string nodeText = childNode.InnerText;

            if (Helper.StringIsNullOrEmpty(nodeText))
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractBool Error node:{0} nodeName:{1}", node.Name, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }
            }
            else
            {
                if (nodeText.Trim().ToLower() == "true" || nodeText.Trim().ToLower() == "1")
                {
                    result = true;
                }

                if (nodeText.Trim().ToLower() == "false" || nodeText.Trim().ToLower() == "0")
                {
                    result = false;
                }
            }

            return(result);
        }
Exemple #10
0
        public static T InvokeMethodByName <T>(string assemblyPath, string assemblyName, string className,
                                               string methodName, object [] args)
        {
            Assembly assembly = GetAssembly(assemblyPath, assemblyName, className);

            if (assembly == null)
            {
                LogSystem.Assert(false, "KernelUtil.LoadClassByName Assembly load failed!");
                return(default(T));
            }

            Type       objType = assembly.GetType(className);
            MethodInfo method  = objType.GetMethod(methodName);

            //method.Invoke(null, args);
            //return default(T);

            T retObj = (T)(method.Invoke(null, args));

            return(retObj);
        }
Exemple #11
0
        /**
         * @brief 从Xml节点中读取布尔值
         *
         * @param node xml节点
         * @param nodeName 节点名字
         * @param defualtVal 默认值
         * @param isMust 是否强制不能为空
         *
         * @return
         */
        public static bool ExtractBool(DBC_Row node, string nodeName, bool defualtVal, bool isMust)
        {
            bool result = defualtVal;

            if (node == null || !node.HasFields || node.SelectFieldByName(nodeName) == null)
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractBool Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }

                return(result);
            }

            string nodeText = node.SelectFieldByName(nodeName);

            if (Helper.StringIsNullOrEmpty(nodeText))
            {
                if (isMust)
                {
                    string errorInfo = string.Format("ExtractBool Error node:{0} nodeName:{1}", node.RowIndex, nodeName);
                    LogSystem.Assert(false, errorInfo);
                }
            }
            else
            {
                if (nodeText.Trim().ToLower() == "true" || nodeText.Trim().ToLower() == "1")
                {
                    result = true;
                }

                if (nodeText.Trim().ToLower() == "false" || nodeText.Trim().ToLower() == "0")
                {
                    result = false;
                }
            }

            return(result);
        }