Пример #1
0
        private static void HandleCommand(string messageJson)
        {
            Message message = JsonConvert.DeserializeObject <Message>(messageJson);

            ICommand command = null;

            if (message.Type == typeof(GenericCommand).Name)
            {
                command = JsonConvert.DeserializeObject <GenericCommand>(message.JsonMessage);
                HandlerFactory.CreateGenericHandler(SimpleRetryPolicy).Handle((GenericCommand)command);
            }

            if (message.Type == typeof(DoorOpenCommand).Name)
            {
                command = JsonConvert.DeserializeObject <DoorOpenCommand>(message.JsonMessage);
                HandlerFactory.CreateDoorOpenHandler(ExponentialRetryPolicy).Handle((DoorOpenCommand)command);
            }

            if (message.Type == typeof(TempAlertCommand).Name)
            {
                command = JsonConvert.DeserializeObject <TempAlertCommand>(message.JsonMessage);
                HandlerFactory.CreateTempAlarmHandler(ExponentialRetryPolicy).Handle((TempAlertCommand)command);
            }

            if (message.Type == typeof(NullCommand).Name)
            {
                command = JsonConvert.DeserializeObject <NullCommand>(message.JsonMessage);
                HandlerFactory.CreateNullHandler().Handle((NullCommand)command);
            }
        }