internal void OpenHomepage(string homepage)
 {
     if (!string.IsNullOrEmpty(homepage))
     {
         VsShellUtilities.OpenBrowser(homepage);
     }
 }
Esempio n. 2
0
        private void MoreInformationAction()
        {
            LogEvent(PythonVersionNotSupportedInfoBarAction.MoreInfo);
            Close();

            VsShellUtilities.OpenBrowser(_moreInformationLink);
        }
Esempio n. 3
0
        private void StartWithChromeV2Debugger(string file, string nodePath, bool startBrowser)
        {
            var serviceProvider = _project.Site;

            // Here we need to massage the env variables into the format expected by node and vs code
            var webBrowserUrl = GetFullUrl();
            var envVars       = GetEnvironmentVariables(webBrowserUrl);

            var runtimeArguments = ConvertArguments(this._project.GetProjectProperty(NodeProjectProperty.NodeExeArguments));
            var scriptArguments  = ConvertArguments(this._project.GetProjectProperty(NodeProjectProperty.ScriptArguments));

            var cwd           = _project.GetWorkingDirectory(); // Current working directory
            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", file),
                new JProperty("args", scriptArguments),
                new JProperty("runtimeExecutable", nodePath),
                new JProperty("runtimeArgs", runtimeArguments),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("env", JObject.FromObject(envVars)),
                new JProperty("trace", CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true));

            var jsonContent = configuration.ToString();

            var debugTargets = new[] {
                new VsDebugTargetInfo4()
                {
                    dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess,
                    guidLaunchDebugEngine = WebKitDebuggerV2Guid,
                    bstrExe     = file,
                    bstrOptions = jsonContent
                }
            };

            var processInfo = new VsDebugTargetProcessInfo[debugTargets.Length];

            var debugger = (IVsDebugger4)serviceProvider.GetService(typeof(SVsShellDebugger));

            debugger.LaunchDebugTargets4(1, debugTargets, processInfo);

            // Launch browser
            if (startBrowser && !string.IsNullOrWhiteSpace(webBrowserUrl))
            {
                var uri = new Uri(webBrowserUrl);
                OnPortOpenedHandler.CreateHandler(
                    uri.Port,
                    timeout: 5_000, // 5 seconds
                    action: () =>
                {
                    VsShellUtilities.OpenBrowser(webBrowserUrl, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
                }
                    );
            }
        }
Esempio n. 4
0
        private void StartAndAttachDebugger(string file, string nodePath, bool startBrowser)
        {
            // start the node process
            var workingDir         = _project.GetWorkingDirectory();
            var url                = GetFullUrl();
            var env                = GetEnvironmentVariablesString(url);
            var interpreterOptions = _project.GetProjectProperty(NodeProjectProperty.NodeExeArguments);
            var debugOptions       = this.GetDebugOptions();
            var script             = GetFullArguments(file, includeNodeArgs: false);

            var process = NodeDebugger.StartNodeProcessWithInspect(exe: nodePath, script: script, dir: workingDir, env: env, interpreterOptions: interpreterOptions, debugOptions: debugOptions);

            process.Start();

            // setup debug info and attach
            var debugUri = $"http://127.0.0.1:{process.DebuggerPort}";

            var dbgInfo = new VsDebugTargetInfo4();

            dbgInfo.dlo         = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning;
            dbgInfo.LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd;

            dbgInfo.guidLaunchDebugEngine = WebkitDebuggerGuid;
            dbgInfo.dwDebugEngineCount    = 1;

            var enginesPtr = MarshalDebugEngines(new[] { WebkitDebuggerGuid });

            dbgInfo.pDebugEngines       = enginesPtr;
            dbgInfo.guidPortSupplier    = WebkitPortSupplierGuid;
            dbgInfo.bstrPortName        = debugUri;
            dbgInfo.fSendToOutputWindow = 0;

            // we connect through a URI, so no need to set the process,
            // we need to set the process id to '1' so the debugger is able to attach
            dbgInfo.bstrExe = $"\01";

            AttachDebugger(dbgInfo);

            if (startBrowser)
            {
                Uri uri = null;
                if (!String.IsNullOrWhiteSpace(url))
                {
                    uri = new Uri(url);
                }

                if (uri != null)
                {
                    OnPortOpenedHandler.CreateHandler(
                        uri.Port,
                        shortCircuitPredicate: () => process.HasExited,
                        action: () =>
                    {
                        VsShellUtilities.OpenBrowser(url, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
                    }
                        );
                }
            }
        }
Esempio n. 5
0
        private int Start(string file, bool debug)
        {
            string nodePath = GetNodePath();

            if (nodePath == null)
            {
                Nodejs.ShowNodejsNotInstalled();
                return(VSConstants.S_OK);
            }

            bool startBrowser = ShouldStartBrowser();

            if (debug)
            {
                StartWithDebugger(file);
            }
            else
            {
                var psi = new ProcessStartInfo();
                psi.UseShellExecute = false;

                psi.FileName         = nodePath;
                psi.Arguments        = GetFullArguments(file);
                psi.WorkingDirectory = _project.GetWorkingDirectory();

                string webBrowserUrl = GetFullUrl();
                Uri    uri           = null;
                if (!String.IsNullOrWhiteSpace(webBrowserUrl))
                {
                    uri = new Uri(webBrowserUrl);

                    psi.EnvironmentVariables["PORT"] = uri.Port.ToString();
                }

                foreach (var nameValue in GetEnvironmentVariables())
                {
                    psi.EnvironmentVariables[nameValue.Key] = nameValue.Value;
                }

                var process = NodeProcess.Start(
                    psi,
                    NodejsPackage.Instance.GeneralOptionsPage.WaitOnAbnormalExit,
                    NodejsPackage.Instance.GeneralOptionsPage.WaitOnNormalExit);
                _project.OnDispose += process.ResponseToTerminateEvent;

                if (startBrowser && uri != null)
                {
                    OnPortOpenedHandler.CreateHandler(
                        uri.Port,
                        shortCircuitPredicate: () => process.HasExited,
                        action: () => {
                        VsShellUtilities.OpenBrowser(webBrowserUrl, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
                    }
                        );
                }
            }
            return(VSConstants.S_OK);
        }
Esempio n. 6
0
        private static void CheckNuget(Project project)
        {
            var references = project.GetReferences().ToArray();

            if (references.All(r => r.Name != "LinqToSalesforce"))
            {
                MessageBox.Show("NuGet LinqToSalesforce should be added to project.");
                VsShellUtilities.OpenBrowser("https://www.nuget.org/packages/LinqToSalesforce");
            }
        }
Esempio n. 7
0
        private void Task_Help(object sender, EventArgs e)
        {
            var task = sender as VulnerabilityTask;

            if (task != null)
            {
                string url = string.Format("https://ossindex.sonatype.org/vuln/{0}", task.Vulnerability.Id);
                VsShellUtilities.OpenBrowser(url);
            }
        }
Esempio n. 8
0
 private static void OpenBrowser(string browserPath, string webBrowserUrl)
 {
     // Chrome has known issues with being launched as admin.
     if (!string.IsNullOrEmpty(browserPath) && browserPath.EndsWith(NodejsConstants.ChromeApplicationName))
     {
         SystemUtility.ExecuteProcessUnElevated(browserPath, webBrowserUrl);
     }
     else
     {
         VsShellUtilities.OpenBrowser(webBrowserUrl, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
     }
 }
Esempio n. 9
0
        private void StartNodeProcess(string file, string nodePath, bool startBrowser)
        {
            //TODO: looks like this duplicates a bunch of code in NodeDebugger
            var psi = new ProcessStartInfo()
            {
                UseShellExecute = false,

                FileName         = nodePath,
                Arguments        = GetFullArguments(file, includeNodeArgs: true),
                WorkingDirectory = _project.GetWorkingDirectory()
            };

            var webBrowserUrl = GetFullUrl();
            Uri uri           = null;

            if (!String.IsNullOrWhiteSpace(webBrowserUrl))
            {
                uri = new Uri(webBrowserUrl);
                psi.EnvironmentVariables["PORT"] = uri.Port.ToString();
            }

            foreach (var nameValue in GetEnvironmentVariables())
            {
                psi.EnvironmentVariables[nameValue.Key] = nameValue.Value;
            }

            var process = NodeProcess.Start(
                psi,
                waitOnAbnormal: NodejsPackage.Instance.GeneralOptionsPage.WaitOnAbnormalExit,
                waitOnNormal: NodejsPackage.Instance.GeneralOptionsPage.WaitOnNormalExit);

            this._project.OnDispose += process.ResponseToTerminateEvent;

            if (startBrowser && uri != null)
            {
                OnPortOpenedHandler.CreateHandler(
                    uri.Port,
                    shortCircuitPredicate: () => process.HasExited,
                    action: () =>
                {
                    VsShellUtilities.OpenBrowser(webBrowserUrl, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
                }
                    );
            }
        }
Esempio n. 10
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     VsShellUtilities.OpenBrowser("https://rflechner.github.io/LinqToSalesforce/getting_started_with_salesforce.html");
 }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private async void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));
                var workspace      = componentModel.GetService <VisualStudioWorkspace>();

                var selectedItem = this.GetSelectedSolutionExplorerItem();
                Microsoft.CodeAnalysis.Document doc = null;

                if (selectedItem != null && selectedItem.Name != null && !selectedItem.Name.EndsWith(".cs"))
                {
                    VsShellUtilities.ShowMessageBox(this.package, "Generate DTO action can only be invoked on CSharp files.", "Error",
                                                    OLEMSGICON.OLEMSGICON_WARNING,
                                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                    return;
                }

                if (selectedItem?.Document != null)
                {
                    doc = workspace.CurrentSolution.GetDocumentByFilePath(selectedItem.Document.FullName);
                }
                else if (selectedItem != null)
                {
                    var file        = selectedItem.Name;
                    var projectName = selectedItem.ContainingProject.Name;

                    var docs = workspace.CurrentSolution.Projects
                               .Where(p => p.Name == projectName)
                               .SelectMany(p => p.Documents)
                               .Where(d => d.Name == file)
                               .ToList();

                    if (docs.Count == 0)
                    {
                        VsShellUtilities.ShowMessageBox(this.package, "Shitty exception - cannot get current selected solution item :/// . Try opening desired document, and then activating this command.", "Error",
                                                        OLEMSGICON.OLEMSGICON_WARNING,
                                                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }

                    if (docs.Count > 1)
                    {
                        VsShellUtilities.ShowMessageBox(this.package, "Multiple documents with same name exist - cannot get current selected solution item. Try opening desired document, and then activating this command.", "Error",
                                                        OLEMSGICON.OLEMSGICON_WARNING,
                                                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }

                    doc = docs.FirstOrDefault();
                }
                else
                {
                    VsShellUtilities.ShowMessageBox(this.package, "Shitty exception - cannot get current selected solution item :/// . Try opening desired document, and then activating this command.", "Error",
                                                    OLEMSGICON.OLEMSGICON_WARNING,
                                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                    return;
                }
                var possibleProjects = doc.GetPossibleProjects();

                var vmBasic = BasicOptionsViewModel.Create(possibleProjects, doc.Name.Replace(".cs", ""), doc.Project.Solution.GetMostLikelyDtoLocation());
                var shouldProceed = new BasicOptionsWindow {
                    DataContext = vmBasic
                }.ShowModal();

                if (shouldProceed != true)
                {
                    return;
                }

                var existingDoc = doc.Project.Solution.GetDocumentByLocation(vmBasic.DtoLocation, vmBasic.DtoName);
                if (existingDoc != null)
                {
                    var result = VsShellUtilities.ShowMessageBox(this.package, "There is already a DTO class in the specified location. Press OK if you would like to regenerate it, or cancel to choose different name.", "Warninig - regenerate DTO?",
                                                                 OLEMSGICON.OLEMSGICON_WARNING,
                                                                 OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                                                                 OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                    if (result != 1)
                    {
                        return;
                    }
                }

                var vm = await PropertySelectorViewModel.Create(doc, vmBasic.DtoName, vmBasic.DtoLocation, existingDto : existingDoc);

                var isConfirmed = new PropertySelectorWindow()
                {
                    DataContext = vm
                }.ShowModal();

                if (isConfirmed == true)
                {
                    var modifiedSolution = await doc.Project.Solution.WriteDto(vm.DtoLocation, vm.EntityModel.ConvertToMetadata(), vm.GenerateMapper, vm.AddDataContract);

                    var ok = workspace.TryApplyChanges(modifiedSolution);

                    if (!ok)
                    {
                        VsShellUtilities.ShowMessageBox(this.package, "Unable to generate DTO. Please try again (could not apply changes).", "Error", OLEMSGICON.OLEMSGICON_WARNING, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    VsShellUtilities.ShowMessageBox(this.package, ex.Message, "An exception has occurred. Please c/p stack trace to project website (https://github.com/yohney/dto-generator), with brief description of the problem.",
                                                    OLEMSGICON.OLEMSGICON_WARNING,
                                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                    var tmpFile = Path.GetTempFileName();

                    string stackTrace = "";

                    Exception tmp = ex;
                    while (tmp != null)
                    {
                        stackTrace += tmp.StackTrace;
                        stackTrace += "\n----------------------------\n\n";
                        tmp         = ex.InnerException;
                    }


                    File.WriteAllText(tmpFile, stackTrace);

                    VsShellUtilities.OpenBrowser("file:///" + tmpFile);
                }
                catch (Exception innerEx)
                {
                    VsShellUtilities.ShowMessageBox(this.package, innerEx.Message, "An exception has occurred. Unable to write stack trace to TEMP directory.",
                                                    OLEMSGICON.OLEMSGICON_WARNING,
                                                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                                                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }
        }
Esempio n. 12
0
        private void StartWithChromeV2Debugger(string file, string nodePath, bool startBrowser)
        {
            var serviceProvider = _project.Site;

            var setupConfiguration = new SetupConfiguration();

            var setupInstance = setupConfiguration.GetInstanceForCurrentProcess();

            var visualStudioInstallationInstanceID = setupInstance.GetInstanceId();

            // The Node2Adapter depends on features only in Node v6+, so the old v5.4 version of node will not suffice for this scenario
            // This node.exe will be the one used by the node2 debug adapter, not the one used to host the user code.
            var pathToNodeExe = Path.Combine(setupInstance.GetInstallationPath(), "JavaScript\\Node.JS\\v6.4.0_x86\\Node.exe");

            // We check the registry to see if any parameters for the node.exe invocation have been specified (like "--inspect"), and append them if we find them.
            string nodeParams = CheckForRegistrySpecifiedNodeParams();

            if (!string.IsNullOrEmpty(nodeParams))
            {
                pathToNodeExe = pathToNodeExe + " " + nodeParams;
            }

            var pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\extension\out\src\nodeDebug.js""");

            string trimmedPathToNode2DebugAdapter = pathToNode2DebugAdapterRuntime.Replace("\"", "");

            if (!File.Exists(trimmedPathToNode2DebugAdapter))
            {
                pathToNode2DebugAdapterRuntime = Environment.ExpandEnvironmentVariables(@"""%ALLUSERSPROFILE%\" +
                                                                                        $@"Microsoft\VisualStudio\NodeAdapter\{visualStudioInstallationInstanceID}\out\src\nodeDebug.js""");
            }

            // Here we need to massage the env variables into the format expected by node and vs code
            var webBrowserUrl = GetFullUrl();
            var envVars       = GetEnvironmentVariables(webBrowserUrl);

            var cwd           = _project.GetWorkingDirectory(); // Current working directory
            var configuration = new JObject(
                new JProperty("name", "Debug Node.js program from Visual Studio"),
                new JProperty("type", "node2"),
                new JProperty("request", "launch"),
                new JProperty("program", file),
                new JProperty("runtimeExecutable", nodePath),
                new JProperty("cwd", cwd),
                new JProperty("console", "externalTerminal"),
                new JProperty("env", JObject.FromObject(envVars)),
                new JProperty("trace", CheckEnableDiagnosticLoggingOption()),
                new JProperty("sourceMaps", true),
                new JProperty("stopOnEntry", true),
                new JProperty("$adapter", pathToNodeExe),
                new JProperty("$adapterArgs", pathToNode2DebugAdapterRuntime));

            var jsonContent = configuration.ToString();

            var debugTargets = new[] {
                new VsDebugTargetInfo4()
                {
                    dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess,
                    guidLaunchDebugEngine = WebKitDebuggerV2Guid,
                    bstrExe     = file,
                    bstrOptions = jsonContent
                }
            };

            var processInfo = new VsDebugTargetProcessInfo[debugTargets.Length];

            var debugger = serviceProvider.GetService(typeof(SVsShellDebugger)) as IVsDebugger4;

            debugger.LaunchDebugTargets4(1, debugTargets, processInfo);

            // Launch browser
            if (startBrowser)
            {
                Uri uri = null;
                if (!String.IsNullOrWhiteSpace(webBrowserUrl))
                {
                    uri = new Uri(webBrowserUrl);
                }

                if (uri != null)
                {
                    OnPortOpenedHandler.CreateHandler(
                        uri.Port,
                        shortCircuitPredicate: () => false,
                        action: () =>
                    {
                        VsShellUtilities.OpenBrowser(webBrowserUrl, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
                    }
                        );
                }
            }
        }
Esempio n. 13
0
 public void StartInBrowser(string url)
 {
     VsShellUtilities.OpenBrowser(url, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
 }
Esempio n. 14
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            try
            {
                VisualStudioWorkspace workspace = ((IComponentModel)Package.GetGlobalService(typeof(SComponentModel))).GetService <VisualStudioWorkspace>();

                ProjectItem selectedItem = this.GetSelectedSolutionExplorerItem();
                if (selectedItem != null && selectedItem.Name != null && !selectedItem.Name.EndsWith(".cs"))
                {
                    "52ABP代码生成器(官网:52abp.com),仅支持C#文件!".ErrorMsg();
                }
                else
                {
                    Document currentSelectedDocument;
                    if (((selectedItem != null) ? selectedItem.Document : null) != null)
                    {
                        currentSelectedDocument = workspace.CurrentSolution.GetDocumentByFilePath(selectedItem.Document.FullName);
                    }
                    else
                    {
                        if (selectedItem == null)
                        {
                            "致命异常-无法获得当前选择的解决方案:请重新打开这个解决方案,然后重试本工具。(官网:52abp.com)".ErrorMsg();
                            return;
                        }
                        string         file        = selectedItem.Name;
                        string         projectName = selectedItem.ContainingProject.Name;
                        List <Project> allProjects = workspace.CurrentSolution.Projects.ToList <Project>();
                        List <Project> tmpProjects = (from o in allProjects
                                                      where o.Name.StartsWith(projectName + "(net")
                                                      select o).ToList <Project>();
                        List <Document> docs;
                        if (allProjects.Exists((Project p) => p.Name.Contains(".Shared")))
                        {
                            docs = (from d in (from p in allProjects
                                               where p.Name.Contains(projectName) && !p.Name.Contains(".Shared")
                                               select p).FirstOrDefault <Project>().Documents
                                    where d.Name == file
                                    select d).ToList <Document>();
                        }
                        else if (tmpProjects.Count > 1)
                        {
                            docs = (from d in tmpProjects.FirstOrDefault <Project>().Documents
                                    where d.Name == file
                                    select d).ToList <Document>();
                        }
                        else
                        {
                            docs = (from d in (from p in allProjects
                                               where p.Name == projectName
                                               select p).SelectMany((Project p) => p.Documents)
                                    where d.Name == file
                                    select d).ToList <Document>();
                        }
                        if (docs.Count == 0)
                        {
                            "致命异常-无法获得当前选择的解决方案。请尝试重新打开解决方案,然后再使用本工具(官网:52abp.com)".ErrorMsg();
                            return;
                        }
                        if (docs.Count > 1)
                        {
                            "当前解决方案中,有多个同名的类文件,请处理之后再使用本工具,比如删除一个^_^(官网:52abp.com)。".ErrorMsg();
                            return;
                        }
                        currentSelectedDocument = docs.FirstOrDefault <Document>();
                    }
                    SolutionInfoModel solutionInfo     = SolutionInfoCreator.Create(currentSelectedDocument);
                    string            path             = Path.Combine(solutionInfo.SolutionPath, "solutionInfo.json");
                    string            solutionInfoJson = JsonConvert.SerializeObject(solutionInfo);
                    path.CreateFile(solutionInfoJson);
                    ProcessStartInfo processStartInfo = new ProcessStartInfo();
                    string           exePath          = Path.Combine(Path.GetDirectoryName(typeof(CommonConsts).Assembly.Location), "YoyoAbpCodePowerProject.WPF.exe");
                    processStartInfo.FileName  = exePath;
                    processStartInfo.Arguments = " \"" + solutionInfo.SolutionPath + "\"";
                    Process.Start(processStartInfo);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    "发生了一个异常。请复制 c/p 堆栈信息,然后打开项目网站(https://github.com/52ABP/52ABP.CodeGenerator),补充问题和增加简短描述。".ErrorMsg();
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<html><head></head><body><a hrf='https://github.com/52ABP/52ABP.CodeGenerator/issues/new'>baidu</a><br>");
                    sb.Append(ex.ToString());
                    sb.Append("</body></html>");
                    string tmpFile = Path.GetTempFileName();
                    File.WriteAllText(tmpFile, sb.ToString());
                    VsShellUtilities.OpenBrowser("file:///" + tmpFile);
                }
                catch (Exception)
                {
                    "发生了一个异常。 无法将堆栈跟踪写入临时目录.".ErrorMsg();
                }
            }
        }
Esempio n. 15
0
        public static void Show(NodejsProjectNode projectNode)
        {
            var serviceProvider = projectNode.Site;

            serviceProvider.GetUIThread().MustBeCalledFromUIThread();

            var vsShell          = (IVsShell)serviceProvider.GetService(typeof(SVsShell));
            var infoBarUIFactory = (IVsInfoBarUIFactory)serviceProvider.GetService(typeof(SVsInfoBarUIFactory));

            if (ErrorHandler.Failed(vsShell.GetProperty((int)__VSSPROPID7.VSSPROPID_MainWindowInfoBarHost, out var tmp)))
            {
                // we don't want to crash just because we can't show the error bar
                return;
            }
            var infoBarHost = (IVsInfoBarHost)tmp;

            // make sure we close the previous infobar
            CurrentInfoBarElement?.Close();

            Action downloadNode     = DownloadNode;
            Action openProjectProps = ShowProjectProperties;

            var actionItems = new[]
            {
                new InfoBarHyperlink(Resources.ConfigureProjectProperties, openProjectProps),
                new InfoBarHyperlink(Resources.DownloadNodejs, downloadNode),
            };

            var infoBarModel = new InfoBarModel(Resources.NodejsNotInstalledInfoBar, actionItems, isCloseButtonVisible: true, image: KnownMonikers.StatusError);

            uint eventCookie = 0;

            CurrentInfoBarElement = infoBarUIFactory.CreateInfoBar(infoBarModel);
            CurrentInfoBarElement.Advise(new InfoBarUIEvents(OnClose), out eventCookie);

            infoBarHost.AddInfoBar(CurrentInfoBarElement);

            void OnClose()
            {
                CurrentInfoBarElement.Unadvise(eventCookie);
            }

            void DownloadNode()
            {
                const string url = @"https://aka.ms/downloadnode";

                VsShellUtilities.OpenBrowser(url, (uint)__VSOSPFLAGS.OSP_LaunchNewBrowser);
            }

            void ShowProjectProperties()
            {
                // open Project Properties
                var logicalView = VSConstants.LOGVIEWID_Primary;

                if (ErrorHandler.Succeeded(projectNode.GetGuidProperty(VSConstants.VSITEMID_ROOT, (int)VsHierarchyPropID.ProjectDesignerEditor, out var editorType)) &&
                    ErrorHandler.Succeeded(projectNode.OpenItemWithSpecific(VSConstants.VSITEMID_ROOT, 0, ref editorType, "", ref logicalView, (IntPtr)(-1), out var frame)))
                {
                    frame?.Show();
                }
            }
        }