Пример #1
0
        protected void UpdateTask(string instanceId, Action <TaskInstance> act)
        {
            RunProcessTransaction(this.DefaultPersistenceMode, ps =>
            {
                string ol = MappedDiagnosticsContext.Get("NG_TaskInstanceId");
                try
                {
                    MappedDiagnosticsContext.Set("NG_TaskInstanceId", instanceId);

                    var ti = ps.TaskPersister.GetForUpdate(instanceId);
                    if (ti == null)
                    {
                        log.Warn("Task instance not found: {0}", instanceId);
                        var pti = (CompositeTaskInstance)ps.TaskPersister.GetForRead(InstanceId.GetParentTaskInstanceId(instanceId));
                        if (pti == null)
                        {
                            throw new Exception("Task instance not found and no parent. Instance ID: " + instanceId);
                        }
                        var tin = pti.GetChildTransitionInfo(instanceId);
                        if (tin == null)
                        {
                            throw new Exception("Task instance not found anywhere: " + instanceId);
                        }
                        log.Info("Task instance not found, parent says that status is {0}", tin.Status);
                        return;
                    }
                    ;
                    var pd      = this.GetProcessDef(ti.ProcessDefinitionId);
                    var pscript = this.GetProcessScriptRuntime(ti.ProcessDefinitionId);
                    ti.Activate(ps, pd, pscript);
                    var pstat = ti.Status;
                    act(ti);
                    OnTaskInstanceStatusChange(ti, pstat);
                    ti.Deactivate();
                    ps.TaskPersister.Update(ti);
                }
                finally
                {
                    MappedDiagnosticsContext.Set("NG_TaskInstanceId", ol);
                }
            });
        }