コード例 #1
0
        /// <summary>
        /// Work item goals should be structured as
        // <Asset_Name>:<Predicate>;<Value>+
        // <Asset_Name>:<Predicate>;<Value>+
        // etc...
        /// </summary>
        public static Goal ExtractGoal(this string goalString)
        {
            const string GoalStateSeparator = "+";
            const string PartSeparator = ":;";
            const int RequiredNumberOfParts = 3;

            Goal newGoal = new Goal();
            var goalStates = goalString.Split(GoalStateSeparator.ToCharArray());

            foreach (var state in goalStates)
            {
                var parts = state.Split(PartSeparator.ToCharArray(), 3);
                if (parts.Count() < RequiredNumberOfParts) continue;

                State goalState = new State
                {
                    Asset = parts[0].Replace('_', ' '),
                    Predicate = PredicateDeUnderscore(parts[1]),
                    Value = parts[2].Replace('_', ' ')
                };
                newGoal.GoalStates.Add(goalState);
            }

            return newGoal;
        }
コード例 #2
0
ファイル: GoalService.cs プロジェクト: johnfelipe/inn690
 public void RegisterGoal(Goal goal)
 {
     // Make sure its not already satisfied
     bool satisfied = ValidateGoal(goal);
     if (satisfied)
         goal.Satisfy();
     else
         _registeredGoals.Add(goal);
 }
コード例 #3
0
ファイル: GoalService.cs プロジェクト: johnfelipe/inn690
        /// <summary>
        /// Checks if a Goal's states is satisfied by the world state.
        /// </summary>
        /// <returns>True if all goal states are satisfied</returns>
        public bool ValidateGoal(Goal goal)
        {
            // Find the world states relavent to the goal states
            var allStates = _stateService.GetAll();
            var relevantStates = allStates
                .Where(state => goal.GoalStates.Any(goalstate =>
                    String.Compare(goalstate.Asset, state.Asset, true) == 0 &&
                    String.Compare(goalstate.Predicate,state.Predicate, true) == 0));

            // For each goal state, compare its existance in the list of total states
            foreach (State goalState in goal.GoalStates)
            {
                // If the goal state is not in the world state
                if (!relevantStates.Contains(goalState, _stateComparer))
                {
                    return false;
                }
            }
            return true;
        }
コード例 #4
0
 public void GoalSatisified(Goal goal, WorkItem workitem)
 {
     if (_workitemGoals.ContainsKey(workitem))
     {
         // 8. Remove the goal from the list of necessary goals
         // _workitemGoals[workitem].Remove(goal);
         // 9. If all goals are satisfied, check out (complete) the work item
         if (_workitemGoals[workitem].Count(g => !g.IsSatisfied()) == 0)
         {
             CompleteWork(workitem);
         }
     }
 }