/// <summary>
 /// Marks a plugin as uninstalled
 /// </summary>
 /// <param name="pluginInfo"></param>
 public static void MarkUninstalled(PluginInfo pluginInfo)
 {
     pluginInfo.Installed = false;
     pluginInfo.Active    = false;
     PluginConfigurator.WriteConfigFile(Plugins.ToList(), HostingEnvironment.MapPath(PluginsFile));
 }
        /// <summary>
        /// Initializes the plugin engine for the application
        /// </summary>
        public static void Initialize()
        {
            //first we load the assemblies which have been compiled into
            LoadAssemblySystemPlugins();

            //now the other plugins
            //first read the plugins list
            var allPluginsSystemNames = PluginConfigurator.ReadConfigFile(HostingEnvironment.MapPath(PluginsFile));

            //create shadow directory
            Directory.CreateDirectory(_shadowDirectory);

            //delete all files from shadow directory if it's /loaded directory
            if (TrustLevel != AspNetHostingPermissionLevel.Unrestricted)
            {
                var allFiles = ShadowDirectory.GetFiles("*", SearchOption.AllDirectories);
                foreach (var file in allFiles)
                {
                    file.Delete();
                }
            }
            //make sure that we don't have null for all pluginnames
            allPluginsSystemNames = allPluginsSystemNames ?? new List <PluginConfigurator.ReadPluginInfo>();

            //load plugins
            var allPlugins = PluginConfigurator.GetAllPluginsInfos(PluginsDirectory, allPluginsSystemNames.ToList());

            foreach (var plugin in allPlugins)
            {
                //discard the plugin which is incompatible
                if (!plugin.SupportedVersions.Contains(GlobalSettings.AppVersion))
                {
                    continue;
                }

                if (string.IsNullOrEmpty(plugin.SystemName))
                {
                    throw new mobSocialException(
                              $"A plugin with empty system name {plugin.Name}({plugin.OriginalAssemblyFileInfo.FullName}) can't be loaded");
                }
                //is this plugin already there
                if (Plugins.Any(x => x.SystemName == plugin.SystemName))
                {
                    throw new mobSocialException(
                              $"A plugin with same name {plugin.Name}({plugin.SystemName}) has already been loaded");
                }

                //add to plugin list
                Plugins.Add(plugin);

                //if plugin is installed, copy it's dlls to shadow
                //if (!plugin.Installed)
                //    continue;

                //load to build manager
                if (plugin.OriginalAssemblyFileInfo.Directory == null)
                {
                    continue;
                }

                var allDlls = plugin.OriginalAssemblyFileInfo.Directory.GetFiles("*.dll",
                                                                                 SearchOption.AllDirectories);

                //copy all the dlls to shadow directory
                foreach (var dllFile in allDlls)
                {
                    try
                    {
                        var shadowedFilePath = Path.Combine(ShadowDirectory.FullName, dllFile.Name);
                        var shadowedFileInfo = dllFile.CopyTo(shadowedFilePath, true);

                        plugin.ShadowAssembly = Assembly.LoadFrom(shadowedFileInfo.FullName);

                        //add this assembly to buildmanager to load
                        AssemblyLoader.AddToBuildManager(plugin.ShadowAssembly);

                        //assign instances
                    }
                    catch (System.Exception ex)
                    {
                        //TODO: handle the failed case accordingly
                        throw;
                    }
                }
            }
        }
示例#3
0
 public static PluginInfo Load(string fileName)
 {
     return(PluginConfigurator.LoadPluginInfo(fileName));
 }