Esempio n. 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);
 }
Esempio n. 2
0
        public void AddFlow(FlowDef t)
        {
            if (string.IsNullOrEmpty(t.From) || string.IsNullOrEmpty(t.To))
            {
                throw new Exception("Flow must have start and target node");
            }
            NodeDef p = GetNode(t.From);

            if (p == null)
            {
                throw new Exception("Node not defined: " + t.From);
            }
            NodeDef q = GetNode(t.To);

            if (q == null)
            {
                throw new Exception("Node not defined: " + t.To);
            }
            t.Parent = this;

            if (t.IsCancelling || t.SourcePortType != TaskOutPortType.Out)
            {
                if (t.InputCondition != null && t.InputCondition.Length > 0)
                {
                    throw new NGinnBPM.ProcessModel.Exceptions.ProcessDefinitionException(this.ParentProcess.DefinitionId, t.From, "InputCondition not allowed");
                }
            }

            if (p is PlaceDef && q is PlaceDef)
            {
                throw new Exception("Flow cannot connect two places");
            }
            if (p is TaskDef && q is TaskDef)
            {
                //adding implicit place between p and q
                TaskDef  tq    = q as TaskDef;
                TaskDef  tp    = p as TaskDef;
                PlaceDef ptran = new PlaceDef {
                    Id        = string.Format("{0}.-.{1}", tp.Id, tq.Id),
                    PlaceType = PlaceTypes.Intermediate,
                    Implicit  = true
                };
                AddPlace(ptran);
                t.To = ptran.Id;
                FlowDef f2 = new FlowDef();
                f2.From = ptran.Id;
                f2.To   = tq.Id;
                AddFlow(t);
                AddFlow(f2);
            }
            else
            {
                Flows.Add(t);
            }
        }
 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);
     }
 }
 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);
     }
 }
 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;
             }
         }
     }
 }
        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();
        }
        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;
        }
Esempio n. 9
0
 public void AddTask(TaskDef td)
 {
     td.Parent = this;
     Tasks.Add(td);
 }
Esempio n. 10
0
 public void AddTask(TaskDef td)
 {
     td.Parent = this;
     Tasks.Add(td);
 }