Repository navigation
Expand file tree
/
Copy pathAsyncPowerShellHost.cs
More file actions
58 lines (52 loc) · 1.94 KB
/
Copy pathAsyncPowerShellHost.cs
File metadata and controls
58 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using NuGet.VisualStudio;
namespace NuGetConsole.Host.PowerShell.Implementation
{
internal class AsyncPowerShellHost : PowerShellHost, IAsyncHost
{
public event EventHandler ExecuteEnd;
public AsyncPowerShellHost(string name, IRunspaceManager runspaceManager)
: base(name, runspaceManager)
{
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
protected override bool ExecuteHost(string fullCommand, string command, params object[] inputs)
{
SetSyncModeOnHost(false);
try
{
Pipeline pipeline = Runspace.InvokeAsync(fullCommand, inputs, true, (sender, e) =>
{
switch (e.PipelineStateInfo.State)
{
case PipelineState.Completed:
case PipelineState.Failed:
case PipelineState.Stopped:
if (e.PipelineStateInfo.Reason != null)
{
ReportError(e.PipelineStateInfo.Reason);
}
OnExecuteCommandEnd();
ExecuteEnd.Raise(this, EventArgs.Empty);
break;
}
});
ExecutingPipeline = pipeline;
return true;
}
catch (RuntimeException e)
{
ReportError(e.ErrorRecord);
ExceptionHelper.WriteToActivityLog(e);
}
catch (Exception e)
{
ReportError(e);
ExceptionHelper.WriteToActivityLog(e);
}
return false; // Error occurred, command not executing
}
}
}