IsHttpApplication() private static method

Gets a value indicating whether the given type implements HttpApplication.
private static IsHttpApplication ( Type type ) : bool
type System.Type The type to check.
return bool
Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Finds <see cref="Assembly"/> instances in the current bin path
        /// that contain types that implement <see cref="HttpApplication"/>.
        /// </summary>
        /// <returns>A collection of <see cref="Assembly"/> instances.</returns>
        public IEnumerable <Assembly> FindApplicationAssemblies()
        {
            List <Assembly> result = new List <Assembly>();

            string[] assemblyPaths = null;

            try
            {
                assemblyPaths = Directory.GetFiles(this.BinPath, "*.dll");
            }
            catch (IOException ex)
            {
                this.Logger.Error(ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                this.Logger.Error(ex);
            }

            if (assemblyPaths != null)
            {
                foreach (string assemblyPath in assemblyPaths)
                {
                    AssemblyName assemblyName = null;
                    Assembly     assembly     = null;

                    try
                    {
                        assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
                    }
                    catch (Exception ex)
                    {
                        this.Logger.Error(ex);
                    }

                    if (assemblyName != null &&
                        !assemblyName.FullName.StartsWith("System.", StringComparison.OrdinalIgnoreCase) &&
                        !assemblyName.FullName.StartsWith("Microsoft.", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            assembly = Assembly.Load(assemblyName);
                        }
                        catch (ArgumentException ex)
                        {
                            this.Logger.Error(ex);
                        }
                        catch (BadImageFormatException ex)
                        {
                            this.Logger.Error(ex);
                        }
                        catch (IOException ex)
                        {
                            this.Logger.Error(ex);
                        }
                        catch (ReflectionTypeLoadException ex)
                        {
                            this.Logger.Error(ex);
                        }
                        catch (SecurityException ex)
                        {
                            this.Logger.Error(ex);
                        }
                    }

                    try
                    {
                        if (assembly != null && assembly.GetTypes().Any(t => HttpApplicationProbe.IsHttpApplication(t)))
                        {
                            result.Add(assembly);
                        }
                    }
                    catch (ReflectionTypeLoadException ex)
                    {
                        try
                        {
                            this.Logger.Error(ex);
                        }
                        catch
                        {
                            // This can fail for various reasons...
                        }
                    }
                }
            }

            return(result);
        }