Beispiel #1
0
        static void Main(string[] args)
        {
            string connectionString = ConnectionStrings.Get();

            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.Is(connectionString));

            DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration)
                                             .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

            dd.Drop();
            Console.WriteLine("Database dropped.");
            Thread.Sleep(1000);

            dd.Create();
            Console.WriteLine("Database created.");

            ISession session = sessionFactory.OpenSession();

            using (ITransaction tx = session.BeginTransaction())
            {
                dd.Seed(new List <IDataSeeder>
                {
                    new AccountSeeder(session),
                });
                tx.Commit();
            }
            session.Close();
            sessionFactory.Close();
            Console.WriteLine("Seed data added.");
            Thread.Sleep(2000);
        }
        public void Run()
        {
            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.Is(ConnectionStrings.Get()));

            container.Register(c => { return(c.Resolve <ISessionFactory>().OpenSession()); }).As
            <ISession>()
            .InstancePerLifetimeScope()
            .OnActivating(c =>
            {
                if (!c.Instance.Transaction.IsActive)
                {
                    c.Instance.BeginTransaction();
                }
            }
                          )
            .OnRelease(c =>
            {
                if (c.Transaction.IsActive)
                {
                    c.Transaction.Commit();
                }
                c.Dispose();
            });

            container.Register(c =>
                               new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration).Build())
            .SingleInstance()
            .As <ISessionFactory>();
        }
        protected override IFileStorage GetStorage()
        {
            if (String.IsNullOrEmpty(ConnectionStrings.Get("AzureStorageConnectionString")))
            {
                return(null);
            }

            return(new AzureFileStorage(ConnectionStrings.Get("AzureStorageConnectionString")));
        }
Beispiel #4
0
        protected override IFileStorage GetStorage()
        {
            if (ConnectionStrings.Get("AzureStorageConnectionString") == null)
            {
                return(null);
            }

            return(new AzureFileStorage(ConnectionStrings.Get("AzureStorageConnectionString")));
        }
Beispiel #5
0
        public static ISessionFactory CreateSessionFactory()
        {
            string             connectionString      = ConnectionStrings.Get();
            MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                       ConnectionString(x => x.Is(connectionString));
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration).Build();

            return(sessionFactory);
        }
Beispiel #6
0
        protected override ICacheClient GetCacheClient()
        {
            if (ConnectionStrings.Get("AzureConnectionString") == null)
            {
                return(null);
            }

            //var muxer = ConnectionMultiplexer.Connect(ConnectionStrings.Get("AzureConnectionString"));
            //return new RedisCacheClient(muxer);
            return(null);
        }
        public void GetConnectionString_NameProvided_ReturnsConnectionString()
        {
            // Arrange
            var name           = "TestDb";
            var expectedResult = "Server=.;Database=TestDb;Trusted_Connection=true;";

            // Act
            var result = ConnectionStrings.Get(name);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }
        public void GetConnectionString_NoNameProvided_ThrowsException()
        {
            // Arrange
            var name           = string.Empty;
            var expectedResult = string.Empty;

            // Act
            var result = ConnectionStrings.Get(name);

            // Assert
            Assert.AreEqual(expectedResult, result);
        }
        public static ConnectionMultiplexer GetMuxer()
        {
            if (ConnectionStrings.Get("RedisConnectionString") == null)
            {
                return(null);
            }

            if (_muxer == null)
            {
                _muxer = ConnectionMultiplexer.Connect(ConnectionStrings.Get("RedisConnectionString"));
            }

            return(_muxer);
        }
Beispiel #10
0
        protected override IMessageBus GetMessageBus()
        {
            if (_messageBus != null)
            {
                return(_messageBus);
            }

            if (String.IsNullOrEmpty(ConnectionStrings.Get("ServiceBusConnectionString")))
            {
                return(null);
            }

            _messageBus = new AzureServiceBusMessageBus(ConnectionStrings.Get("ServiceBusConnectionString"), Guid.NewGuid().ToString("N"), loggerFactory: Log);

            return(_messageBus);
        }
        protected override IMessageBus GetMessageBus()
        {
            if (_messageBus != null)
            {
                return(_messageBus);
            }

            if (ConnectionStrings.Get("ServiceBusConnectionString") == null)
            {
                return(null);
            }

            _messageBus = new ServiceBusMessageBus(ConnectionStrings.Get("ServiceBusConnectionString"), Guid.NewGuid().ToString("N"));

            return(_messageBus);
        }
Beispiel #12
0
        public static ConnectionMultiplexer GetMuxer()
        {
            if (ConnectionStrings.Get("RedisConnectionString") == null)
            {
                return(null);
            }

            if (_muxer == null)
            {
                _muxer = ConnectionMultiplexer.Connect(ConnectionStrings.Get("RedisConnectionString"));
            }

            _muxer.PreserveAsyncOrder = false;

            return(_muxer);
        }
Beispiel #13
0
        private static void Main(string[] args)
        {
            try
            {
                string connectionString = ConnectionStrings.Get();

                MsSqlConfiguration databaseConfiguration = MsSqlConfiguration.MsSql2008.ShowSql().
                                                           ConnectionString(x => x.Is(connectionString));

                DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
                ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration)
                                                 .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

                dd.Drop();
                Console.WriteLine("Database dropped.");
                Thread.Sleep(1000);

                dd.Create();
                Console.WriteLine("Database created.");

                ISession session = sessionFactory.OpenSession();
                using (ITransaction tx = session.BeginTransaction())
                {
                    dd.Seed(new List <IDataSeeder>
                    {
                        new UserSeeder(session),
                        new ProjectEntitySeeder(session),
                        new UserTypeEntitySeeder(session),
                        new UserHistoryEntitySeeder(session)
                    });
                    tx.Commit();
                }
                session.Close();
                sessionFactory.Close();
                Console.WriteLine("Seed data added.");
                Thread.Sleep(2000);
            }
            catch (Exception ex)
            {
                String innerMessage = (ex.InnerException != null)
                              ? ex.InnerException.Message
                              : "";
                Console.WriteLine(ex.Message);
                Console.WriteLine(innerMessage);
                string n = Console.ReadLine();
            }
        }
Beispiel #14
0
        protected override IQueue <SimpleWorkItem> GetQueue(int retries = 1, TimeSpan?workItemTimeout = null, TimeSpan?retryDelay = null, int deadLetterMaxItems = 100, bool runQueueMaintenance = true)
        {
            if (String.IsNullOrEmpty(ConnectionStrings.Get("ServiceBusConnectionString")))
            {
                return(null);
            }

            if (!retryDelay.HasValue)
            {
                retryDelay = TimeSpan.Zero;
            }

            var maxBackoff = retryDelay.Value > TimeSpan.Zero
                ? retryDelay.Value + retryDelay.Value
                : TimeSpan.FromSeconds(1);
            var retryPolicy = new RetryExponential(retryDelay.Value, maxBackoff, retries + 1);

            return(new AzureServiceBusQueue <SimpleWorkItem>(ConnectionStrings.Get("ServiceBusConnectionString"),
                                                             QueueName, retries, workItemTimeout, false, retryPolicy, loggerFactory: Log));
        }
        protected override IQueue <SimpleWorkItem> GetQueue(int retries = 1, TimeSpan?workItemTimeout = null, TimeSpan?retryDelay = null, int deadLetterMaxItems = 100)
        {
            if (ConnectionStrings.Get("ServiceBusConnectionString") == null)
            {
                return(null);
            }

            if (!retryDelay.HasValue)
            {
                retryDelay = TimeSpan.Zero;
            }

            var maxBackoff = retryDelay.Value > TimeSpan.Zero
                ? retryDelay.Value + retryDelay.Value
                : TimeSpan.FromSeconds(1);
            var retryPolicy = new RetryExponential(retryDelay.Value, maxBackoff, retries + 1);

            return(new ServiceBusQueue <SimpleWorkItem>(ConnectionStrings.Get("ServiceBusConnectionString"),
                                                        QueueName, retries, workItemTimeout, false, retryPolicy));
        }
Beispiel #16
0
        protected override IQueue <SimpleWorkItem> GetQueue(int retries = 1, TimeSpan?workItemTimeout = null, TimeSpan?retryDelay = null, int deadLetterMaxItems = 100, bool runQueueMaintenance = true)
        {
            if (String.IsNullOrEmpty(ConnectionStrings.Get("StorageConnectionString")))
            {
                return(null);
            }

            if (!retryDelay.HasValue)
            {
                retryDelay = TimeSpan.Zero;
            }

            return(new AzureStorageQueue <SimpleWorkItem>(
                       ConnectionStrings.Get("StorageConnectionString"),
                       QueueName,
                       retries,
                       workItemTimeout,
                       TimeSpan.FromMilliseconds(50),
                       new ExponentialRetry(retryDelay.Value, retries + 1),
                       loggerFactory: Log
                       ));
        }
        public static void Configure(IConfiguration config, IServiceCollection services)
        {
            // Connection factory must be able to create a new connection for each region.
            // ... For now we only have one region.
            var eventStoreRegionXUri = ConnectionStrings.Get(config).EventStoreRegionX;
            var eventStoreUris       = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { Shared.Constants.DEFAULT_REGION_ID, eventStoreRegionXUri }
            };

            var settings = EventSourcingSettings.Get(config);

            services.AddSingleton <IStreamClientFactory>(
                sp =>
            {
                return(new EventStoreStreamClientFactory(
                           sp.GetRequiredService <IStandardLogger <EventStoreStreamClientFactory> >(),
                           eventStoreUris, settings.StreamReadBatchSize, settings.ReconnectDelaySeconds));
            }
                );
            services.AddSingleton <IStreamIdBuilder, EventSourcing.StreamIdBuilder>();
        }
Beispiel #18
0
 public void GetConnectionString()
 {
     var conn = ConnectionStrings.Get("mongodb39911");
 }
Beispiel #19
0
        // ***
        // Everything below this line configures specific aggregate roots.
        // ***

        private static void ConfigureEmailBuilder(IServiceCollection services, IConfiguration config)
        {
            ConfigureGenericAggregateRoot <Domain.EmailBuilder.EmailBuilderAggregate, Domain.EmailBuilder.EmailBuilderState>(services);

            services.AddDbContext <Domain.EmailBuilder.StateModels.EmailBuilderDbContext>(o => o.UseSqlServer(ConnectionStrings.Get(config).AggRootStatesDb));

            services.AddScoped <Domain.EmailBuilder.EmailBuilderStateFactory>(
                sp => new Domain.EmailBuilder.EmailBuilderStateFactory(
                    sp.GetRequiredService <AggregateRootStateBusinessEventResolver <Domain.EmailBuilder.EmailBuilderState> >(),
                    (regionId) =>
            {
                // If supporting multiple regions then return db context based on region id given.
                // if (string.Equals(regionId, "RegionA", StringComparison.OrdinalIgnoreCase)) return sp.GetRequiredService<RegionAEmailBuilderDbContext>();
                // if (string.Equals(regionId, "RegionB", StringComparison.OrdinalIgnoreCase)) return sp.GetRequiredService<RegionBEmailBuilderDbContext>();
                // return null;
                return(sp.GetRequiredService <Domain.EmailBuilder.StateModels.EmailBuilderDbContext>());
            }
                    )
                );

            services.AddScoped <IAggregateRootStateRepo <Domain.EmailBuilder.EmailBuilderState> >(
                sp => new Domain.EmailBuilder.EmailBuilderStateRepo(
                    sp.GetRequiredService <IStreamClientFactory>(),
                    sp.GetRequiredService <Domain.EmailBuilder.EmailBuilderStateFactory>()
                    )
                );
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            args = args.Select(x => x.ToLower()).ToArray();
            bool noArgs = !args.Any();

            ConnectionStringSettings connectionStringSettings = ConnectionStrings.Get();
            MsSqlConfiguration       databaseConfiguration    =
                MsSqlConfiguration.MsSql2008.ShowSql().ConnectionString(
                    x => x.Is(connectionStringSettings.ConnectionString))
                .Dialect <MsSqlAzureDialect>();

            CreateDatabaseIfNotExists(connectionStringSettings);

            DomainDrivenDatabaseDeployer.DatabaseDeployer dd = null;
            ISessionFactory sessionFactory = new SessionFactoryBuilder(new MappingScheme(), databaseConfiguration, new EntityInterceptor())
                                             .Build(cfg => { dd = new DomainDrivenDatabaseDeployer.DatabaseDeployer(cfg); });

            if (noArgs || args.Contains("drop"))
            {
                using (ISession sess = sessionFactory.OpenSession())
                {
                    using (IDbCommand cmd = sess.Connection.CreateCommand())
                    {
                        cmd.ExecuteSqlFile("dropForeignKeys.sql");
                        //cmd.ExecuteSqlFile("dropPrimaryKeys.sql");
                        cmd.ExecuteSqlFile("dropTables.sql");
                    }
                }
                dd.Drop();
                Console.WriteLine("");
                Console.WriteLine("Database dropped.");
            }

            if (noArgs || args.Contains("create"))
            {
                dd.Create();
                Console.WriteLine("");
                Console.WriteLine("Database created.");
            }
            else if (args.Contains("update"))
            {
                dd.Update();
                Console.WriteLine("");
                Console.WriteLine("Database updated.");
            }

            if (noArgs || args.Contains("seed"))
            {
                ISession session = sessionFactory.OpenSession();
                using (ITransaction tx = session.BeginTransaction())
                {
                    dd.Seed(new List <IDataSeeder>
                    {
                        //add data seeders here.
                        new UserSeeder(session)
                    });
                    tx.Commit();
                }
                session.Close();
                sessionFactory.Close();
                Console.WriteLine("");
                Console.WriteLine("Seed data added.");
            }

            Console.WriteLine("Done");
        }
Beispiel #21
0
        public static void Configure(IConfiguration config, IServiceCollection services)
        {
            services.AddSingleton <ISubscriberFactory, SubscriberFactory>();

            // EmailQueue
            AddDbContextScopeFactory <Projections.EmailReport.EmailReportDb.EmailReportDbContext>(services);
            services.AddDbContext <Projections.EmailReport.EmailReportDb.EmailReportDbContext>(o => o.UseSqlServer(ConnectionStrings.Get(config).ProjectionsDb));
            services.AddSingleton <Projections.EmailReport.EmailReportProjector>(sp => (Projections.EmailReport.EmailReportProjector)BuildProjector <Projections.EmailReport.EmailReportProjector>(sp, config));
            services.AddHostedService <ProjectorHostedService <Projections.EmailReport.EmailReportProjector> >();

            // SalesReport
            AddDbContextScopeFactory <Projections.SalesReport.SalesReportDb.SalesReportDbContext>(services);
            services.AddDbContext <Projections.SalesReport.SalesReportDb.SalesReportDbContext>(o => o.UseSqlServer(ConnectionStrings.Get(config).ProjectionsDb));
            services.AddSingleton <Projections.SalesReport.SalesReportProjector>(sp => (Projections.SalesReport.SalesReportProjector)BuildProjector <Projections.SalesReport.SalesReportProjector>(sp, config));
            services.AddHostedService <ProjectorHostedService <Projections.SalesReport.SalesReportProjector> >();
        }