Exemplo n.º 1
0
        public override object OnGet(Coordinator request)
        {
            using (var session = RavenDocStore.GetStore().OpenSession())
            {
                var trackingData = session.Load <CoordinatorTrackingData>(request.RequestId.ToString());
                var response     = new CoordinatorResponse {
                    RequestId = request.RequestId
                };
                if (trackingData == null)
                {
                    response.ResponseStatus = new ResponseStatus("NotFound");
                    return(response);
                }

                response.Messages          = trackingData.GetListOfCoordinatedSchedules(RavenDocStore.GetStore());
                response.CoordinatorStatus = trackingData.CurrentStatus.ToString();
                return(response);
            }
        }
Exemplo n.º 2
0
        public override object OnPost(Coordinator request)
        {
            var response = new ResponseStatus {
                Errors = new List <ResponseError>()
            };

            if (request.StartTimeUtc == DateTime.MinValue)
            {
                response.Errors.Add(new ResponseError {
                    Message = "Start time must be set"
                });
            }
            if (request.StartTimeUtc < DateTime.Now.ToUniversalTime())
            {
                response.Errors.Add(new ResponseError {
                    Message = "Start time must not be in the past"
                });
            }
            if (string.IsNullOrWhiteSpace(request.Message))
            {
                response.Errors.Add(new ResponseError {
                    Message = "Sms Message Required"
                });
            }
            else if (request.Message.Length > 160)
            {
                response.Errors.Add(new ResponseError {
                    Message = "Sms exceeds 160 character length"
                });
            }
            if (request.Numbers == null || request.Numbers.Count == 0)
            {
                response.Errors.Add(new ResponseError {
                    Message = "List of numbers required"
                });
            }
            if (!MessageTypeValid(request))
            {
                response.Errors.Add(new ResponseError {
                    Message = "Message must contain either Time Separator OR DateTime to send all messages by."
                });
            }
            if (string.IsNullOrWhiteSpace(request.Topic))
            {
                response.Errors.Add(new ResponseError {
                    Message = "Topic must be set"
                });
            }

            var coordinatorResponse = new CoordinatorResponse {
                ResponseStatus = response
            };

            if (response.Errors.Count > 0)
            {
                response.ErrorCode = "InvalidMessage";
            }

            if (response.Errors.Count == 0)
            {
                if (request.RequestId == Guid.Empty)
                {
                    coordinatorResponse.RequestId = Guid.NewGuid();
                }
                else
                {
                    coordinatorResponse.RequestId = request.RequestId;
                }
                if (GetMessageTypeFromModel(request) == typeof(TrickleSmsOverCalculatedIntervalsBetweenSetDates))
                {
                    var message = Mapper.MapToTrickleOverPeriod(request, coordinatorResponse.RequestId);
                    Bus.Send(message);
                }
                else if (GetMessageTypeFromModel(request) == typeof(SendAllMessagesAtOnce))
                {
                    var message = Mapper.MapToSendAllAtOnce(request, coordinatorResponse.RequestId);
                    Bus.Send(message);
                }
                else
                {
                    throw new NotImplementedException("This option has been removed");
                }
            }

            return(coordinatorResponse);
        }