Beispiel #1
0
 /// <summary>
 /// Sets the context object.
 /// </summary>
 /// <typeparam name="U"></typeparam>
 /// <param name="key">The key.</param>
 /// <param name="obj">The object.</param>
 protected void SetContextObject <U>(string key, U obj)
     where U : class
 {
     StateAttributesHelper.VerifyProvidedAttributes(this.State, key);
     if (this.context.ContainsKey(key))
     {
         this.context[key] = obj;
     }
     else
     {
         this.context.Add(key, obj);
     }
 }
        /// <summary>
        /// Verifies the required consistency.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="existingKeys">The existing keys.</param>
        private void VerifyRequiredConsistency(MachineState <FlowState, string, LanguageUnderstandingResult> state, IEnumerable <string> existingKeys, List <MachineState <FlowState, string, LanguageUnderstandingResult> > statesAlreadySeen)
        {
            StateAttributesHelper.VerifyRequiredAttributes(state.State, existingKeys.ToArray());
            statesAlreadySeen.Add(state);
            var providedObjects = StateAttributesHelper.GetProvidedObjectsKeys(state.State.BehaviorType);
            var newExistingKeys = new List <string>(existingKeys.ToArray());

            foreach (var destination in state.Links)
            {
                if (!statesAlreadySeen.Contains(destination.DestinationState))
                {
                    VerifyRequiredConsistency(destination.DestinationState, newExistingKeys, statesAlreadySeen);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Executes the behavior.
        /// </summary>
        /// <param name="state">The state.</param>
        /// <param name="context">The context.</param>
        /// <exception cref="Exception"></exception>
        public void ExecuteBehavior(FlowState state, Dictionary <string, object> context)
        {
            if (state.BehaviorType == null)
            {
                return;
            }

            var behavior = Activator.CreateInstance(state.BehaviorType, state, context) as IStateBehavior;

            if (behavior == null)
            {
                throw new Exception($"Type '{state.BehaviorType}' is not {typeof(IStateBehavior).Name}.");
            }

            StateAttributesHelper.VerifyRequiredAttributes(state, context.Keys.ToArray());
            behavior.ExecuteBehavior();
            StateAttributesHelper.VerifyProvidedAttributes(state, context.Keys.ToArray());
        }