示例#1
0
 /// <summary>
 /// 清理所有缓存
 /// </summary>
 private static void ClearAllCache()
 {
     foreach (KeyValuePair <string, InjectorItem> item in BusinessInters)
     {
         CacheInjector.RemoveCatche(item.Key);
     }
 }
示例#2
0
        /// <summary>
        /// 重新加载配置信息
        /// </summary>
        private static void ReloadConfigFile()
        {
            try
            {
                if (File.Exists(ConfigFilePath))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(ConfigFilePath);

                    // Modified by Michael Feng at 2013-05-08
                    XmlNodeList injectNodesList = doc.DocumentElement.SelectNodes("./Injector");
                    foreach (XmlNode node in injectNodesList)
                    {
                        bool isGlobal = true;
                        if (node.Attributes["global"] != null)
                        {
                            isGlobal = bool.Parse(node.Attributes["global"].Value);
                        }

                        if (node.Attributes["interface"] != null &&
                            node.Attributes["instance"] != null &&
                            node.Attributes["file"] != null &&
                            !string.IsNullOrEmpty(node.Attributes["interface"].Value) &&
                            !string.IsNullOrEmpty(node.Attributes["instance"].Value) &&
                            !string.IsNullOrEmpty(node.Attributes["file"].Value) &&
                            !string.IsNullOrEmpty(node.Attributes["file"].Value))
                        {
                            if (BusinessInters.ContainsKey(node.Attributes["interface"].Value) &&
                                (!BusinessInters[node.Attributes["interface"].Value].Instance.Equals(node.Attributes["instance"].Value) ||
                                 !BusinessInters[node.Attributes["interface"].Value].File.Equals(node.Attributes["file"].Value)))
                            {
                                BusinessInters[node.Attributes["interface"].Value].Instance = node.Attributes["instance"].Value;
                                BusinessInters[node.Attributes["interface"].Value].File     = node.Attributes["file"].Value;
                                BusinessInters[node.Attributes["interface"].Value].IsGlobal = isGlobal;
                                CacheInjector.RemoveCatche(node.Attributes["interface"].Value);
                            }

                            if (!BusinessInters.ContainsKey(node.Attributes["interface"].Value))
                            {
                                InjectorItem item = new InjectorItem();
                                item.InterFace = node.Attributes["interface"].Value;
                                item.Instance  = node.Attributes["instance"].Value;
                                item.File      = node.Attributes["file"].Value;
                                item.IsGlobal  = isGlobal;
                                BusinessInters.Add(node.Attributes["interface"].Value, item);
                            }
                        }
                    }

                    string[] keys = new string[BusinessInters.Count];
                    BusinessInters.Keys.CopyTo(keys, 0);

                    foreach (string key in keys)
                    {
                        bool isExist = false;
                        foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                        {
                            if (node.Attributes["interface"] != null &&
                                key.Equals(node.Attributes["interface"].Value))
                            {
                                isExist = true;
                                break;
                            }
                        }
                        if (isExist == false)
                        {
                            BusinessInters.Remove(key);
                            CacheInjector.RemoveCatche(key);
                        }
                    }
                }
            }
            catch
            {
            }
        }