예제 #1
0
        /// <summary>
        /// Populates a private class variable with all of the assemblies located within the
        /// configured injection folder. This allows for a single retrieval of those files
        /// so that other methods do not need to load the assemblies multiple times.
        /// </summary>
        /// <returns>An array of <see cref="T:System.Reflection.Assembly"/> instances for the current application,
        /// including any modules currently loaded.</returns>
        protected static Assembly[] GetAssemblies()
        {
            if (BaseApplication._areaassemblies != null)
            {
                return(BaseApplication._areaassemblies.ToArray());
            }
            BaseApplication._areaassemblies = new List <Assembly>();
            BaseApplication._areafolders    = new List <string>();
            var config = BaseConfiguration.GetInstance(false);

            if (config != null && config.Injection.Folders != null)
            {
                config.Injection.Folders
                .Cast <FolderConfigurationElement>()
                .ForEach(f =>
                {
                    if (!string.IsNullOrEmpty(f.Path))
                    {
                        string path = f.Path;
                        if (path.StartsWith("~"))
                        {
                            path = HttpContext.Current.Server.MapPath(path);
                        }
                        BaseApplication._areafolders.AddIfNotNull <string>(path);
                        DirectoryInfo dinfo = new DirectoryInfo(path);
                        if (dinfo.Exists)
                        {
                            foreach (FileInfo fi in dinfo.EnumerateFiles("*.dll", SearchOption.AllDirectories))
                            {
                                //****************************************************************************
                                // this should be the only place where the additional assemblies are loaded
                                //****************************************************************************
                                if (AppDomain.CurrentDomain.GetAssemblies().Count(x =>
                                                                                  x.ManifestModule.FullyQualifiedName.Contains(fi.Name)) == 0 &&
                                    fi.Name != "Geocrest.Data.Sources.Gis.dll" &&
                                    fi.Name != "Geocrest.Data.Sources.dll" &&
                                    fi.Name != "Geocrest.Model.Representations.dll")
                                {
                                    BaseApplication._areaassemblies.Add(Assembly.LoadFrom(fi.FullName));
                                }
                            }
                        }
                    }
                });
            }
            return(BaseApplication._areaassemblies.ToArray());
        }