private static void EnsureAppDomainInitialized(PluginFileInfo pluginFileInfo)
        {
            var pluginInfoName = pluginFileInfo.Name;

            if (Instances.ContainsKey(pluginInfoName))
            {
                return;
            }

            Logger.Info($"当前机器人平台为:{MahuaGlobal.CurrentPlatform:G}");
            Logger.Info("开始加载插件");
            Logger.Debug(pluginFileInfo.ToString());
            Logger.Debug($"当前插件名称为{pluginInfoName}");
            var domainLoader = new DomainLoader(
                pluginInfoName,
                pluginFileInfo.PluginEntyPointDirectory,
                pluginFileInfo.PluginEntryPointConfigFullFilename,
                true);

            Logger.Debug($"创建AppDomain进行加载插件:{pluginInfoName}");
            domainLoader.Load();
            Logger.Debug("开始创建透明代理");
            var loader = domainLoader.Create <IPluginLoader>(typeof(CrossAppDomainPluginLoader).FullName);

            Logger.Debug(
                $"透明代理创建完毕,类型为{loader.GetType().FullName},将开始调用{nameof(CrossAppDomainPluginLoader.LoadPlugin)}方法");
            if (!loader.LoadPlugin(pluginFileInfo.PluginEntryPointDllFullFilename))
            {
                throw new PluginLoadException(pluginInfoName, loader.Message);
            }

            Instances.Add(pluginInfoName, loader);
        }
Ejemplo n.º 2
0
        public void Create()
        {
            var domain = new DomainLoader("API", false);

            domain.Load();
            domain.Unload();
            Assert.IsTrue(true);
        }
Ejemplo n.º 3
0
        public void CreateWithShadowCopy()
        {
            var domain = new DomainLoader("API", true);

            domain.Load();
            Assert.IsTrue(System.IO.Directory.Exists(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "API\\cache")), "API\\cache failed to create");
            domain.Unload();
            Assert.IsTrue(true);
        }
Ejemplo n.º 4
0
        public void CheckDomainName()
        {
            var domain = new DomainLoader("TestDomain", "API", true);

            domain.Load();
            domain.DoCallback(() =>
            {
                //this method executes in the other domain
                Assert.IsTrue(AppDomain.CurrentDomain.FriendlyName == "TestDomain");
            });
            domain.Unload();
            Assert.IsTrue(true);
        }
Ejemplo n.º 5
0
        public void CallDoCallback()
        {
            var domain = new DomainLoader("API", true);

            domain.Load();
            domain.DoCallback(() =>
            {
                //this method executes in the other domain
                var al = AppDomain.CurrentDomain.GetData("AssemblyLoader");
                Assert.IsTrue(al != null);
            });
            domain.Unload();
            Assert.IsTrue(true);
        }
Ejemplo n.º 6
0
        public static void Initialize()
        {
            AppDomain.CurrentDomain.SetupInformation.ShadowCopyFiles       = "true";
            AppDomain.CurrentDomain.SetupInformation.ShadowCopyDirectories = WebSettings.PluginBinPath;

            MoveFiles(new DirectoryInfo(WebSettings.PluginPath), new DirectoryInfo(WebSettings.PluginBinPath));

            DomainLoader loader = new DomainLoader("app", "loader", WebSettings.PluginBinPath.Substring(WebSettings.PluginBinPath.LastIndexOf(Path.DirectorySeparatorChar) + 1));

            loader.Load();
            loader.Unload();

            RegisterPlugins();
            //ObjectResolver.Init();


            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new SpiderViewEngine());
            ControllerBuilder.Current.SetControllerFactory(new SpiderControllerFactory());

            PluginWatcher watcher = new PluginWatcher();

            watcher.Watch();
        }
Ejemplo n.º 7
0
        private static void EnsureAppDomainInitialized(PluginFileInfo pluginFileInfo)
        {
            var pluginInfoName = pluginFileInfo.Name;

            if (Instances.ContainsKey(pluginInfoName))
            {
                return;
            }

            lock (PluginInitLocker)
            {
                if (Instances.ContainsKey(pluginInfoName))
                {
                    return;
                }
                Logger.Info($"当前机器人平台为:{MahuaGlobal.CurrentPlatform:G}");
                Logger.Info("开始加载插件");
                Logger.Debug(pluginFileInfo.ToString());
                Logger.Debug($"当前插件名称为{pluginInfoName}");
                Logger.Debug($"开始复制插件Asset文件 : {pluginInfoName}");
                var pluginAssetDir   = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AssetDirName, pluginInfoName);
                var pluginRuntimeDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pluginInfoName);
                if (Directory.Exists(pluginRuntimeDir))
                {
                    Directory.Delete(pluginRuntimeDir, true);
                }

                Directory.CreateDirectory(pluginRuntimeDir);
                foreach (var fileFullname in Directory.GetFiles(pluginAssetDir))
                {
                    var filename = Path.GetFileName(fileFullname);
                    File.Copy(fileFullname, Path.Combine(pluginRuntimeDir, filename));
                }
                Logger.Debug($"复制Asset文件完毕 : {pluginInfoName}");
                var domainLoader = new DomainLoader(
                    pluginInfoName,
                    pluginFileInfo.PluginEntyPointDirectory,
                    pluginFileInfo.PluginEntryPointConfigFullFilename,
                    true);
                Logger.Debug($"创建AppDomain进行加载插件:{pluginInfoName}");
                domainLoader.Load();
                Logger.Debug("开始创建透明代理");
                var loader = domainLoader.Create <IPluginLoader>(typeof(CrossAppDomainPluginLoader).FullName);
                Logger.Debug(
                    $"透明代理创建完毕,类型为{loader.GetType().FullName},将开始调用{nameof(CrossAppDomainPluginLoader.LoadPlugin)}方法");
                if (!loader.LoadPlugin(pluginFileInfo.PluginEntryPointDllFullFilename))
                {
                    throw new PluginLoadException(pluginInfoName, loader.Message);
                }

                var pluginInstance = new PluginInstance
                {
                    DomainLoader   = domainLoader,
                    PluginLoader   = loader,
                    PluginFileInfo = pluginFileInfo,
                };
                var watcher = new FileSystemWatcher
                {
                    Path         = Path.Combine(pluginAssetDir),
                    NotifyFilter = NotifyFilters.LastWrite,
                    Filter       = "hash.txt"
                };
                watcher.Changed                 += Watcher_Changed;
                watcher.EnableRaisingEvents      = true;
                pluginInstance.FileSystemWatcher = watcher;
                Instances.Add(pluginInfoName, pluginInstance);
            }
        }