Beispiel #1
0
        /// <summary>
        /// 获取单项配置
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="commandName"></param>
        public static ServerConfigItem GetItem(string serverName, string commandName)
        {
            var key = ServerCommand.BuildCommandKey(serverName, commandName);
            ServerConfigItem item = null;

            items.TryGetValue(key, out item);
            return(item);
        }
Beispiel #2
0
        /// <summary>
        /// 服务配置读取
        /// </summary>
        /// <param name="serverName"></param>
        /// <param name="serverExpire"></param>
        /// <param name="nodes"></param>
        private static void LoadServerConfig(string serverName, int serverExpire, XmlNodeList nodes)
        {
            var commandName       = string.Empty;
            var expires           = 0;
            var mixedsplit        = string.Empty;
            var version           = string.Empty;
            var cacheDeleteAction = string.Empty;
            var objectName        = string.Empty;

            foreach (XmlNode node in nodes)
            {
                commandName = XmlHelper.GetAttribute(node, "name", null);
                if (string.IsNullOrEmpty(commandName))
                {
                    continue;
                }
                if (Exists(serverName, commandName))
                {
                    throw new ConfigurationErrorsException(string.Format("Repeated Command Item {0}.{1} in {0}.config", serverName, commandName));
                }
                var commandInfo = ServerCommand.GetCommand(serverName, commandName);
                if (commandInfo == null)
                {
                    throw new ConfigurationErrorsException(string.Format("No Find Server Command {0}.{1} in {0}.config", serverName, commandName));
                }
                var settingItem = new ServerConfigItem();
                //cache expires
                settingItem.CacheExpires = int.TryParse(XmlHelper.GetAttribute(node, "expires", null), out expires) ? expires : serverExpire;
                //version
                version = XmlHelper.GetAttribute(node, "version");
                if (!string.IsNullOrEmpty(version))
                {
                    if (GetVersionExpires(serverName, version) == 0)
                    {
                        throw new ConfigurationErrorsException(string.Format("Not Find Version:{2} config node, version info {0}.{1} version attribute in {0}.config", serverName, commandName, version));
                    }
                    settingItem.CacheVersion = version;
                }
                settingItem.CacheKey = XmlHelper.GetAttribute(node, "key", null);
                if (string.IsNullOrEmpty(settingItem.CacheKey))
                {
                    settingItem.CacheKey = string.Concat(serverName, ".", commandName);
                }

                //deletes
                var deletes = node.SelectNodes("delete");
                if (deletes.Count > 0)
                {
                    settingItem.CacheDeletes = InitCacheDelete(commandInfo, deletes);
                }

                items.Add(ServerCommand.BuildCommandKey(serverName, commandName), settingItem);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 是否具有指定项
 /// </summary>
 /// <param name="serverName"></param>
 /// <param name="commandName"></param>
 private static bool Exists(string serverName, string commandName)
 {
     return(items.ContainsKey(ServerCommand.BuildCommandKey(serverName, commandName)));
 }