Esempio n. 1
0
        /// <summary>
        /// Deserialize the byte array into NsMessage.
        /// </summary>
        /// <param name="data">The serialized byte array</param>
        /// <returns>The deserialized NsMessage</returns>
        public NsMessage <T> Decode(byte[] data)
        {
            using (var stream = new MemoryStream(data))
            {
                NsMessageProto proto = Serializer.Deserialize <NsMessageProto>(stream);

                IIdentifier   sourceId = _idFactory.Create(proto.SourceId);
                IIdentifier   destId   = _idFactory.Create(proto.DestId);
                NsMessage <T> message  = new NsMessage <T>(sourceId, destId);

                var messages = proto.Data.Select(byteArr => _codec.Decode(byteArr));
                message.Data.AddRange(messages);
                return(message);
            }
        }
Esempio n. 2
0
        protected AggregateRootBase(IRecorder recorder, IIdentifierFactory idFactory,
                                    Func <Identifier, IChangeEvent> createdEventFactory) : this(recorder, idFactory,
                                                                                                Identifier.Empty())
        {
            createdEventFactory.GuardAgainstNull(nameof(createdEventFactory));

            Id = idFactory.Create(this);
            RaiseCreateEvent(createdEventFactory(Id));
        }
Esempio n. 3
0
        private Tuple <NsMessage <T>, int, Type> GenerateMetaDataDecoding(byte[] obj)
        {
            int srcCount     = BitConverter.ToInt32(obj, 0);
            int dstCount     = BitConverter.ToInt32(obj, sizeof(int));
            int msgTypeCount = BitConverter.ToInt32(obj, 2 * sizeof(int));

            int    offset    = 3 * sizeof(int);
            string srcString = BytesToString(obj.Skip(offset).Take(srcCount).ToArray());

            offset += srcCount;
            string dstString = BytesToString(obj.Skip(offset).Take(dstCount).ToArray());

            offset += dstCount;
            Type msgType = Type.GetType(BytesToString(obj.Skip(offset).Take(msgTypeCount).ToArray()));

            offset += msgTypeCount;
            int messageCount = BitConverter.ToInt32(obj, offset);

            NsMessage <T> msg = new NsMessage <T>(_idFactory.Create(srcString), _idFactory.Create(dstString));

            return(new Tuple <NsMessage <T>, int, Type>(msg, messageCount, msgType));
        }
        /// <summary>
        /// Read the class fields.
        /// </summary>
        /// <param name="reader">The reader from which to read </param>
        public void Read(IDataReader reader)
        {
            SourceId = _factory.Create(reader.ReadString());
            DestId   = _factory.Create(reader.ReadString());
            int    messageCount = reader.ReadInt32();
            string dataType     = reader.ReadString();

            Data = new List <T>();

            for (int index = 0; index < messageCount; index++)
            {
                var dataPoint = (T)_injection.ForkInjector().GetInstance(Type.GetType(dataType));

                if (null == dataPoint)
                {
                    throw new Exception("T type instance cannot be created from the stream data in Network Service Message");
                }

                dataPoint.Read(reader);
                Data.Add(dataPoint);
            }
        }
Esempio n. 5
0
        protected EntityBase(ILogger logger, IIdentifierFactory idFactory)
        {
            logger.GuardAgainstNull(nameof(logger));
            idFactory.GuardAgainstNull(nameof(idFactory));
            Logger    = logger;
            IdFactory = idFactory;
            Id        = idFactory.Create(this);

            var now = DateTime.UtcNow;

            LastPersistedAtUtc = null;
            CreatedAtUtc       = now;
            LastModifiedAtUtc  = now;
        }
Esempio n. 6
0
        protected EntityBase(IRecorder recorder, IIdentifierFactory idFactory)
        {
            recorder.GuardAgainstNull(nameof(recorder));
            idFactory.GuardAgainstNull(nameof(idFactory));
            Recorder  = recorder;
            IdFactory = idFactory;
            Id        = idFactory.Create(this);

            var now = DateTime.UtcNow;

            LastPersistedAtUtc = null;
            IsDeleted          = null;
            CreatedAtUtc       = now;
            LastModifiedAtUtc  = now;
        }
Esempio n. 7
0
        /// <summary>
        /// Send the GroupCommunicationMessage to the Task whose name is
        /// included in the message.
        /// </summary>
        /// <param name="message">The message to send.</param>
        public void Send(GeneralGroupCommunicationMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (string.IsNullOrEmpty(message.Destination))
            {
                throw new ArgumentException("Message destination cannot be null or empty");
            }

            IIdentifier destId = _idFactory.Create(message.Destination);
            var         conn   = _networkService.NewConnection(destId);

            conn.Open();
            conn.Write(message);
        }
 public void Create_Should_Create_Id_With_Six_Characters() => _factory.Create().Length.Should().Be(6);
 protected PersistableEntityBase(IRecorder recorder, IIdentifierFactory idFactory)
     : this(recorder, idFactory, Identifier.Empty())
 {
     Id = idFactory.Create(this);
 }
Esempio n. 10
0
        public void SetIdentifier(IIdentifierFactory factory)
        {
            factory.GuardAgainstNull(nameof(factory));

            Id = factory.Create(this);
        }
Esempio n. 11
0
 private TestEntity(IIdentifierFactory idFactory)
 {
     Id = idFactory.Create(this);
 }