예제 #1
0
        /// <summary>
        /// 解析全局配置。
        /// </summary>
        /// <param name="configManager">全局配置管理器。</param>
        /// <param name="configBytes">要解析的全局配置二进制流。</param>
        /// <param name="startIndex">全局配置二进制流的起始位置。</param>
        /// <param name="length">全局配置二进制流的长度。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>是否解析全局配置成功。</returns>
        public override bool ParseData(IConfigManager configManager, byte[] configBytes, int startIndex, int length, object userData)
        {
            try
            {
                using (MemoryStream memoryStream = new MemoryStream(configBytes, startIndex, length, false))
                {
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))
                    {
                        while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
                        {
                            string configName  = binaryReader.ReadString();
                            string configValue = binaryReader.ReadString();
                            if (!configManager.AddConfig(configName, configValue))
                            {
                                Log.Warning("Can not add config with config name '{0}' which may be invalid or duplicate.", configName);
                                return(false);
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception exception)
            {
                Log.Warning("Can not parse config bytes with exception '{0}'.", exception.ToString());
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// 增加指定配置项
        /// </summary>
        /// <param name="configName">要增加配置项的名称</param>
        /// <param name="configValue">要增加配置项的值</param>
        /// <returns>是否增加配置项成功</returns>
        private bool AddConfig(string configName, string configValue)
        {
            bool boolValue;

            bool.TryParse(configValue, out boolValue);

            int intValue;

            int.TryParse(configValue, out intValue);

            float floatValue;

            float.TryParse(configValue, out floatValue);

            return(m_ConfigManager.AddConfig(configName, boolValue, intValue, floatValue, configValue));
        }
예제 #3
0
        /// <summary>
        /// 解析全局配置。
        /// </summary>
        /// <param name="configManager">全局配置管理器。</param>
        /// <param name="configString">要解析的全局配置字符串。</param>
        /// <param name="userData">用户自定义数据。</param>
        /// <returns>是否解析全局配置成功。</returns>
        public override bool ParseData(IConfigManager configManager, string configString, object userData)
        {
            try
            {
                int    position         = 0;
                string configLineString = null;
                while ((configLineString = configString.ReadLine(ref position)) != null)
                {
                    if (configLineString[0] == '#')
                    {
                        continue;
                    }

                    string[] splitedLine = configLineString.Split(ColumnSplitSeparator, StringSplitOptions.None);
                    if (splitedLine.Length != ColumnCount)
                    {
                        Log.Warning("Can not parse config line string '{0}' which column count is invalid.", configLineString);
                        return(false);
                    }

                    string configName  = splitedLine[1];
                    string configValue = splitedLine[3];
                    if (!configManager.AddConfig(configName, configValue))
                    {
                        Log.Warning("Can not add config with config name '{0}' which may be invalid or duplicate.", configName);
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception exception)
            {
                Log.Warning("Can not parse config string with exception '{0}'.", exception.ToString());
                return(false);
            }
        }
 /// <summary>
 /// 增加指定配置项。
 /// </summary>
 /// <param name="configName">要增加配置项的名称。</param>
 /// <param name="boolValue">配置项布尔值。</param>
 /// <param name="intValue">配置项整数值。</param>
 /// <param name="floatValue">配置项浮点数值。</param>
 /// <param name="stringValue">配置项字符串值。</param>
 /// <returns>是否增加配置项成功。</returns>
 protected bool AddConfig(string configName, bool boolValue, int intValue, float floatValue, string stringValue)
 {
     return(m_ConfigManager.AddConfig(configName, boolValue, intValue, floatValue, stringValue));
 }