private List <CandidateAction> FindCandidateActions(List <IAction> actions, ProcessBase scope)
        {
            List <CandidateAction> candidates = new List <CandidateAction>();

            for (int i = 0; i < actions.Count; i++)
            {
                if (actions[i].IsAsynchronous)
                {
                    candidates.Add(new CandidateAction(actions[i], null, GetProcessByID(actions[i].ProcessID), null, scope));
                }
                else
                {
                    for (int j = i + 1; j < actions.Count; j++)
                    {
                        int p1id = actions[i].ProcessID,
                            p2id = actions[j].ProcessID;
                        Guid p1setID = ProcessIdToSetId(p1id), p2setID = ProcessIdToSetId(p2id);
                        if (actions[i].CanSyncWith(actions[j]) &&
                            (p1setID != p2setID || p1setID == Guid.Empty))
                        {
                            candidates.Add(new CandidateAction(actions[i], actions[j], GetProcessByID(p1id), GetProcessByID(p2id), scope));
                        }
                    }
                }
            }
            return(candidates);
        }
        /// <summary>
        /// Finds all candidate actions, both those restricted to particular processes
        /// and those that aren´t restricted at all and therefore have global scope.
        /// </summary>
        /// <returns></returns>
        private List <CandidateAction> FindAllCandidateActions()
        {
            List <ProcessBase>     finished   = new List <ProcessBase>();
            List <CandidateAction> candidates = new List <CandidateAction>();

            //Start by finding all actions that were restricted and therefore
            //have process scope
            lock (_activeProcs) {
                foreach (ProcessBase proc in _activeProcs)
                {
                    ProcessBase parent = proc;
                    while (parent != null)
                    {
                        if (!finished.Contains(parent))
                        {
                            Debug(parent + " contains " + parent.LocalActions.Count + " candidate actions: " + Util.Join(", ", parent.LocalActions));
                            candidates.AddRange(FindCandidateActions(parent.LocalActions, parent));
                            finished.Add(parent);
                        }
                        parent = parent.Parent;
                    }
                }
            }

            ///...then add the unrestricted actions
            Debug("Global scope contains " + GlobalScope.Actions.Count + " candidate actions: " + Util.Join(", ", GlobalScope.Actions));
            candidates.AddRange(FindCandidateActions(GlobalScope.Actions, null));
            return(candidates);
        }
 public ChannelSyncAction(string name, ProcessBase p, int paramCount, bool input)
 {
     _proc = p;
     _name = name;
     _input = input;
     _paramCount = paramCount;
 }
 public ChannelSyncAction(string name, ProcessBase p, int paramCount, bool input)
 {
     _proc       = p;
     _name       = name;
     _input      = input;
     _paramCount = paramCount;
 }
 public void AddProcess(ProcessBase p)
 {
     Debug("Added " + p);
     lock (_activeProcs) {
         _activeProcs.Add(p);
     }
     if (ProcessRegistered != null)
     {
         ProcessRegistered(this, new ProcessEventArgs()
         {
             Process = p
         });
     }
 }
 public void KillProcess(ProcessBase p)
 {
     lock (_activeProcs) {
         _activeProcs.Remove(p);
         Debug("Killed " + p);
     }
     if (ProcessKilled != null)
     {
         ProcessKilled(this, new ProcessEventArgs()
         {
             Process = p
         });
     }
 }
 protected void CleanActions()
 {
     //Kill our candidate actions
     for (ProcessBase parent = this; parent != null; parent = parent.Parent)
     {
         lock (parent.LocalActions) {
             parent.LocalActions.RemoveAll(delegate(IAction act) {
                 return(act == null || act.ProcessID == this.ID);
             });
         }
     }
     lock (GlobalScope.Actions) {
         GlobalScope.Actions.RemoveAll(delegate(IAction act) {
             return(act == null || act.ProcessID == this.ID);
         });
     }
 }
 public MethodCallAction(string name, ProcessBase p)
 {
     _proc        = p;
     _displayName = name;
 }
 public MethodCallAction(string name, ProcessBase p)
 {
     _proc = p;
     _displayName = name;
 }
 private void UpdateProcessActions(ProcessBase p)
 {
     string name = p.ToString();
     if (!_performedActionsCount.ContainsKey(name)) {
         _performedActionsCount.Add(name, 1);
     } else {
         Node proc = GetProcess(name);
         int count = 0;
         while (proc is ActionPrefix) {
             proc = ((ActionPrefix)proc).Process;
             count++;
         }
         int countPerformed = _performedActionsCount[name];
         //System.Windows.Forms.MessageBox.Show("Count: " + count + ", countperformed: " + countPerformed);
         if (countPerformed == count-1) {
             _performedActionsCount[name] = 0;
         } else {
             _performedActionsCount[name]++;
         }
     }
 }
 private void AddProcess(ProcessBase p)
 {
     _processes.Add(p);
     UpdateProcesses();
 }
 private void RemoveProcess(ProcessBase p)
 {
     if (_processes.Contains(p)) {
         _processes.Remove(p);
         UpdateProcesses();
     }
 }
 public void AddProcess(ProcessBase p)
 {
     Debug("Added " + p);
     lock (_activeProcs) {
         _activeProcs.Add(p);
     }
     if (ProcessRegistered != null) {
         ProcessRegistered(this, new ProcessEventArgs() { Process = p });
     }
 }
 private List<CandidateAction> FindCandidateActions(List<IAction> actions, ProcessBase scope)
 {
     List<CandidateAction> candidates = new List<CandidateAction>();
     for (int i = 0; i < actions.Count; i++) {
         if (actions[i].IsAsynchronous) {
             candidates.Add(new CandidateAction(actions[i], null, GetProcessByID(actions[i].ProcessID), null, scope));
         } else {
             for (int j = i + 1; j < actions.Count; j++) {
                 int p1id = actions[i].ProcessID,
                     p2id = actions[j].ProcessID;
                 Guid p1setID = ProcessIdToSetId(p1id), p2setID = ProcessIdToSetId(p2id);
                 if (actions[i].CanSyncWith(actions[j])
                     && (p1setID != p2setID || p1setID == Guid.Empty)) {
                     candidates.Add(new CandidateAction(actions[i], actions[j], GetProcessByID(p1id), GetProcessByID(p2id), scope));
                 }
             }
         }
     }
     return candidates;
 }
 public void KillProcess(ProcessBase p)
 {
     lock (_activeProcs) {
         _activeProcs.Remove(p);
         Debug("Killed " + p);
     }
     if (ProcessKilled != null) {
         ProcessKilled(this, new ProcessEventArgs() { Process = p });
     }
 }
 public KLAIMAction(ProcessBase p, string displayName)
 {
     _proc = p;
     _displayName = displayName;
 }