Example #1
0
 public IActiveTask CreateActiveTask(Task tsk)
 {
     IActiveTask at;
     if (tsk is EmptyTask)
     {
         at = new EmptyTaskActive(tsk);
     }
     else if (tsk is TimerTask)
     {
         at = new TimerTaskActive(tsk);
     }
     else if (tsk is ScriptTask)
     {
         at = new ScriptTaskActive((ScriptTask)tsk);
     }
     else if (tsk is NotificationTask)
     {
         at = new NotificationTaskActive((NotificationTask)tsk);
     }
     else if (tsk is ReceiveMessageTask)
     {
         at = new ReceiveMessageTaskActive(tsk);
     }
     else if (tsk is ManualTask)
     {
         at = new ManualTaskActive((ManualTask)tsk);
     }
     else throw new Exception();
     return at;
 }
 public XmlHttpTaskActiveCurl(Task tsk)
     : base(tsk)
 {
 }
 internal ActiveTransition CreateSingleInstanceTransitionForTask(Task tsk)
 {
     ActiveTransition at = _transitionFactory.CreateTransition(tsk);
     at.ProcessInstanceId = this.InstanceId;
     at.CorrelationId = GetNextTransitionId();
     at.SetProcessInstance(this);
     at.ContainerCallback = this;
     return at;
 }
 internal MultiInstanceTaskActive CreateMultiInstanceTransitionForTask(Task tsk)
 {
     MultiInstanceTaskActive mit = new MultiInstanceTaskActive(tsk);
     mit.CorrelationId = GetNextTransitionId();
     mit.ProcessInstanceId = this.InstanceId;
     mit.SetProcessInstance(this);
     mit.ContainerCallback = this;
     return mit;
 }
        private TaskShell CreateActiveTransitionForTask(Task tsk)
        {
            if (tsk.IsMultiInstance)
            {

                //return CreateMultiInstanceTransitionForTask(tsk);
                return new TaskShell();
            }
            else
            {
                //return CreateSingleInstanceTransitionForTask(tsk);
                return new TaskShell();
            }
        }
 /// <summary>
 /// Transition can be initiated if it has required number (depending on join type) of tokens in statuses:
 /// READY, WAITING or WAITING_TASK
 /// </summary>
 /// <param name="tsk"></param>
 /// <returns></returns>
 private bool CanEnableTransition(Task tsk, IDictionary<string, string> ignoreTokens, out IList<Token> enablingTokens)
 {
     enablingTokens = new List<Token>();
     if (tsk.JoinType == JoinType.AND)
     {
         foreach (Place pl in tsk.NodesIn)
         {
             bool foundTokInPlace = false;
             IList<Token> toksInPlace = GetConsumableTokensInPlace(pl.Id);
             foreach (Token t in toksInPlace)
             {
                 if (!ignoreTokens.ContainsKey(t.TokenId))
                 {
                     foundTokInPlace = true;
                     enablingTokens.Add(t);
                     break;
                 }
             }
             if (!foundTokInPlace)
             {
                 return false;
             }
         }
         return true;
     }
     else if (tsk.JoinType == JoinType.XOR)
     {
         foreach (Place pl in tsk.NodesIn)
         {
             IList<Token> toksInPlace = GetConsumableTokensInPlace(pl.Id);
             foreach (Token t in toksInPlace)
             {
                 if (!ignoreTokens.ContainsKey(t.TokenId))
                 {
                     enablingTokens.Add(t);
                     return true;
                 }
             }
         }
         return false;
     }
     else if (tsk.JoinType == JoinType.OR)
     {
         foreach (Place pl in tsk.NodesIn)
         {
             bool foundTokInPlace = false;
             IList<Token> toksInPlace = GetConsumableTokensInPlace(pl.Id);
             foreach (Token t in toksInPlace)
             {
                 if (!ignoreTokens.ContainsKey(t.TokenId))
                 {
                     foundTokInPlace = true;
                     enablingTokens.Add(t);
                     break;
                 }
             }
         }
         if (enablingTokens.Count == 0)
         {
             return false; //no input tokens for OR join
         }
         ///now check the OrJoinCheckList. If there are tokens in places from the list,
         ///don't enable the transition - we have to wait until all the tokens disappear from
         ///these places.
         foreach (string plid in tsk.ORJoinChecklist)
         {
             Place pl = Definition.GetPlace(plid);
             if (tsk.NodesIn.Contains(pl)) continue;
             IList<Token> toks = GetTokensInPlace(plid);
             foreach (Token t in toks)
             {
                 if (t.Status == TokenStatus.READY ||
                     t.Status == TokenStatus.WAITING ||
                     t.Status == TokenStatus.LOCKED_ALLOCATED ||
                     t.Status == TokenStatus.LOCKED_ENABLED)
                 {
                     log.Info("OR join not enabled: token in {0}", plid);
                     return false;
                 }
             }
         }
         return true;
     }
     else throw new Exception();
 }
Example #7
0
 public virtual void Passivate()
 {
     if (ActiveTask != null)
     {
         ActiveTask.Passivate();
     }
     _parentProces = null;
     _taskDefinition = null;
     _parentCallback = null;
     _activated = false;
 }
Example #8
0
 public TimerTaskActive(Task tsk)
     : base(tsk)
 {
 }
 private void GenerateTaskCode(ProcessDefinition pd, Task tsk, TextWriter output)
 {
 }
Example #10
0
 public EmptyTaskActive(Task tsk)
     : base(tsk)
 {
 }
        private TaskShell CreateActiveTransitionForTask(Task tsk)
        {
            if (tsk.IsMultiInstance)
            {
                MultiTaskShell mts = new MultiTaskShell(this, tsk.Id);
                mts.CorrelationId = GetNextTransitionId();
                mts.SetProcessInstance(this);
                mts.ParentCallback = this;
                return mts;
            }
            else
            {

                TaskShell ts = new TaskShell(this, tsk.Id);
                ts.CorrelationId = GetNextTransitionId();
                ts.SetProcessInstance(this);
                ts.ParentCallback = this;
                return ts;
            }
        }
        /// <summary>
        /// Check if a synchronizing transition can be enabled.
        /// Synchronizing transition is a task with 1 or more input places. All input places must not be implicit-choice places.
        /// The consequence is that we will not have to consider LOCKED_ENABLED tokens - only READY or WAITING tokens can be used.
        /// </summary>
        /// <param name="tsk"></param>
        /// <param name="currentEnablingTokens"></param>
        /// <returns></returns>
        private bool CanEnableSynchronizingTransition(Task tsk, IList<Token> currentEnablingTokens)
        {
            Dictionary<string, Token> toksInPlaces = new Dictionary<string, Token>();
            foreach (Token t in currentEnablingTokens)
            {
                if (toksInPlaces.ContainsKey(t.PlaceId)) throw new Exception("currentEnablingTokens contains two tokens from the same place: " + t.PlaceId);
                toksInPlaces[t.PlaceId] = t;
                if (t.Status != TokenStatus.READY && t.Status != TokenStatus.WAITING)
                    throw new Exception("Invalid status of input token {0}: " + t.TokenId);
            }
            List<Token> newEnablingTokens = new List<Token>();
            if (tsk.JoinType == JoinType.AND)
            {
                foreach (Place pl in tsk.NodesIn)
                {
                    Token t;
                    if (!toksInPlaces.TryGetValue(pl.Id, out t))
                    {
                        log.Debug("CanEnableTransition2: looking for enabling token for transition {0}, place {1}", tsk.Id, pl.Id);
                        t = SelectReadyTokenInPlace(pl.Id);
                        if (t != null)
                        {
                            log.Debug("CanEnableTransition2: found input token in place {0} required to enable transition {1}", pl.Id, tsk.Id);
                            newEnablingTokens.Add(t);
                        }
                        else
                        {
                            log.Debug("CanEnableTransition2: no suitable input token in place {0} to enable transition {1}", pl.Id, tsk.Id);
                            return false;
                        }
                    }
                }
                foreach (Token t2 in newEnablingTokens) currentEnablingTokens.Add(t2);
                return true;
            }
            else if (tsk.JoinType == JoinType.XOR)
            {
                foreach (Place pl in tsk.NodesIn)
                {
                    Token t;
                    if (!toksInPlaces.TryGetValue(pl.Id, out t))
                    {
                        t = SelectReadyTokenInPlace(pl.Id);
                        if (t != null)
                        {
                            newEnablingTokens.Add(t);
                        }
                    }
                    else
                    {
                        return true;
                    }
                }
                if (newEnablingTokens.Count > 0)
                {
                    currentEnablingTokens.Add(newEnablingTokens[0]);
                    return true;
                }
                return false;
            }
            else if (tsk.JoinType == JoinType.OR)
            {
                foreach (Place pl in tsk.NodesIn)
                {
                    Token t;
                    if (!toksInPlaces.TryGetValue(pl.Id, out t))
                    {
                        t = SelectReadyTokenInPlace(pl.Id);
                        if (t != null)
                        {
                            newEnablingTokens.Add(t);
                        }
                    }
                }
                if (currentEnablingTokens.Count + newEnablingTokens.Count == 0)
                {
                    return false; //no input tokens
                }

                ///now check the OrJoinCheckList. If there are tokens in places from the list,
                ///don't enable the transition - we have to wait until all the tokens disappear from
                ///these places.
                foreach (string plid in tsk.ORJoinChecklist)
                {
                    Place pl = Definition.GetPlace(plid);
                    if (tsk.NodesIn.Contains(pl)) continue;
                    IList<Token> toks = GetTokensInPlace(plid);
                    foreach (Token t in toks)
                    {
                        if (t.Status == TokenStatus.READY ||
                            t.Status == TokenStatus.WAITING ||
                            t.Status == TokenStatus.LOCKED_ALLOCATED ||
                            t.Status == TokenStatus.LOCKED_ENABLED)
                        {
                            log.Info("OR join not enabled: token in {0}", plid);
                            return false;
                        }
                    }
                }
                foreach (Token t2 in newEnablingTokens) currentEnablingTokens.Add(t2);
                return true;
            }
            else throw new Exception();
        }
 public ReceiveMessageTaskActive(Task tsk)
     : base(tsk)
 {
 }
Example #14
0
 /// <summary>
 /// Restore task's state from DataObject.
 /// Use INGinnPersistent if supported. If not, use binary serialization.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 protected IActiveTask RestoreTaskState(DataObject data, Task definition)
 {
     string bs = (string)data["NGINN_BINARY_DATA"];
     if (bs != null)
     {
         //binary restore here
     }
     //restore activetask here...
     IActiveTask at = EnvironmentContext.ActiveTaskFactory.CreateActiveTask(definition);
     INGinnPersistent pers = at as INGinnPersistent;
     if (pers != null)
     {
         pers.RestoreState(data);
         return at;
     }
     log.Error("Don't know how to restore state of task {0} from {1}", at.GetType().FullName, data.ToString());
     throw new Exception(string.Format("Don't know how to restore state of task {0}", at.GetType().FullName));
 }
Example #15
0
 public ActiveTaskBase(Task tsk)
 {
     log = LogManager.GetCurrentClassLogger();
     log.Warn("Created task {0}: {1}", _cnt++, this.GetType().Name);
 }
Example #16
0
 public TaskScript(ScriptNetProcessScriptManager mgr, Task taskDef)
 {
     _taskDef = taskDef;
     _mgr = mgr;
     log = LogManager.GetLogger("TaskScript");
 }
Example #17
0
 private TaskShell CreateActiveTransitionForTask(Task tsk)
 {
     TaskShell ts;
     if (tsk.IsMultiInstance)
     {
         ts = new MultiTaskShell();
     }
     else
     {
         ts = new TaskShell();
     }
     ts.TaskId = tsk.Id;
     ts.CorrelationId = GetNextTransitionId();
     ts.SetProcessInstance(this);
     ts.ParentCallback = this;
     ts.EnvironmentContext = this.Environment;
     return ts;
 }
Example #18
0
 public MultiInstanceTask(Task tsk, ProcessInstance pi)
     : base(tsk, pi)
 {
 }
Example #19
0
 public ActiveTransition(Task tsk)
 {
     this.Status = TransitionStatus.ENABLED;
     this.TaskId = tsk.Id;
 }
Example #20
0
 public virtual void Activate()
 {
     lock (this)
     {
         if (_activated) throw new Exception("Already activated");
         if (_parentCallback == null)
             throw new Exception("Set process parent callback before activation");
         if (_envCtx == null) throw new Exception("EnvironmentContext not set");
         if (_parentProces == null) throw new Exception("Process instance not set");
         if (TaskId == null) throw new Exception("TaskId not set");
         _taskDefinition = ParentProcess.Definition.GetTask(this.TaskId);
         log = LogManager.GetCurrentClassLogger();
         if (_taskDefinition == null) throw new Exception("Task definition not found: " + this.TaskId);
         if (_taskState != null)
         {
             log.Debug("TaskShell {0}: Restoring task state from {1}", CorrelationId, _taskState.ToString());
             IActiveTask at = RestoreTaskState(_taskState, _taskDefinition);
             ActiveTask = at;
         }
         if (ActiveTask != null)
         {
             ActiveTask.SetContext(this);
             ActiveTask.Activate();
         }
         _activated = true;
     }
 }