public async Task <bool> ExecuteCommand(Guid processId, string commandName) { var identityId = AbpSession.UserId?.ToString(); var commands = await _runtime.GetAvailableCommandsAsync(processId, new List <string> { identityId }, commandName); var command = commands.FirstOrDefault(); if (command != null) { var res = await _runtime.ExecuteCommandAsync(command, identityId, null); return(res.WasExecuted); } return(false); }
public async Task <Response> WorkflowApiProcessing(RequestContext ctx) { object data = string.Empty; string error = string.Empty; try { string operation = ctx.Request.HttpParams.QueryString["operation"]; if (string.IsNullOrWhiteSpace(operation)) { throw new Exception("Parameter 'operation' is required!"); } Guid processid; if (!Guid.TryParse(ctx.Request.HttpParams.QueryString["processid"], out processid)) { throw new Exception("Parameter 'processid' is required and must be is GUID!"); } var identityid = ctx.Request.HttpParams.QueryString["identityid"]; var impersonatedIdentityId = ctx.Request.HttpParams.QueryString["impersonatedIdentityId"]; var value = ctx.Request.HttpParams.QueryString["parameters"]; var parameters = !string.IsNullOrWhiteSpace(value) ? JsonConvert.DeserializeObject <Dictionary <string, object> >(value) : null; CultureInfo culture = CultureInfo.CurrentUICulture; if (!string.IsNullOrWhiteSpace(ctx.Request.HttpParams.QueryString["culture"])) { culture = new CultureInfo(ctx.Request.HttpParams.QueryString["culture"]); } switch (operation.ToLower()) { case "createinstance": var schemacode = ctx.Request.HttpParams.QueryString["schemacode"]; if (string.IsNullOrWhiteSpace(schemacode)) { throw new Exception("Parameter 'schemacode' is required!"); } if (parameters == null) { parameters = new Dictionary <string, object>(); } var initialPrameters = await GetInitialProcessParameters(ctx, schemacode); var createInstanceParams = new CreateInstanceParams(schemacode, processid) { IdentityId = identityid, ImpersonatedIdentityId = impersonatedIdentityId, InitialProcessParameters = initialPrameters, SchemeCreationParameters = parameters }; await _runtime.CreateInstanceAsync(createInstanceParams); break; case "getavailablecommands": var availableCommands = await _runtime.GetAvailableCommandsAsync(processid, new List <string>() { identityid }, null, impersonatedIdentityId); data = JsonConvert.SerializeObject(availableCommands); break; case "executecommand": var command = ctx.Request.HttpParams.QueryString["command"]; var wfcommands = await _runtime.GetAvailableCommandsAsync(processid, new List <string>() { identityid }, command, impersonatedIdentityId); var wfcommand = wfcommands.FirstOrDefault(); if (wfcommand == null) { throw new Exception(string.Format("Command {0} is not found", command)); } FillCommandParameters(ctx, wfcommand); await _runtime.ExecuteCommandAsync(wfcommand, identityid, impersonatedIdentityId); break; case "getavailablestatetoset": var availableStateToSet = await _runtime.GetAvailableStateToSetAsync(processid, culture); data = JsonConvert.SerializeObject(availableStateToSet); break; case "setstate": var state = ctx.Request.HttpParams.QueryString["state"]; if (parameters == null) { parameters = new Dictionary <string, object>(); } await _runtime.SetStateAsync(processid, identityid, impersonatedIdentityId, state, parameters); break; case "isexistprocess": var isProcessExists = await _runtime.IsProcessExistsAsync(processid); data = JsonConvert.SerializeObject(isProcessExists); break; default: throw new Exception(string.Format("operation={0} is not suported!", operation)); } } catch (Exception ex) { error = string.Format("{0}{1}", ex.Message, ex.InnerException == null ? string.Empty : string.Format(". InnerException: {0}", ex.InnerException.Message)); } var res = JsonConvert.SerializeObject(new { data = data, success = error.Length == 0, error = error }); return(new StringResponse(res)); }