예제 #1
0
        public void Configure()
        {
            var config = ConfigurationManager.GetSection("WriteHttp") as WriteHttpPluginConfig;

            if (config == null)
            {
                throw new Exception("Cannot get configuration section : WriteHttp");
            }

            _httpWriters.Clear();

            foreach (WriteHttpPluginConfig.WriteHttpNodeConfig node in config.Nodes)
            {
                var writer = new HttpWriter
                {
                    Url         = node.Url,
                    Timeout     = node.Timeout,
                    BatchSize   = node.BatchSize,
                    MaxIdleTime = node.MaxIdleTime,
                    EnableProxy = node.Proxy.Enable
                };

                if (writer.EnableProxy)
                {
                    writer.WebProxy = node.Proxy.Url.Length > 0 ? new WebProxy(node.Proxy.Url) : new WebProxy();
                }
                _httpWriters.Add(writer);
            }

            Logger.Info("WriteHttp plugin configured");
        }
예제 #2
0
        public void Configure()
        {
            var config = ConfigurationManager.GetSection("WriteHttp") as WriteHttpPluginConfig;
            if (config == null)
            {
                throw new Exception("Cannot get configuration section : WriteHttp");
            }

            _httpWriters.Clear();

            foreach (WriteHttpPluginConfig.WriteHttpNodeConfig node in config.Nodes)
            {
                var writer = new HttpWriter
                {
                    Url = node.Url,
                    Timeout = node.Timeout,
                    BatchSize = node.BatchSize,
                    MaxIdleTime = node.MaxIdleTime,
                    EnableProxy = node.Proxy.Enable
                };

                if (writer.EnableProxy)
                {
                    writer.WebProxy = node.Proxy.Url.Length > 0 ? new WebProxy(node.Proxy.Url) : new WebProxy();
                }

                if (!string.IsNullOrEmpty(node.UserName) && !string.IsNullOrEmpty(node.Password))                
                {
                    /* Possibly misfeature- adding BasicAuthHeaderData to HttpWriter class to efficiently support basic auth,
                     * but saves the ToBase64String string encode on each request. Better, but more expensive, would be
                     * to put both on as secure strings and add a config param to support other auth methods while
                     * building the HttpWebResponse on each call. @FerventGeek */ 
                    writer.BasicAuthHeaderData = System.Convert.ToBase64String(
                        System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(node.UserName + ":" + node.Password));
                    Logger.Info("Using BasicAuth for node {0}, user {1}", node.Name, node.UserName);
                }
                
                if (!string.IsNullOrEmpty(node.SafeCharsRegex))
                {
                    // compile for perfomace, since config is only loaded on start
                    writer.SafeCharsRegex = new Regex("[^" + node.SafeCharsRegex + "]", RegexOptions.Compiled);
                    Logger.Info("Using SafeChars for node {0}, regex \"{1}\" replaced with \"{2}\"",
                        node.Name, writer.SafeCharsRegex.ToString(), node.ReplaceWith);
                }

                if (node.ReplaceWith == null)
                {
                    // default, strip unsafe chars
                    writer.ReplaceWith = "";
                }
                else
                {
                    writer.ReplaceWith = node.ReplaceWith;
                }

                _httpWriters.Add(writer);
            }

            Logger.Info("WriteHttp plugin configured");
        }
예제 #3
0
        public void Configure()
        {
            var config = ConfigurationManager.GetSection("WriteHttp") as WriteHttpPluginConfig;

            if (config == null)
            {
                throw new Exception("Cannot get configuration section : WriteHttp");
            }

            _httpWriters.Clear();

            foreach (WriteHttpPluginConfig.WriteHttpNodeConfig node in config.Nodes)
            {
                var writer = new HttpWriter
                {
                    Url         = node.Url,
                    Timeout     = node.Timeout,
                    BatchSize   = node.BatchSize,
                    MaxIdleTime = node.MaxIdleTime,
                    EnableProxy = node.Proxy.Enable
                };

                if (writer.EnableProxy)
                {
                    writer.WebProxy = node.Proxy.Url.Length > 0 ? new WebProxy(node.Proxy.Url) : new WebProxy();
                }

                if (!string.IsNullOrEmpty(node.UserName) && !string.IsNullOrEmpty(node.Password))
                {
                    /* Possibly misfeature- adding BasicAuthHeaderData to HttpWriter class to efficiently support basic auth,
                     * but saves the ToBase64String string encode on each request. Better, but more expensive, would be
                     * to put both on as secure strings and add a config param to support other auth methods while
                     * building the HttpWebResponse on each call. @FerventGeek */
                    writer.BasicAuthHeaderData = System.Convert.ToBase64String(
                        System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(node.UserName + ":" + node.Password));
                    Logger.Info("Using BasicAuth for node {0}, user {1}", node.Name, node.UserName);
                }

                if (!string.IsNullOrEmpty(node.SafeCharsRegex))
                {
                    // compile for perfomace, since config is only loaded on start
                    writer.SafeCharsRegex = new Regex("[^" + node.SafeCharsRegex + "]", RegexOptions.Compiled);
                    Logger.Info("Using SafeChars for node {0}, regex \"{1}\" replaced with \"{2}\"",
                                node.Name, writer.SafeCharsRegex.ToString(), node.ReplaceWith);
                }

                if (node.ReplaceWith == null)
                {
                    // default, strip unsafe chars
                    writer.ReplaceWith = "";
                }
                else
                {
                    writer.ReplaceWith = node.ReplaceWith;
                }

                _httpWriters.Add(writer);
            }

            Logger.Info("WriteHttp plugin configured");
        }
        public void Configure()
        {
            var config = ConfigurationManager.GetSection("WriteHttp") as WriteHttpPluginConfig;
            if (config == null)
            {
                throw new Exception("Cannot get configuration section : WriteHttp");
            }

            _httpWriters.Clear();

            foreach (WriteHttpPluginConfig.WriteHttpNodeConfig node in config.Nodes)
            {
                var writer = new HttpWriter
                {
                    Url = node.Url,
                    Timeout = node.Timeout,
                    BatchSize = node.BatchSize,
                    MaxIdleTime = node.MaxIdleTime,
                    EnableProxy = node.Proxy.Enable
                };

                if (writer.EnableProxy)
                {
                    writer.WebProxy = node.Proxy.Url.Length > 0 ? new WebProxy(node.Proxy.Url) : new WebProxy();
                }
                _httpWriters.Add(writer);
            }

            Logger.Info("WriteHttp plugin configured");
        }