/*
*
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Configuration;
using IReaper.Properties;
namespace IReaper.Net{
/// <summary>
///
/// </summary>
public class NetworkManager
{
static NetworkManager()
{
//
Settings.Default.SettingChanging += new System.Configuration.SettingChangingEventHandler(Default_SettingChanging);
SetProxy((ProxySelector)Settings.Default.ProxySelector);
}
static void Default_SettingChanging(object sender, System.Configuration.SettingChangingEventArgs e)
{
if (e.SettingName == "ProxySelector")
{
Settings set = Settings.Default;
SetProxy((ProxySelector)e.NewValue);
}
}
/// <summary>
/// Selector
/// </summary>
/// <param name="Selector"></param>
private static void SetProxy(ProxySelector Selector)
{
switch (Selector)
{
case ProxySelector.IE:
WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy();
break;
case ProxySelector.None:
WebRequest.DefaultWebProxy = null;
break;
case ProxySelector.UserSpecified:
WebProxy proxy = new WebProxy();
proxy.Address = new Uri(Settings.Default.ProxyURI);
NetworkCredential credential = null;
string[] spliter = Settings.Default.ProxyCredentials.Split(':');
if (spliter.Length == 2)
{
credential = new NetworkCredential();
credential.UserName = spliter[0];
credential.Password = spliter[1];
}
proxy.Credentials = credential;
WebRequest.DefaultWebProxy = proxy;
break;
}
}
public static void SetConnectionLimit()
{
ServicePointManager.DefaultConnectionLimit = 20;
}
}
/// <summary>
/// Proxy
/// </summary>
public enum ProxySelector : short
{
None = 0,//
IE = 1,//IE
UserSpecified = 2//
}
}
|