本文整理汇总了C#中Shadowsocks.Model.Configuration类的典型用法代码示例。如果您正苦于以下问题:C# Configuration类的具体用法?C# Configuration怎么用?C# Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Configuration类属于Shadowsocks.Model命名空间,在下文中一共展示了Configuration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start(Configuration configuration)
{
Server server = configuration.GetCurrentServer();
if (_process == null)
{
Process[] existingPolipo = Process.GetProcessesByName("ss_privoxy");
foreach (Process p in existingPolipo.Where(IsChildProcess))
{
KillProcess(p);
}
string polipoConfig = Resources.privoxy_conf;
_runningPort = this.GetFreePort();
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", configuration.localPort.ToString());
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_PORT__", _runningPort.ToString());
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1");
FileManager.ByteArrayToFile(Utils.GetTempPath(UniqueConfigFile), Encoding.UTF8.GetBytes(polipoConfig));
_process = new Process();
// Configure the process using the StartInfo properties.
_process.StartInfo.FileName = "ss_privoxy.exe";
_process.StartInfo.Arguments = UniqueConfigFile;
_process.StartInfo.WorkingDirectory = Utils.GetTempPath();
_process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_process.StartInfo.UseShellExecute = true;
_process.StartInfo.CreateNoWindow = true;
_process.Start();
/*
* Add this process to job obj associated with this ss process, so that
* when ss exit unexpectedly, this process will be forced killed by system.
*/
PolipoJob.AddProcess(_process.Handle);
}
RefreshTrayArea();
}
示例2: Update
public static void Update(Configuration config, bool forceDisable)
{
bool global = config.global;
bool enabled = config.enabled;
if (forceDisable)
{
enabled = false;
}
if (enabled)
{
if (global)
{
WinINet.SetIEProxy(true, true, "127.0.0.1:" + config.localPort.ToString(), "");
}
else
{
string pacUrl;
if (config.useOnlinePac && !config.pacUrl.IsNullOrEmpty())
pacUrl = config.pacUrl;
else
pacUrl = $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp(DateTime.Now)}";
WinINet.SetIEProxy(true, false, "", pacUrl);
}
}
else
{
WinINet.SetIEProxy(false, false, "", "");
}
}
示例3: Start
public void Start(Configuration configuration)
{
Server server = configuration.GetCurrentServer();
if (_process == null)
{
Kill();
string polipoConfig = Resources.privoxy_conf;
_runningPort = this.GetFreePort();
polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", configuration.localPort.ToString());
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_PORT__", _runningPort.ToString());
polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1");
FileManager.ByteArrayToFile(runningPath + "/privoxy.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig));
_process = new Process();
// Configure the process using the StartInfo properties.
_process.StartInfo.FileName = runningPath + "/ss_privoxy.exe";
_process.StartInfo.Arguments = " \"" + runningPath + "/privoxy.conf\"";
_process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_process.StartInfo.UseShellExecute = true;
_process.StartInfo.CreateNoWindow = true;
//_process.StartInfo.RedirectStandardOutput = true;
//_process.StartInfo.RedirectStandardError = true;
try
{
_process.Start();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
示例4: MergeConfiguration
public List<Server> MergeConfiguration(Configuration mergeConfig, List<Server> servers)
{
if (servers != null)
{
for (int j = 0; j < servers.Count; ++j)
{
for (int i = 0; i < mergeConfig.configs.Count; ++i)
{
if (mergeConfig.configs[i].server == servers[j].server
&& mergeConfig.configs[i].server_port == servers[j].server_port
&& mergeConfig.configs[i].method == servers[j].method
&& mergeConfig.configs[i].password == servers[j].password
&& mergeConfig.configs[i].tcp_over_udp == servers[j].tcp_over_udp
&& mergeConfig.configs[i].udp_over_tcp == servers[j].udp_over_tcp
&& mergeConfig.configs[i].obfs_tcp == servers[j].obfs_tcp
//&& mergeConfig.configs[i].remarks == servers[j].remarks
)
{
servers[j].CopyServer(mergeConfig.configs[i]);
break;
}
}
}
}
return servers;
}
示例5: TCPRelay
public TCPRelay(ShadowsocksController controller, Configuration conf)
{
_controller = controller;
_config = conf;
Handlers = new HashSet<TCPHandler>();
_lastSweepTime = DateTime.Now;
}
示例6: ShadowsocksController
public ShadowsocksController()
{
_config = Configuration.Load();
StatisticsConfiguration = StatisticsStrategyConfiguration.Load();
_strategyManager = new StrategyManager(this);
StartReleasingMemory();
}
示例7: Save
public static void Save(Configuration config)
{
if (config.index >= config.configs.Count)
{
config.index = config.configs.Count - 1;
}
if (config.index < 0)
{
config.index = 0;
}
config.isDefault = false;
try
{
using (StreamWriter sw = new StreamWriter(File.Open(CONFIG_FILE, FileMode.Create)))
{
string jsonString = SimpleJson.SimpleJson.SerializeObject(config);
sw.Write(jsonString);
sw.Flush();
}
}
catch (IOException e)
{
Console.Error.WriteLine(e);
}
}
示例8: Start
public void Start(Configuration configuration)
{
try
{
config = configuration;
// Create a TCP/IP socket.
_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
IPEndPoint localEndPoint = null;
if (configuration.shareOverLan)
{
localEndPoint = new IPEndPoint(IPAddress.Any, PORT);
}
else
{
localEndPoint = new IPEndPoint(IPAddress.Loopback, PORT);
}
// Bind the socket to the local endpoint and listen for incoming connections.
_listener.Bind(localEndPoint);
_listener.Listen(100);
_listener.BeginAccept(
new AsyncCallback(AcceptCallback),
_listener);
WatchPacFile();
}
catch (SocketException)
{
_listener.Close();
throw;
}
}
示例9: UpdatePACFromGFWList
public void UpdatePACFromGFWList(Configuration config)
{
WebClient http = new WebClient();
http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), config.localPort);
http.DownloadStringCompleted += http_DownloadStringCompleted;
http.DownloadStringAsync(new Uri(GFWLIST_URL));
}
示例10: LoadCurrentConfiguration
private void LoadCurrentConfiguration()
{
_modifiedConfiguration = controller.GetConfigurationCopy();
UseProxyCheckBox.Checked = _modifiedConfiguration.useProxy;
ProxyServerTextBox.Text = _modifiedConfiguration.proxyServer;
ProxyPortTextBox.Text = _modifiedConfiguration.proxyPort.ToString();
}
示例11: Update
public static void Update(Configuration config, bool forceDisable)
{
bool global = config.global;
bool enabled = config.enabled;
if (forceDisable)
{
enabled = false;
}
RegistryKey registry = null;
try {
registry = Utils.OpenUserRegKey( @"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true );
if ( registry == null ) {
Logging.Error( @"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" );
return;
}
if ( enabled ) {
if ( global ) {
registry.SetValue( "ProxyEnable", 1 );
registry.SetValue( "ProxyServer", "127.0.0.1:" + config.localPort.ToString() );
registry.SetValue( "AutoConfigURL", "" );
} else {
string pacUrl;
if ( config.useOnlinePac && ! config.pacUrl.IsNullOrEmpty() )
pacUrl = config.pacUrl;
else
pacUrl = $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp( DateTime.Now )}";
registry.SetValue( "ProxyEnable", 0 );
var readProxyServer = registry.GetValue( "ProxyServer" );
registry.SetValue( "ProxyServer", "" );
registry.SetValue( "AutoConfigURL", pacUrl );
}
} else {
registry.SetValue( "ProxyEnable", 0 );
registry.SetValue( "ProxyServer", "" );
registry.SetValue( "AutoConfigURL", "" );
}
//Set AutoDetectProxy
IEAutoDetectProxy( ! enabled );
NotifyIE();
//Must Notify IE first, or the connections do not chanage
CopyProxySettingFromLan();
} catch ( Exception e ) {
Logging.LogUsefulException( e );
// TODO this should be moved into views
MessageBox.Show( I18N.GetString( "Failed to update registry" ) );
} finally {
if ( registry != null ) {
try {
registry.Close();
registry.Dispose();
} catch (Exception e)
{ Logging.LogUsefulException(e); }
}
}
}
示例12: Update
public static void Update(Configuration config, bool forceDisable)
{
bool global = config.global;
bool enabled = config.enabled;
if (forceDisable)
{
enabled = false;
}
try
{
RegistryKey registry =
Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
true);
if (enabled)
{
if (global)
{
registry.SetValue("ProxyEnable", 1);
registry.SetValue("ProxyServer", "127.0.0.1:" + config.localPort.ToString());
registry.SetValue("AutoConfigURL", "");
}
else
{
string pacUrl;
if (config.useOnlinePac && !string.IsNullOrEmpty(config.pacUrl))
pacUrl = config.pacUrl;
else
pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?t=" + GetTimestamp(DateTime.Now);
registry.SetValue("ProxyEnable", 0);
var readProxyServer = registry.GetValue("ProxyServer");
if (readProxyServer != null && readProxyServer.Equals("127.0.0.1:" + config.localPort.ToString()))
registry.SetValue("ProxyServer", "");
registry.SetValue("AutoConfigURL", pacUrl);
}
}
else
{
registry.SetValue("ProxyEnable", 0);
if (global)
{
registry.SetValue("ProxyServer", "");
}
registry.SetValue("AutoConfigURL", "");
}
//Set AutoDetectProxy Off
IEAutoDetectProxy(false);
SystemProxy.NotifyIE();
//Must Notify IE first, or the connections do not chanage
CopyProxySettingFromLan();
}
catch (Exception e)
{
Logging.LogUsefulException(e);
// TODO this should be moved into views
MessageBox.Show(I18N.GetString("Failed to update registry"));
}
}
示例13: TCPHandler
public TCPHandler(ShadowsocksController controller, Configuration config, TCPRelay tcprelay, Socket socket)
{
this._controller = controller;
this._config = config;
this._tcprelay = tcprelay;
this._connection = socket;
lastActivity = DateTime.Now;
}
示例14: TCPHandler
public TCPHandler(ShadowsocksController controller, Configuration config, TCPRelay tcprelay, Socket socket)
{
_controller = controller;
_config = config;
_tcprelay = tcprelay;
_connection = socket;
_proxyTimeout = config.proxy.proxyTimeout * 1000;
_serverTimeout = config.GetCurrentServer().timeout * 1000;
lastActivity = DateTime.Now;
}
示例15: isConfigChange
public bool isConfigChange(Configuration config)
{
if (this._shareOverLAN != config.shareOverLan
//|| _buildinHttpProxy != config.buildinHttpProxy
|| _authUser != config.authUser
|| _authPass != config.authPass
|| _socket == null
|| ((IPEndPoint)_socket.LocalEndPoint).Port != config.localPort)
{
return true;
}
return false;
}