protected virtual void OnInterceptorCalled(InterceptionMode mode, InterceptionContextBase context) { if (InterceptorCalled != null) { InterceptorCalled(mode, context); } }
protected List <TInterceptor> GetInterceptors(InterceptionMode mode) { List <TInterceptor> result = null; this.interceptors.TryGetValue(mode, out result); return(result); }
/// <summary> /// Constructor of the interception processor /// </summary> /// <param name="conn">Connection instance</param> /// <param name="initMessage">Initialization message</param> public Interception(Connection conn, ClientInitMessage initMessage) : base(conn) { InterceptInitMessage interceptInitMessage = (InterceptInitMessage)initMessage; _mode = interceptInitMessage.InterceptionMode; _interceptors.TryAdd(this, _mode); }
/// <summary> /// Establishes a connection to the given UNIX socket file /// </summary> /// <param name="mode">Interception mode</param> /// <param name="socketPath">Path to the UNIX socket file</param> /// <param name="cancellationToken">Optional cancellation token</param> /// <returns>Asynchronous task</returns> /// <exception cref="IncompatibleVersionException">API level is incompatible</exception> /// <exception cref="IOException">Connection mode is unavailable</exception> public Task Connect(InterceptionMode mode, string socketPath = Defaults.SocketPath, CancellationToken cancellationToken = default(CancellationToken)) { InterceptInitMessage initMessage = new InterceptInitMessage { InterceptionMode = mode }; Mode = mode; return(Connect(initMessage, socketPath, cancellationToken)); }
/// <summary> /// Constructor of the interception processor /// </summary> /// <param name="conn">Connection instance</param> /// <param name="initMessage">Initialization message</param> public CodeInterception(Connection conn, ClientInitMessage initMessage) : base(conn) { InterceptInitMessage interceptInitMessage = (InterceptInitMessage)initMessage; _mode = interceptInitMessage.InterceptionMode; _channels = (interceptInitMessage.Channels != null) ? interceptInitMessage.Channels.ToList() : new List <CodeChannel>(Enum.GetValues(typeof(CodeChannel)).Cast <CodeChannel>()); _filters = interceptInitMessage.Filters ?? new List <string>(); _priorityCodes = interceptInitMessage.PriortyCodes; }
public Task Connect(InterceptionMode mode, string socketPath = Defaults.FullSocketPath, CancellationToken cancellationToken = default) { Mode = mode; Channels.Clear(); Channels.AddRange(Enum.GetValues(typeof(CodeChannel)).Cast<CodeChannel>()); Filters.Clear(); PriortyCodes = false; InterceptInitMessage initMessage = new InterceptInitMessage { InterceptionMode = mode }; return Connect(initMessage, socketPath, cancellationToken); }
/// <summary> /// Called by the <see cref="Code"/> class to intercept a code. /// This method goes through each connected interception channel and notifies the clients. /// </summary> /// <param name="code">Code to intercept</param> /// <param name="type">Type of the interception</param> /// <returns>True if the code has been resolved</returns> public static async Task <bool> Intercept(Code code, InterceptionMode type) { foreach (var pair in _interceptors) { if (code.SourceConnection != pair.Key.Connection.Id && pair.Value == type) { if (await pair.Key.Intercept(code)) { return(true); } } } return(false); }
/// <summary> /// Called by the <see cref="Code"/> class to intercept a code. /// This method goes through each connected interception channel and notifies the clients. /// </summary> /// <param name="code">Code to intercept</param> /// <param name="type">Type of the interception</param> /// <returns>True if the code has been resolved</returns> /// <exception cref="OperationCanceledException">Code has been cancelled</exception> public static async Task <bool> Intercept(Code code, InterceptionMode type) { List <Interception> processors = new List <Interception>(); lock (_connections[type]) { processors.AddRange(_connections[type].Connections); } foreach (Interception processor in processors) { if (processor.Connection.IsConnected && code.SourceConnection != processor.Connection.Id) { lock (_connections[type]) { _connections[type].InterceptingConnection = processor.Connection.Id; _connections[type].CodeBeingIntercepted = code; } try { try { processor.Connection.Logger.Debug("Intercepting code {0} ({1})", code, type); if (await processor.Intercept(code)) { processor.Connection.Logger.Debug("Code has been resolved"); return(true); } processor.Connection.Logger.Debug("Code has been ignored"); } catch (OperationCanceledException) { processor.Connection.Logger.Debug("Code has been cancelled"); throw; } } finally { lock (_connections[type]) { _connections[type].InterceptingConnection = -1; _connections[type].CodeBeingIntercepted = null; } } } } return(false); }
/// <summary> /// Called by the <see cref="Code"/> class to intercept a code. /// This method goes through each connected interception channel and notifies the clients. /// </summary> /// <param name="code">Code to intercept</param> /// <param name="type">Type of the interception</param> /// <returns>null if not intercepted and a CodeResult otherwise</returns> public static async Task <CodeResult> Intercept(Code code, InterceptionMode type) { foreach (var pair in _interceptors) { if (code.SourceConnection != pair.Key.Connection.Id && pair.Value == type) { CodeResult result = await pair.Key.Intercept(code); if (result != null) { return(result); } } } return(null); }
/// <summary> /// Establishes a connection to the given UNIX socket file /// </summary> /// <param name="mode">Interception mode</param> /// <param name="channels">Optional list of input channels where codes may be intercepted</param> /// <param name="filters">Optional list of codes that may be intercepted</param> /// <param name="priortyCodes">Define if priorty codes may be intercepted</param> /// <param name="socketPath">Path to the UNIX socket file</param> /// <param name="cancellationToken">Optional cancellation token</param> /// <returns>Asynchronous task</returns> /// <exception cref="IncompatibleVersionException">API level is incompatible</exception> /// <exception cref="IOException">Connection mode is unavailable</exception> /// <exception cref="OperationCanceledException">Operation has been cancelled</exception> /// <exception cref="SocketException">Init message could not be processed</exception> public Task Connect(InterceptionMode mode, IEnumerable<CodeChannel> channels = null, IEnumerable<string> filters = null, bool priortyCodes = false, string socketPath = Defaults.FullSocketPath, CancellationToken cancellationToken = default) { Mode = mode; Channels.Clear(); if (channels == null) { Channels.AddRange(Enum.GetValues(typeof(CodeChannel)).Cast<CodeChannel>()); } else { Channels.AddRange(channels); } Filters.Clear(); if (filters != null) { Filters.AddRange(filters); } PriortyCodes = priortyCodes; InterceptInitMessage initMessage = new InterceptInitMessage { InterceptionMode = mode, Channels = Channels, Filters = Filters, PriortyCodes = priortyCodes }; return Connect(initMessage, socketPath, cancellationToken); }
/// <summary> /// Called by the <see cref="Code"/> class to intercept a code. /// This method goes through each connected interception channel and notifies the clients. /// </summary> /// <param name="code">Code to intercept</param> /// <param name="type">Type of the interception</param> /// <returns>True if the code has been resolved</returns> /// <exception cref="OperationCanceledException">Code has been cancelled</exception> public static async Task <bool> Intercept(Code code, InterceptionMode type) { if (Program.CancellationToken.IsCancellationRequested) { // Don't intercept any more codes if the application is being shut down return(false); } List <CodeInterception> processors = new List <CodeInterception>(); lock (_connections[type]) { processors.AddRange(_connections[type]); } foreach (CodeInterception processor in processors) { if (processor.CanIntercept(code)) { try { processor.Connection.Logger.Debug("Intercepting code {0} ({1})", code, type); if (await processor.Intercept(code)) { processor.Connection.Logger.Debug("Code has been resolved"); return(true); } processor.Connection.Logger.Debug("Code has been ignored"); } catch (OperationCanceledException) { processor.Connection.Logger.Debug("Code has been cancelled"); throw; } } } return(false); }
public DelegateAsyncMethodInterceptor(Func <AsyncInterceptionContext, Task> interceptor, InterceptionMode mode) { this.interceptor = interceptor; this.InterceptionMode = mode; }
public MethodInterceptorAttribute(InterceptionMode mode) { this.InterceptionMode = mode; }
public DelegateMethodInterceptor(Action <InterceptionContext> interceptor, InterceptionMode mode) { this.interceptor = interceptor; this.InterceptionMode = mode; }
/// <summary> /// Constructor of the interception processor /// </summary> /// <param name="conn">Connection instance</param> /// <param name="initMessage">Initialization message</param> public Interception(Connection conn, ClientInitMessage initMessage) : base(conn) { InterceptInitMessage interceptInitMessage = (InterceptInitMessage)initMessage; _mode = interceptInitMessage.InterceptionMode; }