private SmartServiceDescriptor OnDependencyRegistering(SmartServiceDescriptor serviceDescriptor) { DependencySetupEventArgs args = new DependencySetupEventArgs(serviceDescriptor); ShellEvents.NotifyDependencyRegistering(_options, args); var newDesc = args.ActualDependency ?? args.OriginalDependency; return(Object.ReferenceEquals(newDesc, serviceDescriptor) ? serviceDescriptor : SmartServiceDescriptor.Create(newDesc, serviceDescriptor.Options)); }
public static void StartSchubertEngine(this IServiceProvider provider) { //启动引擎,为我们动态注册服务,创建 Shell 上下文。 SchubertEngine.Current.Start(provider); IOptions <SchubertOptions> schubertOptions = provider.GetRequiredService <IOptions <SchubertOptions> >(); ShellEvents.NotifyEngineStarted(schubertOptions.Value, provider); LogEngineStarted(provider); }
public virtual void TestInitialize() { UIThreadInvoker.Initialize(); // Causes devenv to initialize var devEnv = Clide.DevEnv.Get(new Guid(IntegrationPackage.Constants.PackageGuid)); this.tracer = Tracer.Get(this.GetType()); this.strings = new StringBuilder(); this.listener = new TextWriterTraceListener(new StringWriter(this.strings)); // Just in case, re-set the tracers. Tracer.Manager.SetTracingLevel(TracerManager.DefaultSourceName, SourceLevels.All); Tracer.Manager.AddListener(TracerManager.DefaultSourceName, this.listener); tracer.Info("Running test from: " + this.TestContext.TestDeploymentDir); if (Dte != null) { Dte.SuppressUI = false; Dte.MainWindow.Visible = true; Dte.MainWindow.WindowState = EnvDTE.vsWindowState.vsWindowStateNormal; } var shellEvents = new ShellEvents(ServiceProvider); var initialized = shellEvents.IsInitialized; while (!initialized) { System.Threading.Thread.Sleep(10); } tracer.Info("Shell initialized successfully"); if (VsIdeTestHostContext.ServiceProvider == null) { VsIdeTestHostContext.ServiceProvider = new VsServiceProvider(); } cleanupFolders = new List <string>(); }
internal static extern IntPtr CallNextHookEx(IntPtr hhk, ShellEvents nCode, IntPtr wParam, IntPtr lParam);
public void Initialize() { this.shellEvents = new ShellEvents(ServiceProvider.GlobalProvider); this.shellEvents.ShellInitialized += (sender, args) => initializeRaised = true; this.shellEvents.ShellInitialized += OnShellInitalized; }
private static void InitShell(SchubertServicesBuilder schubertBuilder, Action <ShellCreationScope> setup) { ShellCreationScope shellScope = new ShellCreationScope(); setup?.Invoke(shellScope); var builder = schubertBuilder.ServiceCollection.FillToOther(); builder.AddSmart(SchubertServices.GetServices(schubertBuilder.Configuration)); builder.AddLogging(lb => { shellScope.LoggingConfigure?.Invoke(lb); }); var scopeFactory = builder.BuildServiceProvider().GetRequiredService <IServiceScopeFactory>(); using (IServiceScope scope = scopeFactory.CreateScope()) { IServiceProvider provider = scope.ServiceProvider; var shellLogger = provider.GetRequiredService <ILoggerFactory>().CreateLogger("Schubert"); shellLogger.WriteInformation("开始加载 Shell。"); var sw = Stopwatch.StartNew(); SchubertEngine.Current.LoadEnvironment(provider); var factory = provider.GetRequiredService <IShellContextFactory>(); var context = factory.CreateShellContext(); AddConfiguredOptions(schubertBuilder.ServiceCollection, schubertBuilder.Configuration, context); //微软框架依然存在解决日志组件创建后的销毁问题,只能通过移除日志来达到清理目的。 schubertBuilder.ServiceCollection.Remove(sd => sd.ServiceType.Equals(typeof(ILoggerFactory))); schubertBuilder.ServiceCollection.AddLogging(b => b.AddConfiguration(schubertBuilder.Configuration.GetSection("Logging"))); schubertBuilder.ServiceCollection.AddSingleton(context); schubertBuilder.ServiceCollection.AddSmart(context.Services); schubertBuilder.ServiceCollection.AddSmart(SchubertServices.GetServices(schubertBuilder.Configuration)); SchubertEngine.Current.ShellCreated = true; IOptions <SchubertOptions> schubertOptions = provider.GetRequiredService <IOptions <SchubertOptions> >(); context.RegisteredServices = builder; ShellEvents.NotifyShellInitialized(schubertOptions.Value, context); sw.Stop(); var table = new Tuple <int, int, int, int, String>( context.Blueprint.Modules.Count(), context.Blueprint.Controllers.Count(), context.Blueprint.Dependencies.Count(), context.Blueprint.DependencyDescribers.Count(), context.Blueprint.Modules.ToArrayString(System.Environment.NewLine)); StringBuilder info = new StringBuilder(); info.AppendLine(@" ________ ________ ___ ___ ___ ___ ________ _______ ________ _________ |\ ____\|\ ____\|\ \|\ \|\ \|\ \|\ __ \|\ ___ \ |\ __ \|\___ ___\ \ \ \___|\ \ \___|\ \ \\\ \ \ \\\ \ \ \|\ /\ \ __/|\ \ \|\ \|___ \ \_| \ \_____ \ \ \ \ \ __ \ \ \\\ \ \ __ \ \ \_|/_\ \ _ _\ \ \ \ \|____|\ \ \ \____\ \ \ \ \ \ \\\ \ \ \|\ \ \ \_|\ \ \ \\ \| \ \ \ ____\_\ \ \_______\ \__\ \__\ \_______\ \_______\ \_______\ \__\\ _\ \ \__\ |\_________\|_______|\|__|\|__|\|_______|\|_______|\|_______|\|__|\|__| \|__| \|_________| "); info.AppendLine($"Shell 加载完成,Schubert Version: {typeof(SchubertException).GetTypeInfo().Assembly.GetName().Version.ToString()} ({sw.ElapsedMilliseconds} ms)。"); info.AppendLine(" "); info.AppendLine((new Tuple <int, int, int, int, String>[] { table }).ToStringTable(new String[] { "modules", "controllers", "dependencies", "describers", "moduleList" }, t => t.Item1, t => t.Item2, t => t.Item3, t => t.Item4, t => t.Item5)); info.AppendLine(" "); info.Append(context.Blueprint.Dependencies.GroupBy(d => d.Feature.Descriptor.ModuleName, d => (ShellBlueprintDependencyItem)d).ToStringTable( new string[] { "module", "dependencies", "internfaces", "lifetime" }, f => f.Key, d => d.SelectMany(t => CreateArray(t.Type.Name, t.Interfaces.Count)).ToArrayString(System.Environment.NewLine), d => d.SelectMany(t => t.Interfaces).Select(i => i.Item1.Name).ToArrayString(System.Environment.NewLine), d => d.SelectMany(t => t.Interfaces).Select(i => i.Item2.ToString().ToLower()).ToArrayString(System.Environment.NewLine))); info.AppendLine(" "); shellLogger.WriteInformation(info.ToString()); } }