コード例 #1
0
    private async Task <int> LoadSnapshot(string streamName, AggregateRootSnapshot snapshotAggregate)
    {
        var snapshotEnvelope = await _store.LoadSnapshot(streamName);

        if (snapshotEnvelope != null)
        {
            snapshotAggregate.LoadSnapshot(snapshotEnvelope.Snapshot, snapshotEnvelope.Metadata.Version);
            return(snapshotEnvelope.Metadata.Version + 1);
        }

        return(-1);
    }
コード例 #2
0
        /// <summary>
        /// Saves the snapshot.
        /// </summary>
        /// <param name="aggregateType">Type of the aggregate.</param>
        /// <param name="snapshot">The snapshot.</param>
        public void SaveSnapshot(Type aggregateType, AggregateRootSnapshot snapshot)
        {
            var snapshotType = snapshot.GetType();
            var snapshotBlob = _serializer.WriteObject(snapshotType, snapshot);

            using (var connection = new SqlConnection(_connectionString))
            {
                var sql     = string.Format(@"
With _Target As (
	Select *
	From dbo.[{0}]
		Where (AggregateID = @id)
        And (AggregateType = @aType)
)
Merge _Target
Using (
	Select @id As AggregateID, @aType as AggregateType, @sequence as LastEventSequence,
    @type As Type, @blob As Blob) As _Source
On (_Target.AggregateID = _Source.AggregateID)
And (_Target.AggregateType = _Source.AggregateType)
When Matched Then
	Update Set Type = _Source.Type, Blob = _Source.Blob
When Not Matched By Target Then
	Insert (AggregateID, AggregateType, Type, Blob)
	Values (_Source.AggregateID, _Source.AggregateType, _Source.Type, _Source.Blob);"    , _tableName);
                var command = new SqlCommand(sql, connection)
                {
                    CommandType = CommandType.Text
                };
                command.Parameters.AddRange(new[] {
                    new SqlParameter {
                        ParameterName = "@id", SqlDbType = SqlDbType.NVarChar, Value = snapshot.AggregateID
                    },
                    new SqlParameter {
                        ParameterName = "@aType", SqlDbType = SqlDbType.NVarChar, Value = aggregateType.AssemblyQualifiedName
                    },
                    new SqlParameter {
                        ParameterName = "@sequence", SqlDbType = SqlDbType.Int, Value = snapshot.LastEventSequence
                    },
                    new SqlParameter {
                        ParameterName = "@type", SqlDbType = SqlDbType.NVarChar, Value = snapshotType.AssemblyQualifiedName
                    },
                    new SqlParameter {
                        ParameterName = "@blob", SqlDbType = SqlDbType.NVarChar, Value = snapshotBlob
                    }
                });
                connection.Open();
                command.ExecuteNonQuery();
            }
        }
コード例 #3
0
 /// <summary>
 /// Saves the snapshot.
 /// </summary>
 /// <param name="aggregateType">Type of the aggregate.</param>
 /// <param name="snapshot">The snapshot.</param>
 public void SaveSnapshot(Type aggregateType, AggregateRootSnapshot snapshot)
 {
     _snapshots.Add(snapshot);
 }
コード例 #4
0
 /// <summary>
 /// Saves the snapshot.
 /// </summary>
 /// <param name="aggregateType">Type of the aggregate.</param>
 /// <param name="snapshot">The snapshot.</param>
 public void SaveSnapshot(Type aggregateType, AggregateRootSnapshot snapshot)
 {
     throw new NotImplementedException();
 }