///------------------------------------------------------------------------------------------------- /// <summary> /// Constructor. /// </summary> /// <param name="ruleCommandType"> /// Type of the rule command. /// </param> /// <param name="interceptor"> /// The interceptor. /// </param> ///------------------------------------------------------------------------------------------------- public InterceptorWrapper(Type ruleCommandType, ICommandInterceptor interceptor) { DebugContract.Requires(ruleCommandType); DebugContract.Requires(interceptor); _ruleCommandType = ruleCommandType; _interceptor = interceptor; }
///------------------------------------------------------------------------------------------------- /// <summary> /// Registers the rule. /// </summary> /// <param name="rule"> /// The rule. /// </param> /// <param name="priority"> /// The priority. /// </param> /// ### <exception cref="System.InvalidCastException"> /// . /// </exception> ///------------------------------------------------------------------------------------------------- public void RegisterInterceptor(ICommandInterceptor rule, int priority) { Contract.Requires(rule != null, "rule"); if (_interceptors == null) { _interceptors = new Dictionary <Type, SortedDictionary <int, List <ICommandInterceptor> > >(); } SortedDictionary <int, List <ICommandInterceptor> > rules; if (!_interceptors.TryGetValue(typeof(T), out rules)) { rules = new SortedDictionary <int, List <ICommandInterceptor> >(new DescendantComparer()); _interceptors.Add(typeof(T), rules); } List <ICommandInterceptor> list; if (!rules.TryGetValue(priority, out list)) { list = new List <ICommandInterceptor>(); rules.Add(priority, list); } list.Add(rule); }
/// <summary> /// Creates an instance of a database of type <see cref="RelationalStorage"/>. /// </summary> /// <param name="invariantName">The invariant name of the connector for this database.</param> /// <param name="connectionString">The connection string this database should use for database operations.</param> private RelationalStorage(string invariantName, string connectionString) { this.connectionString = connectionString; this.invariantName = invariantName; supportsCommandCancellation = DbConstantsStore.SupportsCommandCancellation(InvariantName); isSynchronousAdoNetImplementation = DbConstantsStore.IsSynchronousAdoNetImplementation(InvariantName); this.databaseCommandInterceptor = DbConstantsStore.GetDatabaseCommandInterceptor(InvariantName); }
public EntityStateWrapper(State state, object entity, ICommandInterceptor commandInterceptor) { Check.NotNull(entity, "entity"); Check.NotNull(commandInterceptor, "commandInterceptor"); State = state; Entity = entity; CommandInterceptor = commandInterceptor; }
/// <summary> /// Sets the command interceptor to be used. /// </summary> /// <param name="configurator">The configurator.</param> /// <param name="interceptor">A <see cref="ICommandInterceptor"/>.</param> /// <returns>A configurator that can be used to configure the application further.</returns> public static IConfigurator SetInterceptor(this IConfigurator configurator, ICommandInterceptor interceptor) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } configurator.Settings.Interceptor = interceptor; return(configurator); }
/// <summary> /// Adds the specified command interceptor implementation to the manager, /// with the specified explicit metadata. /// </summary> /// <param name="interceptor">The command interceptor instance, which does not need to /// be annotated with the <see cref="CommandInterceptorAttribute"/> attribute since /// it's provided explicitly.</param> /// <param name="metadata">Explicit metadata to use for the command interceptor, /// instead of reflecting the <see cref="CommandInterceptorAttribute"/>.</param> public void AddInterceptor(ICommandInterceptor interceptor, CommandInterceptorAttribute metadata) { Guard.NotNull(() => interceptor, interceptor); Guard.NotNull(() => metadata, metadata); var commandInterceptors = this.registeredInterceptors.GetOrAdd( Tuple.Create(new Guid(metadata.GroupId), metadata.CommandId), key => new List <ICommandInterceptor>()); commandInterceptors.Add(interceptor); }
public DbConstants(char startEscapeIndicator, char endEscapeIndicator, string unionAllSelectTemplate, bool isSynchronousAdoNetImplementation, bool supportsStreamNatively, bool supportsCommandCancellation, ICommandInterceptor commandInterceptor) { StartEscapeIndicator = startEscapeIndicator; EndEscapeIndicator = endEscapeIndicator; UnionAllSelectTemplate = unionAllSelectTemplate; IsSynchronousAdoNetImplementation = isSynchronousAdoNetImplementation; SupportsStreamNatively = supportsStreamNatively; SupportsCommandCancellation = supportsCommandCancellation; DatabaseCommandInterceptor = commandInterceptor; }
private static CommandExecutionDelegate BuildExecutionDelegate(ICommandInterceptor target) { var type = target.GetType(); const string methodName = "InvokeAsync"; MethodInfo? method; try { method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public); } catch (AmbiguousMatchException) { method = null; } if (method == null) { throw new InvalidOperationException($"Type {type} declares no or multiple {methodName} methods."); } var methodReturnType = typeof(Task); if (method.ReturnType != methodReturnType) { throw new InvalidOperationException($"Method {type}.{methodName} must return {methodReturnType}."); } return(method.BuildMethodInjectionDelegate <CommandExecutionDelegate>( getTargetInstance: _ => Expression.Constant(target), getStaticArguments: (delegateParams, methodParam, _) => { if (methodParam.ParameterType == typeof(CommandContext)) { return delegateParams[0]; } if (methodParam.ParameterType == typeof(CancellationToken)) { return delegateParams[1]; } return null; }, getServiceProvider: delegateParams => Expression.MakeMemberAccess(delegateParams[0], s_contextScopedServicesProperty))); }
private void RegisterCommandInterceptor(Type commandRuleType, ICommandInterceptor interceptor, int priority = 0) { DebugContract.Requires(interceptor != null); List <InterceptorInfo> list; if (!_interceptors.TryGetValue(commandRuleType, out list)) { list = new List <InterceptorInfo>(); _interceptors.Add(commandRuleType, list); } list.Add(new InterceptorInfo { Priority = priority, Interceptor = interceptor, CommandType = commandRuleType }); foreach (var item in _commandProcessors) { var commandType = item.Value.CommandType; // Command type if (ReflectionHelper.IsAssignableFrom(commandRuleType, commandType)) { item.Value.IsPrepared = false; } } }
///------------------------------------------------------------------------------------------------- /// <summary> /// Enregistrement d'une règle (after/before) associée à une commande. /// </summary> /// <typeparam name="T"> /// Type de la commande. /// </typeparam> /// <param name="interceptor"> /// Régle à exécuter. /// </param> /// <param name="priority"> /// (Optional) Priorité d'éxécution (ascendant) - Default is 0. /// </param> ///------------------------------------------------------------------------------------------------- public void RegisterInterceptor <T>(ICommandInterceptor <T> interceptor, int priority = 0) where T : IDomainCommand { Contract.Requires(interceptor, "interceptor"); RegisterCommandInterceptor(typeof(T), interceptor, priority); }
/// <summary> /// 构造一个命令执行器 /// </summary> /// <param name="defaultConfig"></param> /// <param name="first"></param> public CommandExecutorImpl(CommandConfig defaultConfig, ICommandInterceptor first) { this.defaultConfig = defaultConfig; this.first = first; }
/// <summary> /// Adds the specified command interceptor implementation to the manager, /// with the specified explicit metadata. /// </summary> /// <param name="interceptor">The command interceptor instance, which does not need to /// be annotated with the <see cref="CommandInterceptorAttribute"/> attribute since /// it's provided explicitly.</param> /// <param name="metadata">Explicit metadata to use for the command interceptor, /// instead of reflecting the <see cref="CommandInterceptorAttribute"/>.</param> public void AddInterceptor(ICommandInterceptor interceptor, CommandInterceptorAttribute metadata) { Guard.NotNull(() => interceptor, interceptor); Guard.NotNull(() => metadata, metadata); var commandInterceptors = this.registeredInterceptors.GetOrAdd( Tuple.Create(new Guid(metadata.GroupId), metadata.CommandId), key => new List<ICommandInterceptor>()); commandInterceptors.Add(interceptor); }
public void AddInboundInterceptor(ICommandInterceptor interceptor, Type commandType) { inboundCommandInterceptors.AddOrReplace(commandType, interceptor); }
/// <summary> /// Adds a ICommandInterceptor command interceptor to this command set. /// </summary> /// <param name="intercepter">The intercepter to add.</param> /// See <see cref="ICommandInterceptor"/> public void AddInterceptor(ICommandInterceptor intercepter) { _intercepters.Add(intercepter); RebuildAllCommandChains(); }
/// <summary> /// Creates a new InterceptedCommand, which serves as a link in an execution /// chain.Contains information about the interceptor that is being used and the /// next command in the chain. /// </summary> /// <param name="interceptor">the interceptor that is intercepting the command.</param> /// <param name="next">Next intercepter or command in the chain.</param> public InterceptedCommand(ICommandInterceptor interceptor, ICommand next) { _interceptor = interceptor; _next = next; }
private static CommandBarButtonItem CreateCommandBarButton(object view, MemberInfo member, string title, UIView buttonView, UIBarButtonItemStyle style, UIBarButtonSystemItem?buttonType, BarButtonLocation location) { ICommandInterceptor commandInterceptor = null; CommandBarButtonItem button = null; ReflectiveCommand command = null; var methodInfo = member as MethodInfo; if (methodInfo != null) { command = GetCommandForMember(view, member); var cellViewTemplates = member.GetCustomAttributes <CellViewTemplate>(); if (cellViewTemplates.Length > 0) { var interceptorTemplate = cellViewTemplates .FirstOrDefault((template) => template.CellViewType != null && template.CellViewType.GetInterfaces() .Any((type) => type == typeof(ICommandInterceptor))) as CellViewTemplate; if (interceptorTemplate != null) { commandInterceptor = Activator.CreateInstance(interceptorTemplate.CellViewType) as ICommandInterceptor; } } } if (!string.IsNullOrEmpty(title)) { button = new CommandBarButtonItem(title, style); } else if (buttonView != null) { button = new CommandBarButtonItem(buttonView); } else { if (!buttonType.HasValue) { buttonType = UIBarButtonSystemItem.Done; } button = new CommandBarButtonItem(buttonType.Value); button.Style = style; } command.CommandButton = button; button.Enabled = true; button.Location = location; button.Command = command; button.CommandInterceptor = commandInterceptor; var orderAttribute = member.GetCustomAttribute <OrderAttribute>(); if (orderAttribute != null) { button.Order = orderAttribute.Order; } else { button.Order = 0; } return(button); }
internal void AddInterceptor(ICommandInterceptor commandInterceptor) { _commandInterceptors.Add(commandInterceptor); }