3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Collections . ObjectModel ;
6
7
using System . IO ;
8
+ using System . Management . Automation ;
9
+ using System . Management . Automation . Host ;
7
10
using System . Management . Automation . Runspaces ;
11
+ using System . Security ;
8
12
using System . Threading ;
9
13
using System . Threading . Tasks ;
10
14
using Microsoft . Extensions . Logging ;
11
15
using Microsoft . Extensions . Logging . Abstractions ;
12
16
using Microsoft . PowerShell . EditorServices . Hosting ;
13
- using Microsoft . PowerShell . EditorServices . Services ;
17
+ using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
14
18
using Microsoft . PowerShell . EditorServices . Test . Shared ;
15
19
using Microsoft . PowerShell . EditorServices . Utility ;
16
20
17
21
namespace Microsoft . PowerShell . EditorServices . Test
18
22
{
19
- /*
20
- internal static class PowerShellContextFactory
23
+ internal static class PsesHostFactory
21
24
{
22
25
// NOTE: These paths are arbitrarily chosen just to verify that the profile paths
23
26
// can be set to whatever they need to be for the given host.
@@ -38,10 +41,8 @@ internal static class PowerShellContextFactory
38
41
39
42
public static System . Management . Automation . Runspaces . Runspace InitialRunspace ;
40
43
41
- public static PowerShellContextService Create(ILogger logger )
44
+ public static PsesInternalHost Create ( ILoggerFactory loggerFactory )
42
45
{
43
- PowerShellContextService powerShellContext = new PowerShellContextService(logger, null, isPSReadLineEnabled: false);
44
-
45
46
// We intentionally use `CreateDefault2()` as it loads `Microsoft.PowerShell.Core` only,
46
47
// which is a more minimal and therefore safer state.
47
48
var initialSessionState = InitialSessionState . CreateDefault2 ( ) ;
@@ -60,67 +61,23 @@ public static PowerShellContextService Create(ILogger logger)
60
61
"PowerShell Editor Services Test Host" ,
61
62
"Test.PowerShellEditorServices" ,
62
63
new Version ( "1.0.0" ) ,
63
- null,
64
+ psHost : null ,
64
65
TestProfilePaths ,
65
- new List <string>(),
66
- new List <string>(),
66
+ featureFlags : Array . Empty < string > ( ) ,
67
+ additionalModules : Array . Empty < string > ( ) ,
67
68
initialSessionState ,
68
- null,
69
- 0 ,
69
+ logPath : null ,
70
+ ( int ) LogLevel . None ,
70
71
consoleReplEnabled : false ,
71
72
usesLegacyReadLine : false ,
72
73
bundledModulePath : BundledModulePath ) ;
73
74
74
- InitialRunspace = PowerShellContextService.CreateTestRunspace(
75
- testHostDetails,
76
- powerShellContext,
77
- new TestPSHostUserInterface(powerShellContext, logger),
78
- logger);
75
+ var psesHost = new PsesInternalHost ( loggerFactory , null , testHostDetails ) ;
79
76
80
- powerShellContext.Initialize(
81
- TestProfilePaths,
82
- InitialRunspace,
83
- ownsInitialRunspace: true,
84
- consoleHost: null);
77
+ psesHost . StartAsync ( new HostStartOptions { LoadProfiles = true } , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
85
78
86
- return powerShellContext ;
79
+ return psesHost ;
87
80
}
88
81
}
89
-
90
- internal class TestPSHostUserInterface : EditorServicesPSHostUserInterface
91
- {
92
- public TestPSHostUserInterface(
93
- PowerShellContextService powerShellContext,
94
- ILogger logger)
95
- : base(
96
- powerShellContext,
97
- new SimplePSHostRawUserInterface(logger),
98
- NullLogger.Instance)
99
- {
100
- }
101
-
102
- public override void WriteOutput(string outputString, bool includeNewLine, OutputType outputType, ConsoleColor foregroundColor, ConsoleColor backgroundColor)
103
- {
104
- }
105
-
106
- protected override ChoicePromptHandler OnCreateChoicePromptHandler()
107
- {
108
- throw new NotImplementedException();
109
- }
110
-
111
- protected override InputPromptHandler OnCreateInputPromptHandler()
112
- {
113
- throw new NotImplementedException();
114
- }
115
-
116
- protected override Task<string> ReadCommandLineAsync(CancellationToken cancellationToken)
117
- {
118
- return Task.FromResult("USER COMMAND");
119
- }
120
-
121
- protected override void UpdateProgress(long sourceId, ProgressDetails progressDetails)
122
- {
123
- }
124
- }
125
- */
126
82
}
83
+
0 commit comments