public static ResponseConfiguration CreateStreamCompleted(HttpResponseConfiguratorArgs entity, Message message, string eventStreamId) { Debug.Assert(message.GetType() == typeof(ClientMessage.CreateStreamCompleted)); var completed = message as ClientMessage.CreateStreamCompleted; if (completed == null) return InternalServerError(); switch (completed.Result) { case OperationResult.Success: { return new ResponseConfiguration( HttpStatusCode.Created, "Stream created", null, Encoding.UTF8, new KeyValuePair<string, string>("Location", HostName.Combine(entity.UserHostName, "/streams/{0}", Uri.EscapeDataString(eventStreamId)))); } case OperationResult.PrepareTimeout: case OperationResult.CommitTimeout: case OperationResult.ForwardTimeout: return InternalServerError("Create timeout"); case OperationResult.WrongExpectedVersion: case OperationResult.StreamDeleted: case OperationResult.InvalidTransaction: return BadRequest(string.Format("Error code : {0}. Reason : {1}", completed.Result, completed.Message)); default: throw new ArgumentOutOfRangeException(); } }
public static ResponseConfiguration DeleteStreamCompleted(HttpResponseConfiguratorArgs entity, Message message) { Debug.Assert(message.GetType() == typeof(ClientMessage.DeleteStreamCompleted)); var completed = message as ClientMessage.DeleteStreamCompleted; if (completed == null) return InternalServerError(); switch (completed.Result) { case OperationResult.Success: return new ResponseConfiguration(HttpStatusCode.NoContent, "Stream deleted", null, Encoding.UTF8); case OperationResult.PrepareTimeout: case OperationResult.CommitTimeout: case OperationResult.ForwardTimeout: return InternalServerError("Delete timeout"); case OperationResult.WrongExpectedVersion: case OperationResult.StreamDeleted: case OperationResult.InvalidTransaction: return BadRequest(string.Format("Error code : {0}. Reason : {1}", completed.Result, completed.Message)); default: throw new ArgumentOutOfRangeException(); } }
public static ResponseConfiguration ReadStreamEventsBackwardCompleted(HttpResponseConfiguratorArgs entity, Message message, bool headOfStream) { Debug.Assert(message.GetType() == typeof(ClientMessage.ReadStreamEventsBackwardCompleted)); var msg = message as ClientMessage.ReadStreamEventsBackwardCompleted; if (msg == null) return InternalServerError(); switch (msg.Result) { case ReadStreamResult.Success: { if (msg.LastEventNumber >= msg.FromEventNumber && !headOfStream) return OkCache(entity.ResponseCodec.ContentType, entity.ResponseCodec.Encoding, MaxPossibleAge); return OkNoCache(entity.ResponseCodec.ContentType, entity.ResponseCodec.Encoding, msg.LastEventNumber.ToString(CultureInfo.InvariantCulture)); } case ReadStreamResult.NoStream: return NotFound(); case ReadStreamResult.StreamDeleted: return Gone(); case ReadStreamResult.NotModified: return NotModified(); case ReadStreamResult.Error: return InternalServerError(msg.Message); default: throw new ArgumentOutOfRangeException(); } }
public static ResponseConfiguration ReadAllEventsForwardCompleted(HttpResponseConfiguratorArgs entity, Message message, bool headOfTf) { Debug.Assert(message.GetType() == typeof(ClientMessage.ReadAllEventsForwardCompleted)); var msg = message as ClientMessage.ReadAllEventsForwardCompleted; if (msg == null) return InternalServerError("Failed to read all events forward."); if (msg.NotModified) return NotModified(); if (!headOfTf && msg.Result.Events.Length == msg.Result.MaxCount) return OkCache(entity.ResponseCodec.ContentType, entity.ResponseCodec.Encoding, MaxPossibleAge); return OkNoCache(entity.ResponseCodec.ContentType, entity.ResponseCodec.Encoding, msg.Result.TfEofPosition.ToString(CultureInfo.InvariantCulture)); }
public static ResponseConfiguration ReadEventCompleted(HttpResponseConfiguratorArgs entity, Message message) { Debug.Assert(message.GetType() == typeof(ClientMessage.ReadEventCompleted)); var completed = message as ClientMessage.ReadEventCompleted; if (completed == null) return InternalServerError(); switch (completed.Result) { case ReadEventResult.Success: return OkCache(entity.ResponseCodec.ContentType, entity.ResponseCodec.Encoding, MaxPossibleAge); case ReadEventResult.NotFound: case ReadEventResult.NoStream: return NotFound(); case ReadEventResult.StreamDeleted: return Gone(); default: throw new ArgumentOutOfRangeException(); } }
public static ResponseConfiguration GetFreshStatsCompleted(HttpResponseConfiguratorArgs entity, Message message) { var completed = message as MonitoringMessage.GetFreshStatsCompleted; if (completed == null) return InternalServerError(); var cacheSeconds = (int)MonitoringService.MemoizePeriod.TotalSeconds; return completed.Success ? Ok(entity.ResponseCodec.ContentType, Helper.UTF8NoBom, null, cacheSeconds, isCachePublic: true) : NotFound(); }
public static ResponseConfiguration GetFreshStatsCompleted(HttpResponseConfiguratorArgs entity, Message message) { Debug.Assert(message.GetType() == typeof(MonitoringMessage.GetFreshStatsCompleted)); var completed = message as MonitoringMessage.GetFreshStatsCompleted; if (completed == null) return InternalServerError(); return completed.Success ? OkNoCache(entity.ResponseCodec.ContentType, Encoding.UTF8) : NotFound(); }
public static ResponseConfiguration WriteEventsCompleted(HttpResponseConfiguratorArgs entity, Message message, string eventStreamId) { var msg = message as ClientMessage.WriteEventsCompleted; if (msg != null) { switch (msg.Result) { case OperationResult.Success: var location = HostName.Combine(entity.RequestedUrl, "/streams/{0}/{1}", Uri.EscapeDataString(eventStreamId), msg.FirstEventNumber); return new ResponseConfiguration(HttpStatusCode.Created, "Created", "text/plain", Helper.UTF8NoBom, new KeyValuePair<string, string>("Location", location)); case OperationResult.PrepareTimeout: case OperationResult.CommitTimeout: case OperationResult.ForwardTimeout: return InternalServerError("Write timeout"); case OperationResult.WrongExpectedVersion: return BadRequest("Wrong expected EventNumber"); case OperationResult.StreamDeleted: return Gone("Stream deleted"); case OperationResult.InvalidTransaction: return InternalServerError("Invalid transaction"); case OperationResult.AccessDenied: return Unauthorized(); default: throw new ArgumentOutOfRangeException(); } } var notHandled = message as ClientMessage.NotHandled; if (notHandled != null) return HandleNotHandled(entity.RequestedUrl, notHandled); return InternalServerError(); }
public static ResponseConfiguration DeleteStreamCompleted(HttpResponseConfiguratorArgs entity, Message message) { var msg = message as ClientMessage.DeleteStreamCompleted; if (msg != null) { switch (msg.Result) { case OperationResult.Success: return new ResponseConfiguration(HttpStatusCode.NoContent, "Stream deleted", "text/plain", Helper.UTF8NoBom); case OperationResult.PrepareTimeout: case OperationResult.CommitTimeout: case OperationResult.ForwardTimeout: return InternalServerError("Delete timeout"); case OperationResult.WrongExpectedVersion: return BadRequest("Wrong expected EventNumber"); case OperationResult.StreamDeleted: return Gone("Stream deleted"); case OperationResult.InvalidTransaction: return InternalServerError("Invalid transaction"); case OperationResult.AccessDenied: return Unauthorized(); default: throw new ArgumentOutOfRangeException(); } } var notHandled = message as ClientMessage.NotHandled; if (notHandled != null) return HandleNotHandled(entity.RequestedUrl, notHandled); return InternalServerError(); }
public static ResponseConfiguration ReadAllEventsForwardCompleted(HttpResponseConfiguratorArgs entity, Message message, bool headOfTf) { var msg = message as ClientMessage.ReadAllEventsForwardCompleted; if (msg != null) { switch (msg.Result) { case ReadAllResult.Success: var codec = entity.ResponseCodec; if (!headOfTf && msg.Events.Length == msg.MaxCount) return Ok(codec.ContentType, codec.Encoding, null, MaxPossibleAge, msg.IsCachePublic); var etag = GetPositionETag(msg.TfLastCommitPosition, codec.ContentType); var cacheSeconds = GetCacheSeconds(msg.StreamMetadata); return Ok(codec.ContentType, codec.Encoding, etag, cacheSeconds, msg.IsCachePublic); case ReadAllResult.NotModified: return NotModified(); case ReadAllResult.Error: return InternalServerError(msg.Error); case ReadAllResult.AccessDenied: return Unauthorized(); default: throw new ArgumentOutOfRangeException(); } } var notHandled = message as ClientMessage.NotHandled; if (notHandled != null) return HandleNotHandled(entity.RequestedUrl, notHandled); return InternalServerError(); }
public static ResponseConfiguration GetStreamEventsBackward(HttpResponseConfiguratorArgs entity, Message message, bool headOfStream) { var msg = message as ClientMessage.ReadStreamEventsBackwardCompleted; if (msg != null) { switch (msg.Result) { case ReadStreamResult.Success: var codec = entity.ResponseCodec; if (msg.LastEventNumber >= msg.FromEventNumber && !headOfStream) return Ok(codec.ContentType, codec.Encoding, null, MaxPossibleAge, msg.IsCachePublic); var etag = GetPositionETag(msg.LastEventNumber, codec.ContentType); var cacheSeconds = GetCacheSeconds(msg.StreamMetadata); return Ok(codec.ContentType, codec.Encoding, etag, cacheSeconds, msg.IsCachePublic); case ReadStreamResult.NoStream: return NotFound(); case ReadStreamResult.StreamDeleted: return Gone(); case ReadStreamResult.NotModified: return NotModified(); case ReadStreamResult.Error: return InternalServerError(msg.Error); case ReadStreamResult.AccessDenied: return Unauthorized(); default: throw new ArgumentOutOfRangeException(); } } var notHandled = message as ClientMessage.NotHandled; if (notHandled != null) return HandleNotHandled(entity.RequestedUrl, notHandled); return InternalServerError(); }
public static ResponseConfiguration EventMetadata(HttpResponseConfiguratorArgs entity) { return NotImplemented(); }
public static ResponseConfiguration EventEntry(HttpResponseConfiguratorArgs entity, Message message, bool headEvent) { var msg = message as ClientMessage.ReadEventCompleted; if (msg != null) { switch (msg.Result) { case ReadEventResult.Success: var codec = entity.ResponseCodec; if (msg.Record.Event == null && msg.Record.Link != null) { return NotFound(); } if (headEvent) { var etag = msg.Record.OriginalEvent != null ? GetPositionETag(msg.Record.OriginalEventNumber, codec.ContentType) : String.Empty; var cacheSeconds = GetCacheSeconds(msg.StreamMetadata); return Ok(codec.ContentType, codec.Encoding, etag, cacheSeconds, msg.IsCachePublic); } return Ok(codec.ContentType, codec.Encoding, null, MaxPossibleAge, msg.IsCachePublic); case ReadEventResult.NotFound: case ReadEventResult.NoStream: return NotFound(); case ReadEventResult.StreamDeleted: return Gone(); case ReadEventResult.Error: return InternalServerError(msg.Error); case ReadEventResult.AccessDenied: return Unauthorized(); default: throw new ArgumentOutOfRangeException(); } } var notHandled = message as ClientMessage.NotHandled; if (notHandled != null) return HandleNotHandled(entity.RequestedUrl, notHandled); return InternalServerError(); }
public static ResponseConfiguration WriteEventsCompleted(HttpResponseConfiguratorArgs entity, Message message, string eventStreamId) { Debug.Assert(message.GetType() == typeof(ClientMessage.WriteEventsCompleted)); var completed = message as ClientMessage.WriteEventsCompleted; if (completed == null) return InternalServerError(); switch (completed.Result) { case OperationResult.Success: { return new ResponseConfiguration( HttpStatusCode.Created, "Created", null, new KeyValuePair<string, string>("Location", HostName.Combine(entity.UserHostName, "/streams/{0}/{1}", Uri.EscapeDataString(eventStreamId), completed.FirstEventNumber == 0 ? 1 : completed.FirstEventNumber))); } case OperationResult.PrepareTimeout: case OperationResult.CommitTimeout: case OperationResult.ForwardTimeout: return InternalServerError("Write timeout"); case OperationResult.WrongExpectedVersion: return BadRequest("Wrong expected EventNumber"); case OperationResult.StreamDeleted: return Gone("Stream deleted"); case OperationResult.InvalidTransaction: return InternalServerError("Invalid transaction"); default: throw new ArgumentOutOfRangeException(); } }