Skip to content

Commit

Permalink
#1067 : Impossible to run scripts due to hanging debug session (ISE E…
Browse files Browse the repository at this point in the history
…diting session)
  • Loading branch information
AdamNaj committed Jun 2, 2024
1 parent f137972 commit 8943f11
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/Spe/Client/Applications/PowerShellIse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Management.Automation.Runspaces;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
Expand Down Expand Up @@ -682,7 +683,6 @@ protected virtual void JobExecute(ClientPipelineArgs args)
{
args.Parameters.Add("message", "ise:execute");
JobExecuteScript(args, Editor.Value, false);
ClearOutput();
}

[HandleMessage("ise:debug", true)]
Expand Down Expand Up @@ -719,6 +719,16 @@ protected virtual void JobExecuteScript(ClientPipelineArgs args, string scriptTo
? ScriptSessionManager.NewSession(ApplicationNames.ISE, true)
: ScriptSessionManager.GetSession(sessionName, ApplicationNames.ISE, true);

ClearOutput();
if (scriptSession.State == RunspaceAvailability.AvailableForNestedCommand || scriptSession.State == RunspaceAvailability.Busy)
{
var errorMessage =
"A Script is already executing in this script session. Use another session or wait for the other script to finish.";
PrintSessionUpdate($"<span style='background:red; color:white'>{errorMessage}</span>");
SheerResponse.Eval(
"spe.showSessionIDGallery();");
return;
}
if (debug)
{
scriptSession.DebugFile = FileUtil.MapPath(Settings.TempFolderPath) + "\\" +
Expand Down
2 changes: 0 additions & 2 deletions src/Spe/Client/Commands/MenuItems/ExecutePowerShellScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ protected void Process(ClientPipelineArgs args)
Assert.ArgumentNotNull(args, "args");
if (args.IsPostBack)
{
var item1 = ContentEditorForm.GetContextItem();
var item = Database.GetDatabase(itemDb).GetItem(itemId, Language.Parse(itemLang), Version.Parse(itemVer));
if (!args.HasResult || args.Result.IsNullOrEmpty()) return;
ScriptExecutionResult result = ScriptExecutionResult.Parse(args.Result);
result.ExecuteResults();
Expand Down
8 changes: 4 additions & 4 deletions src/Spe/Core/Host/ScriptSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public void Initialize()
Initialize(false);
}

public void Initialize(bool reinitialize)
private void Initialize(bool reinitialize)
{
lock (this)
{
Expand Down Expand Up @@ -685,7 +685,7 @@ public void Abort()
abortRequested = true;
}

public static Command OutDefaultCommand
private static Command OutDefaultCommand
=> new Command("Out-Default")
{
MergeUnclaimedPreviousCommandResults = PipelineResultTypes.Output | PipelineResultTypes.Error
Expand All @@ -709,7 +709,7 @@ public static Command OutHostCommand
/// <remarks>
/// "Out-Default" is not suitable for external apps, output goes to console.
/// </remarks>
public static Command OutNullCommand
private static Command OutNullCommand
=> new Command("Out-Null")
{
MergeUnclaimedPreviousCommandResults = PipelineResultTypes.Output | PipelineResultTypes.Error
Expand Down Expand Up @@ -882,7 +882,7 @@ public void Dispose()
GC.SuppressFinalize(this);
}

public void Close()
private void Close()
{
Runspace.DefaultRunspace = null;
host.Runspace.Dispose();
Expand Down
5 changes: 5 additions & 0 deletions src/Spe/sitecore modules/PowerShell/Scripts/ise.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@
registerEventListenersForRibbonButtons();
}
};

spe.showSessionIDGallery = function () {
contextGalery = jQuery("#B0C784F542B464EE2B0BA72384125E123")
contextGalery.click();
};

spe.updateRibbonNeeded = function () {
clearTimeout(typingTimer);
Expand Down

0 comments on commit 8943f11

Please sign in to comment.