/// <summary>
 /// Instanciate an action object for a response.
 /// Reset Start Date, End Date, Status to "Not Started"
 /// </summary>
 /// <param name="action">ResponseActionModel</param>
 private void InstantiateResponseActions(ResponseActionModel action)
 {
     if (action.ActionId == Guid.Empty)
     {
         action.ActionId = Guid.NewGuid();
     }
     action.Status    = ActionStatus.NotStarted;
     action.StartDate = null;
     action.EndDate   = null;
 }
Exemplo n.º 2
0
 public ActionBase(ResponseActionModel model)
 {
     Action = model;
 }
        public async Task Consume(ConsumeContext <IActionEvent> context)
        {
            try
            {
                _logger.LogDebug($"ResponseActionEventConsumer: Retrieved message from response '{context.Message.Action.ActionId}'.");
                ResponseActionModel action = context.Message.Action;
                if (!string.IsNullOrEmpty(action.ActionType))
                {
                    _logger.LogDebug($"ResponseActionEventConsumer: ActionType retrieved: '{action.ActionType}'.");
                    //Switch statement directing different action types
                    switch (action.ActionType)
                    {
                    case "notification":
                        _logger.LogDebug($"ResponseActionEventConsumer: Publish ActionNotificationEvent.");
                        await context.Publish(new ActionNotificationEvent(action) {
                            ResponseId          = context.Message.ResponseId,
                            ActionCorrelationId = context.Message.ActionCorrelationId
                        });

                        break;

                    case "lightsensor":
                        _logger.LogDebug($"ResponseActionEventConsumer: Publish ActionLightSensorEvent.");
                        await context.Publish(new ActionLightSensorEvent(action) {
                            ActionCorrelationId = context.Message.ActionCorrelationId,
                            ResponseId          = context.Message.ResponseId,
                            GeolocationPoint    = context.Message.Geolocation,
                            PrimaryRadius       = context.Message.PrimaryRadius,
                            SecondaryRadius     = context.Message.SecondaryRadius
                        });

                        break;

                    case "twilio":
                        _logger.LogDebug($"ResponseActionEventConsumer: Publish ActionTwilioEvent.");
                        await context.Publish(new ActionTwilioEvent(action)
                        {
                            ResponseId          = context.Message.ResponseId,
                            Message             = context.Message.Action.Parameters["message"],
                            ActionCorrelationId = context.Message.ActionCorrelationId
                        });

                        break;

                    default:
                        await GenerateActionCallback(context, ActionStatus.Skipped, DateTime.UtcNow, $"The action type '{action.ActionType}' cannot be handled.");

                        break;
                    }
                    return;
                }
                _logger.LogError("ResponseActionEventConsumer: Invalid Null or Empty Action Type");
                throw new Exception("Invalid Null or Empty Action Type");
            }
            catch (Exception e)
            {
                await GenerateActionCallback(context, ActionStatus.Error, DateTime.UtcNow, $"There was an issue handling the action: {e.Message}.");

                _logger.LogError($"ResponseActionEventConsumer: {e.Message}");
                throw e;
            }
        }
Exemplo n.º 4
0
 public ActionNotificationEvent(ResponseActionModel model) : base(model)
 {
 }
 public ActionLightSensorEvent(ResponseActionModel model) : base(model)
 {
 }
Exemplo n.º 6
0
 public ActionTwilioEvent(ResponseActionModel model) : base(model)
 {
 }