/// <summary>
        /// Extension on <see cref="SqlServerStreamConfig"/> to build a <see cref="SqlStream"/>.
        /// </summary>
        /// <param name="streamConfig">The stream configuration object.</param>
        /// <param name="serializerFactory">The serializer factory.</param>
        /// <returns>A <see cref="SqlStream"/>.</returns>
        public static SqlStream ToStream(
            this SqlServerStreamConfig streamConfig,
            ISerializerFactory serializerFactory)
        {
            streamConfig.MustForArg(nameof(streamConfig)).NotBeNull();
            serializerFactory.MustForArg(nameof(serializerFactory)).NotBeNull();

            if (streamConfig.AllLocators.Count != 1)
            {
                throw new NotSupportedException(Invariant($"One single resource locators are currently supported and '{streamConfig.AllLocators.Count}' were provided."));
            }

            var resourceLocatorProtocol = new SingleResourceLocatorProtocols(streamConfig.AllLocators.Single());

            var result = new SqlStream(
                streamConfig.Name,
                streamConfig.DefaultConnectionTimeout,
                streamConfig.DefaultCommandTimeout,
                streamConfig.DefaultSerializerRepresentation,
                streamConfig.DefaultSerializationFormat,
                serializerFactory,
                resourceLocatorProtocol);

            return(result);
        }
예제 #2
0
        private SqlStream GetCreatedSqlStream(
            TimeSpan?commandTimeout = null,
            RecordTagAssociationManagementStrategy recordTagAssociationManagementStrategy = RecordTagAssociationManagementStrategy.AssociatedDuringPutInSprocInTransaction,
            int?maxConcurrentHandlingCount = null,
            SerializationFormat defaultSerializationFormat = SerializationFormat.Binary)
        {
            var sqlServerLocator        = GetSqlServerLocator();
            var resourceLocatorProtocol = new SingleResourceLocatorProtocols(sqlServerLocator);

            var defaultSerializerRepresentation = GetSerializerRepresentation();

            var stream = new SqlStream(
                this.streamName,
                TimeSpan.FromMinutes(1),
                commandTimeout ?? TimeSpan.FromMinutes(3),
                defaultSerializerRepresentation,
                defaultSerializationFormat,
                new JsonSerializerFactory(),
                resourceLocatorProtocol);

            stream.Execute(new StandardCreateStreamOp(stream.StreamRepresentation, ExistingStreamStrategy.Skip));
            stream.Execute(new UpdateStreamStoredProceduresOp(recordTagAssociationManagementStrategy, maxConcurrentHandlingCount));

            return(stream);
        }
예제 #3
0
        public void CreateStreamExampleDatabaseAndScripts()
        {
            var sqlServerLocator = new SqlServerLocator("localhost", "StreamExample3", "sa", "<password>", "SQLDEV2017");
            var configuration    = SqlServerDatabaseDefinition.BuildDatabaseConfigurationUsingDefaultsAsNecessary(sqlServerLocator.DatabaseName, @"D:\SQL\");
            var createDatabaseOp = new CreateDatabaseOp(configuration, ExistingDatabaseStrategy.Throw);
            var protocol         = new SqlOperationsProtocol(sqlServerLocator);

            protocol.Execute(createDatabaseOp);

            var resourceLocatorProtocol = new SingleResourceLocatorProtocols(sqlServerLocator);

            var configurationTypeRepresentation = typeof(NullJsonSerializationConfiguration).ToRepresentation();

            SerializerRepresentation defaultSerializerRepresentation = new SerializerRepresentation(
                SerializationKind.Json,
                configurationTypeRepresentation);

            var defaultSerializationFormat = SerializationFormat.String;
            var stream = new SqlStream(
                "Example",
                TimeSpan.FromMinutes(1),
                TimeSpan.FromMinutes(3),
                defaultSerializerRepresentation,
                defaultSerializationFormat,
                new JsonSerializerFactory(),
                resourceLocatorProtocol);

            stream.Execute(new StandardCreateStreamOp(stream.StreamRepresentation, ExistingStreamStrategy.Skip));

            this.testOutputHelper.WriteLine("Created database.");

            /*
             * var path = "D:/Temp/Example";
             * var connectionString = sqlServerLocator.BuildConnectionString(TimeSpan.FromSeconds(20));
             * Scripter.ScriptDatabaseToFilePath(connectionString, path, this.testOutputHelper.WriteLine, false);
             */
        }
        private static Streams BuildStreamsAsync(
            string streamRootDirectoryPath)
        {
            var serializerRepresentation = new SerializerRepresentation(SerializationKind.Json, typeof(IntegrationTestJsonSerializationConfiguration).ToRepresentation());
            var serializerFactory        = new JsonSerializerFactory();
            var resourceLocatorProtocols = new SingleResourceLocatorProtocols(new FileSystemDatabaseLocator(streamRootDirectoryPath));

            var clientOperationStream   = new FileStandardStream("client-operation", serializerRepresentation, SerializationFormat.String, serializerFactory, resourceLocatorProtocols);
            var notificationEventStream = new FileStandardStream("notification-event", serializerRepresentation, SerializationFormat.String, serializerFactory, resourceLocatorProtocols);
            var notificationSagaStream  = new FileStandardStream("notification-saga", serializerRepresentation, SerializationFormat.String, serializerFactory, resourceLocatorProtocols);
            var emailOperationStream    = new FileStandardStream("email-operation", serializerRepresentation, SerializationFormat.String, serializerFactory, resourceLocatorProtocols);
            var emailEventStream        = new FileStandardStream("email-event", serializerRepresentation, SerializationFormat.String, serializerFactory, resourceLocatorProtocols);
            var slackOperationStream    = new FileStandardStream("slack-operation", serializerRepresentation, SerializationFormat.String, serializerFactory, resourceLocatorProtocols);
            var slackEventStream        = new FileStandardStream("slack-event", serializerRepresentation, SerializationFormat.String, serializerFactory, resourceLocatorProtocols);

            clientOperationStream.Execute(new StandardCreateStreamOp(clientOperationStream.StreamRepresentation, ExistingStreamStrategy.Skip));
            notificationEventStream.Execute(new StandardCreateStreamOp(notificationEventStream.StreamRepresentation, ExistingStreamStrategy.Skip));
            notificationSagaStream.Execute(new StandardCreateStreamOp(notificationSagaStream.StreamRepresentation, ExistingStreamStrategy.Skip));
            emailOperationStream.Execute(new StandardCreateStreamOp(emailOperationStream.StreamRepresentation, ExistingStreamStrategy.Skip));
            emailEventStream.Execute(new StandardCreateStreamOp(emailEventStream.StreamRepresentation, ExistingStreamStrategy.Skip));
            slackOperationStream.Execute(new StandardCreateStreamOp(slackOperationStream.StreamRepresentation, ExistingStreamStrategy.Skip));
            slackEventStream.Execute(new StandardCreateStreamOp(slackEventStream.StreamRepresentation, ExistingStreamStrategy.Skip));

            var result = new Streams
            {
                ClientOperationStream   = clientOperationStream,
                NotificationEventStream = notificationEventStream,
                NotificationSagaStream  = notificationSagaStream,
                EmailOperationStream    = emailOperationStream,
                EmailEventStream        = emailEventStream,
                SlackOperationStream    = slackOperationStream,
                SlackEventStream        = slackEventStream,
            };

            return(result);
        }