// // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. // // using Microsoft.PowerShell.EditorServices.Console; // using Microsoft.PowerShell.EditorServices.Extensions; using Microsoft.PowerShell.EditorServices.Session; // using Microsoft.PowerShell.EditorServices.Utility; // using System.IO; namespace Microsoft.PowerShell.EditorServices { /// /// Manages a single session for all editor services. This /// includes managing all open script files for the session. /// public class EditorSession { public void StartSession(HostDetails hostDetails, ProfilePaths profilePaths) { } #if false #region Properties /// /// Gets the Workspace instance for this session. /// public Workspace Workspace { get; private set; } /// /// Gets the PowerShellContext instance for this session. /// public PowerShellContext PowerShellContext { get; private set; } /// /// Gets the LanguageService instance for this session. /// public LanguageService LanguageService { get; private set; } /// /// Gets the AnalysisService instance for this session. /// public AnalysisService AnalysisService { get; private set; } /// /// Gets the DebugService instance for this session. /// public DebugService DebugService { get; private set; } /// /// Gets the ConsoleService instance for this session. /// public ConsoleService ConsoleService { get; private set; } /// /// Gets the ExtensionService instance for this session. /// public ExtensionService ExtensionService { get; private set; } #endregion #region Public Methods /// /// Starts the session using the provided IConsoleHost implementation /// for the ConsoleService. /// /// /// Provides details about the host application. /// /// /// An object containing the profile paths for the session. /// public void StartSession(HostDetails hostDetails, ProfilePaths profilePaths) { // Initialize all services this.PowerShellContext = new PowerShellContext(hostDetails, profilePaths); this.LanguageService = new LanguageService(this.PowerShellContext); this.DebugService = new DebugService(this.PowerShellContext); this.ConsoleService = new ConsoleService(this.PowerShellContext); this.ExtensionService = new ExtensionService(this.PowerShellContext); this.InstantiateAnalysisService(); // Create a workspace to contain open files this.Workspace = new Workspace(this.PowerShellContext.PowerShellVersion); } /// /// Restarts the AnalysisService so it can be configured with a new settings file. /// /// Path to the settings file. public void RestartAnalysisService(string settingsPath) { this.AnalysisService?.Dispose(); InstantiateAnalysisService(settingsPath); } internal void InstantiateAnalysisService(string settingsPath = null) { // Only enable the AnalysisService if the machine has PowerShell // v5 installed. Script Analyzer works on earlier PowerShell // versions but our hard dependency on their binaries complicates // the deployment and assembly loading since we would have to // conditionally load the binaries for v3/v4 support. This problem // will be solved in the future by using Script Analyzer as a // module rather than an assembly dependency. if (this.PowerShellContext.PowerShellVersion.Major >= 5) { // AnalysisService will throw FileNotFoundException if // Script Analyzer binaries are not included. try { this.AnalysisService = new AnalysisService(this.PowerShellContext.ConsoleHost, settingsPath); } catch (FileNotFoundException) { Logger.Write( LogLevel.Warning, "Script Analyzer binaries not found, AnalysisService will be disabled."); } } else { Logger.Write( LogLevel.Normal, "Script Analyzer cannot be loaded due to unsupported PowerShell version " + this.PowerShellContext.PowerShellVersion.ToString()); } } #endregion #region IDisposable Implementation /// /// Disposes of any Runspaces that were created for the /// services used in this session. /// public void Dispose() { if (this.AnalysisService != null) { this.AnalysisService.Dispose(); this.AnalysisService = null; } if (this.PowerShellContext != null) { this.PowerShellContext.Dispose(); this.PowerShellContext = null; } } #endregion #endif } }