Beispiel #1
0
        public static (bool wasSuccessful, string errorReason) TryCreate(ResourceProviderConfig config, out IResourceProvider resourceProvider)
        {
            resourceProvider = null;

            if (Enum.TryParse <ResourceProviderType>(config.Type, out var configType))
            {
                switch (configType)
                {
                case ResourceProviderType.Database:
                    var(worked, errorReason) = DatabaseResourceFactory.TryCreate(config, out var databaseResourceProvider);

                    if (!worked)
                    {
                        return(worked, errorReason);
                    }
                    resourceProvider = databaseResourceProvider;

                    return(worked, errorReason);
                }
            }
            else
            {
                return(false, "Resource type could not be parsed.");
            }

            return(false, null);
        }
Beispiel #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)}");
        }