本文整理汇总了C#中VisualStudioApp.OnDispose方法的典型用法代码示例。如果您正苦于以下问题:C# VisualStudioApp.OnDispose方法的具体用法?C# VisualStudioApp.OnDispose怎么用?C# VisualStudioApp.OnDispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VisualStudioApp
的用法示例。
在下文中一共展示了VisualStudioApp.OnDispose方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActivateInteractiveWindow
public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode) {
string description = null;
if (Version.IsCPython) {
description = string.Format("{0} {1}",
Version.Isx64 ? CPythonInterpreterFactoryConstants.Description64 : CPythonInterpreterFactoryConstants.Description32,
Version.Version.ToVersion()
);
} else if (Version.IsIronPython) {
description = string.Format("{0} {1}",
Version.Isx64 ? "IronPython 64-bit" : "IronPython",
Version.Version.ToVersion()
);
}
Assert.IsNotNull(description, "Unknown interpreter");
var automation = (IVsPython)app.Dte.GetObject("VsPython");
var options = (IPythonOptions)automation;
var replOptions = options.GetInteractiveOptions(description);
Assert.IsNotNull(replOptions, "Could not find options for " + description);
replOptions.InlinePrompts = InlinePrompts;
replOptions.UseInterpreterPrompts = UseInterpreterPrompts;
replOptions.PrimaryPrompt = PrimaryPrompt;
replOptions.SecondaryPrompt = SecondaryPrompt;
replOptions.EnableAttach = EnableAttach;
var oldExecutionMode = replOptions.ExecutionMode;
app.OnDispose(() => replOptions.ExecutionMode = oldExecutionMode);
replOptions.ExecutionMode = executionMode;
var oldAddNewLineAtEndOfFullyTypedWord = options.Intellisense.AddNewLineAtEndOfFullyTypedWord;
app.OnDispose(() => options.Intellisense.AddNewLineAtEndOfFullyTypedWord = oldAddNewLineAtEndOfFullyTypedWord);
options.Intellisense.AddNewLineAtEndOfFullyTypedWord = AddNewLineAtEndOfFullyTypedWord;
bool success = false;
for (int retries = 1; retries < 20; ++retries) {
try {
app.ExecuteCommand("Python.Interactive", "/e:\"" + description + "\"");
success = true;
break;
} catch (AggregateException) {
}
app.DismissAllDialogs();
app.SetFocus();
Thread.Sleep(retries * 100);
}
Assert.IsTrue(success, "Unable to open " + description + " through DTE");
var interpreters = app.ComponentModel.GetService<IInterpreterOptionsService>();
var replId = PythonReplEvaluatorProvider.GetReplId(
interpreters.FindInterpreter(Version.Id, Version.Version.ToVersion())
);
var provider = app.ComponentModel.GetService<InteractiveWindowProvider>();
return (ToolWindowPane)provider.FindReplWindow(replId);
}
示例2: DeferredSaveWithDot
public void DeferredSaveWithDot() {
// http://pytools.codeplex.com/workitem/623
// enable deferred saving on projects
using (var app = new VisualStudioApp()) {
var props = app.Dte.get_Properties("Environment", "ProjectsAndSolution");
var prevValue = props.Item("SaveNewProjects").Value;
props.Item("SaveNewProjects").Value = false;
app.OnDispose(() => props.Item("SaveNewProjects").Value = prevValue);
// now run the test
var newProjDialog = app.FileNewProject();
newProjDialog.FocusLanguageNode("JavaScript");
var consoleApp = newProjDialog.ProjectTypes.FindItem("Blank Node.js Application");
consoleApp.Select();
newProjDialog.ProjectName = "Fob.Baz";
newProjDialog.ClickOK();
// wait for new solution to load...
for (int i = 0; i < 100 && app.Dte.Solution.Projects.Count == 0; i++) {
System.Threading.Thread.Sleep(1000);
}
TestUtils.DteExecuteCommandOnThreadPool("File.SaveAll");
var saveProjDialog = new SaveProjectDialog(app.WaitForDialog());
saveProjDialog.Save();
app.WaitForDialogDismissed();
var fullname = app.Dte.Solution.FullName;
app.Dte.Solution.Close(false);
Directory.Delete(Path.GetDirectoryName(fullname), true);
}
}
示例3: TestPublishVirtualEnvironment
public void TestPublishVirtualEnvironment() {
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\VirtualEnv.sln");
var dir = TestData.GetTempPath(randomSubPath: true);
project.Properties.Item("PublishUrl").Value = dir;
app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
app.OpenSolutionExplorer().SelectProject(project);
var files = PublishAndWaitForFiles(app, "Build.PublishSelection", dir);
Assert.IsNotNull(files, "Timed out waiting for files to publish");
AssertUtil.ContainsAtLeast(
files.Select(f => CommonUtils.GetRelativeFilePath(dir, f).ToLowerInvariant()),
"env\\include\\pyconfig.h",
"env\\lib\\site.py",
"env\\scripts\\python.exe",
"program.py"
);
Directory.Delete(dir, true);
}
}
示例4: TestPublishFtp
public void TestPublishFtp() {
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\HelloWorld.sln");
string subDir = Guid.NewGuid().ToString();
string url = TestFtpUrl + "/" + subDir;
project.Properties.Item("PublishUrl").Value = url;
app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
string dir = Path.Combine(FtpValidateDir, subDir);
Debug.WriteLine(dir);
app.OpenSolutionExplorer().SelectProject(project);
app.ExecuteCommand("Build.PublishSelection");
System.Threading.Thread.Sleep(2000);
var files = WaitForFiles(dir);
Assert.AreEqual(1, files.Length);
Assert.AreEqual("Program.py", Path.GetFileName(files[0]));
// do it again w/ the directories already existing
File.Delete(files[0]);
app.OpenSolutionExplorer().SelectProject(project);
app.ExecuteCommand("Build.PublishSelection");
files = WaitForFiles(dir);
Assert.AreEqual(1, files.Length);
Assert.AreEqual("Program.py", Path.GetFileName(files[0]));
Directory.Delete(dir, true);
}
}
示例5: TestPublishFilesImpersonateCancelCredentials
public void TestPublishFilesImpersonateCancelCredentials() {
WNetCancelConnection2(TestSharePrivate, 0, true);
using (var app = new VisualStudioApp()) {
try {
var project = app.OpenProject(@"TestData\HelloWorld.sln");
string subDir = Guid.NewGuid().ToString();
project.Properties.Item("PublishUrl").Value = Path.Combine(TestSharePrivate, subDir);
app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
string dir = Path.Combine(TestSharePrivate, subDir);
app.OpenSolutionExplorer().SelectProject(project);
using (var creds = CredentialsDialog.PublishSelection(app)) {
creds.UserName = PrivateShareUser;
creds.Password = PrivateSharePasswordIncorrect;
creds.Cancel();
}
var statusBar = app.GetService<IVsStatusbar>(typeof(SVsStatusbar));
string text = null;
const string expected = "Publish failed: Access to the path";
for (int i = 0; i < 10; i++) {
ErrorHandler.ThrowOnFailure(statusBar.GetText(out text));
if (text.StartsWith(expected)) {
break;
}
System.Threading.Thread.Sleep(1000);
}
Assert.IsTrue(text.StartsWith(expected), "Expected '{0}', got '{1}'", expected, text);
} finally {
WNetCancelConnection2(TestSharePrivate, 0, true);
}
}
}
示例6: TestPublishFilesImpersonateNoMachineName
public void TestPublishFilesImpersonateNoMachineName() {
WNetCancelConnection2(TestSharePrivate, 0, true);
using (var app = new VisualStudioApp()) {
try {
var project = app.OpenProject(@"TestData\HelloWorld.sln");
string subDir = Guid.NewGuid().ToString();
project.Properties.Item("PublishUrl").Value = Path.Combine(TestSharePrivate, subDir);
app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
app.OpenSolutionExplorer().SelectProject(project);
using (var creds = CredentialsDialog.PublishSelection(app)) {
creds.UserName = PrivateShareUserWithoutMachine;
creds.Password = PrivateSharePassword;
creds.OK();
}
System.Threading.Thread.Sleep(2000);
using (var helper = new NetUseHelper()) {
string dir = Path.Combine(helper.Drive + "\\", subDir);
var files = WaitForFiles(dir);
Assert.AreEqual(1, files.Length);
Assert.AreEqual("Program.py", Path.GetFileName(files[0]));
Directory.Delete(dir, true);
}
} finally {
WNetCancelConnection2(TestSharePrivate, 0, true);
}
}
}
示例7: TestPublishFilesControlled
public void TestPublishFilesControlled() {
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\PublishTest.sln");
try {
string subDir = Guid.NewGuid().ToString();
project.Properties.Item("PublishUrl").Value = Path.Combine(TestSharePublic, subDir);
app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
string dir = Path.Combine(TestSharePublic, subDir);
app.OpenSolutionExplorer().SelectProject(project);
var files = PublishAndWaitForFiles(app, "Build.PublishSelection", dir);
Assert.IsNotNull(files, "Timed out waiting for files to publish");
Assert.AreEqual(2, files.Length);
AssertUtil.ContainsExactly(
files.Select(Path.GetFileName),
"Program.py",
"TextFile.txt"
);
Directory.Delete(dir, true);
} finally {
WNetCancelConnection2(TestSharePrivate, 0, true);
}
}
}
示例8: TestPublishReadOnlyFiles
public void TestPublishReadOnlyFiles() {
var sourceFile = TestData.GetPath(@"TestData\HelloWorld\Program.py");
Assert.IsTrue(File.Exists(sourceFile), sourceFile + " not found");
var attributes = File.GetAttributes(sourceFile);
using (var app = new VisualStudioApp()) {
var project = app.OpenProject(@"TestData\HelloWorld.sln");
try {
string subDir = Guid.NewGuid().ToString();
project.Properties.Item("PublishUrl").Value = Path.Combine(TestSharePublic, subDir);
app.OnDispose(() => project.Properties.Item("PublishUrl").Value = "");
string dir = Path.Combine(TestSharePublic, subDir);
File.SetAttributes(sourceFile, attributes | FileAttributes.ReadOnly);
app.OpenSolutionExplorer().SelectProject(project);
var files = PublishAndWaitForFiles(app, "Build.PublishSelection", dir);
Assert.IsNotNull(files, "Timed out waiting for files to publish");
Assert.AreEqual(1, files.Length);
Assert.AreEqual("Program.py", Path.GetFileName(files[0]));
Assert.IsTrue(File.GetAttributes(sourceFile).HasFlag(FileAttributes.ReadOnly), "Source file should be read-only");
Assert.IsFalse(File.GetAttributes(files[0]).HasFlag(FileAttributes.ReadOnly), "Published file should not be read-only");
Directory.Delete(dir, true);
} finally {
WNetCancelConnection2(TestSharePublic, 0, true);
File.SetAttributes(sourceFile, attributes);
}
}
}