Ejemplo n.º 1
0
        /// <summary>
        /// 通过单例模式获取一个配置实例
        /// </summary>
        /// <param name="fileName">配置文件名称,区分大小写</param>
        /// <returns></returns>
        public static NameValue GetConfiguration(string fileName)
        {
            NameValue nv = null;

            //
            lock (lockObject)
            {
                if (dictionary.TryGetValue(fileName, out nv) == false)
                {
                    nv = new NameValue(fileName);
                    dictionary.Add(fileName, nv);
                }
            }
            //
            return(nv);
        }
Ejemplo n.º 2
0
        public void Test()
        {
            var waitHandle = new System.Threading.ManualResetEvent(false);

            var userconfig = new Adf.Config.NameValue("users/users.config");
            var size       = 0;

            ConfigWatcher.INTERVAL_MILLISECONDS = 10000;

            var color = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Global:\t{0},\t\twatcher:{1}", GlobalConfig.Instance.Count, GlobalConfig.Instance.IsWatcher);
            Console.WriteLine("App:\t{0}, \t\twatcher:{1}", AppConfig.Instance.Count, AppConfig.Instance.IsWatcher);
            Console.WriteLine("Log:\t{0}, \t\twatcher:{1}", LogConfig.Instance.Count, LogConfig.Instance.IsWatcher);
            Console.WriteLine("Users:\t{0}, \t\twatcher:{1}", userconfig.Count, userconfig.IsWatcher);
            Console.ForegroundColor = color;

            System.Threading.ThreadPool.QueueUserWorkItem(obj =>
            {
                while (true)
                {
                    Console.WriteLine("Global:\t{0},\t\tkey1:{1}", GlobalConfig.Instance.Count, GlobalConfig.Instance["key1"]);
                    Console.WriteLine("App:\t{0}, \t\tkey1:{1}", AppConfig.Instance.Count, AppConfig.Instance["key1"]);
                    Console.WriteLine("Log:\t{0}, \t\tkey1:{1}", LogConfig.Instance.Count, LogConfig.Instance["key1"]);

                    Console.WriteLine("Users:\t{0}, \t\tkey1:{1}", userconfig.Count, userconfig["key1"]);

                    Console.WriteLine("wait 5s for next " + size++);
                    System.Threading.Thread.Sleep(5000);
                }
            });

            GlobalConfig.Instance.Changed += new EventHandler(Instance_Changed);
            AppConfig.Instance.Changed    += new EventHandler(Instance_Changed);
            userconfig.Changed            += new EventHandler(Instance_Changed);



            waitHandle.WaitOne();
        }