Esempio n. 1
0
        protected void init_task(Action act)
        {
            var    tsk = _curTask == null ? (TaskDef)_currentCompositeTask : _curTask;
            string k   = DslUtil.TaskScriptKey(tsk.Id, "_paramInit");

            _taskScripts[k] = act;
        }
Esempio n. 2
0
        protected void prepare_output_data(Action act)
        {
            var    tsk = _curTask == null ? (TaskDef)_currentCompositeTask : _curTask;
            string k   = DslUtil.TaskScriptKey(tsk.Id, "_variableUpdateOnComplete");

            _taskScripts[k] = act;
        }
Esempio n. 3
0
        protected void variable_input_binding(Func <object> f, string codeString)
        {
            if (_curVar == null)
            {
                throw new Exception("input_binding only in variable def");
            }
            string k = DslUtil.TaskVarInBindingKey(_curTask != null ? _curTask.Id : _currentCompositeTask.Id, _curVar.Name);
            var    b = new DataBindingDef
            {
                BindType = DataBindingType.Expr,
                Source   = codeString,
                Target   = _curVar.Name
            };

            _variableBinds[k] = f;
            if (_curTask != null)
            {
                _curTask.AddInputDataBinding(b);
            }
            else if (_currentCompositeTask != null)
            {
                _currentCompositeTask.AddInputDataBinding(b);
            }
            else
            {
                throw new Exception();
            }
        }
Esempio n. 4
0
        protected void output_bindings_code(Func <SC.IDictionary> fun, string codeStr)
        {
            TaskDef tsk = _curTask != null ? _curTask : (TaskDef)_currentCompositeTask;
            string  k   = DslUtil.TaskOutputDataBindingKey(tsk.Id);

            _variableBinds[k] = fun;
        }
Esempio n. 5
0
        protected void variable_default(Func <object> f, string codeString)
        {
            string k = DslUtil.TaskVariableDefaultKey(_curTask == null ? _currentCompositeTask.Id : _curTask.Id, _curVar.Name);

            _curVar.DefaultValueExpr = codeString;
            _variableBinds[k]        = f;
        }
Esempio n. 6
0
        protected void multi_instance_split_expression(Func <object> dataSplitQuery, string code)
        {
            TaskDef tsk = _curTask != null ? _curTask : (TaskDef)_currentCompositeTask;
            string  k   = DslUtil.TaskMultiInstanceSplitKey(tsk.Id);

            tsk.MultiInstanceSplitExpression = string.IsNullOrEmpty(code) ? "# compiled code block" : code;
            _variableBinds[k] = dataSplitQuery;
        }
Esempio n. 7
0
        public Dictionary <string, object> PrepareChildTaskInputData(CompositeTaskInstance cti, TaskDef childTask, ITaskExecutionContext ctx)
        {
            _pd.SetTaskInstanceInfo(cti, ctx);

            string k1 = DslUtil.TaskInputDataBindingKey(childTask.Id);

            if (_pd._variableBinds.ContainsKey(k1))
            {
                //get full data record
                SC.IDictionary dic = (SC.IDictionary)_pd._variableBinds[k1]();
                return(ToTaskData(dic));
            }

            Dictionary <string, object> ret = new Dictionary <string, object>();

            if (childTask.Variables != null)
            {
                if (childTask.AutoBindVariables)
                {
                    foreach (var vd in childTask.Variables)
                    {
                        if (vd.VariableDir == ProcessModel.Data.VariableDef.Dir.In ||
                            vd.VariableDir == ProcessModel.Data.VariableDef.Dir.InOut)
                        {
                            //TODO add type conversion/control
                            if (cti.TaskData.ContainsKey(vd.Name))
                            {
                                ret[vd.Name] = cti.TaskData[vd.Name];
                            }
                        }
                    }
                }
                if (childTask.InputDataBindings != null)
                {
                    foreach (var bd in childTask.InputDataBindings)
                    {
                        if (bd.BindType == DataBindingType.CopyVar)
                        {
                            ret[bd.Target] = cti.TaskData[bd.Source];
                        }
                        else if (bd.BindType == DataBindingType.Literal)
                        {
                            ret[bd.Target] = bd.Source;
                        }
                        else if (bd.BindType == DataBindingType.Expr)
                        {
                            string k = DslUtil.TaskVarInBindingKey(childTask.Id, bd.Target);
                            if (!_pd._variableBinds.ContainsKey(k))
                            {
                                throw new Exception("Fail: missing delegate: " + k);
                            }
                            ret[bd.Target] = _pd._variableBinds[k]();
                        }
                    }
                }
            }
            return(ret);
        }
Esempio n. 8
0
        public bool EvalFlowCondition(TaskInstance ti, ProcessModel.FlowDef fd, ITaskExecutionContext ctx)
        {
            _pd.SetTaskInstanceInfo(ti, ctx);
            string k = DslUtil.FlowConditionKey(fd.Parent.Id, fd.From, fd.To);

            if (!_pd._flowConditions.ContainsKey(k))
            {
                throw new Exception("!no flow cond..");
            }
            _pd.SetTaskInstanceInfo(ti, ctx);
            return(_pd._flowConditions[k]());
        }
Esempio n. 9
0
 protected void flow_condition(Func <bool> cond, string condString)
 {
     if (_curFlow != null)
     {
         _curFlow.InputCondition = condString;
         _flowConditions[DslUtil.FlowConditionKey(_currentCompositeTask.Id, _curFlow.From, _curFlow.To)] = cond;
     }
     else
     {
         throw new Exception();
     }
 }
Esempio n. 10
0
        public Dictionary <string, object> GatherOutputData(TaskInstance ti, ITaskExecutionContext ctx)
        {
            _pd.SetTaskInstanceInfo(ti, ctx);
            string ks = DslUtil.TaskScriptKey(ti.TaskId, "_variableUpdateOnComplete");

            if (_pd._taskScripts.ContainsKey(ks))
            {
                _pd._taskScripts[ks]();
            }
            var td = _def.GetRequiredTask(ti.TaskId);

            foreach (var bd in td.OutputParameterBindings)
            {
                string k = DslUtil.TaskParamOutBindingKey(td.Id, bd.Target);
                if (bd.BindType == DataBindingType.Expr)
                {
                    ti.TaskData[bd.Target] = _pd._variableBinds[k]();
                }
                else if (bd.BindType == DataBindingType.CopyVar)
                {
                    var pi = ti.GetType().GetProperty(bd.Source);
                    if (pi == null)
                    {
                        throw new NGinnBPM.ProcessModel.Exceptions.TaskParameterInvalidException(bd.Source, "Property not found: " + bd.Source).SetTaskId(ti.TaskId);
                    }
                    ti.TaskData[bd.Target] = pi.GetValue(ti, null);
                }
                else if (bd.BindType == DataBindingType.Literal)
                {
                    ti.TaskData[bd.Target] = bd.Source; //todo: type convert
                }
                else
                {
                    throw new Exception();
                }
            }

            string k2 = DslUtil.TaskOutputDataBindingKey(td.Id);

            if (_pd._variableBinds.ContainsKey(k2))
            {
                SC.IDictionary dic = (SC.IDictionary)_pd._variableBinds[k2]();
                return(ToTaskData(dic));
            }
            Dictionary <string, object> ret = new Dictionary <string, object>();

            foreach (var vd in td.Variables.Where(x => x.VariableDir == ProcessModel.Data.VariableDef.Dir.Out || x.VariableDir == ProcessModel.Data.VariableDef.Dir.InOut))
            {
                ret[vd.Name] = ti.TaskData[vd.Name];
            }
            return(ret);
        }
Esempio n. 11
0
        public void ExecuteChildTaskOutputDataBinding(CompositeTaskInstance ti, TaskDef childTask, Dictionary <string, object> childOutputData, ITaskExecutionContext ctx)
        {
            if (string.IsNullOrEmpty(ti.InstanceId) ||
                string.IsNullOrEmpty(ti.TaskId) ||
                string.IsNullOrEmpty(ti.ProcessDefinitionId) ||
                string.IsNullOrEmpty(ti.ProcessInstanceId))
            {
                throw new Exception("Task not inited properly");
            }
            _pd.SetTaskInstanceInfo(ti, ctx);
            _pd.SetOutputData(childOutputData);
            var ctd = childTask.Parent;

            if (childTask.AutoBindVariables && ctd.Variables != null)
            {
                foreach (var vd in ctd.Variables)
                {
                    if (childOutputData.ContainsKey(vd.Name))
                    {
                        ti.TaskData[vd.Name] = childOutputData[vd.Name];
                    }
                }
            }
            if (childTask.OutputDataBindings != null)
            {
                foreach (var bd in childTask.OutputDataBindings)
                {
                    switch (bd.BindType)
                    {
                    case DataBindingType.CopyVar:
                        ti.TaskData[bd.Target] = childOutputData[bd.Source];
                        break;

                    case DataBindingType.Literal:
                        ti.TaskData[bd.Target] = bd.Source;
                        break;

                    case DataBindingType.Expr:
                        string k = DslUtil.TaskVarOutBindingKey(childTask.Id, bd.Target);
                        if (!_pd._variableBinds.ContainsKey(k))
                        {
                            throw new Exception("!");
                        }
                        ti.TaskData[bd.Target] = _pd._variableBinds[k]();
                        break;
                    }
                }
            }
        }
Esempio n. 12
0
        protected void add_output_binding(string destinationVariable, Func <object> expression, string codeString)
        {
            var b = new DataBindingDef
            {
                BindType = DataBindingType.Expr,
                Source   = codeString,
                Target   = destinationVariable
            };
            var k = DslUtil.TaskVarOutBindingKey(_curTask != null ? _curTask.Id : _currentCompositeTask.Id, destinationVariable);

            _variableBinds[k] = expression;
            if (_curTask != null)
            {
                _curTask.AddOutputDataBinding(b);
            }
            else if (_currentCompositeTask != null)
            {
                _currentCompositeTask.AddOutputDataBinding(b);
            }
        }
Esempio n. 13
0
        public void InitializeNewTask(TaskInstance ti, Dictionary <string, object> inputData, ITaskExecutionContext ctx)
        {
            if (string.IsNullOrEmpty(ti.InstanceId) ||
                string.IsNullOrEmpty(ti.TaskId) ||
                string.IsNullOrEmpty(ti.ProcessDefinitionId) ||
                string.IsNullOrEmpty(ti.ProcessInstanceId))
            {
                throw new Exception("Task not inited properly");
            }
            _pd.SetTaskInstanceInfo(ti, ctx);

            TaskDef td = _def.GetRequiredTask(ti.TaskId);

            if (td.Variables != null)
            {
                foreach (var vd in td.Variables)
                {
                    if (vd.VariableDir == ProcessModel.Data.VariableDef.Dir.In ||
                        vd.VariableDir == ProcessModel.Data.VariableDef.Dir.InOut)
                    {
                        if (inputData.ContainsKey(vd.Name))
                        {
                            ti.TaskData[vd.Name] = inputData[vd.Name];
                        }
                    }
                    if (!ti.TaskData.ContainsKey(vd.Name))
                    {
                        var k = DslUtil.TaskVariableDefaultKey(td.Id, vd.Name);
                        if (_pd._variableBinds.ContainsKey(k))
                        {
                            ti.TaskData[vd.Name] = _pd._variableBinds[k]();
                        }
                        else if (!string.IsNullOrEmpty(vd.DefaultValueExpr))
                        {
                            ti.TaskData[vd.Name] = vd.DefaultValueExpr; //TODO: add type conversion
                        }
                        else if (vd.IsRequired)
                        {
                            throw new NGinnBPM.ProcessModel.Exceptions.DataValidationException("Required variable missing: " + vd.Name).SetTaskId(ti.TaskId).SetProcessDef(ti.ProcessDefinitionId);
                        }
                    }
                }
            }
            //now initialize task parameters
            if (td.InputParameterBindings != null)
            {
                foreach (var bd in td.InputParameterBindings)
                {
                    var pi = ti.GetType().GetProperty(bd.Target);
                    if (pi == null)
                    {
                        throw new NGinnBPM.ProcessModel.Exceptions.TaskParameterInvalidException(bd.Target, "Property not found: " + bd.Target).SetTaskId(ti.TaskId);
                    }
                    string k = DslUtil.TaskParamInBindingKey(td.Id, bd.Target);
                    if (bd.BindType == DataBindingType.Expr)
                    {
                        pi.SetValue(ti, _pd._variableBinds[k](), null);
                    }
                    else if (bd.BindType == DataBindingType.CopyVar)
                    {
                        pi.SetValue(ti, ti.TaskData.ContainsKey(bd.Source) ? ti.TaskData[bd.Source] : null, null);
                    }
                    else if (bd.BindType == DataBindingType.Literal)
                    {
                        pi.SetValue(ti, Convert.ChangeType(bd.Source, pi.PropertyType), null);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            string ks = DslUtil.TaskScriptKey(ti.TaskId, "_paramInit");

            if (_pd._taskScripts.ContainsKey(ks))
            {
                _pd._taskScripts[ks]();
            }
        }
Esempio n. 14
0
        public IEnumerable <Dictionary <string, object> > PrepareMultiInstanceTaskInputData(CompositeTaskInstance cti, TaskDef childTask, ITaskExecutionContext ctx)
        {
            if (!childTask.IsMultiInstance)
            {
                throw new Exception();
            }
            var           k   = DslUtil.TaskMultiInstanceSplitKey(childTask.Id);
            Func <object> fun = _pd._variableBinds[k];

            if (fun == null)
            {
                throw new Exception();
            }
            _pd.SetTaskInstanceInfo(cti, ctx);
            SC.IEnumerable enu;
            var            val = fun();

            enu = val is SC.IEnumerable ? (SC.IEnumerable)val : new object[] { val };
            List <Dictionary <string, object> > ret = new List <Dictionary <string, object> >();

            foreach (object item in enu)
            {
                if (item is Dictionary <string, object> )
                {
                    ret.Add((Dictionary <string, object>)item);
                }
                else if (item is SC.IDictionary)
                {
                    ret.Add(ToTaskData((SC.IDictionary)item));
                }
                else
                {
                    throw new Exception();
                }
            }
            return(ret);

            /*
             * ITaskScript scr = Context.ScriptManager.GetTaskScript(this.ParentProcess, taskId);
             * Task tsk = MyTask.RequireTask(taskId);
             * scr.TaskContext = Context;
             * Dictionary<string, object> srcData = new Dictionary<string, object>(TaskData);
             * scr.SourceData = srcData;
             * object obj = scr.EvalMultiInstanceSplitQuery();
             * IEnumerable enu;
             * if (obj is IEnumerable)
             *  enu = (IEnumerable)obj;
             * else
             * {
             *  ArrayList al = new ArrayList();
             *  al.Add(obj);
             *  enu = al;
             * }
             * List<Dictionary<string, object>> lst = new List<Dictionary<string, object>>();
             *
             * foreach (object v in enu)
             * {
             *  srcData[tsk.MultiInstanceItemAlias] = v;
             *  lst.Add(ExecuteInputDataBindings(scr, tsk));
             * }
             * return lst;
             */
            throw new NotImplementedException();
        }