public object RunWorkflow(IFormSubmissionFunction submissionFunc) { if (submissionFunc == null) { return(null); } if (submissionFunc.Cancel) { return(null); } if (submissionFunc.Workflow == null) { return(null); } if (submissionFunc.Workflow.Contains("rest://")) { var processor = new RestWorkflowProcessor(this, submissionFunc); return(processor.Execute()); } return(null); }
private Uri ConstructWorkflowUri(IFormSubmissionFunction submissionFunc) { string workflow = new StringSubstitutor().PerformSubstitutions(submissionFunc.Workflow, null, this.Form); Uri uri = new Uri(workflow); switch (uri.Scheme.ToLower()) { case "mockrest": { this.IsMockRest = true; Uri newUri = this.GenerateHttpUri(uri); return(newUri); } case "rest": { this.IsMockRest = ApplicationContext.Configuration.UseMocksForRestCalls; Uri newUri = this.GenerateHttpUri(uri); return(newUri); } } return(null); }
public object RunWorkflow(IFormSubmissionFunction submissionFunc) { if (submissionFunc == null) { return(null); } if (submissionFunc.Cancel) { return(null); } if (submissionFunc.Workflow == null) { return(null); } var processor = this.LoadWorkflow(submissionFunc); return(submissionFunc.Async ? processor?.ExecuteAsync() : processor?.Execute()); }
protected IWorkflow LoadWorkflow(IFormSubmissionFunction submissionFunc) { const string protocolTag = "://"; string workflowName = submissionFunc.Workflow; if (workflowName.Contains(protocolTag)) { workflowName = workflowName.Substring(0, workflowName.IndexOf(protocolTag, StringComparison.Ordinal)); // "workflow://name" is just an alias for "name" if (workflowName.Equals("workflow", StringComparison.OrdinalIgnoreCase)) { workflowName = submissionFunc.Workflow.Substring("workflow://".Length); } } var workflowType = WorkflowRepository.Instance.GetType(workflowName); if (workflowType == null) { throw new ApplicationException($"Cannot find the workflow named {workflowName}"); } if (typeof(IFormWorkflow).IsAssignableFrom(workflowType)) { if (Activator.CreateInstance(workflowType, this, submissionFunc) is IFormWorkflow processor) { return(processor); } } else { if (Activator.CreateInstance(workflowType, this, submissionFunc) is IWorkflow processor) { return(processor); } } return(null); }
public MockRestWorkflow(SBSFormSubmissionWorkflowProcessor processor, IFormSubmissionFunction submissionFunc) : base(processor, submissionFunc) { this.IsMockRest = true; this.Name = "mockrest"; }
public RestWorkflow(SBSFormSubmissionWorkflowProcessor processor, IFormSubmissionFunction submissionFunc) : base("rest", processor, submissionFunc) { }
private byte[] PreparePayload(WebRequest request, string body, string bodyFormat, IFormSubmissionFunction submissionFunction) { if (string.IsNullOrEmpty(body)) { return(null); } byte[] data; // Evaluate the (possible) expression in the body object objPayload = body; if (this.WorkflowProcessor.BodyExpressionEvaluator != null) { objPayload = this.WorkflowProcessor.BodyExpressionEvaluator(body, submissionFunction); } if (bodyFormat.Equals("json", StringComparison.OrdinalIgnoreCase)) { body = Json.Serialize(objPayload); data = Encoding.UTF8.GetBytes(body); request.ContentType = "application/json"; } else { data = Encoding.UTF8.GetBytes((string)objPayload); request.ContentType = "application/text"; } request.ContentLength = data.Length; return(data); }
private WebResponse PostOrPut(string method, Uri uri, string body, string bodyFormat, IFormSubmissionFunction submissionFunction, out string responsePayload) { // https://docs.microsoft.com/en-us/dotnet/framework/network-programming/how-to-send-data-using-the-webrequest-class var request = this.PrepareWebRequest(method, uri); var data = this.PreparePayload(request, body, bodyFormat, submissionFunction); // The call to the REST endpoint is synchronous here. // TODO - support async try { // Send the request and payload (we don't do this for GET requests) if (data != null) { // Send the request to the REST endpoint Stream dataStream = request.GetRequestStream(); dataStream.Write(data, 0, data.Length); dataStream.Close(); } // Get the response from the server var response = request.GetResponse(); { using (var reader = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException())) { responsePayload = reader.ReadToEnd(); // Right now, we are not doing anything here with the response payload. We will let the caller handle it. } } return(response); } catch (WebException webExc) { this.WorkflowProcessor.Logger.Error(webExc.Message); responsePayload = null; return(webExc.Response); } }
public RestWorkflowProcessor(SBSFormSubmissionWorkflowProcessor processor, IFormSubmissionFunction submissionFunc) { this.WorkflowProcessor = processor; this.Form = processor.Form; this.SubmissionFunction = submissionFunc; }
protected FormWorkflowBase(string name, SBSFormSubmissionWorkflowProcessor processor, IFormSubmissionFunction submissionFunc) { this.Name = name; this.WorkflowProcessor = processor; this.Form = processor.Form; this.SubmissionFunction = submissionFunc; this.Logger = LogManager.GetLogger(this.GetType()); }
public RegisterUserWorkflow(Data.Workflow.SBSFormSubmissionWorkflowProcessor processor, IFormSubmissionFunction submissionFunc) : base("registerUser", processor, submissionFunc) { }