示例#1
0
 /// <summary>
 /// Searches for a compatible entry-point in every compatible plugin file found in the specified directory, and call its <see cref="IEntrypoint.Setup">Setup</see> method.
 /// </summary>
 /// <param name="directory">The plugin assemblies directory, that are loaded via reflection after being sorted alphabetically.</param>
 /// <param name="options">Options for the plugins loader.</param>
 /// <param name="pattern">Pattern to search for in the name of the files within the directory.</param>
 public static void LoadPlugins(this IExpandR expandr, DirectoryInfo directory, PluginLoaderOptions options = default, string pattern = DefaultDirPattern)
 {
     Directory.CreateDirectory(directory.FullName);
     foreach (var file in directory.GetFiles(pattern).OrderBy(dllPath => dllPath.Name))
     {
         expandr.LoadPlugin(file, options);
     }
 }
示例#2
0
 /// <summary>
 /// Searches for a compatible entry-point in every compatible plugin file found in the specified directory, and call its <see cref="IEntrypoint.Setup">Setup</see> method.
 /// </summary>
 /// <param name="path">Either the path of a directory or an existing file.</param>
 /// <param name="options">Options for the plugins loader.</param>
 /// <param name="pattern">Pattern to search for in the name of the files within the directory, if a directory path was supplied.</param>
 public static void LoadPlugins(this IExpandR expandr, string path, PluginLoaderOptions options = default, string pattern = DefaultDirPattern)
 {
     if (File.Exists(path))
     {
         expandr.LoadPlugin(new FileInfo(Path.GetDirectoryName(path)), options);
     }
     else
     {
         expandr.LoadPlugins(new DirectoryInfo(path), options, pattern);
     }
 }
示例#3
0
        /// <summary>
        /// Searches for a compatible entry-point in the specified file, and call its <see cref="IEntrypoint.Setup">Setup</see> method.
        /// </summary>
        /// <param name="file">The plugin assembly binary, to be loaded via reflection.</param>
        /// <param name="options">Options for the plugins loader.</param>
        public static void LoadPlugin(this IExpandR expandr, FileInfo file, PluginLoaderOptions options = default)
        {
            Assembly asm;

            try
            {
                asm = Assembly.LoadFrom(file.FullName);
            }
            catch (Exception ex)
            {
                options?.RaiseError(expandr, new PluginErrorEventArgs()
                {
                    Error = new PluginFileException(file, $"Invalid assembly file: {ex.Message}", ex)
                });
                return;
            }
            expandr.LoadPlugin(asm, options);
        }