示例#1
0
        public void TryParse_Parses()
        {
            var parsed = InMemoryKeyValProvider.TryParse("address=127.0.0.1;name=in_mem_key_val_store");

            parsed.Should().NotBeNull();
            parsed.Address.Should().Be("127.0.0.1");
            parsed.Name.Should().Be("in_mem_key_val_store");
        }
示例#2
0
        public static (bool wasSuccessful, string errorReason) TryCreate(ResourceProviderConfig config, out IDatabaseResourceProvider provider)
        {
            provider = null;

            if (string.IsNullOrEmpty(config.SubType))
            {
                return(false, "no subtype provided");
            }

            if (Enum.TryParse(typeof(DatabaseResourceProviderConfigSubtype), config.SubType.ToLower(), out var subtype))
            {
                switch (subtype)
                {
                case DatabaseResourceProviderConfigSubtype.in_memory_key_value:
                    provider = new InMemoryKeyValProvider
                    {
                        ConnectionString = config.ConnectionString     // this will be a service name for a connected cluster.
                    };
                    break;

                case DatabaseResourceProviderConfigSubtype.sqlserver:
                    provider = new MsSqlDbResourceProvider
                    {
                        ConnectionString = config.ConnectionString     // the connection string will be a TCP binding
                    };
                    break;

                case DatabaseResourceProviderConfigSubtype.redis:
                    provider = new RedisDbResourceProvider
                    {
                        ConnectionString = config.ConnectionString     // this will be an https connection string
                    };
                    break;

                default:
                    return(false, $"subtype {config.SubType} is invalid.");
                }

                return(true, null);
            }



            return(false, errorReason : $"subtype {config.SubType} is invalid. All valid subtypes for {config.Type} are {string.Join(",",AvailableSubTypes)}");
        }