public void Should_try_with_resolved_constructors_in_the_correct_order() { // Arrange var session = A.Fake <IDummyValueCreationSession>(); StubSessionWithDummyValue(session, 1); StubSessionWithDummyValue(session, "dummy"); this.StubProxyGeneratorToFail(); var options = new ProxyOptions(); // Act this.fakeObjectCreator.CreateFake(typeof(TypeWithMultipleConstructors), options, session, throwOnFailure: false); // Assert A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(TypeWithMultipleConstructors), options.AdditionalInterfacesToImplement, A <IEnumerable <object> > .That.IsNull(), A <IEnumerable <Expression <Func <Attribute> > > > ._, A <IFakeCallProcessorProvider> ._)) .MustHaveHappened() .Then(A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(TypeWithMultipleConstructors), options.AdditionalInterfacesToImplement, A <IEnumerable <object> > .That.IsThisSequence(1, 1), A <IEnumerable <Expression <Func <Attribute> > > > ._, A <IFakeCallProcessorProvider> ._)) .MustHaveHappened()) .Then(A.CallTo(() => this.proxyGenerator.GenerateProxy(typeof(TypeWithMultipleConstructors), options.AdditionalInterfacesToImplement, A <IEnumerable <object> > .That.IsThisSequence("dummy"), A <IEnumerable <Expression <Func <Attribute> > > > ._, A <IFakeCallProcessorProvider> ._)) .MustHaveHappened()); }
/// <summary> /// Configures a new proxy instance for the given ProxyOptions /// </summary> /// <typeparam name="T">the type for which a proxy must be created</typeparam> /// <param name="options">the options that are used for proxy-injection</param> /// <param name="configure">a callback that allows the custom configuration of the Proxy-settings</param> /// <returns>the proxy-options that were passed initially for method-chaining.</returns> public static ProxyOptions ConfigureProxy <T>(this ProxyOptions options, Func <ProxyInjector <T> > configure) where T : class { var item = configure(); options.AddInjector(item); return(options); }
void ChangerProxy(string URL) { if (!ProxySet) { if (ckUseSingleProxy.Checked) { if (string.IsNullOrWhiteSpace(Main._Form1.txt_SingleProxy.Text)) { MessageBox.Show("Proxy is null! Please enter proxy", "Proxy Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } try { var split = txt_SingleProxy.Text.Split(':'); proxy = new ProxyOptions(split[0], split[1], split[2], split[3]); } catch (Exception ex) { MessageBox.Show($"Proxy doesn't seem to be in the correct format:{Environment.NewLine}{Environment.NewLine}IP:Port:Username:Pass {Environment.NewLine}{Environment.NewLine}{ex.Message}", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } CefSharpSettings.Proxy = proxy; var rc = chrome.GetBrowser().GetHost().RequestContext; Cef.UIThreadTaskFactory.StartNew(delegate { rc.SetProxy($"{proxy.IP}:{proxy.Port}", out var error); });
public static IWebDavClient CreateWebDavClient( string username, SecureString password, string serverUrl, TimeSpan timeout, ServerAdapterType serverAdapterType, bool closeConnectionAfterEachRequest, bool preemptiveAuthentication, bool forceBasicAuthentication, ProxyOptions proxyOptions, bool acceptInvalidChars ) { switch (serverAdapterType) { case ServerAdapterType.WebDavHttpClientBased: case ServerAdapterType.WebDavHttpClientBasedWithGoogleOAuth: var productAndVersion = GetProductAndVersion(); return(new DataAccess.HttpClientBasedClient.WebDavClient( () => CreateHttpClient(username, password, serverUrl, timeout, serverAdapterType, proxyOptions, preemptiveAuthentication, forceBasicAuthentication), productAndVersion.Item1, productAndVersion.Item2, closeConnectionAfterEachRequest, acceptInvalidChars, RequiresEtagsWithoutQuotes(serverUrl))); default: throw new ArgumentOutOfRangeException("serverAdapterType"); } }
public void UpdateOptions(Options options, bool checkIfOnline) { _pendingOutlookItems.Clear(); _fullSyncPending = false; _profileName = options.Name; _profileId = options.Id; _proxyOptions = options.ProxyOptions; _synchronizer = options.Inactive ? NullOutlookSynchronizer.Instance : _synchronizerFactory.CreateSynchronizer(options); _interval = TimeSpan.FromMinutes(options.SynchronizationIntervalInMinutes); _inactive = options.Inactive; _checkIfOnline = checkIfOnline; if (_folderChangeWatcher != null) { _folderChangeWatcher.ItemSavedOrDeleted -= FolderChangeWatcher_ItemSavedOrDeleted; _folderChangeWatcher.Dispose(); _folderChangeWatcher = null; } if (!_inactive && options.EnableChangeTriggeredSynchronization) { _folderChangeWatcher = _folderChangeWatcherFactory.Create(options.OutlookFolderEntryId, options.OutlookFolderStoreId); _folderChangeWatcher.ItemSavedOrDeleted += FolderChangeWatcher_ItemSavedOrDeleted; } }
public static ProxyOptions FromStream(Stream stream) { using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) { if (reader.ReadByte() != 0) { throw new IOException("Unexpected data"); } var options = new Launcher.ProcessOptions(); var po = new ProxyOptions(options); options.FileName = reader.ReadString(); options.Arguments = reader.ReadString(); options.WorkingDirectory = reader.ReadString(); options.UserName = reader.ReadString(); var variables = reader.ReadByte(); while (variables > 0) { options.Variables[reader.ReadString()] = reader.ReadString(); variables--; } return(po); } }
/// <summary> /// </summary> /// <param name="Options">Pxoxy Options</param> public Settings(ProxyOptions Options) { Initialize(); options = Options; Keys = new List <string> { "UseProxyOrFirewall", "ProxyHost", "ProxyPort", "SessionCloseCheck", "ProxyHostType", "ProxyCustomType", "ProxyCustomData", "ProxyApplyToFs", "UseTls", "PreventRrated", "WarnWhenAccessing" }; values = new List <string> { "Yes", options.ProxyHost, options.LocalhostPort.ToString(), "no", "0", "0", "CONNECT %host% %port%", "no", "no", "no", "no" }; if (Keys.Count != values.Count) { throw new ArgumentOutOfRangeException($"Keys.Length: {Keys.Count} != values.Length: {values.Count}"); } }
public static IWebDavClient CreateWebDavClient( string username, string password, TimeSpan timeout, ServerAdapterType serverAdapterType, bool closeConnectionAfterEachRequest, ProxyOptions proxyOptions ) { switch (serverAdapterType) { case ServerAdapterType.Default: case ServerAdapterType.GoogleOAuth: var productAndVersion = GetProductAndVersion(); return(new DataAccess.HttpClientBasedClient.WebDavClient( () => CreateHttpClient(username, password, timeout, serverAdapterType, proxyOptions), productAndVersion.Item1, productAndVersion.Item2, closeConnectionAfterEachRequest)); case ServerAdapterType.SynchronousWebRequestBased: return(new DataAccess.WebRequestBasedClient.WebDavClient( username, password, timeout, timeout, closeConnectionAfterEachRequest)); default: throw new ArgumentOutOfRangeException("serverAdapterType"); } }
public static Task RunFirefoxServerLoopAsync(ProxyOptions options, string[] args, ILoggerFactory loggerFactory, CancellationToken token) => FirefoxDebuggerProxy.RunServerLoopAsync(browserPort: options.FirefoxDebugPort, proxyPort: options.FirefoxProxyPort, loggerFactory, loggerFactory.CreateLogger("FirefoxMonoProxy"), token, autoSetBreakpointOnEntryPoint: options.AutoSetBreakpointOnEntryPoint);
public static async Task RunDevToolsProxyAsync(ProxyOptions options, string[] args, ILoggerFactory loggerFactory, CancellationToken token) { string proxyUrl = $"http://127.0.0.1:{options.DevToolsProxyPort}"; IWebHost host = new WebHostBuilder() .UseSetting("UseIISIntegration", false.ToString()) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup <Startup>() .ConfigureServices(services => { services.AddSingleton(loggerFactory); services.AddLogging(configure => configure.AddSimpleConsole().AddFilter(null, LogLevel.Information)); services.AddSingleton(Options.Create(options)); services.AddRouting(); }) .ConfigureAppConfiguration((hostingContext, config) => { config.AddCommandLine(args); }) .UseUrls(proxyUrl) .Build(); if (token.CanBeCanceled) { token.Register(async() => await host.StopAsync()); } await host.RunAsync(token); }
/// <summary> /// Configures a new proxy instance for the given ProxyOptions /// </summary> /// <typeparam name="T">the type for which a proxy must be created</typeparam> /// <param name="options">the options that are used for proxy-injection</param> /// <param name="configure">a callback that allows the custom configuration of the Proxy-settings</param> /// <returns>the proxy-options that were passed initially for method-chaining.</returns> public static ProxyOptions ConfigureProxy <T>(this ProxyOptions options, Action <DefaultProxyInjector <T> > configure) where T : class { var item = new DefaultProxyInjector <T>(); options.AddInjector(item); configure(item); return(options); }
/// <summary> /// </summary> /// <param name="LocalPort"> /// </param> public NetProxy(int LocalPort) : base(LocalPort) { Options = new ProxyOptions { LocalhostPort = LocalPort, }; Initialize(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } // Shows UseCors with CorsPolicyBuilder. app.UseCors(builder => { builder.AllowAnyOrigin(); builder.AllowAnyMethod(); builder.AllowAnyHeader(); }); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); if (env.IsDevelopment()) { var proxyOptions = new ProxyOptions { Scheme = "https", Host = new HostString("domainame.com") }; //We can use Træfik for configuration app.Map("/api/cookbook", api => api.RunProxy(new Uri("http://localhost:63744"))); //app.MapWhen( // ctx => ctx.Request.Path.Value.StartsWith("/api/cookbook", StringComparison.InvariantCultureIgnoreCase), // api => api.RunProxy(proxyOptions)); } app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "hmr"); } }); }
/// <summary> /// </summary> /// <param name="port"> /// game-server port /// </param> /// <param name="lport"> /// localhost port /// </param> public NetProxy(int port, int lport) : base(port) { Options = new ProxyOptions { LocalhostPort = lport, GameServerPort = port }; Initialize(); }
/// <summary> /// Connect to game server with default settings /// </summary> public NetProxy() : base() { Options = new ProxyOptions { LocalhostPort = 6700, GameServerPort = 6500 }; Initialize(); }
public DeviceRegistrationDpsProvider( IOptions <DeviceRegistrationDpsOptions> deviceRegistrationOptions, IOptions <ProxyOptions> proxyOptions, SecurityProvider securityProvider ) { _deviceRegistrationOptions = deviceRegistrationOptions.Value; _proxyOptions = proxyOptions.Value; _securityProvider = securityProvider; }
/// <summary> /// </summary> /// <param name="host"> /// Game server host /// </param> /// <param name="port"> /// </param> public NetProxy(string host, int port) : base(host, port) { Options = new ProxyOptions { GameServerPort = port, LocalhostPort = 6700, GameServerHost = host }; Initialize(); }
public AdvancedOptions(bool closeConnectionAfterEachRequest, ProxyOptions proxyOptions, MappingConfigurationBase mappingConfiguration) { if (proxyOptions == null) { throw new ArgumentNullException("proxyOptions"); } _closeConnectionAfterEachRequest = closeConnectionAfterEachRequest; _proxyOptions = proxyOptions; _mappingConfiguration = mappingConfiguration; }
public ConnectionTarget(ServerLocation server, DestinationPort port, List <DestinationPort> portsToReconnect, IPAddress currentManualDns, string username, string password, ProxyOptions proxyOptions, string wireguardInternalClientIp, string wireguardPrivateKey) : this(server, port, portsToReconnect, currentManualDns) { // TODO: necessary to think how to divide implementation for OpenVPN and Wireguard OpenVpnUsername = username; OpenVpnPassword = password; OpenVpnProxyOptions = proxyOptions; WireGuardInternalClientIp = wireguardInternalClientIp; WireGuardLocalPrivateKey = wireguardPrivateKey; }
public void Does_Not_Throw_If_Username_And_Password_Are_Null() { using (var s = new SoulseekClient()) { ProxyOptions o = null; var ex = Record.Exception(() => o = new ProxyOptions("127.0.0.1", 1, username: null, password: null)); Assert.Null(ex); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { var handler = new GatewayHttpClientHandler(new Uri("fabric:/Hosting/CounterService"), message => message.GetHashCode()); var proxyOptions = new ProxyOptions() { Host = "unused", BackChannelMessageHandler = handler }; app.RunProxy(proxyOptions); }
/// <summary> /// Returns Proxy Options /// </summary> /// <param name="options"></param> /// <returns></returns> public static IOptions <ProxyOptions> ToProxyOptions(this ApiProxyServerOptions options) { ProxyOptions proxyOptions = new ProxyOptions() { Host = options.Host, Port = options.Port, Scheme = options.Scheme }; return(Options.Create(proxyOptions)); }
public async Task ProxyWebSocketsSmokeTest() { const string supportedSubProtocol = "myproto2"; const string otherSubProtocol = "myproto1"; const string message1Content = "TEST MESSAGE 1"; const string message2Content = "TEST MSG 2"; const string message3Content = "TEST MESSAGE 3"; const string closeStatusDescription = "My Status1"; using (var server = new WebHostBuilder() .UseKestrel() .Configure(app => app.UseWebSockets().Run(async ctx => { var socket = await ctx.WebSockets.AcceptWebSocketAsync(supportedSubProtocol); var message1 = await ReceiveTextMessage(socket); var message2 = await ReceiveTextMessage(socket); Assert.Equal(message1Content, message1); Assert.Equal(message2Content, message2); await socket.SendAsync(new ArraySegment <byte>(Encoding.UTF8.GetBytes(message3Content)), WebSocketMessageType.Text, true, CancellationToken.None); await socket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeStatusDescription, CancellationToken.None); })).Start("http://localhost:4001")) using (var proxy = new WebHostBuilder() .UseKestrel() .ConfigureServices(services => services.AddProxy(options => { options.GetProxyOptions = request => Task.FromResult(ProxyOptions.FromUri(new Uri($"http://localhost:4001"))); })) .Configure(app => app.UseWebSockets().RunProxy()) .Start("http://localhost:4002")) using (var client = new ClientWebSocket()) { client.Options.AddSubProtocol(otherSubProtocol); client.Options.AddSubProtocol(supportedSubProtocol); await client.ConnectAsync(new Uri("ws://localhost:4002"), CancellationToken.None); Assert.Equal(supportedSubProtocol, client.SubProtocol); await client.SendAsync(new ArraySegment <byte>(Encoding.UTF8.GetBytes(message1Content)), WebSocketMessageType.Text, true, CancellationToken.None); await client.SendAsync(new ArraySegment <byte>(Encoding.UTF8.GetBytes(message2Content)), WebSocketMessageType.Text, true, CancellationToken.None); var message3 = await ReceiveTextMessage(client); Assert.Equal(message3Content, message3); var result = await client.ReceiveAsync(new ArraySegment <byte>(new byte[4096]), CancellationToken.None); Assert.Equal(WebSocketMessageType.Close, result.MessageType); Assert.Equal(WebSocketCloseStatus.NormalClosure, result.CloseStatus); Assert.Equal(closeStatusDescription, result.CloseStatusDescription); await client.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, closeStatusDescription, CancellationToken.None); } }
private HttpClient CreateHttpClient(ProxyOptions proxyOptionsOrNull) { var proxy = proxyOptionsOrNull != null?CreateProxy(proxyOptionsOrNull) : null; var httpClientHandler = new HttpClientHandler { Proxy = proxy, UseProxy = proxy != null }; return(new HttpClient(httpClientHandler)); }
public NetworkAndProxyOptions(bool closeConnectionAfterEachRequest, bool preemptiveAuthentication, bool forceBasicAuthentication, ProxyOptions proxyOptions) { if (proxyOptions == null) { throw new ArgumentNullException("proxyOptions"); } _closeConnectionAfterEachRequest = closeConnectionAfterEachRequest; _preemptiveAuthentication = preemptiveAuthentication; _forceBasicAuthentication = forceBasicAuthentication; _proxyOptions = proxyOptions; }
public DeviceClientFactory( SecurityProvider securityProvider, IAuthenticationMethod authenticationMethod, IDeviceRegistrationProvider registrationProvider, IOptions <ProxyOptions> proxyOptions ) { _securityProvider = securityProvider; _authenticationMethod = authenticationMethod; _registrationProvider = registrationProvider; _proxyOptions = proxyOptions.Value; }
public void Throws_ArgumentException_On_Bad_Address(string address) { using (var s = new SoulseekClient()) { ProxyOptions o = null; var ex = Record.Exception(() => o = new ProxyOptions(address, 1, "u", "p")); Assert.NotNull(ex); Assert.IsType <AddressException>(ex); } }
public void Throws_ArgumentOutOfRangeException_On_Bad_Input(string address, int port, string username, string password) { using (var s = new SoulseekClient()) { ProxyOptions o = null; var ex = Record.Exception(() => o = new ProxyOptions(address, port, username, password)); Assert.NotNull(ex); Assert.IsType <ArgumentOutOfRangeException>(ex); } }
public static void ReferenceService <T>(ProxyOptions options, IInvokeFilter[] filters) where T : class { // 注册调用方信息 options.ServiceKind = ServiceKind.Remote; options.EndpointUri = AppEnv.GlobalConfiguration.ConsumerConfiguration.Url; options.Attributes.Add(AttrKeys.NodeCodeConsumer, AppEnv.GlobalConfiguration.ConsumerConfiguration.NodeCode); IProxyFactory proxyFactory = AppEnv.GlobalConfiguration.ProxyFactory; var proxy = proxyFactory.CreateProxy <T>(options, AppEnv._invokeFilters.Concat(filters).ToArray()); AppEnv._typeBuilder.RegisterType <T>(proxy); }
public void Throws_ArgumentException_On_Bad_Port(int port) { using (var s = new SoulseekClient()) { ProxyOptions o = null; var ex = Record.Exception(() => o = new ProxyOptions("127.0.0.01", port, "u", "p")); Assert.NotNull(ex); Assert.IsType <ArgumentOutOfRangeException>(ex); } }
private void btnTest_Click(object sender, EventArgs e) { this._testing = true; this.EnableControls(); base.Update(); BackgroundWorker worker = this._currentWorker = new BackgroundWorker(); worker.DoWork += delegate (object sender, DoWorkEventArgs e) { try { WebClient webClient; if (this.rbAuto.Checked || (this.txtAddress.Text.Trim().Length == 0)) { webClient = new WebClient(); } else { ProxyOptions p = new ProxyOptions(); this.WriteTo(p); webClient = p.GetWebClient(); } byte[] data = Encoding.UTF8.GetBytes("The quick brown fox jumps over the lazy dog"); webClient.UploadData("http://www.linqpad.net", data); if (!((this._currentWorker != worker) || this.IsDisposed)) { MessageBox.Show("Successful!"); } } catch (Exception exception) { if (!((this._currentWorker != worker) || this.IsDisposed)) { MessageBox.Show("Error: " + exception.Message); } } }; worker.RunWorkerCompleted += delegate (object sender, RunWorkerCompletedEventArgs e) { if (!((worker != this._currentWorker) || this.IsDisposed)) { this._testing = false; this.EnableControls(); } }; worker.RunWorkerAsync(); }
private void WriteTo(ProxyOptions p) { p.IsManual = this.rbManual.Checked; p.Address = this.txtAddress.Text.Trim(); ushort result = 0; ushort.TryParse(this.txtPort.Text, out result); p.Port = result; p.Domain = this.txtDomain.Text.Trim(); p.Username = this.txtUsername.Text.Trim(); p.Password = this.txtPassword.Text.Trim(); p.DisableExpect100Continue = this.chkDisableExpect100.Checked; }