private Task TriggerWorkflowEventAsync(string name, User user) { return(_workflowManager.TriggerEventAsync(name, input: new { User = user }, correlationId: user.UserId )); }
public async Task <ActionResult> AddItem(ShoppingCartLineUpdateModel line, string shoppingCartId = null) { ShoppingCartItem parsedLine = await _shoppingCartHelpers.ParseCartLine(line); if (parsedLine is null) { await _notifier.AddAsync(NotifyType.Error, H["Product with SKU {0} not found.", line.ProductSku]); return(RedirectToAction(nameof(Index), new { shoppingCartId })); } parsedLine = (await _priceService.AddPrices(new[] { parsedLine })).Single(); if (!parsedLine.Prices.Any()) { await _notifier.AddAsync(NotifyType.Error, H["Can't add product {0} because it doesn't have a price.", line.ProductSku]); return(RedirectToAction(nameof(Index), new { shoppingCartId })); } ShoppingCart cart = await _shoppingCartPersistence.Retrieve(shoppingCartId); cart.AddItem(parsedLine); await _shoppingCartPersistence.Store(cart, shoppingCartId); if (_workflowManager != null) { await _workflowManager.TriggerEventAsync( nameof(ProductAddedToCartEvent), new { LineItem = parsedLine }, "ShoppingCart-" + _shoppingCartPersistence.GetUniqueCartId(shoppingCartId)); } return(RedirectToAction(nameof(Index), new { shoppingCartId })); }
private Task TriggerWorkflowEventAsync(string name, ContentItem contentItem) { return(_workflowManager.TriggerEventAsync(name, input: new { ContentItem = contentItem }, correlationId: contentItem.ContentItemId )); }
public async Task <IActionResult> Submit(string formId) { var form = await _contentManager.GetAsync(formId, VersionOptions.Published); if (form == null) { return(NotFound()); } var formPart = form.As <VueForm>(); // Verify if the form is enabled if (!formPart.Enabled.Value) { return(NotFound()); } // form validation server side script var errorsDictionary = new Dictionary <string, List <string> >(); var scriptingProvider = new VueFormMethodsProvider(form, errorsDictionary); var script = form.As <VueFormScripts>(); if (!string.IsNullOrEmpty(script?.OnValidation?.Text)) { _scriptingManager.EvaluateJs(script.OnValidation.Text, scriptingProvider); } if (errorsDictionary.Count > 0) { return(Json(new { validationError = true, errors = errorsDictionary })); } if (!string.IsNullOrEmpty(script?.OnSubmitted?.Text)) { _scriptingManager.EvaluateJs(script.OnSubmitted.Text, scriptingProvider); } // _workflow manager is null if workflow feature is not enabled if (_workflowManager != null) { //todo: make sure this does not create issues if the workflows has a blocking event await _workflowManager.TriggerEventAsync(nameof(VueFormSubmittedEvent), input : new { VueForm = form }, correlationId : form.ContentItemId ); } // 302 are equivalent to 301 in this case. No permanent redirect if (HttpContext.Response.StatusCode == 301 || HttpContext.Response.StatusCode == 302) { var returnValue = new { redirect = WebUtility.UrlDecode(HttpContext.Response.Headers["Location"]) }; HttpContext.Response.Clear(); return(Json(returnValue)); } var formSuccessMessage = await _liquidTemplateManager.RenderAsync(formPart.SuccessMessage?.Text, _htmlEncoder); // everything worked fine. send the success signal to the client return(Json(new { success = true, successMessage = formSuccessMessage })); }
public Task UpdateRoles(UpdateRolesContext context) { return(_workflowManager.TriggerEventAsync(nameof(UserLoggedInEvent), input: new { context.User, context.ExternalClaims, context.UserRoles }, correlationId: ((User)context.User).Id.ToString() )); }
private Task HandleNotification(ContentApprovalPart part) { return(!string.IsNullOrWhiteSpace(part.NotificationNeeded) ? _workflowManager.TriggerEventAsync(part.NotificationNeeded, input: new { ContentItem = part.ContentItem }, correlationId: part.ContentItem.ContentItemId ) : Task.CompletedTask); }
public async Task <IActionResult> Trigger(string token) { if (!_securityTokenService.TryDecryptToken <SignalPayload>(token, out var payload)) { _logger.LogWarning("Invalid SAS token provided"); return(NotFound()); } var input = new Dictionary <string, object> { { "Signal", payload.SignalName } }; // If a specific workflow was provided, then resume that workflow. if (!String.IsNullOrWhiteSpace(payload.WorkflowId)) { var workflow = await _workflowStore.GetAsync(payload.WorkflowId); var signalActivities = workflow?.BlockingActivities.Where(x => x.Name == SignalEvent.EventName).ToList(); if (signalActivities == null) { return(NotFound()); } // If atomic, try to acquire a lock per workflow instance. (var locker, var locked) = await _distributedLock.TryAcquireWorkflowLockAsync(workflow); if (locked) { await using var acquiredLock = locker; // Check if the workflow still exists (without checking if it is correlated). workflow = workflow.IsAtomic ? await _workflowStore.GetAsync(workflow.WorkflowId) : workflow; if (workflow != null) { // The workflow could be blocking on multiple Signal activities, but only the activity with the provided signal name // will be executed as SignalEvent checks for the provided "Signal" input. signalActivities = workflow.BlockingActivities.Where(x => x.Name == SignalEvent.EventName).ToList(); foreach (var signalActivity in signalActivities) { await _workflowManager.ResumeWorkflowAsync(workflow, signalActivity, input); } } } } else { // Resume all workflows with the specified correlation ID and start workflows with SignalEvent as their start activity. await _workflowManager.TriggerEventAsync(SignalEvent.EventName, input, payload.CorrelationId); } return(GetWorkflowActionResult()); }
public Task Handle(Notification notification, string eventName, CancellationToken cancellationToken) { var properties = new Dictionary <string, object> { { "Notification", new Dictionary <string, object>(notification) }, { "EventName", eventName } }; NotificationEvent.TryExtractWorkflowId(eventName, out string workflowId); return(_workflowManager.TriggerEventAsync(NotificationEvent.EventName, properties, workflowId)); }
private async Task TriggerNotificationEvent(LeverPostingApplyViewModel model, bool isSuccessful, string errorMessage) { await _workflowManager.TriggerEventAsync( nameof(LeverPostingNotificationEvent), input : new { LeverPostingNotificationViewModel = new LeverPostingNotificationViewModel { ErrorMessage = errorMessage, IsSuccessful = isSuccessful, LeverPostingApplyViewModel = model } }, correlationId : model.PostingId ); }
private Task TriggerWorkflowEventAsync(string name, ContentItem contentItem) { var contentEvent = new ContentEventContext() { Name = name, ContentType = contentItem.ContentType, ContentItemId = contentItem.ContentItemId }; var input = new Dictionary <string, object> { { ContentEventConstants.ContentItemInputKey, contentItem }, { ContentEventConstants.ContentEventInputKey, contentEvent } }; return(_workflowManager.TriggerEventAsync(name, input, correlationId: contentItem.ContentItemId)); }
public override async Task <IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater) { var httpContext = _httpContextAccessor.HttpContext; var action = (string)httpContext.Request.Form["submit.Save"] ?? httpContext.Request.Form["submit.Publish"]; if (action?.StartsWith("user-task.", StringComparison.Ordinal) == true) { action = action.Substring("user-task.".Length); var availableActions = await GetUserTaskActionsAsync(model.ContentItemId); if (!availableActions.Contains(action)) { await _notifier.ErrorAsync(H["Not authorized to trigger '{0}'.", action]); } else { var contentEvent = new ContentEventContext() { Name = nameof(UserTaskEvent), ContentType = model.ContentType, ContentItemId = model.ContentItemId }; var input = new Dictionary <string, object> { { ContentEventConstants.UserActionInputKey, action }, { ContentEventConstants.ContentItemInputKey, model }, { ContentEventConstants.ContentEventInputKey, contentEvent } }; await _workflowManager.TriggerEventAsync(nameof(UserTaskEvent), input, correlationId : model.ContentItemId); } } return(Edit(model)); }
public override async Task <IDisplayResult> UpdateAsync(ContentItem model, IUpdateModel updater) { var httpContext = _httpContextAccessor.HttpContext; var action = (string)httpContext.Request.Form["submit.Save"]; if (action?.StartsWith("user-task.") == true) { action = action.Substring("user-task.".Length); var availableActions = await GetUserTaskActionsAsync(model.ContentItemId); if (!availableActions.Contains(action)) { _notifier.Error(T["Not authorized to trigger '{0}'", action]); } else { var input = new { UserAction = action }; await _workflowManager.TriggerEventAsync(nameof(UserTaskEvent), input, model.ContentItemId); } } return(await EditAsync(model, updater)); }
public async Task <IActionResult> Submit(string formId) { var canView = ContentTypePermissionsHelper.CreateDynamicPermission(ContentTypePermissionsHelper.PermissionTemplates[CommonPermissions.ViewContent.Name], "VueForm"); if (!await _authorizationService.AuthorizeAsync(User, canView)) { return(NotFound()); } var form = await _contentManager.GetAsync(formId, VersionOptions.Published); if (form == null) { return(NotFound()); } var formPart = form.As <VueForm>(); if (formPart.Disabled.Value) { return(NotFound()); } if (!_contentPermissionsService.CanAccess(form)) { return(NotFound()); } var scriptingProvider = new VueFormMethodsProvider(form); var script = form.As <VueFormScripts>(); // This object holds the return value of the script object serverScriptResult = EvaluateScript(script?.OnValidation?.Text, scriptingProvider, formPart, "OnValidation"); // Return if any errors are returned in the OnValidation script if (ModelState.ErrorCount > 0) { return(Json(new VueFormSubmitResult(GetErrorDictionary(), serverScriptResult, GetDebugLogs(formPart)))); } serverScriptResult = EvaluateScript(script?.OnSubmitted?.Text, scriptingProvider, formPart, "OnSubmitted"); // Return if any errors are returned from the OnSubmitted script if (ModelState.ErrorCount > 0) { return(Json(new VueFormSubmitResult(GetErrorDictionary(), serverScriptResult, GetDebugLogs(formPart)))); } // _workflow manager is null if workflow feature is not enabled if (_workflowManager != null) { await _workflowManager.TriggerEventAsync(nameof(VueFormSubmittedEvent), input : new { VueForm = form }, correlationId : form.ContentItemId ); } // Return if any errors are returned from the Workflow if (ModelState.ErrorCount > 0) { return(Json(new VueFormSubmitResult(GetErrorDictionary(), serverScriptResult, GetDebugLogs(formPart)))); } // Handle the redirects with ajax requests. // 302 are equivalent to 301 in this case. No permanent redirect. // This can come from a scripting method or the HttpRedirect Workflow Task if (HttpContext.Response.StatusCode == 301 || HttpContext.Response.StatusCode == 302) { var returnValue = new { redirect = WebUtility.UrlDecode(HttpContext.Response.Headers["Location"]) }; HttpContext.Response.Clear(); return(Json(returnValue)); } // This get's set by either the workflow's HttpRedirectTask or HttpResponseTask if (HttpContext.Items[WorkflowHttpResult.Instance] != null) { // Let the HttpResponseTask control the response. This will fail on the client if it's anything other than json return(new EmptyResult()); } //try to get the message from the http context as set by the addSuccessMessage() scripting function var successMessage = string.Empty; if (HttpContext.Items[Constants.VueFormSuccessMessage] != null) { successMessage = (string)HttpContext.Items[Constants.VueFormSuccessMessage]; } else { if (!string.IsNullOrWhiteSpace(formPart.SuccessMessage?.Text)) { var formSuccessMessage = await _liquidTemplateManager.RenderStringAsync(formPart.SuccessMessage.Text, _htmlEncoder); successMessage = await _shortcodeService.ProcessAsync(formSuccessMessage); } } return(Json(new VueFormSubmitResult(successMessage, serverScriptResult, GetDebugLogs(formPart)))); }
public override async Task CreatedAsync(CreateContentContext context) { await _workflowManager.TriggerEventAsync(nameof(ContentCreatedEvent), new { Content = context.ContentItem }, context.ContentItem.ContentItemId); }
public static Task TriggerEventAsync(this IWorkflowManager workflowManager, string typeName, object input = null, string correlationId = null) { return(workflowManager.TriggerEventAsync(typeName, input?.AsDictionary(), correlationId)); }
public static Task TriggerEventAsync(this IWorkflowManager workflowManager, string name, object input = null, string correlationId = null) { return(workflowManager.TriggerEventAsync(name, new RouteValueDictionary(input), correlationId)); }
public IActionResult Test() { _workflowManager.TriggerEventAsync(nameof(TestEvent), new { json = "工作流测试" }); return(Json(new { result = "已经触发工作流事件" })); }