Example #1
0
 public RabbitMQConfigurator(
     Func <IClaptrapDesign, bool> designFilter,
     IClaptrapBootstrapperBuilder builder)
 {
     _designFilter = designFilter;
     _builder      = builder;
 }
Example #2
0
 /// <summary>
 /// Add types for scanning claptrap modules
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="types"></param>
 /// <returns></returns>
 public static IClaptrapBootstrapperBuilder ScanClaptrapModule(
     this IClaptrapBootstrapperBuilder builder,
     IEnumerable <Type> types)
 {
     builder.Options.ModuleTypes = builder.Options.ModuleTypes.Concat(types);
     return(builder);
 }
Example #3
0
 /// <summary>
 /// Configure builder options.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="configAction"></param>
 /// <returns></returns>
 public static IClaptrapBootstrapperBuilder ConfigureOptions(
     this IClaptrapBootstrapperBuilder builder,
     Action <ClaptrapBootstrapperBuilderOptions> configAction)
 {
     configAction(builder.Options);
     return(builder);
 }
Example #4
0
 public static IClaptrapBootstrapperBuilder ConfigureClaptrapDesignStore(
     this IClaptrapBootstrapperBuilder builder,
     Action <IClaptrapDesignStore> action)
 {
     builder.Options.ClaptrapDesignStoreConfigurators.Add(new FuncClaptrapDesignStoreConfigurator(action));
     return(builder);
 }
 public static IClaptrapBootstrapperBuilder ConfigConnectionStrings(
     this IClaptrapBootstrapperBuilder builder,
     Action <IDictionary <string, string> > connectionStrings)
 {
     connectionStrings(builder.Options.StorageConnectionStrings);
     return(builder);
 }
Example #6
0
 /// <summary>
 /// Set current culture info about claptrap system.
 /// It will change language about all exception and message about claptrap system.
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="cultureInfo"></param>
 /// <returns></returns>
 public static IClaptrapBootstrapperBuilder SetCultureInfo(
     this IClaptrapBootstrapperBuilder builder,
     CultureInfo cultureInfo)
 {
     builder.Options.CultureInfo = cultureInfo;
     return(builder);
 }
 public static IClaptrapBootstrapperBuilder AddConnectionString(
     this IClaptrapBootstrapperBuilder builder,
     string connectionName,
     string connectionString)
 {
     return(builder.ConfigConnectionStrings(dictionary => dictionary[connectionName] = connectionString));
 }
 /// <summary>
 /// Set design validation
 /// </summary>
 /// <returns></returns>
 public static IClaptrapBootstrapperBuilder SetDesignValidation(
     this IClaptrapBootstrapperBuilder builder,
     bool enabled)
 {
     builder.ConfigureOptions(option => { option.ClaptrapDesignStoreValidationOptions.Enabled = enabled; });
     return(builder);
 }
Example #9
0
 public MongoDBProviderConfigurator(
     Func <IClaptrapDesign, bool> designFilter,
     IClaptrapBootstrapperBuilder builder)
 {
     _designFilter = designFilter;
     _builder      = builder;
 }
 public static IClaptrapBootstrapperBuilder UseDeepClonerStateHolder(
     this IClaptrapBootstrapperBuilder builder,
     Func <IClaptrapDesign, bool> predicate)
 => builder.ConfigureClaptrapDesign(
     predicate,
     x =>
     x.StateHolderFactoryType = typeof(DesignBaseEventHandlerFactory));
Example #11
0
 /// <summary>
 /// Use SQLite as storage in testing environment, it is almost ready for small unit test or integration test
 /// </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public static IClaptrapBootstrapperBuilder UseSQLiteAsTestingStorage(
     this IClaptrapBootstrapperBuilder builder)
 {
     return(builder.UseSQLite(sqlite =>
                              sqlite
                              .AsEventStore(evenStore => evenStore.SharedTable())
                              .AsStateStore(stateStore => stateStore.SharedTable())));
 }
Example #12
0
 public static IClaptrapBootstrapperBuilder UseDeepClonerStateHolder(
     this IClaptrapBootstrapperBuilder builder)
 {
     return(builder.ConfigureClaptrapDesign(
                x => true,
                x =>
                x.StateHolderFactoryType = typeof(DesignBaseEventHandlerFactory)));
 }
        public static IClaptrapBootstrapperBuilder UsePostgreSQL(
            this IClaptrapBootstrapperBuilder builder,
            Func <IClaptrapDesign, bool> designFilter,
            Action <PostgreSQLProviderConfigurator> postgreSQL)
        {
            var configurator = new PostgreSQLProviderConfigurator(designFilter, builder);

            postgreSQL(configurator);
            return(builder);
        }
Example #14
0
        public static IClaptrapBootstrapperBuilder UseSQLite(
            this IClaptrapBootstrapperBuilder builder,
            Func <IClaptrapDesign, bool> designFilter,
            Action <SQLiteProviderConfigurator> sqlite)
        {
            var sqLiteProviderConfigurator = new SQLiteProviderConfigurator(designFilter, builder);

            sqlite(sqLiteProviderConfigurator);
            return(builder);
        }
Example #15
0
        public static IClaptrapBootstrapperBuilder UseMySql(
            this IClaptrapBootstrapperBuilder builder,
            Func <IClaptrapDesign, bool> designFilter,
            Action <MySqlProviderConfigurator> mysql)
        {
            var configurator = new MySqlProviderConfigurator(designFilter, builder);

            mysql(configurator);
            return(builder);
        }
Example #16
0
        public static IClaptrapBootstrapperBuilder UseDaprPubsub(
            this IClaptrapBootstrapperBuilder builder,
            Func <IClaptrapDesign, bool> designFilter,
            Action <DaprPubsubConfigurator> rabbitmq)
        {
            var configurator = new DaprPubsubConfigurator(designFilter, builder);

            rabbitmq(configurator);
            return(builder);
        }
Example #17
0
        public static IClaptrapBootstrapperBuilder UseOrleans(
            this IClaptrapBootstrapperBuilder builder,
            Func <IClaptrapDesign, bool> designFilter,
            Action <OrleansConfigurator> orleans)
        {
            var configurator = new OrleansConfigurator(designFilter, builder);

            orleans(configurator);
            return(builder);
        }
        public static IClaptrapBootstrapperBuilder UseMongoDB(
            this IClaptrapBootstrapperBuilder builder,
            Func <IClaptrapDesign, bool> designFilter,
            Action <MongoDBProviderConfigurator> mongoDB)
        {
            var configurator = new MongoDBProviderConfigurator(designFilter, builder);

            mongoDB(configurator);
            return(builder);
        }
Example #19
0
        public static IClaptrapBootstrapperBuilder UseRabbitMQ(
            this IClaptrapBootstrapperBuilder builder,
            Func <IClaptrapDesign, bool> designFilter,
            Action <RabbitMQConfigurator> rabbitmq)
        {
            var rabbitMQConfigurator = new RabbitMQConfigurator(designFilter, builder);

            rabbitmq(rabbitMQConfigurator);
            return(builder);
        }
Example #20
0
        /// <summary>
        /// Add all assemblies related to Claptrap in application bin directory as claptrap module assembly
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IClaptrapBootstrapperBuilder ScanClaptrapModule(
            this IClaptrapBootstrapperBuilder builder)
        {
            AssemblyHelper.ScanAndLoadClaptrapAssemblies(AppDomain.CurrentDomain.BaseDirectory,
                                                         filePath => filePath.Contains("Claptrap"));
            var claptrapAssemblies =
                AppDomain.CurrentDomain.GetAssemblies().Where(x => x.FullName.Contains("Claptrap"));

            builder.ScanClaptrapModule(claptrapAssemblies);
            return(builder);
        }
Example #21
0
 public static void Configure(IClaptrapBootstrapperBuilder builder)
 {
     builder
     .ConfigureClaptrapDesign(
         x => x.ClaptrapOptions.StateSavingOptions == null,
         x => x.ClaptrapOptions.StateSavingOptions = new StateSavingOptions
     {
         SavingWindowTime         = TimeSpan.FromSeconds(10),
         SaveWhenDeactivateAsync  = true,
         SavingWindowVersionLimit = 1000,
     })
     .ConfigureClaptrapDesign(
         x => x.ClaptrapOptions.MinionActivationOptions == null,
         x => x.ClaptrapOptions.MinionActivationOptions = new MinionActivationOptions
     {
         ActivateMinionsAtMasterStart = false
     })
     .ConfigureClaptrapDesign(
         x => x.ClaptrapOptions.EventLoadingOptions == null,
         x => x.ClaptrapOptions.EventLoadingOptions = new EventLoadingOptions
     {
         LoadingCountInOneBatch = 1000
     })
     .ConfigureClaptrapDesign(
         x => x.ClaptrapOptions.StateRecoveryOptions == null,
         x => x.ClaptrapOptions.StateRecoveryOptions = new StateRecoveryOptions
     {
         StateRecoveryStrategy = StateRecoveryStrategy.FromStore
     })
     .ConfigureClaptrapDesign(
         x => x.InitialStateDataFactoryType == null,
         x => x.InitialStateDataFactoryType = typeof(DefaultInitialStateDataFactory))
     .ConfigureClaptrapDesign(
         x => x.StateHolderFactoryType == null,
         x => x.StateHolderFactoryType = typeof(NoChangeStateHolderFactory))
     .ConfigureClaptrapDesign(
         x => x.EventHandlerFactoryFactoryType == null,
         x => x.EventHandlerFactoryFactoryType = typeof(EventHandlerFactoryFactory))
     .ConfigureClaptrapDesign(
         x => x.EventNotifierFactoryType == null,
         x => x.EventNotifierFactoryType = typeof(CompoundEventNotifierFactory))
     .ConfigureClaptrapDesign(
         x => true,
         DisplayInfoFiller.FillDisplayInfo)
     .ConfigureClaptrapDesign(
         x => x.ClaptrapOptions.EventCenterOptions == null,
         x => x.ClaptrapOptions.EventCenterOptions = new EventCenterOptions
     {
         EventCenterType = EventCenterType.None,
     })
     ;
 }
Example #22
0
 public static IClaptrapBootstrapperBuilder ConfigureClaptrapDesign(
     this IClaptrapBootstrapperBuilder builder,
     Action <IClaptrapDesign> action)
 {
     builder.Options.ClaptrapDesignStoreConfigurators.Add(new FuncClaptrapDesignStoreConfigurator(store =>
     {
         foreach (var claptrapDesign in store)
         {
             action(claptrapDesign);
         }
     }));
     return(builder);
 }
        /// <summary>
        /// it will be invoked form HostExtensions
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="storageOptions"></param>
        /// <returns></returns>
        public static IClaptrapBootstrapperBuilder UsePostgreSQLAsEventStore(
            this IClaptrapBootstrapperBuilder builder,
            StorageOptions storageOptions)
        {
            return(builder.UsePostgreSQL(sqlite =>
                                         sqlite.AsEventStore(eventStore =>
            {
                switch (storageOptions.Strategy)
                {
                case RelationLocatorStrategy.SharedTable:
                    eventStore.SharedTable(ConfigMore);
                    break;

                case RelationLocatorStrategy.OneTypeOneTable:
                    eventStore.OneTypeOneTable(ConfigMore);
                    break;

                case RelationLocatorStrategy.OneIdOneTable:
                    eventStore.OneIdOneTable(ConfigMore);
                    break;

                case RelationLocatorStrategy.Known:
                default:
                    eventStore.UseLocator(new RelationalEventStoreLocator
                    {
                        ConnectionName = storageOptions.ConnectionName,
                        SchemaName = storageOptions.SchemaName,
                        EventTableName = storageOptions.TableName
                    }, ConfigMore);
                    break;
                }

                void ConfigMore(PostgreSQLEventStoreOptions options)
                {
                    options.IsAutoMigrationEnabled = storageOptions.IsAutoMigrationEnabled;
                    if (storageOptions.InsertManyWindowTimeInMilliseconds.HasValue)
                    {
                        options.InsertManyWindowTimeInMilliseconds =
                            storageOptions.InsertManyWindowTimeInMilliseconds;
                    }

                    if (storageOptions.InsertManyWindowCount.HasValue)
                    {
                        options.InsertManyWindowCount = storageOptions.InsertManyWindowCount;
                    }
                }
            })));
        }
Example #24
0
        public static IClaptrapBootstrapperBuilder AddConfiguration(
            this IClaptrapBootstrapperBuilder builder,
            IConfiguration configuration)
        {
            var config         = configuration.GetSection(ClaptrapServerOptions.ConfigurationSectionName);
            var claptrapConfig = new ClaptrapServerOptions();

            config.Bind(claptrapConfig);
            builder.AddConnectionString(Defaults.ConnectionName,
                                        claptrapConfig.DefaultConnectionString);
            foreach (var(key, value) in claptrapConfig.ConnectionStrings)
            {
                builder.AddConnectionString(key, value);
            }

            LoadEventStore(builder, claptrapConfig.EventStore);
            LoadStateStore(builder, claptrapConfig.StateStore);
            return(builder);
        }
        /// <summary>
        /// it will be invoked form HostExtensions
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="storageOptions"></param>
        /// <returns></returns>
        public static IClaptrapBootstrapperBuilder UseMongoDBAsEventStore(
            this IClaptrapBootstrapperBuilder builder,
            StorageOptions storageOptions)
        {
            return(builder.UseMongoDB(sqlite =>
                                      sqlite.AsEventStore(eventStore =>
            {
                switch (storageOptions.Strategy)
                {
                case RelationLocatorStrategy.SharedTable:
                    eventStore.SharedCollection(ConfigMore);
                    break;

                case RelationLocatorStrategy.OneTypeOneTable:
                    eventStore.OneTypeOneCollection(ConfigMore);
                    break;

                case RelationLocatorStrategy.OneIdOneTable:
                    eventStore.OneIdOneCollection(ConfigMore);
                    break;

                case RelationLocatorStrategy.Known:
                default:
                    eventStore.UseLocator(new MongoDBEventStoreLocator
                    {
                        ConnectionName = storageOptions.ConnectionName,
                        DatabaseName = storageOptions.SchemaName,
                        EventCollectionName = storageOptions.TableName
                    }, ConfigMore);
                    break;
                }

                void ConfigMore(MongoDBEventStoreOptions options)
                {
                    options.IsAutoMigrationEnabled = storageOptions.IsAutoMigrationEnabled;
                    options.InsertManyWindowTimeInMilliseconds =
                        storageOptions.InsertManyWindowTimeInMilliseconds;
                    options.InsertManyWindowCount = storageOptions.InsertManyWindowCount;
                }
            })));
        }
Example #26
0
        /// <summary>
        /// it will be invoked form HostExtensions
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="storageOptions"></param>
        /// <returns></returns>
        public static IClaptrapBootstrapperBuilder UseSQLiteAsStateStore(
            this IClaptrapBootstrapperBuilder builder,
            StorageOptions storageOptions)
        {
            return(builder.UseSQLite(sqlite =>
                                     sqlite.AsStateStore(stateStore =>
            {
                switch (storageOptions.Strategy)
                {
                case RelationLocatorStrategy.SharedTable:
                    stateStore.SharedTable(ConfigMore);
                    break;

                case RelationLocatorStrategy.OneTypeOneTable:
                    stateStore.OneTypeOneFile(ConfigMore);
                    break;

                case RelationLocatorStrategy.OneIdOneTable:
                    stateStore.OneIdOneFile(ConfigMore);
                    break;

                case RelationLocatorStrategy.Known:
                default:
                    stateStore.UseLocator(new RelationalStateStoreLocator
                    {
                        ConnectionName = storageOptions.ConnectionName,
                        // it is not support to change schema name in SQLite
                        SchemaName = Consts.SQLiteSchemaName,
                        StateTableName = storageOptions.TableName
                    }, ConfigMore);
                    break;
                }

                void ConfigMore(SQLiteStateStoreOptions options)
                {
                    options.IsAutoMigrationEnabled = storageOptions.IsAutoMigrationEnabled;
                }
            })));
        }
Example #27
0
        private static void LoadEventStore(IClaptrapBootstrapperBuilder builder, StorageOptions options)
        {
            switch (options.DatabaseType)
            {
            case DatabaseType.SQLite:
            case DatabaseType.PostgreSQL:
            case DatabaseType.MySql:
            case DatabaseType.MongoDB:
                Assembly.Load($"Newbe.Claptrap.StorageProvider.{options.DatabaseType:G}");
                InvokeFactory();
                break;

            case DatabaseType.Known:
                return;

            default:
                throw new ArgumentOutOfRangeException(nameof(options), "unsupported database type");
            }

            void InvokeFactory()
            {
                var methodName = $"Use{options.DatabaseType}AsEventStore";
                var method     = AppDomain.CurrentDomain.GetAssemblies()
                                 .Where(x => x.FullName.StartsWith("Newbe.Claptrap"))
                                 .SelectMany(x => x.GetTypes())
                                 .Where(x => x.Namespace == "Newbe.Claptrap.Bootstrapper" &&
                                        x.Name.Contains("BootstrapperBuilderExtensions") && x.GetMethod(methodName) != null)
                                 .Select(x => x.GetMethod(methodName))
                                 .FirstOrDefault();

                Debug.Assert(method != null,
                             "method != null failed",
                             "failed to find method {0}, please add the specific data storage assembly",
                             methodName);
                method.Invoke(null, new object[] { builder, options });
            }
        }
Example #28
0
 public static IClaptrapBootstrapperBuilder UseOrleans(
     this IClaptrapBootstrapperBuilder builder,
     Action <OrleansConfigurator> orleans)
 {
     return(builder.UseOrleans(x => true, orleans));
 }
 public static IClaptrapBootstrapperBuilder UseMongoDB(
     this IClaptrapBootstrapperBuilder builder,
     Action <MongoDBProviderConfigurator> mongoDB)
 {
     return(builder.UseMongoDB(x => true, mongoDB));
 }
Example #30
0
 public static IClaptrapBootstrapperBuilder UseRabbitMQ(
     this IClaptrapBootstrapperBuilder builder,
     Action <RabbitMQConfigurator> rabbitmq)
 {
     return(builder.UseRabbitMQ(x => true, rabbitmq));
 }