コード例 #1
0
        public PhosphorSession StartSession(ModelBase sessionModel)
        {
            if (this.phosphorServer == null)
            {
                this.phosphorServer = new PhosphorServer();
                this.phosphorServer.Start();
            }

            PhosphorSession newSession =
                new PhosphorSession(
                    this.sessionList.Count + 1,
                    this.phosphorServer.ServerBaseUri,
                    sessionModel);

            this.sessionList.Add(newSession);

            return(newSession);
        }
コード例 #2
0
 public void StopSession(PhosphorSession phosphorSession)
 {
     this.sessionList[phosphorSession.Id - 1] = null;
 }
コード例 #3
0
        protected override void ProcessRecord()
        {
            var getCommandScript =
                this.Module != null
                    ? $"Get-Command -Module {string.Join(", ", this.Module)}"
                    : "Get-Command";

            var commandList = this.InvokeCommand.InvokeScript(getCommandScript, true);

            this.currentSession =
                SessionManager.Current.StartSession(
                    new ModuleViewModel(commandList));

            if (this.OpenInBrowser.IsPresent)
            {
                Process browserProcess = new Process();
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    browserProcess.StartInfo.FileName  = "xdg-open";
                    browserProcess.StartInfo.Arguments = this.currentSession.Uri.AbsoluteUri;
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    browserProcess.StartInfo.FileName  = "open";
                    browserProcess.StartInfo.Arguments = this.currentSession.Uri.AbsoluteUri;
                }
                else
                {
                    // TODO: This won't work on Windows when running in CoreCLR.  See this
                    // code in PowerShell Core:
                    // https://github.com/PowerShell/PowerShell/blob/7f83c48ca5e39bc98dbb9071d414bd02166cd4af/src/System.Management.Automation/engine/Utils.cs#L1608
                    browserProcess.StartInfo.FileName = this.currentSession.Uri.AbsoluteUri;
                }

                browserProcess.Start();
            }
            else
            {
                string exePath     = null;
                string urlArgument = this.currentSession.Uri.AbsoluteUri;

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    exePath = GetElectronPath("electron");
                }
                else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    exePath = GetElectronPath("Electron.app");
                }
                else
                {
                    exePath = GetElectronPath("electron.exe");
                }

                Process electronProcess = new Process();
                electronProcess.StartInfo.FileName  = exePath;
                electronProcess.StartInfo.Arguments =
                    this.currentSession.GetClientPath("electron-shell.js")
                    + " " + this.currentSession.Uri.AbsoluteUri;

                electronProcess.Start();
            }
        }