public async Task InitializeAsync(CancellationToken cancellationToken) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); loggerService = await serviceProvider.GetServiceAsync(typeof(SLoggerService)) as ILoggerService; webApplicationManager = await serviceProvider.GetServiceAsync(typeof(SWebApplicationsManagerService)) as IWebApplicationsManagerService; }
/// <summary> /// Initializes a new instance of the <see cref="StartTunnelCommand"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> /// <param name="commandService">Command service to add command to, not null.</param> private StartTunnelCommand(AsyncPackage package, OleMenuCommandService commandService, ILoggerService logger, IProcessManagerService processManager, IWebApplicationsManagerService webApplicationsManager, ITunnelManagerService tunnelManager) { loggerService = logger; processManagerService = processManager; webApplicationsManagerService = webApplicationsManager; tunnelManagerService = tunnelManager; this.package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); var menuCommandID = new CommandID(CommandSet, CommandId); OleMenuCommand startTunnelToggleButtonMenuCommand = new OleMenuCommand(this.Execute, menuCommandID); startTunnelToggleButtonMenuCommand.BeforeQueryStatus += StartTunnelToggleButtonMenuCommand_BeforeQueryStatus; commandService.AddCommand(startTunnelToggleButtonMenuCommand); }
/// <summary> /// Initializes the singleton instance of the command. /// </summary> /// <param name="package">Owner package, not null.</param> public static async Task InitializeAsync(AsyncPackage package) { // Switch to the main thread - the call to AddCommand in StartTunnelCommand's constructor requires // the UI thread. //await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken); ILoggerService loggerService = await package.GetServiceAsync(typeof(SLoggerService), false) as ILoggerService; IProcessManagerService processMangerService = await package.GetServiceAsync(typeof(SProcessManagerService), false) as IProcessManagerService; IWebApplicationsManagerService webApplicationsMangerService = await package.GetServiceAsync(typeof(SWebApplicationsManagerService), false) as IWebApplicationsManagerService; ITunnelManagerService tunnelManagerService = await package.GetServiceAsync(typeof(STunnelManagerService), false) as ITunnelManagerService; OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService; new StartTunnelCommand(package, commandService, loggerService, processMangerService, webApplicationsMangerService, tunnelManagerService); }