예제 #1
0
        private void Deleted(string folderPath)
        {
            lock (_lock)
            {
                _log.Debug("PluginService: folder '{0}' deleted.", folderPath);

                //try remove old
                AppDomain      oldAppDomain = null;
                List <TPlugin> oldPlugins   = new List <TPlugin>();
                if (_plugins.ContainsKey(folderPath))
                {
                    oldPlugins = _plugins[folderPath];
                    _plugins.Remove(folderPath);
                    oldAppDomain = SeparateAppDomain.Extract(folderPath);
                }

                //raise event
                PluginsRemoved(this, oldPlugins);

                if (oldAppDomain != null)
                {
                    AppDomain.Unload(oldAppDomain);
                }
            }
        }
예제 #2
0
        private void Renamed(string oldFolderPath, string newFolderPath)
        {
            lock (_lock)
            {
                _log.Debug("PluginService: folder '{0}' renamed into '{1}'.", oldFolderPath, newFolderPath);

                //try remove old
                AppDomain      oldAppDomain = null;
                List <TPlugin> oldPlugins   = new List <TPlugin>();
                if (_plugins.ContainsKey(oldFolderPath))
                {
                    oldPlugins = _plugins[oldFolderPath];
                    _plugins.Remove(oldFolderPath);
                    oldAppDomain = SeparateAppDomain.Extract(oldFolderPath);
                }

                //try create new
                var mefLoader  = SeparateAppDomain.CreateInstance <MefLoader>(newFolderPath, newFolderPath);
                var newPlugins = LoadPlugins(mefLoader);
                if (newPlugins.Count != 0)
                {
                    _plugins.Add(newFolderPath, newPlugins);
                }

                //raise event
                PluginsChanged(this, oldPlugins, newPlugins);

                if (newPlugins.Count == 0)
                {
                    SeparateAppDomain.Delete(newFolderPath);
                }
                if (oldAppDomain != null)
                {
                    AppDomain.Unload(oldAppDomain);
                }
            }
        }