Skip to content

Fix issue where MS Dynamics CRM #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#

if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") {
Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.VSCode.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.VSCode.dll"
}
else {
Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.VSCode.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.VSCode.dll"
}

if ($psEditor -is [Microsoft.PowerShell.EditorServices.Extensions.EditorObject]) {
Expand All @@ -17,6 +17,6 @@ else {
Write-Verbose '$psEditor object not found in the session, components will not be registered.'
}

Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse | ForEach-Object {
Microsoft.PowerShell.Management\Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 -Recurse | ForEach-Object {
. $PSItem.FullName
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

Import-LocalizedData -BindingVariable Strings -FileName Strings -ErrorAction Ignore
Microsoft.PowerShell.Utility\Import-LocalizedData -BindingVariable Strings -FileName Strings -ErrorAction Ignore

Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 | ForEach-Object {
Microsoft.PowerShell.Management\Get-ChildItem -Path $PSScriptRoot\Public\*.ps1 | ForEach-Object {
. $PSItem.FullName
}

Export-ModuleMember -Function *-*
Microsoft.PowerShell.Core\Export-ModuleMember -Function *-*
49 changes: 29 additions & 20 deletions module/PowerShellEditorServices/PowerShellEditorServices.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
#

if (!$PSVersionTable.PSEdition -or $PSVersionTable.PSEdition -eq "Desktop") {
Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.dll"
Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.Host.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Desktop/Microsoft.PowerShell.EditorServices.Host.dll"
}
else {
Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.dll"
Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Protocol.dll"
Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Host.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Protocol.dll"
Microsoft.PowerShell.Utility\Add-Type -Path "$PSScriptRoot/bin/Core/Microsoft.PowerShell.EditorServices.Host.dll"
}

function Start-EditorServicesHost {
Expand Down Expand Up @@ -75,10 +75,14 @@ function Start-EditorServicesHost {
)

$editorServicesHost = $null
$hostDetails = New-Object Microsoft.PowerShell.EditorServices.Session.HostDetails @($HostName, $HostProfileId, (New-Object System.Version @($HostVersion)))
$hostDetails =
Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Session.HostDetails @(
$HostName,
$HostProfileId,
(Microsoft.PowerShell.Utility\New-Object System.Version @($HostVersion)))

$editorServicesHost =
New-Object Microsoft.PowerShell.EditorServices.Host.EditorServicesHost @(
Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Host.EditorServicesHost @(
$hostDetails,
$BundledModulesPath,
$EnableConsoleRepl.IsPresent,
Expand All @@ -87,15 +91,19 @@ function Start-EditorServicesHost {
$FeatureFlags)

# Build the profile paths using the root paths of the current $profile variable
$profilePaths = New-Object Microsoft.PowerShell.EditorServices.Session.ProfilePaths @(
$hostDetails.ProfileId,
[System.IO.Path]::GetDirectoryName($profile.AllUsersAllHosts),
[System.IO.Path]::GetDirectoryName($profile.CurrentUserAllHosts));
$profilePaths =
Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Session.ProfilePaths @(
$hostDetails.ProfileId,
[System.IO.Path]::GetDirectoryName($profile.AllUsersAllHosts),
[System.IO.Path]::GetDirectoryName($profile.CurrentUserAllHosts))

$editorServicesHost.StartLogging($LogPath, $LogLevel);

$languageServiceConfig = New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig
$debugServiceConfig = New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig
$languageServiceConfig =
Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig

$debugServiceConfig =
Microsoft.PowerShell.Utility\New-Object Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportConfig

if ($Stdio.IsPresent) {
$languageServiceConfig.TransportType = [Microsoft.PowerShell.EditorServices.Host.EditorServiceTransportType]::Stdio
Expand Down Expand Up @@ -143,23 +151,24 @@ function Compress-LogDir {

begin {
function LegacyZipFolder($Path, $ZipPath) {
if (!(Test-Path($ZipPath))) {
Set-Content -LiteralPath $ZipPath -Value ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
(Get-Item $ZipPath).IsReadOnly = $false
if (!(Microsoft.PowerShell.Management\Test-Path($ZipPath))) {
$zipMagicHeader = "PK" + [char]5 + [char]6 + ("$([char]0)" * 18)
Microsoft.PowerShell.Management\Set-Content -LiteralPath $ZipPath -Value $zipMagicHeader
(Microsoft.PowerShell.Management\Get-Item $ZipPath).IsReadOnly = $false
}

$shellApplication = New-Object -ComObject Shell.Application
$shellApplication = Microsoft.PowerShell.Utility\New-Object -ComObject Shell.Application
$zipPackage = $shellApplication.NameSpace($ZipPath)

foreach ($file in (Get-ChildItem -LiteralPath $Path)) {
foreach ($file in (Microsoft.PowerShell.Management\Get-ChildItem -LiteralPath $Path)) {
$zipPackage.CopyHere($file.FullName)
Start-Sleep -MilliSeconds 500
}
}
}

end {
$zipPath = ((Convert-Path $Path) -replace '(\\|/)$','') + ".zip"
$zipPath = ((Microsoft.PowerShell.Management\Convert-Path $Path) -replace '(\\|/)$','') + ".zip"

if (Get-Command Microsoft.PowerShell.Archive\Compress-Archive) {
if ($PSCmdlet.ShouldProcess($zipPath, "Create ZIP")) {
Expand Down Expand Up @@ -196,7 +205,7 @@ function Get-PowerShellEditorServicesVersion {
$versionInfo += "macOS $(lsb_release -d -s)$nl"
}
else {
$osInfo = Get-CimInstance Win32_OperatingSystem
$osInfo = CimCmdlets\Get-CimInstance Win32_OperatingSystem
$versionInfo += "Windows $($osInfo.OSArchitecture) $($osInfo.Version)$nl"
}

Expand Down
18 changes: 9 additions & 9 deletions module/PowerShellEditorServices/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ function ExitWithError($errorString) {
}

function WriteSessionFile($sessionInfo) {
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
$sessionInfoJson = Microsoft.PowerShell.Utility\ConvertTo-Json -InputObject $sessionInfo -Compress
Log "Writing session file with contents:"
Log $sessionInfoJson
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
$sessionInfoJson | Microsoft.PowerShell.Management\Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
}

# Are we running in PowerShell 2 or earlier?
if ($PSVersionTable.PSVersion.Major -le 2) {
# No ConvertTo-Json on PSv2 and below, so write out the JSON manually
"{`"status`": `"failed`", `"reason`": `"unsupported`", `"powerShellVersion`": `"$($PSVersionTable.PSVersion.ToString())`"}" |
Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
Microsoft.PowerShell.Management\Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop

ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled."
}
Expand All @@ -133,9 +133,9 @@ $isPS5orLater = $PSVersionTable.PSVersion.Major -ge 5

# If PSReadline is present in the session, remove it so that runspace
# management is easier
if ((Get-Module PSReadline).Count -gt 0) {
if ((Microsoft.PowerShell.Core\Get-Module PSReadline).Count -gt 0) {
LogSection "Removing PSReadLine module"
Remove-Module PSReadline -ErrorAction SilentlyContinue
Microsoft.PowerShell.Core\Remove-Module PSReadline -ErrorAction SilentlyContinue
}

# This variable will be assigned later to contain information about
Expand All @@ -146,7 +146,7 @@ $resultDetails = $null;
function Test-ModuleAvailable($ModuleName, $ModuleVersion) {
Log "Testing module availability $ModuleName $ModuleVersion"

$modules = Get-Module -ListAvailable $moduleName
$modules = Microsoft.PowerShell.Core\Get-Module -ListAvailable $moduleName
if ($modules -ne $null) {
if ($ModuleVersion -ne $null) {
foreach ($module in $modules) {
Expand Down Expand Up @@ -182,7 +182,7 @@ function Test-PortAvailability {
$ipAddress = [System.Net.IPAddress]::Loopback
Log "Testing availability of port ${PortNumber} at address ${ipAddress} / $($ipAddress.AddressFamily)"

$tcpListener = New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
$tcpListener = Microsoft.PowerShell.Utility\New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
$tcpListener.Start()
$tcpListener.Stop()
}
Expand All @@ -202,7 +202,7 @@ function Test-PortAvailability {
}

$portsInUse = @{}
$rand = New-Object System.Random
$rand = Microsoft.PowerShell.Utility\New-Object System.Random
function Get-AvailablePort() {
$triesRemaining = 10;

Expand Down Expand Up @@ -247,7 +247,7 @@ try {
LogSection "Start up PowerShellEditorServices"
Log "Importing PowerShellEditorServices"

Import-Module PowerShellEditorServices -ErrorAction Stop
Microsoft.PowerShell.Core\Import-Module PowerShellEditorServices -ErrorAction Stop

# Locate available port numbers for services
# There could be only one service on Stdio channel
Expand Down
33 changes: 17 additions & 16 deletions src/PowerShellEditorServices/Session/RemoteFileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function Open-EditorFile {

foreach ($fileName in $Paths)
{
dir $fileName | where { ! $_.PSIsContainer } | foreach {
Microsoft.PowerShell.Management\Get-ChildItem $fileName | Where-Object { ! $_.PSIsContainer } | Foreach-Object {
$filePathName = $_.FullName

# Get file contents
Expand All @@ -89,10 +89,10 @@ function Open-EditorFile {
$params['Encoding']='Byte'
}

$contentBytes = Get-Content @params
$contentBytes = Microsoft.PowerShell.Management\Get-Content @params

# Notify client for file open.
New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($filePathName, $contentBytes, $preview) > $null
Microsoft.PowerShell.Utility\New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($filePathName, $contentBytes, $preview) > $null
}
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ function New-EditorFile {
if ($Path) {
foreach ($fileName in $Path)
{
if (-not (Test-Path $fileName) -or $Force) {
if (-not (Microsoft.PowerShell.Management\Test-Path $fileName) -or $Force) {
$valueList > $fileName

# Get file contents
Expand All @@ -162,7 +162,7 @@ function New-EditorFile {
$params['Encoding']='Byte'
}

$contentBytes = Get-Content @params
$contentBytes = Microsoft.PowerShell.Management\Get-Content @params

if ($Path.Count -gt 1) {
$preview = $false
Expand All @@ -171,25 +171,25 @@ function New-EditorFile {
}

# Notify client for file open.
New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($fileName, $contentBytes, $preview) > $null
Microsoft.PowerShell.Utility\New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($fileName, $contentBytes, $preview) > $null
} else {
$PSCmdlet.WriteError( (
New-Object -TypeName System.Management.Automation.ErrorRecord -ArgumentList @(
Microsoft.PowerShell.Utility\New-Object -TypeName System.Management.Automation.ErrorRecord -ArgumentList @(
[System.Exception]'File already exists.'
$Null
[System.Management.Automation.ErrorCategory]::ResourceExists
$fileName ) ) )
}
}
} else {
$bytes = [System.Text.Encoding]::UTF8.GetBytes(($valueList | Out-String))
New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($null, $bytes) > $null
$bytes = [System.Text.Encoding]::UTF8.GetBytes(($valueList | Microsoft.PowerShell.Utility\Out-String))
Microsoft.PowerShell.Utility\New-Event -SourceIdentifier PSESRemoteSessionOpenFile -EventArguments @($null, $bytes) > $null
}
}
}

Set-Alias psedit Open-EditorFile -Scope Global
Export-ModuleMember -Function Open-EditorFile, New-EditorFile
Microsoft.PowerShell.Utility\Set-Alias psedit Open-EditorFile -Scope Global
Microsoft.PowerShell.Core\Export-ModuleMember -Function Open-EditorFile, New-EditorFile
";

// This script is templated so that the '-Forward' parameter can be added
Expand All @@ -199,14 +199,15 @@ function New-EditorFile {
[string] $PSEditModule
)

Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward -SupportEvent
New-Module -ScriptBlock ([Scriptblock]::Create($PSEditModule)) -Name PSEdit | Import-Module -Global
Microsoft.PowerShell.Utility\Register-EngineEvent -SourceIdentifier PSESRemoteSessionOpenFile -Forward -SupportEvent
Microsoft.PowerShell.Core\New-Module -ScriptBlock ([Scriptblock]::Create($PSEditModule)) -Name PSEdit |
Microsoft.PowerShell.Core\Import-Module -Global
";

private const string RemovePSEditFunctionScript = @"
Get-Module PSEdit | Remove-Module
Microsoft.PowerShell.Core\Get-Module PSEdit | Microsoft.PowerShell.Core\Remove-Module

Unregister-Event -SourceIdentifier PSESRemoteSessionOpenFile -Force -ErrorAction Ignore
Microsoft.PowerShell.Utility\Unregister-Event -SourceIdentifier PSESRemoteSessionOpenFile -Force -ErrorAction Ignore
";

private const string SetRemoteContentsScript = @"
Expand All @@ -226,7 +227,7 @@ function New-EditorFile {
$params['Encoding']='Byte'
}

Set-Content @params 2>&1
Microsoft.PowerShell.Management\Set-Content @params 2>&1
";

#endregion
Expand Down