示例#1
0
		public ServerPool(IMemcachedClientConfiguration configuration)
		{
			if (configuration == null)
				throw new ArgumentNullException("settings", "Invalid or missing pool configuration. Check if the enyim.com/memcached section or your custom section presents in the app/web.config.");

			this.configuration = configuration;
			this.isAliveTimer = new Timer(callback_isAliveTimer, null, (int)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds, (int)this.configuration.SocketPool.DeadTimeout.TotalMilliseconds);

			// create the key transformer instance
			Type t = this.configuration.KeyTransformer;
			this.keyTransformer = (t == null) ? new DefaultKeyTransformer() : (IKeyTransformer)Activator.CreateInstance(t);

			// create the item transcoder instance
			t = this.configuration.Transcoder;
			this.transcoder = (t == null) ? new DefaultTranscoder() : (ITranscoder)Activator.CreateInstance(t);


			// initialize the server list
			ISocketPoolConfiguration ispc = configuration.SocketPool;
			
			foreach (IPEndPoint ip in configuration.Servers)
			{
				this.workingServers.Add(new MemcachedNode(ip, ispc));
			}

			// (re)creates the locator
			this.RebuildIndexes();
		}
示例#2
0
 protected MemcachedClientBase(ICluster cluster, IOperationFactory opFactory, IKeyTransformer keyTransformer, ITranscoder transcoder)
 {
     this.cluster        = cluster;
     this.opFactory      = opFactory;
     this.keyTransformer = keyTransformer;
     this.transcoder     = transcoder;
 }
 public PWDatabaseDataSource(IEncryptionEngine encryptionEngine,
     IKeyTransformer keyTransformer,
     IGZipStreamFactory gzipStreamFactory,
     ICanSHA256Hash hasher)
 {
     _hasher = hasher;
     _gzipStreamFactory = gzipStreamFactory;
     _keyTransformer = keyTransformer;
     _encryptionEngine = encryptionEngine;
 }
示例#4
0
 public KeyGenerator(ICanSHA256Hash hasher, 
     IKeyTransformer keyTransformer, 
     CompositeKey compositeKey, 
     IProgress<double> progress)
 {             
     _hasher = hasher;
     _keyTransformer = keyTransformer;
     _compositeKey = compositeKey;
     _progress = progress;
 }
 public KdbWriterFactory(IEncryptionEngine databaseEncryptor, 
     IKeyTransformer keyTransformer, 
     ICanSHA256Hash hasher, 
     IGZipStreamFactory gzipFactory)
 {
     _gzipFactory = gzipFactory;
     _hasher = hasher;
     _keyTransformer = keyTransformer;
     _databaseEncryptor = databaseEncryptor;
 }
示例#6
0
 public Kdb4Reader(Kdb4File kdb4File, 
     IEncryptionEngine databaseDecryptor,
     IKeyTransformer keyTransformer, 
     ICanSHA256Hash hasher,
     IGZipStreamFactory gZipFactory)
 {            
     file = kdb4File;
     _encryptionEngine = databaseDecryptor;
     _keyTransformer = keyTransformer;
     _hasher = hasher;
     _gZipFactory = gZipFactory;
 }
示例#7
0
 public Kdb4Writer(Kdb4HeaderWriter headerWriter,
     IEncryptionEngine databaseEncryptor,
     IKeyTransformer keyTransformer,
     ICanSHA256Hash hasher,
     IGZipStreamFactory gZipFactory)
 {
     this._gZipFactory = gZipFactory;
     this._hasher = hasher;
     this._keyTransformer = keyTransformer;
     this._databaseEncryptor = databaseEncryptor;
     _headerWriter = headerWriter;
 }
示例#8
0
        public Window(WindowArgs windowArgs)
        {
            // keyboard layout
            switch (windowArgs.KeyboardLayout)
            {
            case KeyboardLayout.Danish:
                keyTransformer = new Input.Languages.DanishKeyTransformer();
                break;

            default:
                throw new ArgumentException("Window(): only Danish keyboard layout is currently supported!");
            }

            // window dimensions
            uint width  = windowArgs.Width;
            uint height = windowArgs.Height;

            switch (windowArgs.AspectRatio)
            {
            case WindowAspectRatio.Aspect_Custom:
                break;

            case WindowAspectRatio.Aspect_1X1:
                width = height;
                break;

            case WindowAspectRatio.Aspect_3X2:
                width = (height * 3) / 2;
                break;

            case WindowAspectRatio.Aspect_4X3:
                width = (height * 4) / 3;
                break;

            case WindowAspectRatio.Aspect_16X9:
                width = (height * 16) / 9;
                break;

            default:
                throw new ArgumentException("Window(): invalid aspect ratio!");
            }

            // create and bind OpenGL context
            ActivateThisWindowContext(windowArgs.Title, width, height, windowArgs.FullScreen);

            // setup event handlers
            if (windowArgs.Resizable)
            {
                AddDefaultResizeHandler();
            }
            AddDefaultKeyEventHandler();
        }
示例#9
0
 public MemcachedClient(ICluster cluster, IOperationFactory opFactory, IKeyTransformer keyTransformer, ITranscoder transcoder)
     : base(cluster, opFactory, keyTransformer, transcoder)
 {
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MemcachedClientConfiguration"/> class.
        /// </summary>
        /// <param name="loggerFactory"></param>
        /// <param name="options"></param>
        public MemcachedClientConfiguration(ILoggerFactory loggerFactory, IOptions <MemcachedClientOptions> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options), "No configuration is found");
            }

            this.PrepareLogger(loggerFactory);

            var configuration = options.Value;

            this.Protocol = configuration.Protocol;

            configuration.Servers.ForEach(server =>
            {
                var address = server.Address;
                if ((address.IndexOf(".") > 0 && address.IndexOf(":") > 0) || (address.IndexOf(":") > 0 && address.IndexOf("]:") > 0))
                {
                    this.AddServer(address);
                }
                else
                {
                    this.AddServer(address, server.Port);
                }
            });

            this.SocketPool = configuration.SocketPool;

            if (!string.IsNullOrWhiteSpace(configuration.Authentication?.Type))
            {
                try
                {
                    this.Authentication = new AuthenticationConfiguration
                    {
                        Type = configuration.Authentication.Type
                    };
                    foreach (var parameter in configuration.Authentication.Parameters)
                    {
                        this.Authentication.Parameters[parameter.Key] = parameter.Value;
                        if (this._logger.IsEnabled(LogLevel.Debug))
                        {
                            this._logger.LogDebug($"Authentication {parameter.Key} is '{parameter.Value}'.");
                        }
                    }
                    if (this._logger.IsEnabled(LogLevel.Debug))
                    {
                        this._logger.LogDebug($"Use '{configuration.Authentication.Type}' authentication");
                    }
                }
                catch (Exception ex)
                {
                    this._logger.LogError(ex, $"Unable to load '{configuration.Authentication.Type}' authentication");
                }
            }

            if (!string.IsNullOrWhiteSpace(configuration.KeyTransformer))
            {
                try
                {
                    this._keyTransformer = FastActivator.Create(configuration.KeyTransformer) as IKeyTransformer;
                    if (this._logger.IsEnabled(LogLevel.Debug))
                    {
                        this._logger.LogDebug($"Use '{configuration.KeyTransformer}' key-transformer");
                    }
                }
                catch (Exception ex)
                {
                    this._logger.LogError(ex, $"Unable to load '{configuration.KeyTransformer}' key-transformer");
                }
            }

            if (!string.IsNullOrWhiteSpace(configuration.Transcoder))
            {
                try
                {
                    this._transcoder = FastActivator.Create(configuration.Transcoder) as ITranscoder;
                    if (this._logger.IsEnabled(LogLevel.Debug))
                    {
                        this._logger.LogDebug($"Use '{configuration.Transcoder}' transcoder");
                    }
                }
                catch (Exception ex)
                {
                    this._logger.LogError(ex, $"Unable to load '{configuration.Transcoder}' transcoder");
                }
            }

            if (!string.IsNullOrWhiteSpace(configuration.NodeLocator))
            {
                try
                {
                    this.NodeLocator = Type.GetType(configuration.NodeLocator);
                    if (this._logger.IsEnabled(LogLevel.Debug))
                    {
                        this._logger.LogDebug($"Use '{configuration.NodeLocator}' node-locator");
                    }
                }
                catch (Exception ex)
                {
                    this._logger.LogError(ex, $"Unable to load '{configuration.NodeLocator}' node-locator");
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MemcachedClientConfiguration"/>.
        /// </summary>
        /// <param name="loggerFactory"></param>
        /// <param name="configuration"></param>
        public MemcachedClientConfiguration(ILoggerFactory loggerFactory, MemcachedClientConfigurationSectionHandler configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration), "No configuration is found");
            }

            this.PrepareLogger(loggerFactory);

            if (Enum.TryParse(configuration.Section.Attributes["protocol"]?.Value ?? "Binary", out MemcachedProtocol protocol))
            {
                this.Protocol = protocol;
            }

            if (configuration.Section.SelectNodes("servers/add") is XmlNodeList servers)
            {
                foreach (XmlNode server in servers)
                {
                    if ("memcached".Equals((server.Attributes["type"]?.Value ?? "Memcached").Trim().ToLower()))
                    {
                        var address = server.Attributes["address"]?.Value ?? "localhost";
                        if ((address.IndexOf(".") > 0 && address.IndexOf(":") > 0) || (address.IndexOf(":") > 0 && address.IndexOf("]:") > 0))
                        {
                            this.AddServer(address);
                        }
                        else
                        {
                            this.AddServer(address, Int32.TryParse(server.Attributes["port"]?.Value ?? "11211", out int port) ? port : 11211);
                        }
                    }
                }
            }

            this.SocketPool = new SocketPoolConfiguration();
            if (configuration.Section.SelectSingleNode("socketPool") is XmlNode socketpool)
            {
                if (Int32.TryParse(socketpool.Attributes["maxPoolSize"]?.Value, out int intValue))
                {
                    this.SocketPool.MaxPoolSize = intValue;
                }
                if (Int32.TryParse(socketpool.Attributes["minPoolSize"]?.Value, out intValue))
                {
                    this.SocketPool.MinPoolSize = intValue;
                }
                if (TimeSpan.TryParse(socketpool.Attributes["connectionTimeout"]?.Value, out TimeSpan timespanValue))
                {
                    this.SocketPool.ConnectionTimeout = timespanValue;
                }
                if (TimeSpan.TryParse(socketpool.Attributes["deadTimeout"]?.Value, out timespanValue))
                {
                    this.SocketPool.DeadTimeout = timespanValue;
                }
                if (TimeSpan.TryParse(socketpool.Attributes["queueTimeout"]?.Value, out timespanValue))
                {
                    this.SocketPool.QueueTimeout = timespanValue;
                }
                if (TimeSpan.TryParse(socketpool.Attributes["receiveTimeout"]?.Value, out timespanValue))
                {
                    this.SocketPool.ReceiveTimeout = timespanValue;
                }
                if (Boolean.TryParse(socketpool.Attributes["noDelay"]?.Value, out bool boolValue))
                {
                    this.SocketPool.NoDelay = boolValue;
                }

                if ("throttling" == socketpool.Attributes["failurePolicy"]?.Value)
                {
                    this.SocketPool.FailurePolicyFactory = new ThrottlingFailurePolicyFactory(Int32.TryParse(socketpool.Attributes["failureThreshold"]?.Value, out intValue) ? intValue : 4, TimeSpan.TryParse(socketpool.Attributes["resetAfter"]?.Value, out timespanValue) ? timespanValue : TimeSpan.FromSeconds(5));
                }
            }

            if (configuration.Section.SelectSingleNode("authentication") is XmlNode authentication)
            {
                if (authentication.Attributes["type"]?.Value != null)
                {
                    try
                    {
                        this.Authentication = new AuthenticationConfiguration
                        {
                            Type = authentication.Attributes["type"].Value
                        };
                        if (authentication.Attributes["zone"]?.Value != null)
                        {
                            this.Authentication.Parameters.Add("zone", authentication.Attributes["zone"].Value);
                        }
                        if (authentication.Attributes["userName"]?.Value != null)
                        {
                            this.Authentication.Parameters.Add("userName", authentication.Attributes["userName"].Value);
                        }
                        if (authentication.Attributes["password"]?.Value != null)
                        {
                            this.Authentication.Parameters.Add("password", authentication.Attributes["password"].Value);
                        }
                        if (this._logger.IsEnabled(LogLevel.Debug))
                        {
                            this._logger.LogDebug($"Use '{authentication.Attributes["type"].Value}' authentication");
                        }
                    }
                    catch (Exception ex)
                    {
                        this._logger.LogError(ex, $"Unable to load '{authentication.Attributes["type"].Value}' authentication");
                    }
                }
            }

            if (configuration.Section.SelectSingleNode("keyTransformer") is XmlNode keyTransformer)
            {
                if (keyTransformer.Attributes["type"]?.Value != null)
                {
                    try
                    {
                        this._keyTransformer = FastActivator.Create(keyTransformer.Attributes["type"].Value) as IKeyTransformer;
                        if (this._logger.IsEnabled(LogLevel.Debug))
                        {
                            this._logger.LogDebug($"Use '{keyTransformer.Attributes["type"].Value}' key-transformer");
                        }
                    }
                    catch (Exception ex)
                    {
                        this._logger.LogError(ex, $"Unable to load '{keyTransformer.Attributes["type"].Value}' key-transformer");
                    }
                }
            }

            if (configuration.Section.SelectSingleNode("transcoder") is XmlNode transcoder)
            {
                if (transcoder.Attributes["type"]?.Value != null)
                {
                    try
                    {
                        this._transcoder = FastActivator.Create(transcoder.Attributes["type"].Value) as ITranscoder;
                        if (this._logger.IsEnabled(LogLevel.Debug))
                        {
                            this._logger.LogDebug($"Use '{transcoder.Attributes["type"].Value}' transcoder");
                        }
                    }
                    catch (Exception ex)
                    {
                        this._logger.LogError(ex, $"Unable to load '{transcoder.Attributes["type"].Value}' transcoder");
                    }
                }
            }

            if (configuration.Section.SelectSingleNode("nodeLocator") is XmlNode nodeLocator)
            {
                if (nodeLocator.Attributes["type"]?.Value != null)
                {
                    try
                    {
                        this.NodeLocator = Type.GetType(nodeLocator.Attributes["type"].Value);
                        if (this._logger.IsEnabled(LogLevel.Debug))
                        {
                            this._logger.LogDebug($"Use '{nodeLocator.Attributes["type"].Value}' node-locator");
                        }
                    }
                    catch (Exception ex)
                    {
                        this._logger.LogError(ex, $"Unable to load '{nodeLocator.Attributes["type"].Value}' node-locator");
                    }
                }
            }
        }