FindEntryPoint() public static method

Finds a method acting as an HttpApplication entry point for the given type.
public static FindEntryPoint ( Type type ) : MethodInfo
type System.Type The type to find the entry point for.
return System.Reflection.MethodInfo
Exemplo n.º 1
0
        /// <summary>
        /// Sets up and invokes an entry point on an <see cref="HttpApplication"/> implementer found
        /// by probing the given bin path.
        /// </summary>
        /// <param name="logger">The logger to use when probing.</param>
        /// <param name="binPath">The bin path to probe.</param>
        private void SetupandInvokeEntryPoint(ILogger logger, string binPath)
        {
            if (Directory.Exists(binPath))
            {
                HttpApplicationProbe probe = new HttpApplicationProbe(logger, binPath);
                Type type = HttpApplicationProbe.FindApplicationTypes(probe.FindApplicationAssemblies()).FirstOrDefault();

                if (type != null)
                {
                    logger.Info("Found an HTTP application requiring startup: {0}.", type.FullName);
                    HttpApplication httpApplication = null;

                    try
                    {
                        httpApplication = (HttpApplication)Activator.CreateInstance(type);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, "Failed to create an instance of the HTTP application {0}.", type.FullName);
                    }

                    if (httpApplication != null)
                    {
                        try
                        {
                            MethodInfo entryPoint = HttpApplicationProbe.FindEntryPoint(type);

                            if (entryPoint != null)
                            {
                                logger.Info("Invoking entry point for HTTP application {0}.", type.FullName);
                                this.InvokeEventHandler(httpApplication, entryPoint);
                            }
                            else
                            {
                                logger.Info("No entry point found for HTTP application {0}.", type.FullName);
                            }

                            this.httpApplication = httpApplication;
                            httpApplication      = null;
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex, "Failed to invoke the entry point for HTTP application {0}.", type.FullName);

                            if (ex.InnerException != null)
                            {
                                logger.Error(ex.InnerException);
                            }
                        }
                        finally
                        {
                            if (httpApplication != null)
                            {
                                httpApplication.Dispose();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Finds all types in the given assembly collection that implement <see cref="HttpApplication"/>
        /// and contain an entry or exit point (or both).
        /// </summary>
        /// <param name="assemblies">The assemblies to find application types for.</param>
        /// <returns>A collection of <see cref="HttpApplication"/> types.</returns>
        public static IEnumerable <Type> FindApplicationTypes(IEnumerable <Assembly> assemblies)
        {
            List <Type> result = new List <Type>();

            foreach (Assembly assembly in assemblies ?? new Assembly[0])
            {
                foreach (Type type in assembly.GetTypes().Where(t => HttpApplicationProbe.IsHttpApplication(t)))
                {
                    if (HttpApplicationProbe.FindEntryPoint(type) != null ||
                        HttpApplicationProbe.FindExitPoint(type) != null)
                    {
                        result.Add(type);
                    }
                }
            }

            return(result);
        }