-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathPowerShellContextFactory.cs
106 lines (91 loc) · 4 KB
/
PowerShellContextFactory.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.IO;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Hosting;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.PowerShellContext;
using Microsoft.PowerShell.EditorServices.Test.Shared;
namespace Microsoft.PowerShell.EditorServices.Test
{
internal static class PowerShellContextFactory
{
// NOTE: These paths are arbitrarily chosen just to verify that the profile paths
// can be set to whatever they need to be for the given host.
public static readonly ProfilePathInfo TestProfilePaths =
new ProfilePathInfo(
Path.GetFullPath(
TestUtilities.NormalizePath("../../../../PowerShellEditorServices.Test.Shared/Profile/Test.PowerShellEditorServices_profile.ps1")),
Path.GetFullPath(
TestUtilities.NormalizePath("../../../../PowerShellEditorServices.Test.Shared/Profile/ProfileTest.ps1")),
Path.GetFullPath(
TestUtilities.NormalizePath("../../../../PowerShellEditorServices.Test.Shared/Test.PowerShellEditorServices_profile.ps1")),
Path.GetFullPath(
TestUtilities.NormalizePath("../../../../PowerShellEditorServices.Test.Shared/ProfileTest.ps1")));
public static System.Management.Automation.Runspaces.Runspace initialRunspace;
public static PowerShellContextService Create(ILogger logger)
{
PowerShellContextService powerShellContext = new PowerShellContextService(logger, null, isPSReadLineEnabled: false);
HostStartupInfo testHostDetails = new HostStartupInfo(
"PowerShell Editor Services Test Host",
"Test.PowerShellEditorServices",
new Version("1.0.0"),
null,
TestProfilePaths,
new List<string>(),
new List<string>(),
PSLanguageMode.FullLanguage,
null,
0,
consoleReplEnabled: false,
usesLegacyReadLine: false);
initialRunspace = PowerShellContextService.CreateRunspace(
testHostDetails,
powerShellContext,
new TestPSHostUserInterface(powerShellContext, logger),
logger);
powerShellContext.Initialize(
TestProfilePaths,
initialRunspace,
ownsInitialRunspace: true,
consoleHost: null);
return powerShellContext;
}
}
internal class TestPSHostUserInterface : EditorServicesPSHostUserInterface
{
public TestPSHostUserInterface(
PowerShellContextService powerShellContext,
ILogger logger)
: base(
powerShellContext,
new SimplePSHostRawUserInterface(logger),
NullLogger.Instance)
{
}
public override void WriteOutput(string outputString, bool includeNewLine, OutputType outputType, ConsoleColor foregroundColor, ConsoleColor backgroundColor)
{
}
protected override ChoicePromptHandler OnCreateChoicePromptHandler()
{
throw new NotImplementedException();
}
protected override InputPromptHandler OnCreateInputPromptHandler()
{
throw new NotImplementedException();
}
protected override Task<string> ReadCommandLineAsync(CancellationToken cancellationToken)
{
return Task.FromResult("USER COMMAND");
}
protected override void UpdateProgress(long sourceId, ProgressDetails progressDetails)
{
}
}
}