当前位置: 首页>>代码示例>>C#>>正文


C# VisualStudioApp.GetService方法代码示例

本文整理汇总了C#中Microsoft.VisualStudioTools.VisualStudioApp.GetService方法的典型用法代码示例。如果您正苦于以下问题:C# VisualStudioApp.GetService方法的具体用法?C# VisualStudioApp.GetService怎么用?C# VisualStudioApp.GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.VisualStudioTools.VisualStudioApp的用法示例。


在下文中一共展示了VisualStudioApp.GetService方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CloudProjectTest

        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
                    ));
                }
            }
        }
开发者ID:raphaelivo,项目名称:nodejstools,代码行数:66,代码来源:AzureProjectTests.cs

示例2: CreateVirtualEnvironment

        internal static IPythonInterpreterFactory CreateVirtualEnvironment(string pythonVersion, VisualStudioApp app, PythonProjectNode pyProj) {
            var uiThread = app.ServiceProvider.GetUIThread();
            var task = uiThread.InvokeTask(() => {
                var model = app.GetService<IComponentModel>(typeof(SComponentModel));
                var service = model.GetService<IInterpreterRegistryService>();

                return pyProj.CreateOrAddVirtualEnvironment(
                    service,
                    true,
                    Path.Combine(pyProj.ProjectHome, "env"),
                    service.FindInterpreter("Global|PythonCore|" + pythonVersion + "-32"),
                    Version.Parse(pythonVersion) >= new Version(3, 3)
                );
            });
            try {
                Assert.IsTrue(task.Wait(TimeSpan.FromMinutes(2.0)), "Timed out waiting for venv");
            } catch (AggregateException ex) {
                throw ex.InnerException;
            }
            var factory = task.Result;
            Assert.IsTrue(uiThread.Invoke(() => factory.Configuration.Id == pyProj.GetInterpreterFactory().Configuration.Id));
            return factory;
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:23,代码来源:WebProjectTests.cs

示例3: LaunchAndVerifyNoDebug

        private static void LaunchAndVerifyNoDebug(
            VisualStudioApp app,
            int port,
            string textInResponse
        ) {
            bool prevNormal = true, prevAbnormal = true;
            string text;
            int retries;

            try {
                using (var processes = new ProcessScope("python")) {
                    EndToEndLog("Transitioning to UI thread to build");
                    app.ServiceProvider.GetUIThread().Invoke(() => {
                        EndToEndLog("Building");
                        app.Dte.Solution.SolutionBuild.Build(true);
                        EndToEndLog("Build output: {0}", app.GetOutputWindowText("Build"));
                        EndToEndLog("Updating settings");
                        prevNormal = app.GetService<PythonToolsService>().DebuggerOptions.WaitOnNormalExit;
                        prevAbnormal = app.GetService<PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit;
                        app.GetService<PythonToolsService>().DebuggerOptions.WaitOnNormalExit = false;
                        app.GetService<PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit = false;

                        EndToEndLog("Starting running");
                        app.Dte.Solution.SolutionBuild.Run();
                        EndToEndLog("Running");
                    });

                    var newProcesses = processes.WaitForNewProcess(TimeSpan.FromSeconds(30)).ToList();
                    Assert.IsTrue(newProcesses.Any(), "Did not find new Python process");
                    EndToEndLog("Found new processes with IDs {0}", string.Join(", ", newProcesses.Select(p => p.Id.ToString())));

                    for (retries = 100;
                        retries > 0 &&
                            !IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Any(p => p.Port == port);
                        --retries) {
                        Thread.Sleep(300);
                    }
                    EndToEndLog("Active at http://localhost:{0}/", port);

                    text = WebDownloadUtility.GetString(new Uri(string.Format("http://localhost:{0}/", port)));
                }
            } finally {
                app.ServiceProvider.GetUIThread().Invoke(() => {
                    app.GetService<PythonToolsService>().DebuggerOptions.WaitOnNormalExit = prevNormal;
                    app.GetService<PythonToolsService>().DebuggerOptions.WaitOnAbnormalExit = prevAbnormal;
                });
            }

            EndToEndLog("Response from http://localhost:{0}/", port);
            EndToEndLog(text);
            Assert.IsTrue(text.Contains(textInResponse), text);

            for (retries = 20;
                retries > 0 && !IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().All(p => p.Port != port);
                --retries) {
                Thread.Sleep(500);
            }
            if (retries > 0) {
                EndToEndLog("Process ended");
            } else {
                EndToEndLog("Timed out waiting for process to exit");
            }
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:63,代码来源:WebProjectTests.cs

示例4: ErrorListAndTaskListAreClearedWhenProjectWithMultipleFilesIsUnloaded

        public void ErrorListAndTaskListAreClearedWhenProjectWithMultipleFilesIsUnloaded() {
            using (var app = new VisualStudioApp()) {
                var project = app.OpenProject(@"TestData\ErrorProjectMultipleFiles.sln");

                app.WaitForTaskListItems(typeof(SVsErrorList), 14);
                app.WaitForTaskListItems(typeof(SVsTaskList), 4);

                var solutionService = app.GetService<IVsSolution>(typeof(SVsSolution));
                Assert.IsNotNull(solutionService);

                IVsHierarchy selectedHierarchy;
                ErrorHandler.ThrowOnFailure(solutionService.GetProjectOfUniqueName(project.UniqueName, out selectedHierarchy));
                Assert.IsNotNull(selectedHierarchy);

                Console.WriteLine("Unloading project");
                ErrorHandler.ThrowOnFailure(solutionService.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, selectedHierarchy, 0));

                app.WaitForTaskListItems(typeof(SVsErrorList), 0);
                app.WaitForTaskListItems(typeof(SVsTaskList), 0);
            }
        }
开发者ID:RussBaz,项目名称:PTVS,代码行数:21,代码来源:ErrorListTaskListTests.cs

示例5: LaunchFileFromProject

        public static SD.Process LaunchFileFromProject(VisualStudioApp app, EnvDTE.Project project, string filename, string interpreterArgs, string programArgs) {
            var item = project.ProjectItems.Item(filename);
            var window = item.Open();
            window.Activate();
            var doc = item.Document;
            var docFN = doc.FullName;
            string fullFilename = Path.GetFullPath(docFN);

            string cmdlineArgs = String.Format("{0} \"{1}\" {2}", interpreterArgs, fullFilename, programArgs);

            var uiThread = app.GetService<UIThreadBase>();
            var projectInterpreter = uiThread.Invoke(() => project.GetPythonProject().GetLaunchConfigurationOrThrow().GetInterpreterPath());

            var psi = new SD.ProcessStartInfo(projectInterpreter, cmdlineArgs);
            psi.RedirectStandardError = true;
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute = false;
            var p = SD.Process.Start(psi);
            p.EnableRaisingEvents = true;
            string output = "";
            p.OutputDataReceived += (sender, args) => {
                output += args.Data;
            };
            p.ErrorDataReceived += (sender, args) => {
                output += args.Data;
            };
            p.BeginErrorReadLine();
            p.BeginOutputReadLine();
            p.Exited += (sender, args) => {
                SD.Debug.WriteLine("Process Id ({0}) exited with ExitCode: {1}", p.Id, p.ExitCode);
                SD.Debug.WriteLine(String.Format("Output: {0}", output));
            };

            Assert.IsNotNull(p, "Failure to start process, {0} {1} ", projectInterpreter, cmdlineArgs);
            return p;
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:36,代码来源:AttachTest.cs

示例6: EnableAutoBraceCompletion

        private bool EnableAutoBraceCompletion(VisualStudioApp app, bool enable) {
            return app.GetService<UIThreadBase>().Invoke(() => {
                var mgr = app.GetService<IVsTextManager4>(typeof(SVsTextManager));
                LANGPREFERENCES3[] langPrefs = { new LANGPREFERENCES3() };

                langPrefs[0].guidLang = GuidList.guidPythonLanguageServiceGuid;
                ErrorHandler.ThrowOnFailure(mgr.GetUserPreferences4(null, langPrefs, null));
                bool old = langPrefs[0].fBraceCompletion != 0;
                langPrefs[0].fBraceCompletion = enable ? 1u : 0u;
                ErrorHandler.ThrowOnFailure(mgr.SetUserPreferences4(null, langPrefs, null));
                return old;
            });
        }
开发者ID:jsschultz,项目名称:PTVS,代码行数:13,代码来源:EditorTests.cs


注:本文中的Microsoft.VisualStudioTools.VisualStudioApp.GetService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。