public ApplicationDirectoryProvider(BaseCommonConfig commonConfig)
        {
            if (!string.IsNullOrWhiteSpace(commonConfig.ApplicationDirectoryOverride))
            {
                ApplicationDirectory = commonConfig.ApplicationDirectoryOverride;
            }
            else
            {
                ApplicationDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            }

            // TODO: Remove this when all code uses IApplicationDirectoryProvider
            Directory.SetCurrentDirectory(ApplicationDirectory);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new <see cref="AssemblyProvider"/> that uses an assembly scanning blacklist from the provided
        /// <see cref="BaseCommonConfig"/>.
        /// </summary>
        /// <param name="commonConfig"></param>
        public AssemblyProvider(IApplicationDirectoryProvider directoryProvider, BaseCommonConfig commonConfig)
        {
            var filesToScan = Directory.GetFiles(directoryProvider.GetApplicationDirectory(), "*.dll")
                              .Where(p => (commonConfig.AssemblyScanningBlacklist ?? new string[0])
                                     .Contains(Path.GetFileName(p)) == false);

            foreach (string assemblyPath in filesToScan)
            {
                try
                {
                    Assembly.LoadFrom(assemblyPath);
                }
                catch (FileNotFoundException) { }
                catch (FileLoadException) { }
                catch (BadImageFormatException) { }
                catch (ReflectionTypeLoadException) { }
            }

            Assemblies = AppDomain.CurrentDomain
                         .GetAssemblies()
                         .Where(a => a.IsDynamic == false)
                         .ToArray();
        }