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); }
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); } }
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); } }
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); } }
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); } } }
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); } } }
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); } } }
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); } } }
private static void CloudProjectTest(string roleType, bool openServiceDefinition) { Assert.IsTrue(roleType == "Web" || roleType == "Worker", "Invalid roleType: " + roleType); using (var app = new VisualStudioApp()) using (FileUtils.Backup(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"))) { app.OpenProject("TestData\\CloudProject.sln", expectedProjects: 3); var ccproj = app.Dte.Solution.Projects.Cast <EnvDTE.Project>().FirstOrDefault(p => p.Name == "CloudProject"); Assert.IsNotNull(ccproj); if (openServiceDefinition) { var wnd = ccproj.ProjectItems.Item("ServiceDefinition.csdef").Open(); wnd.Activate(); app.OnDispose(() => wnd.Close()); } IVsHierarchy hier; var sln = app.GetService <IVsSolution>(typeof(SVsSolution)); ErrorHandler.ThrowOnFailure(sln.GetProjectOfUniqueName(ccproj.FullName, out hier)); app.ServiceProvider.GetUIThread().Invoke(() => NodejsProject.UpdateServiceDefinition( hier, roleType, roleType + "Role1", new ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)app.Dte) ) ); var doc = new XmlDocument(); for (int retries = 5; retries > 0; --retries) { try { doc.Load(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef")); break; } catch (IOException ex) { Console.WriteLine("Exception while reading ServiceDefinition.csdef.{0}{1}", Environment.NewLine, ex); } catch (XmlException) { var copyTo = TestData.GetPath(@"TestData\CloudProject\CloudProject\" + Path.GetRandomFileName()); File.Copy(TestData.GetPath(@"TestData\CloudProject\CloudProject\ServiceDefinition.csdef"), copyTo); Console.WriteLine("Copied file to " + copyTo); throw; } Thread.Sleep(100); } var ns = new XmlNamespaceManager(doc.NameTable); ns.AddNamespace("sd", "http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition"); doc.Save(Console.Out); var nav = doc.CreateNavigator(); if (roleType == "Web") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WebRole[@name='WebRole1']/sd:Startup/sd:Task[@commandLine='setup_web.cmd > log.txt']", ns )); } else if (roleType == "Worker") { Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Startup/sd:Task[@commandLine='setup_worker.cmd > log.txt']", ns )); Assert.IsNotNull(nav.SelectSingleNode( "/sd:ServiceDefinition/sd:WorkerRole[@name='WorkerRole1']/sd:Runtime/sd:EntryPoint/sd:ProgramEntryPoint[@commandLine='node.cmd .\\server.js']", ns )); } } }
public override ToolWindowPane ActivateInteractiveWindow(VisualStudioApp app, string executionMode) { string description = null; if (Version.IsCPython) { description = string.Format("{0} {1}", Version.Isx64 ? "Python 64-bit" : "Python 32-bit", 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 replId = PythonReplEvaluatorProvider.GetReplId(Version.Id); var provider = app.ComponentModel.GetService <InteractiveWindowProvider>(); return((ToolWindowPane)provider.FindReplWindow(replId)); }