danielgerlag / workflow-core

Lightweight workflow engine for .NET Standard
MIT License
5.41k stars 1.2k forks source link

[Question] Workflow Data with multiple Dictionary members with JSON workflow definition. #457

Open bbollard opened 5 years ago

bbollard commented 5 years ago

I am building workflows using JSON definitions and would like to define my workflow data object in a loosely coupled manner like so:

    public class WorkflowData
    {
        public Dictionary<string, object> InstanceData { get; set; } = new Dictionary<string, object>();
        public Dictionary<string, object> WorkflowArguments { get; set; } = new Dictionary<string, object>();
   }

And would like to be able to access both objects within JSON workflow definitions, such as:

{
    'Id': '1',
    'Name': 'Start',
    'StepType': 'DotnetCoreWorkflow.FirstStep, DotnetCoreWorkflow',
    'NextStepId': '2',
    'Inputs': {
      'StepInputValue' : 'data.WorkflowArguments["Argument1"]'
    }
    'Outputs': { 
        'data.InstanceData["CalculatedValue"]': 'step.OutputValue'
    }
},

Any suggestions would be appreciated. The alternative, of course, would be to create a more formally defined data object as most of the samples demonstrate.

Thank you, Brian

danielgerlag commented 4 years ago

you can pass object graphs to step inputs as opposed to just scalar values

"inputs": 
{    
  "Body": {
      "Value1": 1,
      "Value2": 2
  },
  "Headers": {
      "Content-Type": "application/json"
  }
},

If you want to evaluate an expression for a given property of your object, simply prepend and @ and pass an expression string

"inputs": 
{    
  "Body": {
      "@Value1": "data.MyValue * 2",
      "Value2": 5
  },
  "Headers": {
      "Content-Type": "application/json"
  }
},
zhenl commented 4 years ago

Hello,

I tried to pass scalar values to step inputs but met error: "Object of type 'Newtonsoft.Json.Linq.JObject' cannot be converted to type 'ZL.WorflowCoreDemo.InputDictionary.StepPara'."

The json file likes:

{ "Id": "ManualWorkflow", "Version": 1, "DataType": "ZL.WorflowCoreDemo.InputDictionary.ManualWorkflowData,ZL.WorflowCoreDemo", "Steps": [ { "Id": "EnterName1", "StepType": "ZL.WorflowCoreDemo.InputDictionary.ManualInput,ZL.WorflowCoreDemo", "NextStepId": "EnterName2", "inputs": { "stepPara": { "ParaValue": 1 } } }, { "Id": "EnterName2", "StepType": "ZL.WorflowCoreDemo.InputDictionary.ManualInput,ZL.WorflowCoreDemo"

}

] }

The class StepPara: namespace ZL.WorflowCoreDemo.InputDictionary { public class StepPara { public int ParaValue { get; set; } } }

Did I miss something?

brettwinters commented 3 years ago

899