Ejemplo n.º 1
0
        bool IWriterRule.TryToApply(RouteChain chain)
        {
            var customWriters = _serializers.CustomWritersFor(chain.ResourceType);

            if (customWriters.Length == 1)
            {
                chain.Writer = customWriters.Single();
                chain.Postprocessors.Add(new UseWriter(chain, true));
            }
            else if (customWriters.Length > 1)
            {
                chain.ConnegWriter = _serializers.WriterFor(chain.ResourceType);
                var selectWriter = new SelectWriter();
                chain.Middleware.Add(selectWriter);
                chain.Middleware.Add(new CheckForMissing(406, selectWriter.ReturnVariable));
                chain.Middleware.Add(new UseWriter(chain, false));
            }
            else
            {
                chain.Writer = _serializers.JsonWriterFor(chain.ResourceType);
                chain.Postprocessors.Add(new UseWriter(chain, true));
            }

            return(true);
        }
        public async Task ScheduleMessage(Envelope envelope)
        {
            if (envelope.Message == null)
            {
                throw new ArgumentOutOfRangeException(nameof(envelope), "Envelope.Message is required");
            }

            if (!envelope.ExecutionTime.HasValue)
            {
                throw new ArgumentOutOfRangeException(nameof(envelope), "No value for ExecutionTime");
            }

            if (envelope.Data == null || envelope.Data.Length == 0)
            {
                var writer = _serializers.JsonWriterFor(envelope.Message.GetType());
                envelope.Data        = writer.Write(envelope.Message);
                envelope.ContentType = writer.ContentType;
            }

            envelope.Status  = TransportConstants.Scheduled;
            envelope.OwnerId = TransportConstants.AnyNode;
            using (var session = _store.LightweightSession())
            {
                session.StoreIncoming(_marker, envelope);
                await session.SaveChangesAsync();
            }
        }
Ejemplo n.º 3
0
 private void writeMessageData(Envelope envelope)
 {
     if (envelope.Data == null || envelope.Data.Length == 0)
     {
         var writer = _serializers.JsonWriterFor(envelope.Message.GetType());
         envelope.Data        = writer.Write(envelope.Message);
         envelope.ContentType = writer.ContentType;
     }
 }
Ejemplo n.º 4
0
        private Envelope buildAcknowledgement()
        {
            var ack = new Envelope
            {
                ParentId    = Envelope.Id,
                Destination = Envelope.ReplyUri,
                ResponseId  = Envelope.Id,
                SagaId      = Envelope.SagaId,
                Message     = new Acknowledgement {
                    CorrelationId = Envelope.Id
                },
                Route = new MessageRoute(typeof(Acknowledgement), Envelope.ReplyUri, "application/json")
                {
                    Channel = _channels.GetOrBuildChannel(Envelope.ReplyUri),
                },
                Writer = _serialization.JsonWriterFor(typeof(Acknowledgement))
            };

            return(ack);
        }
Ejemplo n.º 5
0
        public Task <Guid> Schedule <T>(T message, DateTimeOffset executionTime)
        {
            var envelope = new Envelope(message)
            {
                ExecutionTime = executionTime
            };

            if (envelope.Data == null || envelope.Data.Length == 0)
            {
                var writer = _serialization.JsonWriterFor(message.GetType());
                envelope.Data        = writer.Write(message);
                envelope.ContentType = writer.ContentType;
            }

            envelope.Status  = TransportConstants.Scheduled;
            envelope.OwnerId = TransportConstants.AnyNode;

            return(EnlistedInTransaction
                ? _persistor.ScheduleJob(envelope).ContinueWith(_ => envelope.Id)
                : Persistence.ScheduleJob(envelope).ContinueWith(_ => envelope.Id));
        }