public void when_attribute_not_contains_and_get_default_value()
        {
            var immutableEnvelope = new ImmutableEnvelope("id", DateTime.UtcNow, new object(), new[] { new MessageAttribute("attr1", "val1"), });
            var attributeVal = immutableEnvelope.GetAttribute("attr2", "default");

            Assert.AreEqual("default", attributeVal);
        }
        static MyContext BuildContextOnTheFly(ImmutableEnvelope envelope, ImmutableMessage item)
        {
            var messageId = string.Format("[{0}]-{1}", envelope.EnvelopeId, item.Index);
            var token     = envelope.GetAttribute("token", "");

            return(new MyContext(messageId, token, envelope.CreatedOnUtc));
        }
        public void when_get_attribute()
        {
            var immutableEnvelope = new ImmutableEnvelope("id", DateTime.UtcNow, new object(), new[] { new MessageAttribute("attr1", "val1"), });
            var attributeVal = immutableEnvelope.GetAttribute("attr1");

            Assert.AreEqual("val1", attributeVal);
        }
示例#4
0
 public void HandleAll(ImmutableEnvelope envelope)
 {
     // we allow multiple handlers
     foreach (var message in envelope.Items)
     {
         Handle(message.Content);
     }
 }
        public void DispatchMessage(ImmutableEnvelope message)
        {
            var entity = message.GetAttribute("to-entity", "");
            if (string.IsNullOrEmpty(entity))
                throw new InvalidOperationException("Message without entity address arrived to this dispatcher");

            var commands = message.Items.Select(i => (ICommand)i.Content);

            Dispatch(entity, commands);
        }
        public void when_create_instance()
        {
            var date = DateTime.UtcNow;
            var immutableEnvelope = new ImmutableEnvelope("id", date, new List<string>(), new[] { new MessageAttribute("attr1", "val1"), });

            Assert.AreEqual("id", immutableEnvelope.EnvelopeId);
            Assert.AreEqual(date, immutableEnvelope.CreatedUtc);
            Assert.AreEqual(1, immutableEnvelope.Attributes.Count);
            Assert.IsTrue(immutableEnvelope.Message.GetType() == typeof(List<string>));
        }
示例#7
0
 string GenerateSha1HashFromContent(object message, MessageAttribute[] attributes)
 {
     // we need to set ID and date to fixed
     var envelope = new ImmutableEnvelope("", default(DateTime), message, attributes);
     var data = _streamer.SaveEnvelopeData(envelope);
     using (var sha1 = new SHA1Managed())
     {
         var hash = sha1.ComputeHash(data);
         return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
     }
 }
 static void CallHandlers(RedirectToDynamicEvent functions, ImmutableEnvelope aem)
 {
     if (aem.Items.Length != 1)
         throw new InvalidOperationException(
             "Unexpected number of items in envelope that arrived to projections: " +
                 aem.Items.Length);
     // we wire envelope contents to both direct message call and sourced call (with date wrapper)
     var content = aem.Items[0].Content;
     functions.InvokeEvent(content);
     functions.InvokeEvent(Source.For(aem.EnvelopeId, aem.CreatedOnUtc, (IRecipeEvent) content));
 }
示例#9
0
        string GenerateSha1HashFromContent(object message, MessageAttribute[] attributes)
        {
            // we need to set ID and date to fixed
            var envelope = new ImmutableEnvelope("", default(DateTime), message, attributes);
            var data     = _streamer.SaveEnvelopeData(envelope);

            using (var sha1 = new SHA1Managed())
            {
                var hash = sha1.ComputeHash(data);
                return(BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant());
            }
        }
示例#10
0
        public void RecordMessage(string key, ImmutableEnvelope envelope)
        {
            // record properties as attributes
            var attribs = new List <MessageAttribute>(envelope.Attributes.Count + 2)
            {
                new MessageAttribute("id", envelope.EnvelopeId),
                new MessageAttribute("utc", envelope.CreatedUtc.ToString("o"))
            };

            // copy existing attributes
            attribs.AddRange(envelope.Attributes);
            AppendToStore(key, attribs, -1, new[] { envelope.Message });
        }
示例#11
0
        public void Send(object message, string envelopeId, params MessageAttribute[] attributes)
        {
            var envelope = new ImmutableEnvelope(envelopeId, DateTime.UtcNow, message, attributes);
            var data     = _streamer.SaveEnvelopeData(envelope);

            _queue.PutMessage(data);

            SystemObserver.Notify(new EnvelopeSent(
                                      _queue.Name,
                                      envelope.EnvelopeId,
                                      envelope.Message.GetType().Name,
                                      envelope.Attributes));
        }
示例#12
0
        public void Send(object message, string envelopeId, params MessageAttribute[] attributes)
        {
            var envelope = new ImmutableEnvelope(envelopeId, DateTime.UtcNow, message, attributes);
            var data = _streamer.SaveEnvelopeData(envelope);

            _queue.PutMessage(data);

            SystemObserver.Notify(new EnvelopeSent(
                _queue.Name,
                envelope.EnvelopeId,
                envelope.Message.GetType().Name,
                envelope.Attributes));
        }
 public void when_attributes_null()
 {
     var immutableEnvelope = new ImmutableEnvelope("id", DateTime.UtcNow, new List<string>(), null);
     
     CollectionAssert.AreEquivalent(MessageAttribute.Empty, immutableEnvelope.Attributes);
 }