コード例 #1
0
        protected override async Task <SetStreamMetadataResult> SetStreamMetadataInternal(
            string streamId,
            int expectedStreamMetadataVersion,
            int?maxAge,
            int?maxCount,
            string metadataJson,
            CancellationToken cancellationToken)
        {
            MsSqlAppendResult result;

            using (var connection = _createConnection())
            {
                var streamIdInfo = new StreamIdInfo(streamId);

                await connection.OpenAsync(cancellationToken).NotOnCapturedContext();

                using (var transaction = connection.BeginTransaction())
                {
                    var metadataMessage = new MetadataMessage
                    {
                        StreamId = streamId,
                        MaxAge   = maxAge,
                        MaxCount = maxCount,
                        MetaJson = metadataJson
                    };
                    var json      = SimpleJson.SerializeObject(metadataMessage);
                    var messageId = MetadataMessageIdGenerator.Create(
                        streamId,
                        expectedStreamMetadataVersion,
                        json);
                    var newmessage = new NewStreamMessage(messageId, "$stream-metadata", json);

                    result = await AppendToStreamInternal(
                        connection,
                        transaction,
                        streamIdInfo.MetadataSqlStreamId,
                        expectedStreamMetadataVersion,
                        new[] { newmessage },
                        cancellationToken);

                    using (var command = new SqlCommand(_scripts.SetStreamMetadata, connection, transaction))
                    {
                        command.Parameters.Add(new SqlParameter("streamId", SqlDbType.Char, 42)
                        {
                            Value = streamIdInfo.SqlStreamId.Id
                        });
                        command.Parameters.AddWithValue("streamIdOriginal", streamIdInfo.SqlStreamId.IdOriginal);
                        command.Parameters.Add("maxAge", SqlDbType.Int);
                        command.Parameters["maxAge"].Value = maxAge ?? -1;
                        command.Parameters.Add("maxCount", SqlDbType.Int);
                        command.Parameters["maxCount"].Value = maxCount ?? -1;
                        await command.ExecuteNonQueryAsync(cancellationToken);
                    }

                    transaction.Commit();
                }
            }

            await CheckStreamMaxCount(streamId, maxCount, cancellationToken);

            return(new SetStreamMetadataResult(result.CurrentVersion));
        }
コード例 #2
0
ファイル: CommandLog.cs プロジェクト: zedr0n/ZES
 private void LogCommands(NewStreamMessage message)
 {
     _log.Debug(message.JsonData);
 }