public HttpResponseMessage Post (IEnumerable <ExchangeData> exchanges) { if (exchanges == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (exchanges.Count() == 0) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } var json = ExchangeDataJsonConverter.SerialiseEnumerable(exchanges); var queueEntry = new IngressQueueEntry( requestId: requestIdentityProvider.GetId() // todo: change this to use a message identity provider , messageId: Guid.NewGuid() , message: json , messageType: IngressGatewayTopic.Messages.Exchanges ); Trace.TraceInformation($"[{queueEntry.RequestId}] - Publishing"); ingressGatewayQueue.Dispatch(queueEntry); Trace.TraceInformation($"[{queueEntry.RequestId}] - Published"); return(new HttpResponseMessage(HttpStatusCode.OK)); }
// Convert the json into ExchangeData. Note we can not be sure // the the json will deserialise into Exchange data so it is // wrapped in an Either Monad. // // Note - // The entire collection has to deserialise correctly this // this should be changes as there is no reason for the // list to be atomic. i.e. just because one record in // the list is not valid json should not stop the other // entries from being processed. // private IEnumerable <Either <StateChangeError, ExchangeData> > deserialise (string message) { if (string.IsNullOrWhiteSpace(message)) { throw new ArgumentNullException(nameof(message)); } try { var exchanges = ExchangeDataJsonConverter .DeserialiseEnumerable(message); return (exchanges .Select(Either <StateChangeError, ExchangeData> .Right)); } catch { return(new [] { Either <StateChangeError, ExchangeData> .Left(new ErrorDeserialisingExchangeDataRecievedMessage()) }); } }