static void Main(string[] args)
        {
            var migrator = new Migrator();
            var dbConnectionString = "DbContext.ConferenceManagement";

            var settings = InfrastructureSettings.Read("Settings.xml");
            var eventSourcingSettings = settings.EventSourcing;
            var eventSourcingAccount = CloudStorageAccount.Parse(eventSourcingSettings.ConnectionString);
            var originalEventStoreName = "ConferenceEventStore"; // should use the real one. No longer in the updated Settings.xml
            var newEventStoreName = eventSourcingSettings.TableName;
            var messageLogSettings = settings.MessageLog;
            var messageLogAccount = CloudStorageAccount.Parse(messageLogSettings.ConnectionString);

            migrator.GeneratePastEventLogMessagesForConferenceManagement(
                messageLogAccount.CreateCloudTableClient(),
                messageLogSettings.TableName,
                dbConnectionString,
                new StandardMetadataProvider(),
                new JsonTextSerializer());
            migrator.MigrateEventSourcedAndGeneratePastEventLogs(
                messageLogAccount.CreateCloudTableClient(),
                messageLogSettings.TableName,
                eventSourcingAccount.CreateCloudTableClient(),
                originalEventStoreName,
                eventSourcingAccount.CreateCloudTableClient(),
                newEventStoreName,
                new StandardMetadataProvider(),
                new JsonTextSerializer());

            var logReader = new AzureEventLogReader(messageLogAccount, messageLogSettings.TableName, new JsonTextSerializer());
            migrator.RegenerateViewModels(logReader, dbConnectionString);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var migrator = new Migrator();
            var dbConnectionString = "DbContext.ConferenceManagement";

            var settings = InfrastructureSettings.Read("Settings.xml");
            var messageLogSettings = settings.MessageLog;
            var messageLogAccount = CloudStorageAccount.Parse(messageLogSettings.ConnectionString);
            var blobStorageAccount = CloudStorageAccount.Parse(settings.BlobStorage.ConnectionString);

            DatabaseSetup.Initialize();
            MigrationToV3.Migration.Initialize();


            Console.WriteLine("Creating new read model subscriptions");

            migrator.CreateV3ReadModelSubscriptions(settings.ServiceBus);

            Console.WriteLine("Creating new read model tables");

            migrator.CreateV3ReadModelTables(ConfigurationManager.ConnectionStrings[dbConnectionString].ConnectionString);

            Console.WriteLine("Waiting to let the new subscriptions fill up with events. This will take {0:F0} minutes.", WaitTime.TotalMinutes);

            Thread.Sleep(WaitTime);

            Console.WriteLine("Replaying events to regenerate read models");

            var logReader = new AzureEventLogReader(messageLogAccount, messageLogSettings.TableName, new JsonTextSerializer());
            var blobStorage = new CloudBlobStorage(blobStorageAccount, settings.BlobStorage.RootContainerName);

            var maxEventTime = DateTime.UtcNow.Subtract(TimeSpan.FromSeconds(WaitTime.TotalSeconds / 2));

            migrator.RegenerateV3ViewModels(logReader, blobStorage, dbConnectionString, maxEventTime);

            Console.WriteLine("Set the MaintenanceMode flag to true in the worker role for v2 through the Windows Azure portal, but let the websites keep running. Make sure that the status for the worker role is updated before continuing.");
            Console.WriteLine("Press enter to start processing events.");
            Console.ReadLine();

            using (var processor = new ConferenceProcessor(false))
            {
                processor.Start();

                Console.WriteLine("Started processing events to keep the v2 read models up to date, so there is no downtime until v3 starts functioning.");
                Console.WriteLine("Set the MaintenanceMode flag to false in all the v3 roles. Once you verify that the v3 roles are working correctly in the Staging area, you can do a VIP swap so the public website points to v3.");
                Console.WriteLine("Press enter to finish and stop processing v2 read models (only do this once v3 is in the Production slot). You can also stop the v2 deployment that should be in the Staging slot after the VIP swap");
                Console.ReadLine();

                processor.Stop();
            }
        }
Esempio n. 3
0
        public given_an_empty_event_log()
        {
            this.tableName = "AzureEventLogFixture" + new Random((int)DateTime.Now.Ticks).Next();
            var settings = InfrastructureSettings.Read("Settings.xml").EventSourcing;
            this.account = CloudStorageAccount.Parse(settings.ConnectionString);

            this.eventA = new EventA();
            this.eventB = new EventB();
            this.eventC = new EventC();

            this.metadata = Mock.Of<IMetadataProvider>(x =>
                x.GetMetadata(eventA) == new Dictionary<string, string>
                {
                    { StandardMetadata.SourceId, eventA.SourceId.ToString() },
                    { StandardMetadata.SourceType, "SourceA" }, 
                    { StandardMetadata.Kind, StandardMetadata.EventKind },
                    { StandardMetadata.AssemblyName, "A" }, 
                    { StandardMetadata.Namespace, "Namespace" }, 
                    { StandardMetadata.FullName, "Namespace.EventA" }, 
                    { StandardMetadata.TypeName, "EventA" }, 
                } &&
                x.GetMetadata(eventB) == new Dictionary<string, string>
                {
                    { StandardMetadata.SourceId, eventB.SourceId.ToString() },
                    { StandardMetadata.SourceType, "SourceB" }, 
                    { StandardMetadata.Kind, StandardMetadata.EventKind },
                    { StandardMetadata.AssemblyName, "B" }, 
                    { StandardMetadata.Namespace, "Namespace" }, 
                    { StandardMetadata.FullName, "Namespace.EventB" }, 
                    { StandardMetadata.TypeName, "EventB" }, 
                } &&
                x.GetMetadata(eventC) == new Dictionary<string, string>
                {
                    { StandardMetadata.SourceId, eventC.SourceId.ToString() },
                    { StandardMetadata.SourceType, "SourceC" }, 
                    { StandardMetadata.Kind, StandardMetadata.EventKind },
                    { StandardMetadata.AssemblyName, "B" }, 
                    { StandardMetadata.Namespace, "AnotherNamespace" }, 
                    { StandardMetadata.FullName, "AnotherNamespace.EventC" }, 
                    { StandardMetadata.TypeName, "EventC" }, 
                });

            this.serializer = new JsonTextSerializer();
            this.writer = new AzureMessageLogWriter(this.account, this.tableName);
            this.sut = new AzureEventLogReader(this.account, this.tableName, new JsonTextSerializer());

            this.startEnqueueTime = new DateTime(2012, 06, 30, 23, 59, 0, DateTimeKind.Utc);
            Save(eventA, startEnqueueTime);
            Save(eventB, startEnqueueTime.AddMinutes(5));
            Save(eventC, startEnqueueTime.AddMinutes(6));
        }
Esempio n. 4
0
        public void RegenerateV3ViewModels(AzureEventLogReader logReader, IBlobStorage blobStorage, string dbConnectionString, DateTime maxEventTime)
        {
            Database.SetInitializer<ConferenceRegistrationDbContext>(null);

            var handlers = new List<IEventHandler>();
            handlers.Add(new DraftOrderViewModelGenerator(() => new ConferenceRegistrationDbContext(dbConnectionString)));
            handlers.Add(new PricedOrderViewModelGenerator(() => new ConferenceRegistrationDbContext(dbConnectionString)));
            handlers.Add(
                new SeatAssignmentsViewModelGenerator(
                    new ConferenceDao(() => new ConferenceRegistrationDbContext(dbConnectionString)),
                    blobStorage,
                    new JsonTextSerializer()));

            var dispatcher = new EventDispatcher(handlers);
            var events = logReader.Query(new QueryCriteria { EndDate = maxEventTime });

            dispatcher.DispatchMessages(events);
        }
        public void RegenerateViewModels(AzureEventLogReader logReader, string dbConnectionString)
        {
            var commandBus = new NullCommandBus();

            Database.SetInitializer<ConferenceRegistrationDbContext>(null);

            var handlers = new List<IEventHandler>();
            handlers.Add(new ConferenceViewModelGenerator(() => new ConferenceRegistrationDbContext(dbConnectionString), commandBus));
            handlers.Add(new PricedOrderViewModelUpdater(() => new ConferenceRegistrationDbContext(dbConnectionString)));

            using (var context = new ConferenceRegistrationMigrationDbContext(dbConnectionString))
            {
                context.UpdateTables();
            }

            try
            {
                var dispatcher = new MessageDispatcher(handlers);
                var events = logReader.Query(new QueryCriteria { });

                dispatcher.DispatchMessages(events);
            }
            catch
            {
                using (var context = new ConferenceRegistrationMigrationDbContext(dbConnectionString))
                {
                    context.RollbackTablesMigration();
                }

                throw;
            }
        }