public SerializationServiceTests()
 {
     HostMock = new Mock<IProtocolEndpoint>();
     ServiceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
     HostLoader.InitializeHostedServices(ServiceProvider, HostMock.Object);
     SerializationService = ServiceProvider.GetService<SerializationService>();
 }
Example #2
0
        private static void InitializeTestServices()
        {
            if (TestServiceProvider.hasInitServices)
            {
                return;
            }

            lock (_lockObject)
            {
                if (TestServiceProvider.hasInitServices)
                {
                    return;
                }
                TestServiceProvider.hasInitServices = true;

                const string hostName      = "SQ Tools Test Service Host";
                const string hostProfileId = "SQLToolsTestService";
                Version      hostVersion   = new Version(1, 0);

                // set up the host details and profile paths
                var             hostDetails     = new HostDetails(hostName, hostProfileId, hostVersion);
                SqlToolsContext sqlToolsContext = new SqlToolsContext(hostDetails);

                // Grab the instance of the service host
                ServiceHost serviceHost = HostLoader.CreateAndStartServiceHost(sqlToolsContext);
            }
        }
Example #3
0
 public FormatterUnitTestsBase()
 {
     HostMock             = new Mock <IProtocolEndpoint>();
     WorkspaceServiceMock = new Mock <WorkspaceService <SqlToolsSettings> >();
     ServiceProvider      = ExtensionServiceProvider.CreateDefaultServiceProvider();
     ServiceProvider.RegisterSingleService(WorkspaceServiceMock.Object);
     HostLoader.InitializeHostedServices(ServiceProvider, HostMock.Object);
     FormatterService = ServiceProvider.GetService <TSqlFormatterService>();
 }
Example #4
0
 public ResourceProviderServiceTests()
 {
     HostMock = new Mock <IProtocolEndpoint>();
     AuthenticationManagerMock = new Mock <IAzureAuthenticationManager>();
     ResourceManagerMock       = new Mock <IAzureResourceManager>();
     ServiceProvider           = ExtensionServiceProvider.CreateFromAssembliesInDirectory(ResourceProviderHostLoader.GetResourceProviderExtensionDlls());
     ServiceProvider.RegisterSingleService <IAzureAuthenticationManager>(AuthenticationManagerMock.Object);
     ServiceProvider.RegisterSingleService <IAzureResourceManager>(ResourceManagerMock.Object);
     HostLoader.InitializeHostedServices(ServiceProvider, HostMock.Object);
     ResourceProviderService = ServiceProvider.GetService <ResourceProviderService>();
 }
        public Assembly LoadModuler(ModuleManifest moduleManifest)
        {
            if (_hostLoader == null)
            {
                var modules = this.GetModules().Select(m => new LazyMan.ModularLoader.Graph.PluginInfo
                {
                    PluginName = m.ModuleName,
                    PluginDll  = m.ModuleEntrypoint
                });
                _hostLoader = new HostLoader(modules);
                //_hostLoader.AddSharedAssembly(typeof(IWebHost).Assembly,
                //    typeof(Microsoft.Extensions.Hosting.IHostBuilder).Assembly,
                //    typeof(IHost).Assembly);
            }

            return(_hostLoader.LoadPlugin(new Graph.PluginInfo
            {
                PluginName = moduleManifest.ModuleName,
                PluginDll = moduleManifest.ModuleEntrypoint
            }));
        }
Example #6
0
        private static LaunchOptions ExecuteLauncher(HostConfigurationStore configStore, Guid clsidLauncher, string exePath, string args, string dir, object launcherXmlOptions, IDeviceAppLauncherEventCallback eventCallback, TargetEngine targetEngine, Logger logger)
        {
            var deviceAppLauncher = (IPlatformAppLauncher)HostLoader.VsCoCreateManagedObject(configStore, clsidLauncher);

            if (deviceAppLauncher == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_LauncherNotFound, clsidLauncher.ToString("B")));
            }

            bool success = false;

            try
            {
                try
                {
                    deviceAppLauncher.Initialize(configStore, eventCallback);
                    deviceAppLauncher.SetLaunchOptions(exePath, args, dir, launcherXmlOptions, targetEngine);
                }
                catch (Exception e) when(!(e is InvalidLaunchOptionsException) && ExceptionHelper.BeforeCatch(e, logger, reportOnlyCorrupting: true))
                {
                    throw new InvalidLaunchOptionsException(e.Message);
                }

                LaunchOptions debuggerLaunchOptions;
                deviceAppLauncher.SetupForDebugging(out debuggerLaunchOptions);
                debuggerLaunchOptions.DeviceAppLauncher = deviceAppLauncher;

                success = true;
                return(debuggerLaunchOptions);
            }
            finally
            {
                if (!success)
                {
                    deviceAppLauncher.Dispose();
                }
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine(typeof(Program).FullName);
            Console.WriteLine(typeof(AutoMapper.Mapper).Assembly.FullName);
            Console.WriteLine("--------开始加载插件------");
            var plugins = new List <PluginInfo>
            {
                new PluginInfo
                {
                    PluginName = "Module1",
                    PluginDll  = Path.Combine(AppContext.BaseDirectory, "modules", "Module1", "Module1.dll"),
                },
                new PluginInfo
                {
                    PluginName = "Module2",
                    PluginDll  = Path.Combine(AppContext.BaseDirectory, "modules", "Module2", "Module2.dll"),
                },
            };

            var loader = new HostLoader();

            loader.AddSharedAssembly(typeof(IPlugIn).Assembly);

            var pluginsInfo = loader.LoadPlugins(plugins);
            var pluginType  = typeof(IPlugIn);

            foreach (var(info, alc) in pluginsInfo)
            {
                Console.WriteLine();
                if (alc == null)
                {
                    Console.WriteLine($"----------plugin {info.PluginName} load faile---------------");
                    continue;
                }
                Console.WriteLine($"----------plugin {info.PluginName} load success---------------");
                Console.WriteLine($"-----------enter {info.PluginName}---------------");
                foreach (var t in alc.EntryAssemlby.DefinedTypes.Where(t => pluginType.IsAssignableFrom(t)))
                {
                    var p = Activator.CreateInstance(t) as IPlugIn;
                    p.WriteOutPut();
                }

                Console.WriteLine($"-----------leave {info.PluginName}---------------");
                Console.WriteLine();
            }


            Console.WriteLine("-------回到核心程序------");

            Console.WriteLine(typeof(Program).FullName);
            Console.WriteLine(typeof(AutoMapper.Mapper).Assembly.FullName);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("-------插件卸载中,开始等待------");
            Task.Run(() =>
            {
                foreach (var info in plugins)
                {
                    var sp = new Stopwatch();
                    sp.Start();
                    loader.Unload(info)
                    .ContinueWith((t) =>
                    {
                        sp.Stop();
                        Console.WriteLine($"{info.PluginName} 卸载完成 , 用时:{ sp.Elapsed.TotalMilliseconds } 毫秒");
                    });
                }
            });

            Console.ReadLine();
        }
Example #8
0
        static void Main(string[] args)
        {
            Console.WriteLine(typeof(Program).FullName);
            Console.WriteLine(typeof(AutoMapper.Mapper).Assembly.FullName);
            Console.WriteLine("--------开始加载插件------");
            var plugins = new List <PluginInfo>
            {
                new PluginInfo
                {
                    PluginName = "Module1",
                    PluginDll  = Path.Combine(AppContext.BaseDirectory, "modules", "Module1", "Module1.dll"),
                },
                new PluginInfo
                {
                    PluginName = "Module2",
                    PluginDll  = Path.Combine(AppContext.BaseDirectory, "modules", "Module2", "Module2.dll"),
                },
            };

            var loader = new HostLoader(plugins);

            loader.AddSharedAssembly(typeof(IPlugIn).Assembly);

            var assemblies = loader.LoadPlugins();
            var pluginType = typeof(IPlugIn);
            var pTypes     = assemblies.SelectMany(x => x.DefinedTypes)
                             .Where(t => pluginType.IsAssignableFrom(t))
                             .ToList();

            foreach (var t in pTypes)
            {
                var p  = Activator.CreateInstance(t) as IPlugIn;
                var pl = AssemblyLoadContext.GetLoadContext(t.Assembly) as PluginAssemblyLoadContext;
                Console.WriteLine();
                Console.WriteLine($"-----------enter {pl.PluginInfo.PluginName}---------------");
                p.WriteOutPut();
                Console.WriteLine($"-----------leave {pl.PluginInfo.PluginName}---------------");
                Console.WriteLine();
            }

            Console.WriteLine("-------回到核心程序------");

            Console.WriteLine(typeof(Program).FullName);
            Console.WriteLine(typeof(AutoMapper.Mapper).Assembly.FullName);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("-------插件卸载中,开始等待------");
            Task.Run(() =>
            {
                foreach (var info in plugins)
                {
                    var sp = new Stopwatch();
                    sp.Start();
                    loader.Unload(info)
                    .ContinueWith((t) =>
                    {
                        sp.Stop();
                        Console.WriteLine($"{info.PluginName} 卸载完成 , 用时:{ sp.Elapsed.TotalMilliseconds } 毫秒");
                    });
                }
            });

            Console.ReadLine();
        }
Example #9
0
 public async Task LoadModules()
 {
     HostLoader = new HostLoader(new PluginInfo[0]);
     HostLoader.AddSharedAssembly(this.GetType().Assembly);
 }