Esempio n. 1
0
        private TType CreateProxyWithMixin <TType>(ProxyKind kind, params object[] mixins)
        {
            var options = new ProxyGenerationOptions(new ProxyNothingHook());

            foreach (var mixin in mixins)
            {
                options.AddMixinInstance(mixin);
            }
            switch (kind)
            {
            case ProxyKind.Class:
                return((TType)generator.CreateClassProxy(typeof(object), Type.EmptyTypes, options));

            case ProxyKind.WithoutTarget:
                return((TType)generator.CreateInterfaceProxyWithoutTarget(typeof(IEmpty), Type.EmptyTypes, options));

            case ProxyKind.WithTarget:
                return((TType)generator.CreateInterfaceProxyWithTarget(typeof(IEmpty), Type.EmptyTypes, new Empty(), options));

            case ProxyKind.WithTargetInterface:
                return((TType)generator.CreateInterfaceProxyWithTargetInterface(typeof(IEmpty), new Empty(), options));
            }

            Assert.Fail("Invalid proxy kind {0}", kind);
            return(default(TType));
        }
Esempio n. 2
0
        public void Explicit_inclusion_of_base_interfaces_not_significant(ProxyKind kind)
        {
            var first  = Proxy(kind, typeof(IBase), typeof(ISub1));
            var second = Proxy(kind, typeof(ISub1));

            Assert.AreSame(first.GetType(), second.GetType());
        }
Esempio n. 3
0
        public void Order_of_additional_interfaces_not_significant(ProxyKind kind)
        {
            var first  = Proxy(kind, typeof(IOne), typeof(ITwo));
            var second = Proxy(kind, typeof(ITwo), typeof(IOne));

            Assert.AreSame(first.GetType(), second.GetType());
        }
Esempio n. 4
0
        private object Proxy(ProxyKind kind, params Type[] additionalInterfacesToProxy)
        {
            switch (kind)
            {
            case ProxyKind.Class:
                return(generator.CreateClassProxy(
                           typeof(SimpleClass),
                           additionalInterfacesToProxy
                           ));

            case ProxyKind.WithoutTarget:
                return(generator.CreateInterfaceProxyWithoutTarget(
                           typeof(IEmpty),
                           additionalInterfacesToProxy
                           ));

            case ProxyKind.WithTarget:
                return(generator.CreateInterfaceProxyWithTarget(
                           typeof(IEmpty),
                           additionalInterfacesToProxy,
                           new Empty()
                           ));

            case ProxyKind.WithTargetInterface:
                return(generator.CreateInterfaceProxyWithTarget(
                           typeof(IEmpty),
                           additionalInterfacesToProxy,
                           new Empty()
                           ));

            default:
                Assert.Fail(string.Format("Invalid proxy kind: {0}", kind));
                return(null);    //to satisfy the compiler
            }
        }
Esempio n. 5
0
        public async Task Run(
            TestContext ctx,
            [WebTestFeatures.SelectProxyKind(IncludeSSL = true)] ProxyKind kind,
            HttpServer server, Handler handler, CancellationToken cancellationToken)
        {
            var           oldCount = server.CountRequests;
            HttpOperation operation;

            if (kind == ProxyKind.Unauthenticated)
            {
                operation = new TraditionalOperation(
                    server, handler, true, HttpOperationFlags.AbortAfterClientExits,
                    HttpStatusCode.ProxyAuthenticationRequired, WebExceptionStatus.ProtocolError);
            }
            else
            {
                operation = new TraditionalOperation(
                    server, handler, true);
            }
            try {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);

                var newCount = server.CountRequests;
                ctx.Assert(newCount, Is.GreaterThan(oldCount), "used proxy");
            } finally {
                operation.Dispose();
            }
        }
Esempio n. 6
0
        public async Task RunAuthentication(
            TestContext ctx,
            [WebTestFeatures.SelectProxyKind(IncludeSSL = true)] ProxyKind kind,
            HttpServer server, [AuthenticationType] AuthenticationType authType,
            Handler handler, CancellationToken cancellationToken)
        {
            var           authHandler = new AuthenticationHandler(authType, handler);
            HttpOperation operation;

            if (kind == ProxyKind.Unauthenticated)
            {
                operation = new TraditionalOperation(server, authHandler, true,
                                                     HttpOperationFlags.AbortAfterClientExits,
                                                     HttpStatusCode.ProxyAuthenticationRequired, WebExceptionStatus.ProtocolError);
            }
            else
            {
                operation = new TraditionalOperation(server, authHandler, true);
            }
            try {
                await operation.Run(ctx, cancellationToken).ConfigureAwait(false);
            } finally {
                operation.Dispose();
            }
        }
Esempio n. 7
0
        public void Duplicated_interfaces_not_significant(ProxyKind kind)
        {
            var first  = Proxy(kind, typeof(IOne), typeof(IOne));
            var second = Proxy(kind, typeof(IOne));

            Assert.AreSame(first.GetType(), second.GetType());
        }
Esempio n. 8
0
 private void VerifyProxyTypeCompatilibily(ProxyKind compatibleProxy)
 {
     if (this.proxyType != ProxyKind.Unspecified && this.proxyType != compatibleProxy)
     {
         throw new InvalidOperationException("Proxy autodetect is incompatible with manual settings");
     }
 }
Esempio n. 9
0
        public void Mixin_method_explicit(ProxyKind kind)
        {
            var proxy  = CreateProxyWithMixin <ISimpleInterface>(kind, new SimpleInterfaceExplicit());
            var result = -1;

            Assert.DoesNotThrow(() => result = proxy.Do());
            Assert.AreEqual(5, result);
        }
Esempio n. 10
0
        public void Mixin_method_generic(ProxyKind kind)
        {
            var proxy  = CreateProxyWithMixin <IGenericInterface>(kind, new GenericClass());
            var result = -1;

            Assert.DoesNotThrow(() => result = proxy.GenericMethod <int>());
            Assert.AreEqual(0, result);
        }
        public void Target_method_generic([Values(ProxyKind.WithTarget, ProxyKind.WithTargetInterface)] ProxyKind kind)
        {
            var proxy  = CreateProxy <IGenericInterface>(kind, new GenericClass());
            int result = -1;

            Assert.DoesNotThrow(() => result = proxy.GenericMethod <int>());
            Assert.AreEqual(0, result);
        }
        public void Target_method_explicit([Values(ProxyKind.WithTarget, ProxyKind.WithTargetInterface)] ProxyKind kind)
        {
            var proxy  = CreateProxy <ISimpleInterface>(kind, new ClassWithExplicitInterface());
            int result = -1;

            Assert.DoesNotThrow(() => result = proxy.Do());
            Assert.AreEqual(5, result);
        }
Esempio n. 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Proxy"/> class with the given proxy settings.
        /// </summary>
        /// <param name="settings">A dictionary of settings to use with the proxy.</param>
        public Proxy(Dictionary <string, object> settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings", "settings dictionary cannot be null");
            }

            if (settings.ContainsKey("proxyType"))
            {
                ProxyKind rawType = (ProxyKind)Enum.Parse(typeof(ProxyKind), settings["proxyType"].ToString(), true);
                this.Kind = rawType;
            }

            if (settings.ContainsKey("ftpProxy"))
            {
                this.FtpProxy = settings["ftpProxy"].ToString();
            }

            if (settings.ContainsKey("httpProxy"))
            {
                this.HttpProxy = settings["httpProxy"].ToString();
            }

            if (settings.ContainsKey("noProxy"))
            {
                this.NoProxy = settings["noProxy"].ToString();
            }

            if (settings.ContainsKey("proxyAutoconfigUrl"))
            {
                this.ProxyAutoConfigUrl = settings["proxyAutoconfigUrl"].ToString();
            }

            if (settings.ContainsKey("sslProxy"))
            {
                this.SslProxy = settings["sslProxy"].ToString();
            }

            if (settings.ContainsKey("socksProxy"))
            {
                this.SocksProxy = settings["socksProxy"].ToString();
            }

            if (settings.ContainsKey("socksUsername"))
            {
                this.SocksUserName = settings["socksUsername"].ToString();
            }

            if (settings.ContainsKey("socksPassword"))
            {
                this.SocksPassword = settings["socksPassword"].ToString();
            }

            if (settings.ContainsKey("autodetect"))
            {
                this.IsAutoDetect = (bool)settings["autodetect"];
            }
        }
Esempio n. 14
0
        public void Mixin_method(
            [Values(ProxyKind.Class, ProxyKind.WithoutTarget, ProxyKind.WithTarget, ProxyKind.WithTargetInterface)] ProxyKind
            kind)
        {
            var proxy  = CreateProxyWithMixin <ISimpleInterface>(kind, new ClassWithInterface());
            int result = -1;

            Assert.DoesNotThrow(() => result = proxy.Do());
            Assert.AreEqual(5, result);
        }
Esempio n. 15
0
        /// <summary>
        /// Adds addresses to the list of addresses against which the proxy will not be used.
        /// </summary>
        /// <param name="addressesToAdd">An <see cref="IEnumerable{T}"/> object of arguments to add.</param>
        public void AddBypassAddresses(IEnumerable <string> addressesToAdd)
        {
            if (addressesToAdd == null)
            {
                throw new ArgumentNullException("addressesToAdd", "addressesToAdd must not be null");
            }

            this.VerifyProxyTypeCompatilibily(ProxyKind.Manual);
            this.proxyKind = ProxyKind.Manual;
            this.noProxyAddresses.AddRange(addressesToAdd);
        }
Esempio n. 16
0
 private void VerifyProxyTypeCompatilibily(ProxyKind compatibleProxy)
 {
     if (this.proxyKind != ProxyKind.Unspecified && this.proxyKind != compatibleProxy)
     {
         throw new InvalidOperationException(
                   string.Format(CultureInfo.InvariantCulture,
                                 "Specified proxy type {0} is not compatible with current setting {1}",
                                 compatibleProxy.ToString().ToUpperInvariant(), this.proxyKind.ToString().ToUpperInvariant())
                   );
     }
 }
Esempio n. 17
0
        public void Mixin_method_out_ref_parameters(ProxyKind kind)
        {
            var proxy = CreateProxyWithMixin <IWithRefOut>(kind, new WithRefOut());

            int[] result = { -1 };
            Assert.DoesNotThrow(() => proxy.Did(ref result[0]));
            Assert.AreEqual(5, result[0]);

            result[0] = -1;
            Assert.DoesNotThrow(() => proxy.Do(out result[0]));
            Assert.AreEqual(5, result[0]);
        }
        public void AdditionalInterfaces_method(ProxyKind kind)
        {
            var proxy  = CreateProxyWithAdditionalInterface <IWithRefOut>(kind);
            int result = -1;

            Assert.DoesNotThrow(() => proxy.Do(out result));
            Assert.AreEqual(0, result);

            result = -1;
            Assert.DoesNotThrow(() => proxy.Did(ref result));
            Assert.AreEqual(-1, result);
        }
        public void Target_method_out_ref_parameters(
            [Values(ProxyKind.WithTarget, ProxyKind.WithTargetInterface)] ProxyKind kind)
        {
            var proxy  = CreateProxy <IWithRefOut>(kind, new WithRefOut());
            int result = -1;

            Assert.DoesNotThrow(() => proxy.Do(out result));
            Assert.AreEqual(5, result);

            result = -1;
            Assert.DoesNotThrow(() => proxy.Did(ref result));
            Assert.AreEqual(5, result);
        }
Esempio n. 20
0
        public ITypeModificationTracker CreateProxy(Type baseType, ProxyKind proxyKind)
        {
            ArgumentUtility.CheckNotNull("baseType", baseType);

            var incrementedCounter = Interlocked.Increment(ref _counter);

            var name       = string.Format("{0}_{1}Proxy_{2}", baseType.Name, proxyKind, incrementedCounter);
            var attributes = TypeAttributes.Public | TypeAttributes.BeforeFieldInit | (baseType.IsTypePipeSerializable() ? TypeAttributes.Serializable : 0);

            var proxyType         = CreateType(name, baseType.Namespace, attributes, baseType, null);
            var constructorBodies = CopyConstructors(baseType, proxyType);

            return(new ProxyTypeModificationTracker(proxyType, constructorBodies));
        }
        private TType CreateProxy <TType>(ProxyKind kind, TType target)
        {
            var options = new ProxyGenerationOptions(new ProxyNothingHook());

            switch (kind)
            {
            case ProxyKind.WithTarget:
                return((TType)generator.CreateInterfaceProxyWithTarget(typeof(TType), Type.EmptyTypes, target, options));

            case ProxyKind.WithTargetInterface:
                return((TType)generator.CreateInterfaceProxyWithTargetInterface(typeof(TType), target, options));
            }

            Assert.Fail("Invalid proxy kind {0}", kind);
            return(default(TType));
        }
Esempio n. 22
0
		private object Proxy(ProxyKind kind, params Type[] additionalInterfacesToProxy)
		{
			switch (kind)
			{
				case ProxyKind.Class:
					return generator.CreateClassProxy(typeof(SimpleClass), additionalInterfacesToProxy);
				case ProxyKind.WithoutTarget:
					return generator.CreateInterfaceProxyWithoutTarget(typeof(IEmpty), additionalInterfacesToProxy);
				case ProxyKind.WithTarget:
					return generator.CreateInterfaceProxyWithTarget(typeof(IEmpty), additionalInterfacesToProxy, new Empty());
				case ProxyKind.WithTargetInterface:
					return generator.CreateInterfaceProxyWithTarget(typeof(IEmpty), additionalInterfacesToProxy, new Empty());
				default:
					Assert.Fail(string.Format("Invalid proxy kind: {0}", kind));
					return null; //to satisfy the compiler
			}
		}
Esempio n. 23
0
        public Task RunAuthentication(
            TestContext ctx,
            [WebTestFeatures.SelectProxyKind(IncludeSSL = true)] ProxyKind kind,
            HttpServer server, [AuthenticationType] AuthenticationType authType,
            Handler handler, CancellationToken cancellationToken)
        {
            var authHandler = new AuthenticationHandler(authType, handler);

            if (kind == ProxyKind.Unauthenticated)
            {
                return(TestRunner.RunTraditional(
                           ctx, server, authHandler, cancellationToken, false,
                           HttpStatusCode.ProxyAuthenticationRequired, WebExceptionStatus.ProtocolError));
            }
            else
            {
                return(TestRunner.RunTraditional(
                           ctx, server, authHandler, cancellationToken, false));
            }
        }
Esempio n. 24
0
        public async Task Run(
            TestContext ctx,
            [WebTestFeatures.SelectProxyKind(IncludeSSL = true)] ProxyKind kind,
            HttpServer server, Handler handler, CancellationToken cancellationToken)
        {
            var oldCount = server.CountRequests;

            if (kind == ProxyKind.Unauthenticated)
            {
                await TestRunner.RunTraditional(
                    ctx, server, handler, cancellationToken, false,
                    HttpStatusCode.ProxyAuthenticationRequired, WebExceptionStatus.ProtocolError);
            }
            else
            {
                await TestRunner.RunTraditional(
                    ctx, server, handler, cancellationToken, false).ConfigureAwait(false);

                var newCount = server.CountRequests;
                ctx.Assert(newCount, Is.GreaterThan(oldCount), "used proxy");
            }
        }
        private TType CreateProxyWithAdditionalInterface <TType>(ProxyKind kind)
        {
            var options    = new ProxyGenerationOptions(new ProxyNothingHook());
            var interfaces = new[] { typeof(TType) };

            switch (kind)
            {
            case ProxyKind.Class:
                return((TType)generator.CreateClassProxy(typeof(object), interfaces, options));

            case ProxyKind.WithoutTarget:
                return((TType)generator.CreateInterfaceProxyWithoutTarget(typeof(IEmpty), interfaces, options));

            case ProxyKind.WithTarget:
                return((TType)generator.CreateInterfaceProxyWithTarget(typeof(IEmpty), interfaces, new Empty(), options));

            case ProxyKind.WithTargetInterface:
                return((TType)generator.CreateInterfaceProxyWithTargetInterface(typeof(IEmpty), interfaces, new Empty(), options));
            }

            Assert.Fail("Invalid proxy kind {0}", kind);
            return(default(TType));
        }
Esempio n. 26
0
        /// <summary>
        /// Creates the proxy object.
        /// </summary>
        /// <param name="proxyKind">Kind of the proxy.</param>
        /// <param name="proxyBaseType">Type of the proxy base.</param>
        /// <param name="proxyBaseInstance">The proxy base instance.</param>
        /// <returns>System.Object.</returns>
        /// <exception cref="System.Exception">Proxy object can not be abstract or interface!</exception>
        /// <exception cref="System.NotImplementedException">Not yet! This case reevaluate in other project!\nYou can see in Dynoxygen project in Github.</exception>
        /// <remarks>Rachistructure</remarks>
        /// TODO Edit XML Comment Template for CreateProxyObject
        public static object CreateProxyObject(ProxyKind proxyKind, Type proxyBaseType, object proxyBaseInstance)
        {
            Type   baseType      = proxyBaseType;
            object proxiesObject = null;

            if (baseType.IsAbstract || baseType.IsInterface)
            {
                throw new Exception("Proxy object can not be abstract or interface!");
            }
            if (baseType.IsClass)
            {
                switch (proxyKind)
                {
                case ProxyKind.RealProxy:
                    dynamic instance = Convert.ChangeType(proxyBaseInstance, proxyBaseType);
                    if (instance != null)
                    {
                        proxiesObject = new RealProxyBuilder(baseType, ref instance).GetTransparentProxy();
                    }
                    else
                    {
                        proxiesObject = new RealProxyBuilder(baseType).GetTransparentProxy();
                    }
                    break;

                case ProxyKind.DynamicProxy:
                    throw new NotImplementedException("Not yet! This case reevaluate in other project!\nYou can see in Dynoxygen project in Github.");
                    break;

                default:
                    break;
                }
            }

            return(proxiesObject);
        }
Esempio n. 27
0
 private void VerifyProxyTypeCompatilibily(ProxyKind compatibleProxy)
 {
     if (this.proxyKind != ProxyKind.Unspecified && this.proxyKind != compatibleProxy)
     {
         throw new InvalidOperationException("Proxy autodetect is incompatible with manual settings");
     }
 }
Esempio n. 28
0
        private void VerifyProxyTypeCompatilibily(ProxyKind compatibleProxy)
        {
            if (this.proxyKind != ProxyKind.Unspecified && this.proxyKind != compatibleProxy)
            {
                string errorMessage = string.Format(
                    CultureInfo.InvariantCulture,
                    "Specified proxy type {0} is not compatible with current setting {1}",
                    compatibleProxy.ToString().ToUpperInvariant(),
                    this.proxyKind.ToString().ToUpperInvariant());

                throw new InvalidOperationException(errorMessage);
            }
        }
Esempio n. 29
0
		public void Duplicated_interfaces_not_significant(ProxyKind kind)
		{
			var first = Proxy(kind, typeof(IOne), typeof(IOne));
			var second = Proxy(kind, typeof(IOne));
			Assert.AreSame(first.GetType(), second.GetType());
		}
Esempio n. 30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Proxy"/> class with the given proxy settings.
        /// </summary>
        /// <param name="settings">A dictionary of settings to use with the proxy.</param>
        public Proxy(Dictionary <string, object> settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings", "settings dictionary cannot be null");
            }

            if (settings.ContainsKey("proxyType"))
            {
                ProxyKind rawType = (ProxyKind)Enum.Parse(typeof(ProxyKind), settings["proxyType"].ToString(), true);
                this.Kind = rawType;
            }

            if (settings.ContainsKey("ftpProxy"))
            {
                this.FtpProxy = settings["ftpProxy"].ToString();
            }

            if (settings.ContainsKey("httpProxy"))
            {
                this.HttpProxy = settings["httpProxy"].ToString();
            }

            if (settings.ContainsKey("noProxy"))
            {
                List <string> bypassAddresses   = new List <string>();
                string        addressesAsString = settings["noProxy"] as string;
                if (addressesAsString != null)
                {
                    bypassAddresses.AddRange(addressesAsString.Split(';'));
                }
                else
                {
                    object[] addressesAsArray = settings["noProxy"] as object[];
                    if (addressesAsArray != null)
                    {
                        foreach (object address in addressesAsArray)
                        {
                            bypassAddresses.Add(address.ToString());
                        }
                    }
                }

                this.AddBypassAddresses(bypassAddresses);
            }

            if (settings.ContainsKey("proxyAutoconfigUrl"))
            {
                this.ProxyAutoConfigUrl = settings["proxyAutoconfigUrl"].ToString();
            }

            if (settings.ContainsKey("sslProxy"))
            {
                this.SslProxy = settings["sslProxy"].ToString();
            }

            if (settings.ContainsKey("socksProxy"))
            {
                this.SocksProxy = settings["socksProxy"].ToString();
            }

            if (settings.ContainsKey("socksUsername"))
            {
                this.SocksUserName = settings["socksUsername"].ToString();
            }

            if (settings.ContainsKey("socksPassword"))
            {
                this.SocksPassword = settings["socksPassword"].ToString();
            }

            if (settings.ContainsKey("autodetect"))
            {
                this.IsAutoDetect = (bool)settings["autodetect"];
            }
        }
Esempio n. 31
0
		public void Explicit_inclusion_of_base_interfaces_not_significant(ProxyKind kind)
		{
			var first = Proxy(kind, typeof(IBase), typeof(ISub1));
			var second = Proxy(kind, typeof(ISub1));
			Assert.AreSame(first.GetType(), second.GetType());
		}
Esempio n. 32
0
		public void Order_of_additional_interfaces_not_significant(ProxyKind kind)
		{
			var first = Proxy(kind, typeof(IOne), typeof(ITwo));
			var second = Proxy(kind, typeof(ITwo), typeof(IOne));
			Assert.AreSame(first.GetType(), second.GetType());
		}
Esempio n. 33
0
 public UseProxyKindAttribute(ProxyKind kind)
 {
     this.kind       = kind;
     this.identifier = Type.Name;
 }
Esempio n. 34
0
 /// <summary>
 /// Creates the proxy object.
 /// </summary>
 /// <typeparam name="TProxyBaseType">The type of the proxy base type.</typeparam>
 /// <param name="kind">The kind.</param>
 /// <returns>TProxyBaseType.</returns>
 /// <remarks>Rachistructure</remarks>
 public static TProxyBaseType CreateProxyObject <TProxyBaseType>(ProxyKind kind = ProxyKind.RealProxy)
 {
     return((TProxyBaseType)CreateProxyObject(kind, typeof(TProxyBaseType), null));
 }
Esempio n. 35
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Proxy"/> class with the given proxy settings.
        /// </summary>
        /// <param name="settings">A dictionary of settings to use with the proxy.</param>
        public Proxy(Dictionary <string, object> settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings", "settings dictionary cannot be null");
            }

            if (settings.ContainsKey("proxyType") && settings["proxyType"] != null)
            {
                // Special-case "PAC" since that is the correct serialization.
                if (settings["proxyType"].ToString().ToLowerInvariant() == "pac")
                {
                    this.Kind = ProxyKind.ProxyAutoConfigure;
                }
                else
                {
                    ProxyKind rawType = (ProxyKind)Enum.Parse(typeof(ProxyKind), settings["proxyType"].ToString(), true);
                    this.Kind = rawType;
                }
            }

            if (settings.ContainsKey("ftpProxy") && settings["ftpProxy"] != null)
            {
                this.FtpProxy = settings["ftpProxy"].ToString();
            }

            if (settings.ContainsKey("httpProxy") && settings["httpProxy"] != null)
            {
                this.HttpProxy = settings["httpProxy"].ToString();
            }

            if (settings.ContainsKey("noProxy") && settings["noProxy"] != null)
            {
                List <string> bypassAddresses   = new List <string>();
                string        addressesAsString = settings["noProxy"] as string;
                if (addressesAsString != null)
                {
                    bypassAddresses.AddRange(addressesAsString.Split(';'));
                }
                else
                {
                    object[] addressesAsArray = settings["noProxy"] as object[];
                    if (addressesAsArray != null)
                    {
                        foreach (object address in addressesAsArray)
                        {
                            bypassAddresses.Add(address.ToString());
                        }
                    }
                }

                this.AddBypassAddresses(bypassAddresses);
            }

            if (settings.ContainsKey("proxyAutoconfigUrl") && settings["proxyAutoconfigUrl"] != null)
            {
                this.ProxyAutoConfigUrl = settings["proxyAutoconfigUrl"].ToString();
            }

            if (settings.ContainsKey("sslProxy") && settings["sslProxy"] != null)
            {
                this.SslProxy = settings["sslProxy"].ToString();
            }

            if (settings.ContainsKey("socksProxy") && settings["socksProxy"] != null)
            {
                this.SocksProxy = settings["socksProxy"].ToString();
            }

            if (settings.ContainsKey("socksUsername") && settings["socksUsername"] != null)
            {
                this.SocksUserName = settings["socksUsername"].ToString();
            }

            if (settings.ContainsKey("socksPassword") && settings["socksPassword"] != null)
            {
                this.SocksPassword = settings["socksPassword"].ToString();
            }

            if (settings.ContainsKey("socksVersion") && settings["socksVersion"] != null)
            {
                this.SocksVersion = Convert.ToInt32(settings["socksVersion"]);
            }

            if (settings.ContainsKey("autodetect") && settings["autodetect"] != null)
            {
                this.IsAutoDetect = (bool)settings["autodetect"];
            }
        }