public ISnapshotRestore Deserialize(ICommitedSnapshot commitedSnapshot)
        {
            var metadata = _textSerializer.Deserialize <Metadata>(commitedSnapshot.SerializedMetadata);

            var snapshotClrType = metadata.GetValue(MetadataKeys.SnapshotClrType, (value) => value.ToString());

            var snapshot = (ISnapshot)_textSerializer.Deserialize(commitedSnapshot.SerializedData, snapshotClrType);

            return(new SnapshotRestore(commitedSnapshot.AggregateId, commitedSnapshot.AggregateVersion, snapshot, metadata));
        }
Example #2
0
        public async Task <ICommitedSnapshot> GetLatestSnapshotByIdAsync(Guid aggregateId)
        {
            var command = Connection.CreateCommand();

            command.CommandText = "SELECT AggregateId, Version, Body, Metadatas FROM Snapshots WHERE AggregateId = @AggregateId ORDER BY Version DESC LIMIT 1";
            command.Parameters.AddWithValue("@AggregateId", aggregateId);

            EnsureOpenedConnection();

            ICommitedSnapshot snapshot = null;

            using (command)
                using (var sqlReader = await command.ExecuteReaderAsync().ConfigureAwait(false))
                {
                    while (await sqlReader.ReadAsync())
                    {
                        snapshot = new SqliteCommitedSnapshot(sqlReader.GetGuid(0), sqlReader.GetInt32(1), sqlReader.GetString(2), sqlReader.GetString(3));
                        break;
                    }
                }

            return(snapshot);
        }