public TCommand Build <TCommand, TOwner> (IFrameworkCommandInfo frameworkCommandInfo, TCommand commandInstance) where TCommand : class, ICommand
            {
                var gen = new ProxyGenerator();

                return(gen.CreateInterfaceProxyWithTarget(
                           typeof(ICommand), commandInstance) as TCommand);
            }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the interceptor options.
        /// </summary>
        /// <typeparam name="TOwner">The type of the owner.</typeparam>
        /// <param name="frameworkCommandInfo">The framework command info.</param>
        /// <returns>Options object to add to Command.</returns>
        public object GetInterceptorOptions <TOwner> (IFrameworkCommandInfo frameworkCommandInfo)
        {
            IRuleSelector ruleSelector;

            if (frameworkCommandInfo is IRuleCommandInfo)
            {
                ruleSelector = (frameworkCommandInfo as IRuleCommandInfo).RuleSelector;
            }
            else
            {
                ruleSelector =
                    new SelectAllRulesInRuleSetSelector(
                        frameworkCommandInfo.Name.EndsWith("RuleSet") ? frameworkCommandInfo.Name : frameworkCommandInfo.Name + "RuleSet");
            }

            IRuleEngine <TOwner> ruleEngine = null;
            var triedCreateRuleEngine       = false;

            var context = new RuleEngineContext <TOwner> (( TOwner )frameworkCommandInfo.Owner, ruleSelector);

            var ruleExecutor = new RuleExecutor
            {
                ExecuteRules = o =>
                {
                    if (!triedCreateRuleEngine)
                    {
                        triedCreateRuleEngine = true;
                        ruleEngine            = _ruleEngineFactory.CreateRuleEngine <TOwner>();
                    }
                    if (ruleEngine != null)
                    {
                        context.Refresh();
                        if (o != null)
                        {
                            context.WorkingMemory.AddContextObject(o);
                            if (context.RuleSelector is ITakeParameter)
                            {
                                (context.RuleSelector as ITakeParameter).Parameter = o;
                            }
                        }
                        return(ruleEngine.ExecuteRules(context));
                    }
                    return(new RuleExecutionResult(Enumerable.Empty <RuleViolation> ()));
                }
            };

            return(ruleExecutor);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds the specified framework command info.
        /// </summary>
        /// <typeparam name="TCommand">The type of the command.</typeparam>
        /// <typeparam name="TOwner">The type of the owner.</typeparam>
        /// <param name="frameworkCommandInfo">The framework command info.</param>
        /// <param name="commandInstance">The command instance.</param>
        /// <returns>Built command.</returns>
        public TCommand Build <TCommand, TOwner> (IFrameworkCommandInfo frameworkCommandInfo, TCommand commandInstance)
            where TCommand : class, ICommand
        {
            var options = new ProxyGenerationOptions();

            options.AddMixinInstance(frameworkCommandInfo);

            foreach (var interceptor in _commandInterceptors)
            {
                var mixin = interceptor.GetInterceptorOptions <TOwner> (frameworkCommandInfo);
                if (mixin != null)
                {
                    options.AddMixinInstance(mixin);
                }
            }

            return(_proxyGenerator.CreateClassProxyWithTarget(commandInstance, options, _commandInterceptors.OfType <IInterceptor> ().ToArray()));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the interceptor options.
 /// </summary>
 /// <typeparam name="TOwner">The type of the owner.</typeparam>
 /// <param name="frameworkCommandInfo">The framework command info.</param>
 /// <returns>Null because has no options.</returns>
 public object GetInterceptorOptions <TOwner> (IFrameworkCommandInfo frameworkCommandInfo)
 {
     return(null);
 }