/// <summary> /// Start a workflow and and wait for it to complete or pause. /// </summary> /// <returns></returns> public WorkflowRun RunWorkflow(WorkflowStartEvent startEvent) { if (startEvent.Workflow == null) { throw new ArgumentException($"{nameof(startEvent)} missing mandatory field Workflow."); } // deny workflow run when tenant is disabled if (TenantHelper.IsDisabled()) { EventLog.Application.WriteWarning("Workflow run denied, tenant is disabled. \"{0\"({1})", startEvent.Workflow.Name, startEvent.Workflow.Id); return(null); } using (Profiler.Measure("WorkflowRunner.Instance.RunWorkflow")) { using (new SecurityBypassContext()) { if (startEvent.Workflow.WfNewerVersion != null) { throw new ArgumentException("Attempted to run a workflow that is not the newest version."); } // create a wf run then pass into the workflow var run = new WorkflowRunDeferred(startEvent.Workflow, startEvent.Trigger) { RunTrace = startEvent.Trace, ParentRun = startEvent.ParentRun }; return(ProcessWorkflowInContext(run, startEvent)); } } }