Пример #1
0
 public virtual void Activate(ITaskExecutionContext ctx, ProcessDef processDef, IProcessScriptRuntime scriptRuntime)
 {
     Context = ctx;
     ProcessDefinition = processDef;
     TaskDefinition = processDef.GetRequiredTask(this.TaskId);
     ScriptRuntime = scriptRuntime;
     if (TaskDefinition == null) throw new Exception("Task not found in process definition: " + this.TaskId);
 }
 protected void GenerateBaseTaskScripts(TaskDef td)
 {
     if (td.Variables != null)
     {
         foreach (var vd in td.Variables.Where(x => !string.IsNullOrEmpty(x.DefaultValueExpr)))
         {
             GenExpression(DslUtil.TaskVariableDefaultKey(td.Id, vd.Name), vd.DefaultValueExpr);
         }
     }
     if (td.InputDataBindings != null)
     {
         foreach (var bnd in td.InputDataBindings.Where(x => x.BindType == DataBindingType.Expr))
         {
             GenExpression(DslUtil.TaskVarInBindingKey(td.Id, bnd.Target), bnd.Source);
         }
     }
     if (td.OutputDataBindings != null)
     {
         foreach (var bnd in td.OutputDataBindings.Where(x => x.BindType == DataBindingType.Expr))
         {
             GenExpression(DslUtil.TaskVarOutBindingKey(td.Id, bnd.Target), bnd.Source);
         }
     }
     if (td.InputParameterBindings != null)
     {
         foreach (var bnd in td.InputParameterBindings.Where(x => x.BindType == DataBindingType.Expr))
         {
             GenExpression(DslUtil.TaskParamInBindingKey(td.Id, bnd.Target), bnd.Source);
         }
     }
     if (td.OutputParameterBindings != null)
     {
         foreach (var bnd in td.OutputParameterBindings.Where(x => x.BindType == DataBindingType.Expr))
         {
             GenExpression(DslUtil.TaskParamOutBindingKey(td.Id, bnd.Target), bnd.Source);
         }
     }
     if (td.IsMultiInstance)
     {
         GenExpression(DslUtil.TaskMultiInstanceSplitKey(td.Id), td.MultiInstanceSplitExpression);
     }
     if (!string.IsNullOrEmpty(td.BeforeEnableScript))
     {
         GenStatement(DslUtil.TaskScriptKey(td.Id, "BeforeEnable"), td.BeforeEnableScript);
     }
     if (!string.IsNullOrEmpty(td.AfterCompleteScript))
     {
         GenStatement(DslUtil.TaskScriptKey(td.Id, "AfterComplete"), td.AfterCompleteScript);
     }
     if (!string.IsNullOrEmpty(td.AfterEnableScript))
     {
         GenStatement(DslUtil.TaskScriptKey(td.Id, "AfterEnable"), td.AfterEnableScript);
     }
 }
Пример #3
0
 private Dictionary<string, object> ExecuteInputDataBindings(TaskDef tsk)
 {
     return this.ScriptRuntime.PrepareChildTaskInputData(this, tsk, this.Context);
 }
 protected void GenerateScript(TaskDef td)
 {
     if (td is CompositeTaskDef)
     {
         GenerateScript((CompositeTaskDef) td);
     }
     else
     {
         GenerateScript((AtomicTaskDef)td);
     }
 }
Пример #5
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);
     _pd.SetInputData(null);
     
     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._exprs.ContainsKey(k)) throw new Exception("!");
                     ti.TaskData[bd.Target] = _pd._exprs[k]();
                     break;
             }
         }
     }
 }
Пример #6
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._exprs[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();
        }
Пример #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._exprs.ContainsKey(k1))
            {
                //get full data record
                SC.IDictionary dic = (SC.IDictionary)_pd._exprs[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._exprs.ContainsKey(k)) throw new Exception("Fail: missing delegate: " + k);
                            ret[bd.Target] = _pd._exprs[k]();
                        }
                    }
                }
            }
            return ret;
        }
Пример #8
0
 public void AddTask(TaskDef td)
 {
     td.Parent = this;
     Tasks.Add(td);
 }