コード例 #1
0
ファイル: PluginHostClient.cs プロジェクト: yonglehou/TheBorg
        public void Launch(string pluginPath, AppDomain appDomain, Uri pluginApiUri, int clientPort, string tokenValue)
        {
            var token           = Token.With(tokenValue);
            var assembly        = appDomain.Load(AssemblyName.GetAssemblyName(pluginPath));
            var pluginDirectory = Path.GetDirectoryName(pluginPath);

            appDomain.AssemblyResolve += (sender, args) =>
            {
                var ad   = sender as AppDomain;
                var path = Path.Combine(pluginDirectory, args.Name.Split(',')[0] + ".dll");
                return(ad.Load(path));
            };
            var pluginBootstrapperType = assembly.GetTypes().Single(t => typeof(IPluginBootstrapper).IsAssignableFrom(t));
            var pluginBootstrapper     = (IPluginBootstrapper)Activator.CreateInstance(pluginBootstrapperType);

            var uri = new Uri($"http://127.0.0.1:{clientPort}");

            var pluginRegistration = new PluginRegistration(
                uri,
                token,
                new CommandApi(pluginApiUri, token),
                new MessageApi(pluginApiUri, token),
                new HttpApi(),
                new Apis.PluginApi(pluginApiUri, token),
                new ConfigApi(pluginApiUri, token),
                new SettingApi(pluginApiUri, token));

            pluginBootstrapper.Start(r =>
            {
                r(pluginRegistration);
                if (pluginRegistration.PluginInformation == null)
                {
                    throw new InvalidOperationException("You must call SetPluginInformation(...)");
                }

                using (var a = AsyncHelper.Wait)
                {
                    a.Run(pluginRegistration.CommandApi.RegisterAsync(
                              pluginRegistration.CommandDescriptions,
                              CancellationToken.None));
                }
            });

            _apiHost = new ApiHost();
            _apiHost.Start(uri, pluginRegistration);
        }
コード例 #2
0
ファイル: PluginHostClient.cs プロジェクト: rasmus/TheBorg
        public void Launch(string pluginPath, AppDomain appDomain, Uri pluginApiUri, int clientPort, string tokenValue)
        {
            var token = Token.With(tokenValue);
            var assembly = appDomain.Load(AssemblyName.GetAssemblyName(pluginPath));
            var pluginDirectory = Path.GetDirectoryName(pluginPath);
            appDomain.AssemblyResolve += (sender, args) =>
                {
                    var ad = sender as AppDomain;
                    var path = Path.Combine(pluginDirectory, args.Name.Split(',')[0] + ".dll");
                    return ad.Load(path);
                };
            var pluginBootstrapperType = assembly.GetTypes().Single(t => typeof (IPluginBootstrapper).IsAssignableFrom(t));
            var pluginBootstrapper = (IPluginBootstrapper) Activator.CreateInstance(pluginBootstrapperType);

            var uri = new Uri($"http://127.0.0.1:{clientPort}");

            var pluginRegistration = new PluginRegistration(
                uri,
                token,
                new CommandApi(pluginApiUri, token),
                new MessageApi(pluginApiUri, token),
                new HttpApi(),
                new Apis.PluginApi(pluginApiUri, token),
                new ConfigApi(pluginApiUri, token),
                new SettingApi(pluginApiUri, token));

            pluginBootstrapper.Start(r =>
                {
                    r(pluginRegistration);
                    if (pluginRegistration.PluginInformation == null)
                    {
                        throw new InvalidOperationException("You must call SetPluginInformation(...)");
                    }

                    using (var a = AsyncHelper.Wait)
                    {
                        a.Run(pluginRegistration.CommandApi.RegisterAsync(
                            pluginRegistration.CommandDescriptions,
                            CancellationToken.None));
                    }
                });
            
            _apiHost = new ApiHost();
            _apiHost.Start(uri, pluginRegistration);
        }