Esempio n. 1
0
    private static void SetupSchema(IDocumentStore documentStore, MartenConfig martenConfig, int retryLeft = 1)
    {
        try
        {
            if (martenConfig.ShouldRecreateDatabase)
            {
                documentStore.Advanced.Clean.CompletelyRemoveAll();
            }

            using (NoSynchronizationContextScope.Enter())
            {
                documentStore.Schema.ApplyAllConfiguredChangesToDatabaseAsync().Wait();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            if (retryLeft == 0)
            {
                throw;
            }

            Thread.Sleep(1000);
            SetupSchema(documentStore, martenConfig, --retryLeft);
        }
    }
Esempio n. 2
0
    private static void SetStoreOptions(StoreOptions options, MartenConfig config,
                                        Action <StoreOptions> configureOptions = null)
    {
        options.Connection(config.ConnectionString);
        options.AutoCreateSchemaObjects = AutoCreate.CreateOrUpdate;

        var schemaName = Environment.GetEnvironmentVariable("SchemaName");

        options.Events.DatabaseSchemaName = schemaName ?? config.WriteModelSchema;
        options.DatabaseSchemaName        = schemaName ?? config.ReadModelSchema;

        options.UseDefaultSerialization(nonPublicMembersStorage: NonPublicMembersStorage.NonPublicSetters,
                                        enumStorage: EnumStorage.AsString);
        options.Projections.AsyncMode = config.DaemonMode;

        configureOptions?.Invoke(options);
    }