Ejemplo n.º 1
0
        public async Task <IActionResult> Create([FromBody] CreateWorkflowTemplateCommand command)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            if (command.InputDefinitions == null)
            {
                command.InputDefinitions = new Dictionary <string, Domain.ValueObjects.DynamicDataDescription>();
            }

            if (command.LogicBlocks == null)
            {
                command.InputDefinitions = new Dictionary <string, Domain.ValueObjects.DynamicDataDescription>();
            }
            try
            {
                command.CreatedBy = ClaimsUtility.GetId(User);
                var result = await Mediator.Send(command);

                return(Ok(new HttpCommandResult <WorkflowTemplate>("/api/workflowTemplate/" + command.Name + "/" + command.Version, result, null)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] CreateExecutionScheduleVM command, bool?runImmediately = false)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                var result = await Mediator.Send(new CreateExecutionScheduleCommand()
                {
                    CreatedBy             = ClaimsUtility.GetId(User),
                    Description           = command.Description,
                    Name                  = command.Name,
                    RunImmediately        = runImmediately.HasValue ? runImmediately.Value : false,
                    ExecutionTemplateName = command.ExecutionTemplateName,
                    Schedule              = command.Schedule
                });


                return(Ok(new HttpCommandResult <ExecutionSchedule>("/api/execution-schedules/" + command.Name, result, null)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([FromBody] CreateStepTemplateCommand command)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            if (command.ReferenceId == null && (command.Name == null || command.Version == null))
            {
                return(BadRequest("Either referenceId needs to be set or name and version must be set."));
            }

            try
            {
                if (command.OutputDefinitions == null)
                {
                    command.OutputDefinitions = new Dictionary <string, Domain.ValueObjects.DynamicDataDescription>();
                }

                command.CreatedBy = ClaimsUtility.GetId(User);
                var result = await Mediator.Send(command);

                return(Ok(new HttpCommandResult <StepTemplate>("/api/steptemplates/" + command.Name + "/" + command.Version, result, null)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(CreateWorkflowCommand command)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            if (command.Inputs == null)
            {
                //Set to an empty dictionary if null
                command.Inputs = new Dictionary <string, object>();
            }
            try
            {
                command.CreatedBy = ClaimsUtility.GetId(User);
                var result = await Mediator.Send(command);

                return(Ok(new HttpCommandResult <Workflow>("workflow", result, result.Result)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([FromBody] CreateExecutionTemplateVM command)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                var result = await Mediator.Send(new CreateExecutionTemplateCommand()
                {
                    CreatedBy             = ClaimsUtility.GetId(User),
                    Description           = command.Description,
                    ExecutionTemplateType = command.ExecutionTemplateType.ToLower(),
                    Inputs      = command.Inputs,
                    Name        = command.Name,
                    ReferenceId = command.ReferenceId
                });


                return(Ok(new HttpCommandResult <ExecutionTemplate>("/api/execution-template/" + command.Name, result, null)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 6
0
 public async Task <IActionResult> ScanWorkflow(Guid id)
 {
     return(Ok(await Mediator.Send(new ScanWorkflowCommand()
     {
         CreatedBy = ClaimsUtility.GetId(User),
         WorkflowId = id
     })));
 }
Ejemplo n.º 7
0
 public async Task <IActionResult> Execute(string name)
 {
     return(Ok(await Mediator.Send(new ExecuteExecutionTemplateCommand()
     {
         Name = name,
         CreatedBy = ClaimsUtility.GetId(User)
     })));
 }
Ejemplo n.º 8
0
        public async Task <IActionResult> UpdateStepStatus(Guid id, PutStepStatus putModel)
        {
            IRequest <CommandResult> request;

            switch (putModel.Status)
            {
            case StepStatuses.Suspended:
                request = new SuspendStepCommand()
                {
                    StepId         = id,
                    CreatedBy      = ClaimsUtility.GetId(User),
                    SuspendedUntil = putModel.SuspendedUntil
                };
                break;

            case StepStatuses.Cancelled:
                request = new CancelStepCommand()
                {
                    StepId    = id,
                    CreatedBy = ClaimsUtility.GetId(User)
                };
                break;

            case StepStatuses.Unassigned:
                request = new UnassignStepCommand()
                {
                    StepId    = id,
                    CreatedBy = ClaimsUtility.GetId(User)
                };
                break;

            default:
                return(BadRequest(new ExceptionResult()
                {
                    ExceptionName = "InvalidStepStatusException",
                    Message = "Step status given was not valid. Steps can only be suspended, unassigned or cancelled by users"
                }));
            }

            var result = await Mediator.Send(request);

            if (result.ObjectRefId != "")
            {
                var resolvedStep = (await Mediator.Send(new GetEntityQuery <Step>()
                {
                    Expression = s => s.Id == new Guid(result.ObjectRefId)
                })).Result;
                return(Ok(new HttpCommandResult <Step>("step", result, resolvedStep)));
            }
            else
            {
                return(Ok(new HttpCommandResult <Step>("", result, null)));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Put(string name, [FromBody] UpdateGlobalValueVM globalValue)
        {
            var result = await Mediator.Send(new UpdateGlobalValueCommand()
            {
                Description = globalValue.Description,
                Name        = name,
                Value       = globalValue.Value,
                CreatedBy   = ClaimsUtility.GetId(User)
            });

            return(Ok(new HttpCommandResult <GlobalValue>("//api//global-values//" + result.ObjectRefId, result, result.Result)));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Post([FromBody] CreateGlobalValueVM globalValue)
        {
            var result = await Mediator.Send(new CreateGlobalValueCommand()
            {
                Description = globalValue.Description,
                Name        = globalValue.Name,
                Type        = globalValue.Type.ToLower(),
                Value       = globalValue.Value,
                CreatedBy   = ClaimsUtility.GetId(User)
            });

            return(Ok(new HttpCommandResult <GlobalValue, GlobalValueVM>("//api//global-values//" + result.ObjectRefId, result, Mapper.Map <GlobalValueVM>(result.Result))));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> UnencryptStepSecret(Guid id, string fieldName, string type)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                return(Ok(await Mediator.Send(new UnencryptStepFieldQuery()
                {
                    StepId = id,
                    FieldName = fieldName,
                    UserId = ClaimsUtility.GetId(User),
                    Type = type.ToLower()
                })));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> GetNextStep(AssignStepCommand command)
        {
            try
            {
                command.BotId = new Guid(ClaimsUtility.GetId(User));
                var result = await Mediator.Send(command);

                if (result.ObjectRefId != "")
                {
                    return(Ok(new HttpCommandResult <Step>("step", result, result.Result)));
                }
                else
                {
                    return(Ok(new HttpCommandResult <Step>("", result, null)));
                }
            }
            catch (BotKeyAssignmentException e)
            {
                return(BadRequest(command.BotId + " has been disabled for assignment."));
            }
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Create(CreateStepCommand command, bool?wait_for_completion, string timeout = "30s")
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                command.CreatedBy = ClaimsUtility.GetId(User);
                var result = await Mediator.Send(command);

                Step step = (await Mediator.Send(new GetEntityQuery <Step>()
                {
                    Expression = s => s.Id == new Guid(result.ObjectRefId),
                    Exclude = (s) => s.Journal
                })).Result;


                if (wait_for_completion.HasValue && wait_for_completion.Value)
                {
                    var ms = DateTimeMathsUtility.GetMs(timeout);

                    while (!StepStatuses.IsCompleteStatus(step.Status) && stopwatch.ElapsedMilliseconds < ms)
                    {
                        step = (await Mediator.Send(new GetEntityQuery <Step>()
                        {
                            Expression = s => s.Id == new Guid(result.ObjectRefId)
                        })).Result;
                    }
                }


                return(Ok(new HttpCommandResult <Step>("step", result, step)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Register(CreateBotKeyCommand command)
        {
            if (!_clusterState.GetSettings.AllowAutoRegistration)
            {
                if (ClaimsUtility.GetId(User) == null)
                {
                    return(Unauthorized());
                }
            }

            var keyCreationResult = await Mediator.Send(command);

            var key = await Mediator.Send(new GetEntityQuery <BotKey>()
            {
                Expression = bk => bk.Id == new Guid(keyCreationResult.ObjectRefId)
            });

            return(Ok(new HttpCommandResult <NewBotKeyVM>("", keyCreationResult, new NewBotKeyVM()
            {
                // BotName = key.Result.BotName,
                IdKey = keyCreationResult.ObjectRefId
            })));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> AddLog(Guid id, AppendStepLogVM command)
        {
            var appendCommand = new AppendStepLogCommand()
            {
                StepId    = id,
                Log       = command.Log,
                CreatedBy = ClaimsUtility.GetId(User)
            };
            var result = await Mediator.Send(appendCommand);

            if (result.ObjectRefId != "")
            {
                var resolvedStep = (await Mediator.Send(new GetEntityQuery <Step>()
                {
                    Expression = s => s.Id == new Guid(result.ObjectRefId)
                })).Result;
                return(Ok(new HttpCommandResult <Step>("step", result, resolvedStep)));
            }
            else
            {
                return(Ok(new HttpCommandResult <Step>("", result, null)));
            }
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Post(CreateUserVM request)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                var command = new CreateUserCommand()
                {
                    Username  = request.Username,
                    Password  = request.Password,
                    CreatedBy = ClaimsUtility.GetId(User)
                };
                var result = await Mediator.Send(command);

                return(Ok(new HttpCommandResult <User>("user", result, null)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> CompleteAssignment(Guid id, CompleteStepVM commandVM)
        {
            //TODO check that the bot who is updating is the same as the one who was assigned

            if (commandVM.Status == StepStatuses.Suspended)
            {
                var result = await Mediator.Send(new SuspendStepCommand()
                {
                    StepId         = id,
                    CreatedBy      = ClaimsUtility.GetId(User),
                    SuspendedUntil = DateTime.Now.AddMilliseconds(_option.DefaultSuspensionTimeMs)
                });

                if (result.ObjectRefId != "")
                {
                    var resolvedStep = (await Mediator.Send(new GetEntityQuery <Step>()
                    {
                        Expression = s => s.Id == new Guid(result.ObjectRefId)
                    })).Result;
                    return(Ok(new HttpCommandResult <Step>("step", result, resolvedStep)));
                }
                else
                {
                    return(Ok(new HttpCommandResult <Step>("", result, null)));
                }
            }
            else
            {
                var completeStepCommand = new CompleteStepCommand()
                {
                    Id         = id,
                    Status     = commandVM.Status.ToLower(),
                    StatusCode = commandVM.StatusCode,
                    Log        = commandVM.Logs,
                    Outputs    = commandVM.Outputs,
                    CreatedBy  = ClaimsUtility.GetId(User),
                    BotId      = new Guid(ClaimsUtility.GetId(User))
                };
                try
                {
                    var result = await Mediator.Send(completeStepCommand);

                    if (result.ObjectRefId != "")
                    {
                        var resolvedStep = (await Mediator.Send(new GetEntityQuery <Step>()
                        {
                            Expression = s => s.Id == new Guid(result.ObjectRefId)
                        })).Result;
                        return(Ok(new HttpCommandResult <Step>("step", result, resolvedStep)));
                    }
                    else
                    {
                        return(Ok(new HttpCommandResult <Step>("", result, null)));
                    }
                }
                catch (DuplicateStepUpdateException exception)
                {
                    return(Ok(new HttpCommandResult <Step>("step", new CommandResult()
                    {
                        Type = CommandResultTypes.None
                    }, (await Mediator.Send(new GetEntityQuery <Step>()
                    {
                        Expression = s => s.Id == id
                    })).Result)));
                }
            }
        }