示例#1
0
 public void PostEntry(HttpEntityManager manager, long expectedVersion, bool requireMaster, string stream, Guid idIncluded, string typeIncluded)
 {
     //TODO GFY SHOULD WE MAKE THIS READ BYTE[] FOR RAW THEN CONVERT? AS OF NOW ITS ALL NO BOM UTF8
     manager.ReadRequestAsync(
         (man, body) =>
     {
         var events = new Event[0];
         try
         {
             events = AutoEventConverter.SmartParse(body, manager.RequestCodec, idIncluded, typeIncluded);
         }
         catch (Exception ex)
         {
             SendBadRequest(manager, ex.Message);
             return;
         }
         if (events.IsEmpty())
         {
             SendBadRequest(manager, "Write request body invalid.");
             return;
         }
         foreach (var e in events)
         {
             if (e.Data.Length + e.Metadata.Length > 4 * 1024 * 1024)
             {
                 SendTooBig(manager);
             }
         }
         var envelope = new SendToHttpEnvelope(_networkSendQueue,
                                               manager,
                                               Format.WriteEventsCompleted,
                                               (a, m) => Configure.WriteEventsCompleted(a, m, stream));
         var corrId = Guid.NewGuid();
         var msg    = new ClientMessage.WriteEvents(corrId, corrId, envelope, requireMaster,
                                                    stream, expectedVersion, events, manager.User);
         Publish(msg);
     },
         e => Log.Debug("Error while reading request (POST entry): {e}.", e.Message));
 }
        private void OnPostEntryRequestRead(HttpEntityManager manager, string body)
        {
            var entity = manager.HttpEntity;
            var stream = (string)manager.AsyncState;

            var write = entity.RequestCodec.From <ClientMessageDto.WriteEventText>(body);

            if (write == null || write.Events == null || write.Events.Length == 0)
            {
                SendBadRequest(entity, "Write request body invalid");
                return;
            }

            var envelope = new SendToHttpEnvelope(entity, Format.WriteEventsCompleted, Configure.WriteEventsCompleted);
            var msg      = new ClientMessage.WriteEvents(
                write.CorrelationId == Guid.Empty ? Guid.NewGuid() : write.CorrelationId,
                envelope,
                stream,
                write.ExpectedVersion,
                write.Events.Select(EventConvertion.ConvertOnWrite).ToArray());

            Publish(msg);
        }
示例#3
0
        public void PostEntry(HttpEntityManager manager, int expectedVersion, bool requireMaster, string stream)
        {
            manager.ReadTextRequestAsync(
                (man, body) =>
            {
                var events = AutoEventConverter.SmartParse(body, manager.RequestCodec);
                if (events.IsEmpty())
                {
                    SendBadRequest(manager, "Write request body invalid.");
                    return;
                }

                var envelope = new SendToHttpEnvelope(_networkSendQueue,
                                                      manager,
                                                      Format.WriteEventsCompleted,
                                                      (a, m) => Configure.WriteEventsCompleted(a, m, stream));
                var corrId = Guid.NewGuid();
                var msg    = new ClientMessage.WriteEvents(corrId, corrId, envelope, requireMaster,
                                                           stream, expectedVersion, events, manager.User);
                Publish(msg);
            },
                e => Log.Debug("Error while reading request (POST entry): {0}.", e.Message));
        }
示例#4
0
        public Guid QueueWriteEvents(
            Guid key,
            string streamId,
            long expectedVersion,
            Event[] events,
            ClaimsPrincipal principal,
            Action <ClientMessage.WriteEventsCompleted> action)
        {
            var corrId = Guid.NewGuid();

            var message = new ClientMessage.WriteEvents(
                corrId,
                corrId,
                Writer.Envelope,
                false,
                streamId,
                expectedVersion,
                events,
                principal);

            _requestTracker.QueuePendingWrite(key, corrId, action, message, Writer);

            return(corrId);
        }
示例#5
0
 public void Enqueue(ClientMessage.WriteEvents message)
 {
     _queue.Enqueue(message);
 }
示例#6
0
 private void Handle(ClientMessage.WriteEvents message)
 {
     _outputBus.Publish(message);
 }