本文整理汇总了C#中DTE2.ExecuteCommand方法的典型用法代码示例。如果您正苦于以下问题:C# DTE2.ExecuteCommand方法的具体用法?C# DTE2.ExecuteCommand怎么用?C# DTE2.ExecuteCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DTE2
的用法示例。
在下文中一共展示了DTE2.ExecuteCommand方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteCommandIfExists
public static bool ExecuteCommandIfExists(string command, DTE2 dte)
{
if (dte.Commands.Cast<Command>().Any(dtecommand => dtecommand.Name == command))
{
try
{
dte.ExecuteCommand(command);
OutputWindowHandler.WriteMessage("Command executed");
}
catch (COMException e)
{
if(command == "ReSharper_Suspend")
{
OutputWindowHandler.WriteMessage("Excecution of '" + command +
"' failed. Maybe ReSharper is already suspended? \n " + e.ToString());
}
else
{
//Command may be found but cannot be executed
OutputWindowHandler.WriteMessage("Excecution of '" + command + "' failed. \n " + e.ToString());
}
return false;
}
return true;
}
return false;
}
示例2: RoslynCodeAnalysisHelper
public RoslynCodeAnalysisHelper(IWpfTextView view, ITextDocument document, IVsTaskList tasks, DTE2 dte, SVsServiceProvider serviceProvider, IVsActivityLog log)
{
_view = view;
_document = document;
_text = new Adornment();
_tasks = tasks;
_serviceProvider = serviceProvider;
_log = log;
_dispatcher = Dispatcher.CurrentDispatcher;
_adornmentLayer = view.GetAdornmentLayer(RoslynCodeAnalysisFactory.LayerName);
_view.ViewportHeightChanged += SetAdornmentLocation;
_view.ViewportWidthChanged += SetAdornmentLocation;
_text.MouseUp += (s, e) => dte.ExecuteCommand("View.ErrorList");
_timer = new Timer(750);
_timer.Elapsed += (s, e) =>
{
_timer.Stop();
System.Threading.Tasks.Task.Run(() =>
{
_dispatcher.Invoke(new Action(() => Update(false)), DispatcherPriority.ApplicationIdle, null);
});
};
_timer.Start();
}
示例3: ErrorHighlighter
public ErrorHighlighter(IWpfTextView view, ITextDocument document, IVsTaskList tasks, DTE2 dte)
{
_view = view;
_document = document;
_text = new Adornment();
_tasks = tasks;
_dispatcher = Dispatcher.CurrentDispatcher;
_adornmentLayer = view.GetAdornmentLayer(ErrorHighlighterFactory.LayerName);
_view.ViewportHeightChanged += SetAdornmentLocation;
_view.ViewportWidthChanged += SetAdornmentLocation;
_text.MouseUp += (s, e) => { dte.ExecuteCommand("View.ErrorList"); };
_timer = new Timer(750);
_timer.Elapsed += (s, e) =>
{
_timer.Stop();
Task.Run(() =>
{
_dispatcher.Invoke(new Action(() =>
{
Update(false);
}), DispatcherPriority.ApplicationIdle, null);
});
};
_timer.Start();
}
示例4: ExecuteCommand
public static void ExecuteCommand(DTE2 dte, string commandName)
{
var command = dte.Commands.Item(commandName);
if (command.IsAvailable)
{
dte.ExecuteCommand(command.Name);
}
}
示例5: LoadTheme
private static void LoadTheme(Theme theme, DTE2 application, Config config)
{
application.ExecuteCommand(
"Tools.ImportandExportSettings",
string.Format("/import:\"{0}\"", theme.FilePath));
config.CurrentThemeName = theme.Name;
ConfigManager.SaveConfig(config);
}
示例6: OnCommand
public override void OnCommand(DTE2 application, OutputWindowPane pane)
{
ThreadPool.QueueUserWorkItem(
o =>
{
string file = GitCommands.RunGitExWait("searchfile", application.Solution.FullName);
if (file == null || string.IsNullOrEmpty(file.Trim()))
return;
application.ExecuteCommand("File.OpenFile", file);
});
}
示例7: ErrorListScanner
public ErrorListScanner(DTE2 dte)
{
_dte = dte;
var errorItems = dte.ToolWindows.ErrorList.ErrorItems;
dte.ExecuteCommand("View.ErrorList", " ");
//Yup these iterator count from 1..
for (int i = 1; i <= errorItems.Count; i++)
{
var item = errorItems.Item(i);
var symbol = GetUnresolvedSymbol(item);
//Check if this is an unresolved external symbol error
if (symbol == null)
continue;
var project = GetProject(item);
AddUnresolvedSymbol(project, symbol);
}
}
示例8: ReloadProject
private void ReloadProject(DTE2 dte2, Project currentProject)
{
// we need to unload and reload the project
dte2.ExecuteCommand("File.SaveAll");
string solutionName = System.IO.Path.GetFileNameWithoutExtension(dte2.Solution.FullName);
string projectName = currentProject.Name;
dte2.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate();
((DTE2)dte2).ToolWindows.SolutionExplorer.GetItem(solutionName + @"\" + projectName).Select(vsUISelectionType.vsUISelectionTypeSelect);
dte2.ExecuteCommand("Project.UnloadProject");
System.Threading.Thread.Sleep(500);
dte2.ExecuteCommand("Project.ReloadProject");
}
示例9: ActivateToolboxItem
/// <summary>
/// Activate an item in the toolbox
/// </summary>
/// <param name="DTE">DTE object</param>
/// <param name="tabName">The toolbox tab name</param>
/// <param name="itemName">The item name in that tab</param>
/// <returns>true if the item has been activated</returns>
public static bool ActivateToolboxItem(DTE2 DTE, string tabName, string itemName)
{
DTE.ExecuteCommand("View.Toolbox", "");
ToolBox toolbox = DTE.ToolWindows.ToolBox;
ToolBoxTab tab = toolbox.ToolBoxTabs.Item(tabName);
if (tab != null)
{
tab.Activate();
ToolBoxItem foundItem = null;
int foundItemIndex = -1;
int selectedItemIndex = -1;
ToolBoxItems items = tab.ToolBoxItems;
ToolBoxItem selectedItem = items.SelectedItem;
foreach (ToolBoxItem currentItem in items)
{
if (foundItem == null)
{
++foundItemIndex;
if (currentItem.Name == itemName)
{
foundItem = currentItem;
if (selectedItem == null)
{
break;
}
}
}
if (selectedItem != null)
{
++selectedItemIndex;
if (selectedItem == currentItem)
{
selectedItem = null;
if (foundItem != null)
{
break;
}
}
}
}
if (foundItem != null)
{
int distance = foundItemIndex - selectedItemIndex;
if (distance != 0)
{
SendKeys.Flush();
if (distance > 0)
{
SendKeys.SendWait(string.Format("{{DOWN {0}}}", distance));
}
else
{
SendKeys.SendWait(string.Format("{{UP {0}}}", -distance));
}
}
return true;
}
}
return false;
}
示例10: XBuild
public static void XBuild(DTE2 dte, bool rebuild = false)
{
OutputWindowPane outputWindowPane = PrepareOutputWindowPane(dte);
if (!rebuild)
{
outputWindowPane.OutputString("MonoHelper: XBuild Solution Start\r\n\r\n");
}
else
{
outputWindowPane.OutputString("MonoHelper: XRebuild Solution Start\r\n\r\n");
}
outputWindowPane.OutputString(string.Format("MonoHelper: Saving Documents\r\n"));
dte.ExecuteCommand("File.SaveAll");
string monoPath = DetermineMonoPath(dte);
// Get current configuration
string configurationName = dte.Solution.SolutionBuild.ActiveConfiguration.Name;
string platformName = ((SolutionConfiguration2)dte.Solution.SolutionBuild.ActiveConfiguration).PlatformName;
string fileName = string.Format(@"{0}\bin\xbuild.bat", monoPath);
string arguments = string.Format(@"""{0}"" /p:Configuration=""{1}"" /p:Platform=""{2}"" {3}", dte.Solution.FileName,
configurationName, platformName, rebuild ? " /t:Rebuild" : string.Empty);
// Run XBuild and show in output
System.Diagnostics.Process proc = new System.Diagnostics.Process
{
StartInfo =
new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments,
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
outputWindowPane.OutputString(string.Format("MonoHelper: Running {0} {1}\r\n\r\n", fileName, arguments));
proc.Start();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
outputWindowPane.OutputString(line);
outputWindowPane.OutputString("\r\n");
}
// XBuild returned with error, stop processing XBuild Command
if (proc.ExitCode != 0)
{
if (!rebuild)
{
outputWindowPane.OutputString("\r\n\r\nMonoHelper: XBuild Solution End");
}
else
{
outputWindowPane.OutputString("\r\n\r\nMonoHelper: XRebuild Solution End");
}
return;
}
foreach (Project project in dte.Solution.Projects)
{
if (project.ConfigurationManager == null || project.ConfigurationManager.ActiveConfiguration == null)
{
continue;
}
Property debugSymbolsProperty = GetProperty(project.ConfigurationManager.ActiveConfiguration.Properties,
"DebugSymbols");
// If DebugSymbols is true, generate pdb symbols for all assemblies in output folder
if (debugSymbolsProperty != null && debugSymbolsProperty.Value is bool && (bool)debugSymbolsProperty.Value)
{
outputWindowPane.OutputString(
string.Format("\r\nMonoHelper: Generating DebugSymbols and injecting DebuggableAttributes for project {0}\r\n",
project.Name));
// Determine Outputpath, see http://www.mztools.com/articles/2009/MZ2009015.aspx
string absoluteOutputPath = GetAbsoluteOutputPath(project);
GenerateDebugSymbols(absoluteOutputPath, outputWindowPane);
}
}
if (!rebuild)
{
outputWindowPane.OutputString("\r\nMonoHelper: XBuild Solution End");
}
else
{
outputWindowPane.OutputString("\r\nMonoHelper: XRebuild Solution End");
}
}
示例11: PrepareOutputWindowPane
private static OutputWindowPane PrepareOutputWindowPane(DTE2 dte)
{
dte.ExecuteCommand("View.Output");
OutputWindow outputWindow = dte.ToolWindows.OutputWindow;
OutputWindowPane outputWindowPane = null;
foreach (OutputWindowPane pane in outputWindow.OutputWindowPanes)
{
if (pane.Name == "MonoHelper")
{
outputWindowPane = pane;
break;
}
}
if (outputWindowPane == null)
{
outputWindowPane = outputWindow.OutputWindowPanes.Add("MonoHelper");
}
outputWindowPane.Activate();
outputWindowPane.Clear();
outputWindowPane.OutputString("MonoHelper, Version 1.2\r\n");
outputWindowPane.OutputString("Copyright (C) Christopher Dresel 2015\r\n");
outputWindowPane.OutputString("\r\n");
return outputWindowPane;
}
示例12: ExecuteCommand
public static void ExecuteCommand(string command, DTE2 dte)
{
dte.ExecuteCommand(command);
}
示例13: RunTest
/// <summary>
/// Test body
/// </summary>
/// <param name="DTE">The environment application object</param>
public static void RunTest(DTE2 DTE)
{
DTE.ItemOperations.OpenFile(Environment.GetEnvironmentVariable("ORMFile", EnvironmentVariableTarget.Process), "");
// The test file has three binary facts in it. FactType1, FactType2, FactType3, and an entity type EntityType1. EntityType1 is connected
// the first role of the three facts. FactType1 and FactType2 are mandatory and unique on the first role.
// Standard test handling
ORMTestHooks hooks = new ORMTestHooks(DTE);
ORMTestWindow testWindow = hooks.FindORMTestWindow(null);
using (StreamWriter writer = File.AppendText(Environment.GetEnvironmentVariable("TestLog", EnvironmentVariableTarget.Process)))
{
// Grab accessible objects for the diagram and the 4 roles we'll be connecting to
AccessibleObject accDiagram = CommonTestHooks.FindAccessibleObject(
testWindow.AccessibleObject,
new AccessiblePathNode[]{
new AccessiblePathNode("ORMDiagram")});
AccessibleObject accRole1_1 = CommonTestHooks.FindAccessibleObject(
accDiagram,
new AccessiblePathNode[]{
new AccessiblePathNode("FactType", "EntityType1A"),
new AccessiblePathNode("Roles"),
new AccessiblePathNode("Role", 0)});
AccessibleObject accRole2_1 = CommonTestHooks.FindAccessibleObject(
accDiagram,
new AccessiblePathNode[]{
new AccessiblePathNode("FactType", "EntityType1B"),
new AccessiblePathNode("Roles"),
new AccessiblePathNode("Role", 0)});
AccessibleObject accRole3_1 = CommonTestHooks.FindAccessibleObject(
accDiagram,
new AccessiblePathNode[]{
new AccessiblePathNode("FactType", "EntityType1C"),
new AccessiblePathNode("Roles"),
new AccessiblePathNode("Role", 0)});
AccessibleObject accRole3_2 = CommonTestHooks.FindAccessibleObject(
accDiagram,
new AccessiblePathNode[]{
new AccessiblePathNode("FactType", "EntityType1C"),
new AccessiblePathNode("Roles"),
new AccessiblePathNode("Role", 1)});
// Add the equality constraint and get its accessible object
testWindow.ActivateToolboxItem("Equality Constraint");
testWindow.ClickAccessibleObject(accDiagram, 1, ClickLocation.UpperLeft, 50, 50);
AccessibleObject accEquality = testWindow.GetSelectedAccessibleObjects()[0];
EqualityConstraint equalityConstraint = (EqualityConstraint)testWindow.TranslateAccessibleObject(accEquality, false);
bool scenarioPassed;
// Scenario 1: Attach the two mandatory roles
testWindow.ClickAccessibleObject(accRole1_1, 2);
testWindow.ClickAccessibleObject(accRole2_1, 2);
SendKeys.SendWait("{ESC}");
scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError;
writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when all roles are mandatory");
// Scenario 2: Remove the mandatory constraint from the second role
testWindow.ClickAccessibleObject(accRole2_1);
DTE.ExecuteCommand("OtherContextMenus.ORMDesignerContextMenu.IsMandatory", "");
scenarioPassed = null == equalityConstraint.EqualityImpliedByMandatoryError;
writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError does not exist when some roles are not mandatory");
// Scenario 3: Delete the non-mandatory role
SendKeys.SendWait("^{DEL}");
scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError;
writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when the last non-mandatory role is deleted");
// Scenario 4: Delete the role sequence
DTE.ExecuteCommand("Edit.Undo", "");
testWindow.ClickAccessibleObject(accEquality);
testWindow.ClickAccessibleObject(accRole2_1);
DTE.ExecuteCommand("OtherContextMenus.ORMDesignerContextMenu.DeleteRoleSequence", "");
scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError;
writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when a role sequence with the last non-mandatory role is deleted");
// Scenario 5: Delete the associated fact
DTE.ExecuteCommand("Edit.Undo", "");
testWindow.ClickAccessibleObject(accRole2_1.Parent, 1, ClickLocation.UpperLeft, 1, 1);
SendKeys.SendWait("^{DEL}");
scenarioPassed = null != equalityConstraint.EqualityImpliedByMandatoryError;
writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError exists when the fact with the last non-mandatory role is deleted");
// Scenario 6: Add an additional role sequence to a non-mandatory role
DTE.ExecuteCommand("Edit.Undo", "");
DTE.ExecuteCommand("Edit.Undo", "");
testWindow.ClickAccessibleObject(accEquality, 2);
testWindow.ClickAccessibleObject(accRole3_1, 2);
SendKeys.SendWait("{ESC}");
scenarioPassed = null == equalityConstraint.EqualityImpliedByMandatoryError;
writer.WriteLine((scenarioPassed ? "Passed: " : "Failed: ") + "EqualityImpliedByMandatoryError does not exist a role sequence with a single non-mandatory role is added");
// Scenario 7: Add a mandatory constraint to the non-mandatory role
//.........这里部分代码省略.........