Esempio n. 1
0
        public async Task <HttpResponse> Process(string request, HttpClientInfo clientInfo)
        {
            Logger.Info($"REQ RECIEVED");
            if (string.IsNullOrWhiteSpace(request))
            {
                Logger.Error("BAD REQ - Empty Command");
                return(HttpResponse.BadRequest());
            }

            var parsedRequest = requestParser.Parse(request);

            Logger.Info("REQ PARSED", parsedRequest);
            if (!parsedRequest.Success)
            {
                Logger.Error("Could not parse request", parsedRequest);
                return(HttpResponse.BadRequest("Could not parse RPC Request"));
            }

            var command = commandLocator.Locate(parsedRequest.Request.Method);

            if (command == null)
            {
                Logger.Error("Could not locate method", parsedRequest);
                return(HttpResponse.NotFound("Could not locate requested method"));
            }

            Logger.Trace("command located", command);

            var response = await translator.ExecuteCommand(command, parsedRequest.Request, clientInfo);

            Logger.Info("REQ COMPLETE", response);
            return(converter.Convert(response));
        }
Esempio n. 2
0
        public override async Task <bool> IsValid()
        {
            var command          = commandLocator.Locate(CommandName);
            var validCommandName = command != null;

            commandHydrator.Hydrate(ref command, Parameters);
            var validParameters = await command.IsValid();

            var validSchedule = Schedule != null &&
                                Schedule.start != default(DateTime) &&
                                (Schedule.repeat_count == null || Schedule.repeat_count > 0);

            return(validCommandName && validParameters && validSchedule);
        }
Esempio n. 3
0
        public override async Task <CommandResult> Execute()
        {
            await Task.CompletedTask;
            var cmd = commandLocator.Locate(command);

            if (cmd == null)
            {
                throw new ArgumentException("Command not found", nameof(command));
            }

            var cmdType = cmd.GetType();

            var typeDescription = GetFullPropertyDescriptions(cmdType, command);

            return(CommandResult.CreateSuccessResult(typeDescription));
        }
Esempio n. 4
0
        public async Task FireEvent(Job job)
        {
            var executionId = Guid.NewGuid().ToNakedString();

            try
            {
                Logger.Info($"Beginning job {job.command_name}:{executionId}", job);
                await jobsDataService.BeginExecution(job, executionId);

                var command    = commandLocator.Locate(job.command_name);
                var parameters = jsonSerializer.Deserialize <object>(job.parameters);
                var result     = await commandProcessor.Process(command, parameters, true);

                await jobsDataService.EndExecution(job, executionId, result);

                Logger.Info($"Completed job {job.command_name}:{executionId}", new { job, result });
            }
            catch (Exception exception)
            {
                Logger.Error($"Job {job.command_name}:{executionId} Failed: {exception.Message}");
                await jobsDataService.ExecutionError(job, executionId, exception);
            }
        }
Esempio n. 5
0
 public void ANonExistingCommandName_ReturnsNull()
 {
     Assert.Null(classUnderTest.Locate("Wokka wokka"));
 }
Esempio n. 6
0
        public override Task <CommandResult> Execute()
        {
            var cmd = commandLocator.Locate(command);

            return(Task.FromResult(CommandResult.CreateSuccessResult(cmd.ExamplePayload())));
        }