示例#1
0
        private CacheInfo GetCacheInfo(PortalCacheSettingsDto cacheSettingsDto, out CacheProviders provider)
        {
            provider = CacheProviders.Memory;
            if (!Enum.TryParse(cacheSettingsDto.CacheProvider, out provider))
            {
                throw new ValidationException($"{provider} is not supported");
            }

            CacheInfo result = null;

            if (provider == CacheProviders.Redis)
            {
                var cacheProvider = _cacheProviderResolver();
                if (string.IsNullOrWhiteSpace(cacheSettingsDto.CacheHost))
                {
                    throw new ValidationException("Host cannot be an empty string");
                }
                result = new CacheInfo(CacheProviders.Redis, cacheSettingsDto.CacheHost, cacheSettingsDto.CachePort,
                                       cacheSettingsDto.CacheUseSsl, cacheSettingsDto.CachePassword);
            }
            else
            {
                result = new CacheInfo(CacheProviders.Memory, "", 0);
            }
            return(result);
        }
示例#2
0
 public CacheInfo(
     CacheProviders provider,
     string host,
     int port,
     bool ssl               = false,
     string password        = null,
     int?db                 = null,
     string client          = null,
     int?connectTimeout     = null,
     int?sendTimeout        = null,
     int?receiveTimeout     = null,
     int?idleTimeOutSecs    = null,
     string namespacePrefix = null) : this(provider)
 {
     Host            = host;
     Port            = port;
     Ssl             = ssl;
     Password        = password;
     Db              = db;
     Client          = client;
     ConnectTimeout  = connectTimeout;
     SendTimeout     = sendTimeout;
     ReceiveTimeout  = receiveTimeout;
     IdleTimeOutSecs = idleTimeOutSecs;
     NamespacePrefix = namespacePrefix;
 }
示例#3
0
        /// <summary>
        ///		Obtiene un proveedor de base de datos
        /// </summary>
        private IDbProvider GetDbProvider(ConnectionModel connection)
        {
            IDbProvider provider = CacheProviders.GetProvider(connection);

            // Si no se ha encontrado el proveedor en el diccionario, se crea uno ...
            if (provider == null)
            {
                // Crea el proveedor
                switch (connection.Type)
                {
                case ConnectionModel.ConnectionType.Spark:
                    provider = new SparkProvider(new SparkConnectionString(connection.Parameters.ToDictionary()));
                    break;

                case ConnectionModel.ConnectionType.SqlServer:
                    provider = new LibDbProviders.SqlServer.SqlServerProvider(new LibDbProviders.SqlServer.SqlServerConnectionString(connection.Parameters.ToDictionary()));
                    break;

                case ConnectionModel.ConnectionType.Odbc:
                    provider = new LibDbProviders.ODBC.OdbcProvider(new LibDbProviders.ODBC.OdbcConnectionString(connection.Parameters.ToDictionary()));
                    break;

                default:
                    throw new ArgumentOutOfRangeException($"Cant find provider for '{connection.Name}'");
                }
                // Abre el proveedor
                provider.Open();
                // Lo añade a la caché
                CacheProviders.Add(connection, provider);
            }
            // Devuelve el proveedor
            return(provider);
        }
示例#4
0
        public CacheInfo CreateInfo(CacheProviders provider, string connectionString)
        {
            switch (provider)
            {
            case CacheProviders.Memory:
                return(new CacheInfo(provider));

            case CacheProviders.Redis:
                return(RedisCache.CreateInfo(connectionString));

            default:
                throw new NotSupportedException($"{provider} cache provider is not supported");
            }
        }
示例#5
0
        public CacheEngine(CacheProviders Provider, string DataPath)
        {
            switch (Provider)
            {
            case CacheProviders.Default:
                cacheProvider = new STSdbCache(DataPath);
                break;

            case CacheProviders.Raw:
                cacheProvider = new RawCache(DataPath);
                break;

            default:
                break;
            }
        }
示例#6
0
 public bool TryConnect(CacheProviders provider, string connectionString, out string errorMessage)
 {
     errorMessage = "";
     if (provider == CacheProviders.Redis)
     {
         try
         {
             ConnectionMultiplexer.Connect(connectionString);
         }
         catch (Exception ex)
         {
             errorMessage = ex.Message;
             return(false);
         }
     }
     return(true);
 }
示例#7
0
 public CacheInfo(CacheProviders provider)
 {
     Provider = provider;
 }