public static async Task OnCreateWorkflow(CreateWorkflow action, IEffectContext context)
        {
            var dispatcher = context.Services.GetRequiredService <IDispatcher>();

            if (dispatcher == null)
            {
                throw new NullReferenceException("Unable to resolved service 'IDispatcher'.");
            }
            dispatcher.Dispatch(new DisableCreateButton());
            var api = context.Services.GetRequiredService <ISynapseManagementApi>();

            if (api == null)
            {
                throw new NullReferenceException("Unable to resolved service 'ISynapseManagementApi'.");
            }
            var command = new V1CreateWorkflowCommand()
            {
                Definition = action.Definition
            };

            try
            {
                var workflow = await api.CreateWorkflowAsync(command);

                dispatcher.Dispatch(new EnableCreateButton());
                if (workflow != null)
                {
                    context.Dispatcher.Dispatch(new NavigateTo("workflows"));
                }
            }
            catch (Exception ex)
            {
                dispatcher.Dispatch(new EnableCreateButton());
            }
        }
 /// <inheritdoc/>
 public virtual async Task <V1Workflow> CreateWorkflowAsync(V1CreateWorkflowCommand command, CancellationToken cancellationToken = default)
 {
     if (command == null)
     {
         throw new ArgumentNullException(nameof(command));
     }
     return(await this.Mediator.ExecuteAndUnwrapAsync(this.Mapper.Map <Application.Commands.Workflows.V1CreateWorkflowCommand>(command), cancellationToken));
 }
Example #3
0
        /// <inheritdoc/>
        public virtual async Task <V1Workflow> CreateWorkflowAsync(V1CreateWorkflowCommand command, CancellationToken cancellationToken = default)
        {
            var result = await this.Adapter.CreateWorkflowAsync(command, cancellationToken);

            if (!result.Succeeded)
            {
                throw new SynapseApiException(result);
            }
            return(result.Data !);
        }
        /// <inheritdoc/>
        public virtual async Task <V1Workflow> CreateWorkflowAsync(V1CreateWorkflowCommand command, CancellationToken cancellationToken = default)
        {
            var requestUri = "/api/v1/workflows";

            using var request = this.CreateRequest(HttpMethod.Post, requestUri);
            var json = await this.Serializer.SerializeAsync(command, cancellationToken);

            request.Content    = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json);
            using var response = await this.HttpClient.SendAsync(request, cancellationToken);

            json = await response.Content?.ReadAsStringAsync(cancellationToken) !;

            if (!response.IsSuccessStatusCode)
            {
                this.Logger.LogError("An error occured while creating a new workflow: {details}", json);
            }
            response.EnsureSuccessStatusCode();
            return(await this.Serializer.DeserializeAsync <V1Workflow>(json, cancellationToken));
        }