/// <summary>
        /// Reads the configuration file.
        /// </summary>
        /// <param name="path">The path to the config file. Defaults to KeyValueStore.config</param>
        /// <param name="watchFile">If the config file should be watched and automatically reloaded.</param>
        /// <returns></returns>
        public static RedisConfiguration ReadConfigFile(string path = CONFIG_FILE, bool watchFile = true)
        {
            string fullPath;
            if (HttpContext.Current == null)
            {
                fullPath = Path.Combine(Directory.GetCurrentDirectory(), path);
            }
            else
            {
                fullPath = Path.Combine(HttpContext.Current.Server.MapPath("~/"), path);
            }

            var xmlDoc = LoadXmlDocFromPath(fullPath);

            var node = xmlDoc.SelectSingleNode(SETTINGS_SECTION);

            var config = new RedisConfiguration();
            if (node != null && node.Attributes != null)
            {
                if (node.Attributes["host"] != null)
                {
                    config.Host = node.Attributes["host"].Value;
                }

                if (node.Attributes["port"] != null)
                {
                    config.Port = Int32.Parse(node.Attributes["port"].Value);
                }
            }

            SetUpFileWatcher(fullPath, config);

            return config;
        }
Esempio n. 2
0
        private static void SetUpFileWatcher(string fullPath, RedisConfiguration config)
        {
            string dir  = Path.GetDirectoryName(fullPath),
                   file = Path.GetFileName(fullPath);
            var watcher = new FileSystemWatcher(dir, file);

            watcher.EnableRaisingEvents = true;
            watcher.Changed            += new FileSystemEventHandler((obj, args) =>
            {
                //TODO: this could be better, as
                var newConfig = ReadConfigFile(fullPath, watchFile: false);
                config.Host   = newConfig.Host;
                config.Port   = newConfig.Port;
            });
        }
Esempio n. 3
0
        /// <summary>Reads the configuration file.</summary>
        /// <param name="path">The path to the config file. Defaults to KeyValueStore.config</param>
        /// <param name="watchFile">If the config file should be watched and automatically reloaded.</param>
        /// <returns></returns>
        public static RedisConfiguration ReadConfigFile(string path = "KeyValueStore.config", bool watchFile = true)
        {
            string str = HttpContext.Current != null?Path.Combine(HttpContext.Current.Server.MapPath("~/"), path) : Path.Combine(Directory.GetCurrentDirectory(), path);

            XmlNode            xmlNode = RedisConfiguration.LoadXmlDocFromPath(str).SelectSingleNode("KeyValueStore/Master");
            RedisConfiguration config  = new RedisConfiguration();

            if (xmlNode != null && xmlNode.Attributes != null)
            {
                if (xmlNode.Attributes["host"] != null)
                {
                    config.Host = xmlNode.Attributes["host"].Value;
                }
                if (xmlNode.Attributes["port"] != null)
                {
                    config.Port = int.Parse(xmlNode.Attributes["port"].Value);
                }
            }
            RedisConfiguration.SetUpFileWatcher(str, config);
            return(config);
        }
Esempio n. 4
0
        /// <summary>
        /// Reads the configuration file.
        /// </summary>
        /// <param name="path">The path to the config file. Defaults to KeyValueStore.config</param>
        /// <param name="watchFile">If the config file should be watched and automatically reloaded.</param>
        /// <returns></returns>
        public static RedisConfiguration ReadConfigFile(string path = CONFIG_FILE, bool watchFile = true)
        {
            string fullPath;

            if (HttpContext.Current == null)
            {
                fullPath = Path.Combine(Directory.GetCurrentDirectory(), path);
            }
            else
            {
                fullPath = Path.Combine(HttpContext.Current.Server.MapPath("~/"), path);
            }

            var xmlDoc = LoadXmlDocFromPath(fullPath);

            var node = xmlDoc.SelectSingleNode(SETTINGS_SECTION);

            var config = new RedisConfiguration();

            if (node != null && node.Attributes != null)
            {
                if (node.Attributes["host"] != null)
                {
                    config.Host = node.Attributes["host"].Value;
                }

                if (node.Attributes["port"] != null)
                {
                    config.Port = Int32.Parse(node.Attributes["port"].Value);
                }
            }


            SetUpFileWatcher(fullPath, config);

            return(config);
        }
 private static void SetUpFileWatcher(string fullPath, RedisConfiguration config)
 {
     string dir = Path.GetDirectoryName(fullPath),
            file = Path.GetFileName(fullPath);
     var watcher = new FileSystemWatcher(dir, file);
     watcher.EnableRaisingEvents = true;
     watcher.Changed += new FileSystemEventHandler((obj, args) =>
     {
         //TODO: this could be better, as
         var newConfig = ReadConfigFile(fullPath, watchFile: false);
         config.Host = newConfig.Host;
         config.Port = newConfig.Port;
     });
 }
Esempio n. 6
0
        /// <summary>
        /// Read the default configuration file for host/port
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Bucket Bucket(string name)
        {
            var config = new RedisBucketConfiguration(RedisConfiguration.ReadConfigFile(), name);

            return(Bucket(config));
        }
Esempio n. 7
0
 /// <summary>Read the default configuration file for host/port</summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static Bucket Bucket(string name)
 {
     return(KeyValueStore.Bucket(new RedisBucketConfiguration(RedisConfiguration.ReadConfigFile("KeyValueStore.config", true), name)));
 }
 /// <summary>
 /// Create a RedisBucketConfiguration from existing RedisConfiguration
 /// </summary>
 /// <param name="redisConfig"></param>
 /// <param name="name"></param>
 public RedisBucketConfiguration(RedisConfiguration redisConfig, string name)
 {
     Host = redisConfig.Host;
     Port = redisConfig.Port;
     Name = name;
 }
Esempio n. 9
0
 /// <summary>
 /// Create a RedisBucketConfiguration from existing RedisConfiguration
 /// </summary>
 /// <param name="redisConfig"></param>
 /// <param name="name"></param>
 public RedisBucketConfiguration(RedisConfiguration redisConfig, string name)
 {
     Host = redisConfig.Host;
     Port = redisConfig.Port;
     Name = name;
 }