Пример #1
0
        /// <summary>
        /// Function to find a plug-in assembly on a given path.
        /// </summary>
        /// <param name="plugInPath">Initial path to the plug-in</param>
        /// <returns>The assembly name for the plug-in assembly.</returns>
        private AssemblyName FindPlugInAssembly(string plugInPath)
        {
            if (plugInPath == null)
            {
                throw new ArgumentNullException("plugInPath");
            }

            if (string.IsNullOrWhiteSpace(plugInPath))
            {
                throw new ArgumentException(Resources.GOR_PARAMETER_MUST_NOT_BE_EMPTY, "plugInPath");
            }

            plugInPath = Path.GetFullPath(plugInPath);

            if (string.IsNullOrWhiteSpace(plugInPath))
            {
                throw new FileNotFoundException();
            }

            // We can't find the plug-in assembly on the initial path, so check the path list.
            if (File.Exists(plugInPath))
            {
                return(AssemblyName.GetAssemblyName(plugInPath));
            }

            var assemblyFile = Path.GetFileName(plugInPath);

            plugInPath = SearchPaths.FirstOrDefault(path => File.Exists(path + assemblyFile));

            if (string.IsNullOrWhiteSpace(plugInPath))
            {
                throw new FileNotFoundException(string.Format(Resources.GOR_PLUGIN_CANNOT_FIND_FILE,
                                                              assemblyFile));
            }

            plugInPath += assemblyFile;

            return(AssemblyName.GetAssemblyName(plugInPath));
        }