Ejemplo n.º 1
0
        private void InitialiseMef(PreVerbExecutionContext context)
        {
            // get the current assembly
            var assembly = typeof(Program).Assembly;
            var directory = Path.GetDirectoryName(assembly.Location) ?? Directory.GetCurrentDirectory();

            // An aggregate catalogue that combines multiple catalogues
            this.container =
                new CompositionContainer(
                    new AggregateCatalog(new AssemblyCatalog(assembly), new DirectoryCatalog(directory)));
        }
Ejemplo n.º 2
0
 static void Pre(PreVerbExecutionContext x, string y)
 {
 }
Ejemplo n.º 3
0
            public void BeforeVerbExecution(PreVerbExecutionContext context)
            {
                PreContext = context;

                context.UserContext.Add("a", 54);
            }
Ejemplo n.º 4
0
 private void Pre2(PreVerbExecutionContext context)
 {
 }
Ejemplo n.º 5
0
        private void Pre(PreVerbExecutionContext context)
        {
            PreContext = context;

            context.Cancel = true;
        }
Ejemplo n.º 6
0
        private void Pre(PreVerbExecutionContext context)
        {
            PreContext = context;

            context.UserContext.Add("a", 54);
        }
Ejemplo n.º 7
0
        private PreVerbExecutionContext PreInterception(
            object target,
            Method method,
            ParameterAndValue[] parameters)
        {
            var preVerbExecutionContext = new PreVerbExecutionContext(method, target, parameters);

            // registered interceptors get top priority
            //
            if (m_registration.RegisteredPreVerbInterceptor != null)
            {
                m_registration.RegisteredPreVerbInterceptor(preVerbExecutionContext);
            }
            else
            {
                // try a defined verb interceptor
                //
                var preInterceptionMethods = Type.GetMethodsWith<PreVerbExecutionAttribute>();

                if (preInterceptionMethods.Any())
                {
                    Debug.Assert(preInterceptionMethods.Count() == 1);

                    var preInterceptionMethod = preInterceptionMethods.First();

                    MethodInvoker.Invoke(preInterceptionMethod, target, new[] { preVerbExecutionContext });
                }
                else
                {
                    // try a defined interceptor type
                    //
                    if (Type.HasAttribute<VerbInterception>())
                    {
                        var interception = Type.GetAttribute<VerbInterception>();

                        var interceptor = (IPreVerbInterceptor)Activator.CreateInstance(interception.InterceptorType);

                        interceptor.BeforeVerbExecution(preVerbExecutionContext);
                    }
                }
            }

            return preVerbExecutionContext;
        }
Ejemplo n.º 8
0
        private void PostInterception(
            object target,
            Method method,
            ParameterAndValue[] parameters,
            PreVerbExecutionContext preVerbExecutionContext,
            Exception verbException)
        {
            var postVerbExecutionContext = new PostVerbExecutionContext(
                method,
                target,
                parameters,
                preVerbExecutionContext.Cancel,
                verbException,
                preVerbExecutionContext.UserContext);

            // registered interceptors get top priority
            //
            if (m_registration.RegisteredPostVerbInterceptor != null)
            {
                m_registration.RegisteredPostVerbInterceptor(postVerbExecutionContext);
            }
            else
            {
                var postInterceptionMethods = Type.GetMethodsWith<PostVerbExecutionAttribute>();

                // try a defined interceptor type
                //
                if (postInterceptionMethods.Any())
                {
                    Debug.Assert(postInterceptionMethods.Count() == 1);

                    var postInterceptionMethod = postInterceptionMethods.First();

                    MethodInvoker.Invoke(postInterceptionMethod, target, new[] { postVerbExecutionContext });
                }
                else
                {
                    // try a defined interceptor type
                    //
                    if (Type.HasAttribute<VerbInterception>())
                    {
                        var interception = Type.GetAttribute<VerbInterception>();

                        var interceptor = (IPostVerbInterceptor)Activator.CreateInstance(interception.InterceptorType);

                        interceptor.AfterVerbExecution(postVerbExecutionContext);
                    }
                }
            }
        }