Exemple #1
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="reader">TBD</param>
        /// <returns>TBD</returns>
        protected virtual IPersistentRepresentation ReadEvent(DbDataReader reader)
        {
            var persistenceId = reader.GetString(PersistenceIdIndex);
            var sequenceNr    = reader.GetInt64(SequenceNrIndex);
            var timestamp     = reader.GetInt64(TimestampIndex);
            var isDeleted     = reader.GetBoolean(IsDeletedIndex);
            var manifest      = reader.GetString(ManifestIndex);
            var payload       = reader[PayloadIndex];

            object deserialized;

            if (reader.IsDBNull(SerializerIdIndex))
            {
                // Support old writes that did not set the serializer id
                var type         = Type.GetType(manifest, true);
                var deserializer = Serialization.FindSerializerForType(type, Configuration.DefaultSerializer);
                // TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
                deserialized = Akka.Serialization.Serialization.WithTransport(
                    Serialization.System, (deserializer, (byte[])payload, type),
                    (state) =>
                {
                    return(state.deserializer.FromBinary(state.Item2,
                                                         state.type));
                });
                //deserialized = Akka.Serialization.Serialization.WithTransport(Serialization.System, () => deserializer.FromBinary((byte[])payload, type) );
            }
            else
            {
                var serializerId = reader.GetInt32(SerializerIdIndex);
                // TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
                deserialized = Serialization.Deserialize((byte[])payload, serializerId, manifest);
            }

            return(new Persistent(deserialized, sequenceNr, persistenceId, manifest, isDeleted, ActorRefs.NoSender, null, timestamp));
        }
Exemple #2
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="reader">TBD</param>
        /// <returns>TBD</returns>
        protected virtual IPersistentRepresentation ReadEvent(DbDataReader reader)
        {
            var persistenceId = reader.GetString(PersistenceIdIndex);
            var sequenceNr    = reader.GetInt64(SequenceNrIndex);
            var timestamp     = reader.GetInt64(TimestampIndex);
            var isDeleted     = reader.GetBoolean(IsDeletedIndex);
            var manifest      = reader.GetString(ManifestIndex);
            var payload       = reader[PayloadIndex];

            object deserialized;

            if (reader.IsDBNull(SerializerIdIndex))
            {
                // Support old writes that did not set the serializer id
                var type         = Type.GetType(manifest, true);
                var deserializer = Serialization.FindSerializerForType(type, Configuration.DefaultSerializer);
                deserialized = deserializer.FromBinary((byte[])payload, type);
            }
            else
            {
                var serializerId = reader.GetInt32(SerializerIdIndex);
                deserialized = Serialization.Deserialize((byte[])payload, serializerId, manifest);
            }

            return(new Persistent(deserialized, sequenceNr, persistenceId, manifest, isDeleted, ActorRefs.NoSender, null));
        }
Exemple #3
0
        protected object GetSnapshot(SnapshotRow reader)
        {
            var manifest = reader.Manifest;
            var binary   = (byte[])reader.Payload;

            object obj;

            if (reader.SerializerId == null)
            {
                var type = Type.GetType(manifest, true);
                // TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
                obj = Akka.Serialization.Serialization.WithTransport(
                    _serialization.System,
                    (serializer: _serialization.FindSerializerForType(type, _config.DefaultSerializer),
                     binary, type),
                    (state) => state.serializer.FromBinary(state.binary, state.type));
            }
            else
            {
                var serializerId = reader.SerializerId.Value;
                obj = _serialization.Deserialize(binary, serializerId, manifest);
            }

            return(obj);
        }
Exemple #4
0
        private SequencedOnNext DeserializeSequenceOnNext(byte[] bytes)
        {
            var onNext  = Proto.Msg.SequencedOnNext.Parser.ParseFrom(bytes);
            var p       = onNext.Payload;
            var payload = _serialization.Deserialize(
                p.EnclosedMessage.ToByteArray(),
                p.SerializerId,
                p.MessageManifest?.ToStringUtf8());

            return(new SequencedOnNext(onNext.SeqNr, payload));
        }
Exemple #5
0
        private SelectedSnapshot ToSelectedSnapshot(SnapshotEntry entry)
        {
            var legacy = entry.SerializerId.HasValue || !string.IsNullOrEmpty(entry.Manifest);

            if (!legacy)
            {
                var ser      = _serialization.FindSerializerForType(typeof(Serialization.Snapshot));
                var snapshot = ser.FromBinary <Serialization.Snapshot>((byte[])entry.Snapshot);
                return(new SelectedSnapshot(new SnapshotMetadata(entry.PersistenceId, entry.SequenceNr), snapshot.Data));
            }

            int? serializerId = null;
            Type type         = null;

            // legacy serialization
            if (!entry.SerializerId.HasValue && !string.IsNullOrEmpty(entry.Manifest))
            {
                type = Type.GetType(entry.Manifest, true);
            }
            else
            {
                serializerId = entry.SerializerId;
            }

            if (entry.Snapshot is byte[] bytes)
            {
                object deserialized;

                if (serializerId.HasValue)
                {
                    deserialized = _serialization.Deserialize(bytes, serializerId.Value, entry.Manifest);
                }
                else
                {
                    var deserializer = _serialization.FindSerializerForType(type);
                    deserialized = deserializer.FromBinary(bytes, type);
                }

                if (deserialized is Serialization.Snapshot snap)
                {
                    return(new SelectedSnapshot(
                               new SnapshotMetadata(entry.PersistenceId, entry.SequenceNr, new DateTime(entry.Timestamp)), snap.Data));
                }

                return(new SelectedSnapshot(
                           new SnapshotMetadata(entry.PersistenceId, entry.SequenceNr, new DateTime(entry.Timestamp)), deserialized));
            }

            // backwards compat - loaded an old snapshot using BSON serialization. No need to deserialize via Akka.NET
            return(new SelectedSnapshot(
                       new SnapshotMetadata(entry.PersistenceId, entry.SequenceNr, new DateTime(entry.Timestamp)), entry.Snapshot));
        }
Exemple #6
0
        private Persistent ToPersistenceRepresentation(JournalEntry entry, IActorRef sender)
        {
            var legacy = entry.SerializerId.HasValue || !string.IsNullOrEmpty(entry.Manifest);

            if (!legacy)
            {
                var ser = _serialization.FindSerializerForType(typeof(Persistent));
                return(ser.FromBinary <Persistent>((byte[])entry.Payload));
            }

            int? serializerId = null;
            Type type         = null;

            // legacy serialization
            if (!entry.SerializerId.HasValue && !string.IsNullOrEmpty(entry.Manifest))
            {
                type = Type.GetType(entry.Manifest, true);
            }
            else
            {
                serializerId = entry.SerializerId;
            }

            if (entry.Payload is byte[] bytes)
            {
                object deserialized = null;
                if (serializerId.HasValue)
                {
                    deserialized = _serialization.Deserialize(bytes, serializerId.Value, entry.Manifest);
                }
                else
                {
                    var deserializer = _serialization.FindSerializerForType(type);
                    deserialized = deserializer.FromBinary(bytes, type);
                }

                if (deserialized is Persistent p)
                {
                    return(p);
                }

                return(new Persistent(deserialized, entry.SequenceNr, entry.PersistenceId, entry.Manifest, entry.IsDeleted, sender));
            }
            else // backwards compat for object serialization - Payload was already deserialized by BSON
            {
                return(new Persistent(entry.Payload, entry.SequenceNr, entry.PersistenceId, entry.Manifest,
                                      entry.IsDeleted, sender));
            }
        }
Exemple #7
0
        protected override Try <(IPersistentRepresentation, IImmutableSet <string>, long)> Deserialize(JournalRow t)
        {
            try
            {
                //object deserialized = null;
                var identifierMaybe = t.Identifier;
                if (identifierMaybe.HasValue == false)
                {
                    var type = System.Type.GetType(t.manifest, true);

                    // TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811

                    return(new Try <(IPersistentRepresentation, IImmutableSet <string>
                                     , long)>((
                                                  new Persistent(Akka.Serialization.Serialization.WithTransport(
                                                                     _serializer.System, (_serializer.FindSerializerForType(type, _journalConfig.DefaultSerializer), t.message, type),
                                                                     (state) =>
                    {
                        return state.Item1.FromBinary(
                            state.message, state.type);
                    }), t.sequenceNumber,
                                                                 t.persistenceId,
                                                                 t.manifest, t.deleted, ActorRefs.NoSender, null, t.Timestamp),
                                                  t.tags?.Split(_separatorArray,
                                                                StringSplitOptions.RemoveEmptyEntries)
                                                  .ToImmutableHashSet() ?? ImmutableHashSet <string> .Empty,
                                                  t.ordering)));
                }
                else
                {
                    return(new Try <(IPersistentRepresentation, IImmutableSet <string>
                                     , long)>((
                                                  new Persistent(_serializer.Deserialize(t.message,
                                                                                         identifierMaybe.Value, t.manifest), t.sequenceNumber,
                                                                 t.persistenceId,
                                                                 t.manifest, t.deleted, ActorRefs.NoSender, null, t.Timestamp),
                                                  t.tags?.Split(_separatorArray,
                                                                StringSplitOptions.RemoveEmptyEntries)
                                                  .ToImmutableHashSet() ?? ImmutableHashSet <string> .Empty,
                                                  t.ordering)));
                    // TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
                }
            }
            catch (Exception e)
            {
                return(new Try <(IPersistentRepresentation, IImmutableSet <string>
                                 , long)>(e));
            }
        }
Exemple #8
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="reader">TBD</param>
        /// <returns>TBD</returns>
        protected object GetSnapshot(DbDataReader reader)
        {
            var manifest = reader.GetString(3);
            var binary   = (byte[])reader[4];

            object obj;

            if (reader.IsDBNull(5))
            {
                var type       = Type.GetType(manifest, true);
                var serializer = Serialization.FindSerializerForType(type, Configuration.DefaultSerializer);
                obj = serializer.FromBinary(binary, type);
            }
            else
            {
                var serializerId = reader.GetInt32(5);
                obj = Serialization.Deserialize(binary, serializerId, manifest);
            }

            return(obj);
        }
Exemple #9
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="reader">TBD</param>
        /// <returns>TBD</returns>
        protected object GetSnapshot(DbDataReader reader)
        {
            var manifest = reader.GetString(3);
            var binary   = (byte[])reader[4];

            object obj;

            if (reader.IsDBNull(5))
            {
                var type = Type.GetType(manifest, true);
                // TODO: hack. Replace when https://github.com/akkadotnet/akka.net/issues/3811
                var serializer = Serialization.FindSerializerForType(type, Configuration.DefaultSerializer);
                obj = Akka.Serialization.Serialization.WithTransport(Serialization.System, () => serializer.FromBinary(binary, type));
            }
            else
            {
                var serializerId = reader.GetInt32(5);
                obj = Serialization.Deserialize(binary, serializerId, manifest);
            }

            return(obj);
        }
        protected override IPersistentRepresentation ReadEvent(DbDataReader reader)
        {
            var persistenceId = reader.GetString(PersistenceIdIndex);
            var sequenceNr    = reader.GetInt64(SequenceNrIndex);
            var isDeleted     = Convert.ToBoolean(reader.GetInt16(IsDeletedIndex));
            var manifest      = reader.GetString(ManifestIndex).Trim(); // HACK
            var payload       = reader[PayloadIndex];

            object deserialized;

            if (reader.IsDBNull(SerializerIdIndex))
            {
                var type         = Type.GetType(manifest, true);
                var deserializer = serialization.FindSerializerForType(type, Setup.DefaultSerializer);
                deserialized = deserializer.FromBinary((byte[])payload, type);
            }
            else
            {
                var serializerId = reader.GetInt32(SerializerIdIndex);
                deserialized = serialization.Deserialize((byte[])payload, serializerId, manifest);
            }

            return(new Persistent(deserialized, sequenceNr, persistenceId, manifest, isDeleted, ActorRefs.NoSender));
        }