Here are the examples of the csharp api Microsoft.VisualStudio.Shell.AsyncPackage.GetServiceAsync(System.Type) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
55 Examples
19
Source : HotReloadPackage.cs
with MIT License
from AndreiMisiukevich
with MIT License
from AndreiMisiukevich
protected override async Task InitializeAsync(CancellationToken cancellationToken,
IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var settingsManager = new ShellSettingsManager(this);
var writableSettingsStore = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);
var settingsStore = new SettingsService(writableSettingsStore);
var dte = (DTE) await GetServiceAsync(typeof(SDTE));
var applicationEvents = dte.Application.Events;
var doreplacedentEvents = applicationEvents.DoreplacedentEvents;
var devEnvEvents = dte.Events.DTEEvents;
var enviromentEvents = new WindowsEnvironmentService(this, doreplacedentEvents, applicationEvents.SolutionEvents,
dte.Application.Solution, devEnvEvents);
var dependencyContainer = new DependencyContainer(new DependenciesRegistrar());
var guiPresenter = new GuiService(this, dependencyContainer);
await EnableExtensionCommand.InitializeAsync(this);
await DisableExtensionCommand.InitializeAsync(this);
var commandsDictionary = new Dictionary<HotReloadCommands, IEnvironmentCommand>
{
{HotReloadCommands.Enable, EnableExtensionCommand.Instance},
{HotReloadCommands.Disable, DisableExtensionCommand.Instance}
};
Main.Init(enviromentEvents, commandsDictionary, guiPresenter, settingsStore);
}
19
Source : DisableExtensionCommand.cs
with MIT License
from AndreiMisiukevich
with MIT License
from AndreiMisiukevich
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in DisableExtensionCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService =
await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new DisableExtensionCommand(package, commandService);
}
19
Source : EnableExtensionCommand.cs
with MIT License
from AndreiMisiukevich
with MIT License
from AndreiMisiukevich
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in ToolbarTestCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService =
await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new EnableExtensionCommand(package, commandService);
}
19
Source : ArasMainMenuCmdPackage.cs
with MIT License
from arasplm
with MIT License
from arasplm
protected override async System.Threading.Tasks.Task InitializeAsync(System.Threading.CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
// When initialized asynchronously, we *may* be on a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
// Otherwise, remove the switch to the UI thread if you don't need it.
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
IVisualStudioServiceProvider serviceProvider = new VisualStudioServiceProvider(this);
this.messageManager = new VisualStudioMessageManager();
this.iOWrapper = new IOWrapper();
this.projectConfigurationManager = new ProjectConfigurationManager(this.messageManager);
this.vsPackageWrapper = new VsPackageWrapper();
this.projectManager = new ProjectManager(serviceProvider, iOWrapper, vsPackageWrapper, messageManager, projectConfigurationManager);
this.authManager = new AuthenticationManager(messageManager, projectManager);
this.arasDataProvider = new ArasDataProvider(authManager, messageManager);
this.dialogFactory = new DialogFactory(authManager, arasDataProvider, serviceProvider, iOWrapper, messageManager);
ICodeFormatter codeFormatter = new VisualStudioCodeFormatter(this.projectManager);
this.codeProviderFactory = new CodeProviderFactory(codeFormatter, messageManager, iOWrapper);
this.globalConfiguration = new GlobalConfiguration(iOWrapper);
this.projectUpdater = new ProjectUpdater(this.iOWrapper);
this.eventListener = new EventListener(projectManager, projectUpdater, projectConfigurationManager, iOWrapper);
this.openContextParser = new OpenContextParser();
this.methodOpener = new MethodOpener(projectManager, dialogFactory, openContextParser, messageManager);
Commands.OpenFromArasCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.OpenFromPackageCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.CreateMethodCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, globalConfiguration, messageManager);
Commands.SaveToArasCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.SaveToPackageCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.UpdateMethodCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.ConnectionInfoCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, messageManager);
Commands.CreateCodeItemCmd.Initialize(projectManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.RefreshConfigCmd.Initialize(projectManager, dialogFactory, projectConfigurationManager, messageManager);
Commands.DebugMethodCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.MoveToCmd.Initialize(projectManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
Commands.ImportOpenInVSActionCmd.Initialize(projectManager, authManager, dialogFactory, projectConfigurationManager, codeProviderFactory, messageManager);
this.eventListener.StartListening();
IVsAppCommandLine cmdLine = await GetServiceAsync(typeof(SVsAppCommandLine)) as IVsAppCommandLine;
ErrorHandler.ThrowOnFailure(cmdLine.GetOption(OpenInVSConstants.ProtocolName, out int isPresent, out string openMethodRequest));
if (isPresent == 1)
{
methodOpener.OpenMethodFromAras(openMethodRequest);
}
}
19
Source : CommandHandler.cs
with MIT License
from BigEggTools
with MIT License
from BigEggTools
protected async System.Threading.Tasks.Task InitalizeAsync(AsyncPackage package)
{
commandService = (IMenuCommandService)await package.GetServiceAsync(typeof(IMenuCommandService));
var menuCommandID = new CommandID(commandSet, commandid);
menuCommand = new OleMenuCommand(Invoke, menuCommandID);
menuCommand.BeforeQueryStatus += MenuCommand_BeforeQueryStatus;
commandService.AddCommand(menuCommand);
}
19
Source : ConvertAppToCore3Command.cs
with MIT License
from brianlagunas
with MIT License
from brianlagunas
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in ConvertAppToCore3Command's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new ConvertAppToCore3Command(package, commandService);
}
19
Source : FixRedirectsCommandPackage.cs
with MIT License
from CloudNimble
with MIT License
from CloudNimble
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
_dte = await GetServiceAsync(typeof(DTE)) as DTE2;
replacedumes.Present(_dte);
Instance = this;
Logger.Initialize(this, "BindingRedirects Doctor");
_commandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
replacedumes.Present(_commandService);
AddCommand(0x0100, (s, e) => {
ThreadHelper.JoinableTaskFactory.RunAsync(() => FixBindingRedirectsAsync());
});
}
19
Source : VSConanPackage.cs
with MIT License
from conan-io
with MIT License
from conan-io
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// Handle commandline switch
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var cmdLine = await GetServiceAsync(typeof(SVsAppCommandLine)) as IVsAppCommandLine;
ErrorHandler.ThrowOnFailure(cmdLine.GetOption(_cliSwitch, out int isPresent, out string optionValue));
if (isPresent == 1)
{
System.Console.WriteLine(Vsix.Version);
}
_dte = await GetServiceAsync<DTE>();
_solution = await GetServiceAsync<SVsSolution>() as IVsSolution;
_solutionBuildManager = await GetServiceAsync<IVsSolutionBuildManager>() as IVsSolutionBuildManager3;
var serviceProvider = new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)_dte);
await TaskScheduler.Default;
var commandService = await GetServiceAsync<IMenuCommandService>();
_vcProjectService = new VcProjectService();
_settingsService = new VisualStudioSettingsService(this);
_errorListService = new ErrorListService();
_conanService = new ConanService(_settingsService, _errorListService, _vcProjectService);
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
_addConanDependsProject = new AddConanDependsProject(commandService, _errorListService, _vcProjectService, _conanService);
_addConanDependsSolution = new AddConanDependsSolution(commandService, _errorListService, _vcProjectService, _conanService);
_conanOptions = new ConanOptions(commandService, _errorListService, ShowOptionPage);
_conanAbout = new ConanAbout(commandService, _errorListService);
await TaskScheduler.Default;
Logger.Initialize(serviceProvider, "Conan");
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
SubscribeToEvents();
EnableMenus(_dte.Solution != null && _dte.Solution.IsOpen);
await TaskScheduler.Default;
}
19
Source : VSConanPackage.cs
with MIT License
from conan-io
with MIT License
from conan-io
private async Task<T> GetServiceAsync<T>() where T : clreplaced =>
await GetServiceAsync(typeof(T)) as T ?? throw new Exception($"Cannot initialize service {typeof(T).FullName}");
19
Source : Command.cs
with MIT License
from DaisukeAtaraxiA
with MIT License
from DaisukeAtaraxiA
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in Command's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new Command(package, commandService);
Instance.dte = await package.GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
}
19
Source : RainbowFart.cs
with MIT License
from gameguo
with MIT License
from gameguo
public async Task InitializeAsync(AsyncPackage package, Setting setting)
{
// 切换到主线程-在MainCommand的构造函数中调用AddCommand需要 the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
var commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
replacedumes.Present(commandService);
var dte = await package.GetServiceAsync(typeof(DTE)) as DTE2;
replacedumes.Present(dte);
var events = dte.Events;
_dte = dte;
_events = events;
this.setting = setting;
this.package = package;
setting.LoadSettingsFromStorage();
var opemSetting = new OleMenuCommand(this.OpenSetting, new CommandID(Consts.MenuGroup, Consts.Btn_Enable));
commandService.AddCommand(opemSetting);
var testAudio = new MenuCommand(this.TestAudio, new CommandID(Consts.MenuGroup, Consts.Btn_Test));
commandService.AddCommand(testAudio);
SoundUtility.Instance.Init();
data = new Data(setting.RootPath);
//events.TextEditorEvents.LineChanged += OnLineChanged;
}
19
Source : VSMonoDebuggerPackage.cs
with MIT License
from GordianDotNet
with MIT License
from GordianDotNet
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
try
{
NLogService.Setup($"{nameof(VSMonoDebuggerPackage)}.log");
DebugEngineInstallService.TryRegisterreplacedembly();
// see https://github.com/microsoft/VSSDK-Extensibility-Samples/tree/master/AsyncPackageMigration
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
// TODO replace by services
UserSettingsManager.Initialize(this);
_monoVisualStudioExtension = new MonoVisualStudioExtension(this, dte);
_monoDebuggerCommands = new VSMonoDebuggerCommands(this, menuCommandService, _monoVisualStudioExtension);
}
catch (UnauthorizedAccessException uex)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var package = this as Package;
VsShellUtilities.ShowMessageBox(
package,
"Failed finish installation of VSMonoDebugger - Please run Visual Studio once as Administrator...",
$"{nameof(VSMonoDebuggerPackage)} - Register mono debug engine",
OLEMSGICON.OLEMSGICON_CRITICAL,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
Logger.Error(uex);
}
catch (Exception ex)
{
Logger.Error(ex);
}
await base.InitializeAsync(cancellationToken, progress);
}
19
Source : AddMultipleProjectsCommand.cs
with MIT License
from guudan
with MIT License
from guudan
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in AddMultipleProjectsCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
var commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new AddMultipleProjectsCommand(package, commandService);
}
19
Source : MonitorToolWindowCommand.cs
with MIT License
from ilchenkob
with MIT License
from ilchenkob
public static async Task InitializeAsync(AsyncPackage package)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new MonitorToolWindowCommand(package, commandService);
Instance.Ide = await package.GetServiceAsync(typeof(DTE)) as EnvDTE80.DTE2;
}
19
Source : AWPackage.cs
with Mozilla Public License 2.0
from LaggAt
with Mozilla Public License 2.0
from LaggAt
private async Task BackgroundThreadInitialization()
{
// Logger
_logService = new Services.LogService(this, await GetServiceAsync(typeof(SVsGeneralOutputWindowPane)) as IVsOutputWindowPane);
try
{
// ... Services VS
_dte2Service = await GetServiceAsync(typeof(DTE)) as DTE2;
// ... our Services
_awBinaryService = new Services.AwBinaryService(this);
_eventService = new Services.EventService(this);
// we are ready to send events
// ... Listeners
_dte2EventListener = new Listeners.DTE2EventListener(this);
}
catch (Exception ex)
{
_logService.Log(ex, "ActivityWatchVS: This is a bug, please report it!", activate: true);
}
}
19
Source : CodeAtlasCommand.cs
with GNU General Public License v2.0
from league1991
with GNU General Public License v2.0
from league1991
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in Command1's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new CodeAtlasCommand(package, commandService);
}
19
Source : GiteaPackage.cs
with MIT License
from maikebing
with MIT License
from maikebing
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, async delegate
{
// Added the following line to prevent the error "Due to high risk of deadlock you cannot call GetService from a background thread in an AsyncPackage derived clreplaced"
var replacedemblyCatalog = new replacedemblyCatalog(typeof(GiteaPackage).replacedembly);
CompositionContainer container = new CompositionContainer(replacedemblyCatalog);
container.ComposeParts(this);
var mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
if (mcs != null)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
try
{
new []{
PackageIds.OpenMaster,
PackageIds.OpenBranch,
PackageIds.OpenRevision,
PackageIds.OpenRevisionFull,
PackageIds.OpenBlame,
PackageIds.OpenCommits,
PackageIds.OpenFromUrl
}.ToList().ForEach(item =>
{
var menuCommandID = new CommandID(PackageGuids.guidGitea4VSCmdSet, (int)item);
var menuItem = new OleMenuCommand(ExecuteCommand, menuCommandID);
menuItem.BeforeQueryStatus += MenuItem_BeforeQueryStatus;
mcs.AddCommand(menuItem);
});
}
catch (Exception ex)
{
OutputWindowHelper.DiagnosticWriteLine(ex.Message);
}
}
else
{
OutputWindowHelper.DiagnosticWriteLine("mcs 为空");
}
});
}
19
Source : GitLabPackage.cs
with MIT License
from maikebing
with MIT License
from maikebing
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
await JoinableTaskFactory.RunAsync(VsTaskRunContext.UIThreadNormalPriority, async delegate
{
timer = new System.Timers.Timer(TimeSpan.FromMinutes(1).TotalMilliseconds);
timer.Elapsed += Timer_Elapsed;
DTE.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing;
DTE.Events.SolutionEvents.Opened += SolutionEvents_Opened;
var replacedemblyCatalog = new replacedemblyCatalog(typeof(GitLabPackage).replacedembly);
CompositionContainer container = new CompositionContainer(replacedemblyCatalog);
container.ComposeParts(this);
var mcs = await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
if (mcs != null)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
try
{
foreach (var item in new[]
{
PackageIds.OpenMaster,
PackageIds.OpenBranch,
PackageIds.OpenRevision,
PackageIds.OpenRevisionFull,
PackageIds.OpenBlame,
PackageIds.OpenCommits,
PackageIds.OpenCreateSnippet,
PackageIds.OpenFromUrl
})
{
var menuCommandID = new CommandID(PackageGuids.guidOpenOnGitLabCmdSet, (int)item);
var menuItem = new OleMenuCommand(ExecuteCommand, menuCommandID);
menuItem.BeforeQueryStatus += MenuItem_BeforeQueryStatus;
mcs.AddCommand(menuItem);
}
var IssuesToolmenuCommandID = new CommandID(PackageGuids.guidIssuesToolWindowPackageCmdSet, (int)PackageIds.IssuesToolWindowCommandId);
var IssuesToolmenuItem = new OleMenuCommand(this.ShowToolWindow, IssuesToolmenuCommandID);
IssuesToolmenuItem.BeforeQueryStatus += MenuItem_BeforeQueryStatus;
IssuesToolmenuItem.Enabled = false;
mcs.AddCommand(IssuesToolmenuItem);
}
catch (Exception ex)
{
OutputWindowHelper.DiagnosticWriteLine( ex.Message);
}
}
else
{
OutputWindowHelper.DiagnosticWriteLine("mcs 为空");
}
});
}
19
Source : ClearDocumentsHistoryCommand.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
public static async Task InitializeAsync(AsyncPackage package, IHistoryCommand clearHistoryCommand)
{
var commandService = package == null
? null
: await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new ClearDoreplacedentsHistoryCommand(package, commandService, clearHistoryCommand);
}
19
Source : DocumentsHistoryCommand.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
private void DynamicStartBeforeQueryStatus(object sender, EventArgs e)
{
var currentCommand = (sender as OleMenuCommand) ?? throw new InvalidCastException($"Unable to cast {nameof(sender)} to {typeof(OleMenuCommand)}");
var mcs = _package.GetServiceAsync(typeof(IMenuCommandService)).GetAwaiter().GetResult() as OleMenuCommandService
?? throw new InvalidCastException($"Unable to cast {nameof(IMenuCommandService)} to {typeof(OleMenuCommandService)}");
foreach (var cmd in Commands)
{
mcs.RemoveCommand(cmd);
}
var history = _doreplacedentHistoryQueries.Get(Infrastructure.ConfigurationManager.Current.Config.MaxNumberOfHistoryItemsOnMenu);
currentCommand.Visible = true;
currentCommand.Text = history.Any() ? "<History>" : "<No History>";
var j = 1;
foreach (var item in history)
{
var menuCommandId = new CommandID(CommandSet, CommandId + j);
var command = new OleMenuCommand(DynamicCommandCallback, menuCommandId);
command.Properties.Add(HistoryItemKey, item);
command.Text = $"{j++}: {PathFormatter.ShrinkPath(item.FullName, 50)}";
command.BeforeQueryStatus += (x, y) =>
{
(x as OleMenuCommand).Visible = true;
};
Commands.Add(command);
mcs.AddCommand(command);
}
}
19
Source : DocumentsHistoryCommand.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
public static async Task InitializeAsync(AsyncPackage package, IDoreplacedentHistoryQueries doreplacedentHistoryQueries, IHistoryCommandFactory reopenSomeDoreplacedentsCommandFactory)
{
var commandService = package == null
? null
: await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new DoreplacedentsHistoryCommand(package, commandService, doreplacedentHistoryQueries, reopenSomeDoreplacedentsCommandFactory);
}
19
Source : RemoveClosedDocumentsCommand.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
public static async Task InitializeAsync(AsyncPackage package, IHistoryCommand historyCommand)
{
var commandService = package == null
? null
: await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new RemoveClosedDoreplacedentsCommand(package, commandService, historyCommand);
}
19
Source : ReopenClosedDocumentsCommand.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
public static async Task InitializeAsync(AsyncPackage package, IHistoryCommand historyCommand)
{
var commandService = package == null
? null
: await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new ReopenClosedDoreplacedentsCommand(package, commandService, historyCommand);
}
19
Source : ShowDocumentsHIstoryCommand.cs
with Apache License 2.0
from majorimi
with Apache License 2.0
from majorimi
public static async Task InitializeAsync(AsyncPackage package)
{
var commandService = package == null
? null
: await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new ShowDoreplacedentsHIstoryCommand(package, commandService);
}
19
Source : GitClientVSPackage.cs
with MIT License
from MistyKuu
with MIT License
from MistyKuu
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress);
var componentModel = (IComponentModel)await GetServiceAsync(typeof(SComponentModel));
Application.Current.Dispatcher.Invoke(() =>
{
InitializePackageAsync(componentModel);
});
}
19
Source : CodeSiteCmd.cs
with MIT License
from noctwolf
with MIT License
from noctwolf
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in CodeSiteCmd's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new CodeSiteCmd(package, commandService);
}
19
Source : CodeSiteCmd.cs
with MIT License
from noctwolf
with MIT License
from noctwolf
async Task<bool> CheckCodeModelAsync()
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
try
{
DTE dte = await package.GetServiceAsync(typeof(DTE)) as DTE;
replacedumes.Present(dte);
Doreplacedent doc = dte.ActiveDoreplacedent;
if (doc == null)
ShowMessage("没有活动文档");
else
{
FileCodeModel fcm = doc.Projecreplacedem.FileCodeModel;
if (fcm == null)
ShowMessage("活动文档没有代码模型");
else if (!fcm.Language.Equals(CodeModelLanguageConstants.vsCMLanguageCSharp))
ShowMessage("代码的编程语言不是C#语言");
else
return true;
}
}
catch (Exception ex)
{
//ex.SendCodeSite();
ShowMessage("未知异常\r\n" + ex.Message);
}
return false;
}
19
Source : ReloadGlobalsCommand.cs
with MIT License
from Nucs
with MIT License
from Nucs
public static async Task InitializeAsync(AsyncPackage package) {
// Switch to the main thread - the call to AddCommand in EnableDisableRegenCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new ReloadGlobalsCommand(package, commandService);
}
19
Source : CompileSelectionCommand.cs
with MIT License
from Nucs
with MIT License
from Nucs
public static async Task InitializeAsync(AsyncPackage package) {
// Switch to the main thread - the call to AddCommand in EnableDisableRegenCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new CompileSelectionCommand(package, commandService);
ShortcutInstance = new MenuCommand((sender, args) => Instance.Execute(sender, args), new CommandID(CommandSet, CommandId));
}
19
Source : CompileTemplateCommand.cs
with MIT License
from Nucs
with MIT License
from Nucs
public static async Task InitializeAsync(AsyncPackage package) {
// Switch to the main thread - the call to AddCommand in EnableDisableRegenCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new CompileTemplateCommand(package, commandService);
}
19
Source : EnableDisableRegenCommand.cs
with MIT License
from Nucs
with MIT License
from Nucs
public static async Task InitializeAsync(AsyncPackage package) {
// Switch to the main thread - the call to AddCommand in EnableDisableRegenCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new EnableDisableRegenCommand(package, commandService);
}
19
Source : ClearCompilationsCommand.cs
with MIT License
from Nucs
with MIT License
from Nucs
public static async Task InitializeAsync(AsyncPackage package) {
// Switch to the main thread - the call to AddCommand in EnableDisableRegenCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new ClearCompilationsCommand(package, commandService);
}
19
Source : ClearCompilationsSelectionCommand.cs
with MIT License
from Nucs
with MIT License
from Nucs
public static async Task InitializeAsync(AsyncPackage package) {
// Switch to the main thread - the call to AddCommand in EnableDisableRegenCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new ClearCompilationsSelectionCommand(package, commandService);
}
19
Source : CompileFileCommand.cs
with MIT License
from Nucs
with MIT License
from Nucs
public static async Task InitializeAsync(AsyncPackage package) {
// Switch to the main thread - the call to AddCommand in EnableDisableRegenCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new CompileFileCommand(package, commandService);
}
19
Source : Global.cs
with Microsoft Public License
from oleg-shilo
with Microsoft Public License
from oleg-shilo
static public T GetService<T>()
=> (T)Package?.GetServiceAsync(typeof(T))?.Result;
19
Source : FormatCommand.cs
with Microsoft Public License
from oleg-shilo
with Microsoft Public License
from oleg-shilo
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in FormatCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new FormatCommand(package, commandService);
}
19
Source : SettingsWindowCommand.cs
with Microsoft Public License
from oleg-shilo
with Microsoft Public License
from oleg-shilo
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in SettingsWindowCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new SettingsWindowCommand(package, commandService);
}
19
Source : ProductivityToolsPackage.cs
with MIT License
from philippleidig
with MIT License
from philippleidig
private async Task<bool> IsSolutionLoadedAsync()
{
await JoinableTaskFactory.SwitchToMainThreadAsync();
var solService = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution;
ErrorHandler.ThrowOnFailure(solService.GetProperty((int)__VSPROPID.VSPROPID_IsSolutionOpen, out object value));
return value is bool isSolOpen && isSolOpen;
}
19
Source : HotReloadingPadCommand.cs
with MIT License
from pranshu-aggarwal
with MIT License
from pranshu-aggarwal
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in HotReloadingPadCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new HotReloadingPadCommand(package, commandService);
}
19
Source : SolutionOpenPackage.cs
with MIT License
from pranshu-aggarwal
with MIT License
from pranshu-aggarwal
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var componentModel = (IComponentModel)GetGlobalService(typeof(SComponentModel));
workspace = componentModel.GetService<Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>();
this.dte = (DTE)(await GetServiceAsync(typeof(DTE)));
windowEvents = dte.Events.WindowEvents;
doreplacedentEvents = dte.Events.DoreplacedentEvents;
windowEvents.WindowActivated += WindowEvents_WindowActivated;
doreplacedentEvents.DoreplacedentSaved += DoreplacedentEvents_DoreplacedentSaved;
ActiveDoreplacedentChanged(dte.ActiveDoreplacedent);
}
19
Source : FormatStructuredText.cs
with MIT License
from Roald87
with MIT License
from Roald87
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in FormatStructuredText's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory
.SwitchToMainThreadAsync(package.DisposalToken);
OleMenuCommandService commandService = await package.GetServiceAsync(
(typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new FormatStructuredText(package, commandService);
}
19
Source : UnitTestGeneratorPackage.cs
with Apache License 2.0
from sentryone
with Apache License 2.0
from sentryone
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
await base.InitializeAsync(cancellationToken, progress).ConfigureAwait(true);
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var componentModel = (IComponentModel)await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true);
if (componentModel == null)
{
throw new InvalidOperationException();
}
PackageInstallerServices = componentModel.GetService<IVsPackageInstallerServices>();
PackageInstaller = componentModel.GetService<IVsPackageInstaller>();
Workspace = componentModel.GetService<VisualStudioWorkspace>();
await GoToUnitTestsCommand.InitializeAsync(this).ConfigureAwait(true);
await GenerateUnitTestsCommand.InitializeAsync(this).ConfigureAwait(true);
await GenerateTestForSymbolCommand.InitializeAsync(this).ConfigureAwait(true);
await GoToUnitTestsForSymbolCommand.InitializeAsync(this).ConfigureAwait(true);
}
19
Source : VsNerdXPackage.cs
with MIT License
from stevium
with MIT License
from stevium
private async System.Threading.Tasks.Task MainThreadInitializationAsync()
{
Dte = await GetServiceAsync(typeof(_DTE)) as DTE2;
var solutionExplorerControl = new HierarchyControl(this, _logger);
_commandProcessor = new CommandProcessor(solutionExplorerControl, _logger);
_keyDispatcher = new ConditionalKeyDispatcher(
new SolutionExplorerDispatchCondition(solutionExplorerControl, _logger),
new KeyDispatcher(_commandProcessor),
_logger);
}
19
Source : SoftwareCoPackage.cs
with Apache License 2.0
from swdotcom
with Apache License 2.0
from swdotcom
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
try
{
await JoinableTaskFactory.SwitchToMainThreadAsync();
base.Initialize();
// create the anon user if it's a new install (async)
await InitializeUserInfoAsync();
// obtain the DTE service to track doc changes
ObjDte = await GetServiceAsync(typeof(DTE)) as DTE;
events = (Events2)ObjDte.Events;
// Intialize the doreplacedent event handlers
_textEditorEvents = events.TextEditorEvents;
_textDocKeyEvents = events.TextDoreplacedentKeyPressEvents;
_docEvents = events.DoreplacedentEvents;
_windowVisibilityEvents = events.WindowVisibilityEvents;
// init the package manager that will use the AsyncPackage to run main thread requests
PackageManager.initialize(this, ObjDte);
// init the doc event mgr and inject ObjDte
docEventMgr = DocEventManager.Instance;
// setup event handlers
_textDocKeyEvents.BeforeKeyPress += this.BeforeKeyPress;
_docEvents.DoreplacedentClosing += docEventMgr.DocEventsOnDoreplacedentClosedAsync;
_windowVisibilityEvents.WindowShowing += docEventMgr.WindowVisibilityEventAsync;
_textEditorEvents.LineChanged += docEventMgr.LineChangedAsync;
// initialize the rest of the plugin in 10 seconds (allow the user to select a solution to open)
System.Threading.Tasks.Task.Delay(10000).ContinueWith((task) => { CheckSolutionActivation(); });
}
catch (Exception ex)
{
Logger.Error("Error Initializing Code Time", ex);
}
}
19
Source : SoftwareDashboardLaunchCommand.cs
with Apache License 2.0
from swdotcom
with Apache License 2.0
from swdotcom
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
{
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
Instance = new SoftwareDashboardLaunchCommand(package, commandService);
}
19
Source : SoftwareLaunchCommand.cs
with Apache License 2.0
from swdotcom
with Apache License 2.0
from swdotcom
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
{
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
menuItem = new MenuCommand(Execute, menuCommandID);
menuItem.Enabled = false;
menuItem.Visible = false;
commandService.AddCommand(menuItem);
}
Instance = new SoftwareLaunchCommand(package, commandService);
UpdateMenuItemVisibility();
}
19
Source : SoftwareLoginCommand.cs
with Apache License 2.0
from swdotcom
with Apache License 2.0
from swdotcom
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
{
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
menuItem = new MenuCommand(Execute, menuCommandID);
commandService.AddCommand(menuItem);
}
Instance = new SoftwareLoginCommand(package, commandService);
UpdateMenuItemVisibility();
}
19
Source : SoftwareOpenCodeMetricsTreeCommand.cs
with Apache License 2.0
from swdotcom
with Apache License 2.0
from swdotcom
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
{
OleMenuCommandService commandService = await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
menuItem = new MenuCommand(Execute, menuCommandID);
commandService.AddCommand(menuItem);
}
Instance = new SoftwareOpenCodeMetricsTreeCommand(package, commandService);
}
19
Source : SoftwareToggleStatusInfoCommand.cs
with Apache License 2.0
from swdotcom
with Apache License 2.0
from swdotcom
public static async System.Threading.Tasks.Task InitializeAsync(AsyncPackage package)
{
OleMenuCommandService commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new SoftwareToggleStatusInfoCommand(package, commandService);
}
19
Source : ChooseLocalsCommand.cs
with MIT License
from Szpi
with MIT License
from Szpi
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in DumpStackToCSharpCodeCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
var commandService = await package.GetServiceAsync((typeof(IMenuCommandService))) as OleMenuCommandService;
Instance = new ChooseLocalsCommand(package, commandService);
}
See More Examples