/// <summary> /// Create a model with a workflow from the database /// </summary> /// <param name="name"></param> /// <param name="version"></param> public Model(string name, string version) { try { var json = RestClient.Get($"/workflows/{name}/versions/{version}"); Workflow = JsonConvert.DeserializeObject <WorkflowObj>(json); CreateWorkflowInputVariables(Workflow); } catch (Exception) { MessageBox.Show("Failed to load Workflow", "Error"); } }
/// <summary> /// Create variables for the workflow input values /// </summary> /// <param name="wf"></param> static void CreateWorkflowInputVariables(WorkflowObj wf) { // TODO: These should come from site-specific configuration (possible in the app config?) var initialVars = new Dictionary <string, string> { ["_config"] = "object", // Workflow config ["_job"] = "object", // Job data ["_jobType"] = "string", // Job source/type ["_jobId"] = "string" // External identifier }; foreach (var v in initialVars) { wf.Variables[v.Key] = new VariableObj { Type = v.Value, Description = "Workflow input variable", Path = $"$.{v.Key}" } } ; }
/// <summary> /// Create a model with a new workflow /// </summary> public Model() { Workflow = new WorkflowObj { Name = Guid.NewGuid().ToString().Substring(0, 8), Version = "0.0.0.0", ObjType = "workflow", TaskList = "decider", Tasks = new List <TaskObj>(), Variables = new VariableCollection() }; // The single, required start task var start = new TaskObj { TaskId = "start", ActivityName = "start", ActivityVersion = "0.0.0.0", Outflows = new [] { new FlowObj { Name = "Out" } }, HiddenProperties = new List <string> { "AsyncSignal", "Inputs", "Outputs", "TaskList", "HeartbeatTimeout", "ScheduleToCloseTimeout", "ScheduleToStartTimeout", "StartToCloseTimeout", "TaskPriority" }, Symbol = new SymbolObj { Name = "start", Label = "Start", Style = "circle", LocationX = 100, LocationY = 100 } }; Workflow.Tasks.Add(start); CreateWorkflowInputVariables(Workflow); }