Пример #1
0
        private EditorServicesConfig CreateConfigObject()
        {
            _logger.Log(PsesLogLevel.Diagnostic, "Creating host configuration");

            string bundledModulesPath = BundledModulesPath;

            if (!Path.IsPathRooted(bundledModulesPath))
            {
                // For compatibility, the bundled modules path is relative to the PSES bin directory
                // Ideally it should be one level up, the PSES module root
                bundledModulesPath = Path.GetFullPath(
                    Path.Combine(
                        Assembly.GetExecutingAssembly().Location,
                        "..",
                        bundledModulesPath));
            }

            var profile = (PSObject)GetVariableValue("profile");

            var hostInfo             = new HostInfo(HostName, HostProfileId, HostVersion);
            var editorServicesConfig = new EditorServicesConfig(hostInfo, Host, SessionDetailsPath, bundledModulesPath, LogPath)
            {
                FeatureFlags             = FeatureFlags,
                LogLevel                 = LogLevel,
                ConsoleRepl              = GetReplKind(),
                AdditionalModules        = AdditionalModules,
                LanguageServiceTransport = GetLanguageServiceTransport(),
                DebugServiceTransport    = GetDebugServiceTransport(),
                ProfilePaths             = new ProfilePathConfig
                {
                    AllUsersAllHosts       = GetProfilePathFromProfileObject(profile, ProfileUserKind.AllUsers, ProfileHostKind.AllHosts),
                    AllUsersCurrentHost    = GetProfilePathFromProfileObject(profile, ProfileUserKind.AllUsers, ProfileHostKind.CurrentHost),
                    CurrentUserAllHosts    = GetProfilePathFromProfileObject(profile, ProfileUserKind.CurrentUser, ProfileHostKind.AllHosts),
                    CurrentUserCurrentHost = GetProfilePathFromProfileObject(profile, ProfileUserKind.CurrentUser, ProfileHostKind.CurrentHost),
                },
            };

            if (StartupBanner != null)
            {
                editorServicesConfig.StartupBanner = StartupBanner;
            }

            return(editorServicesConfig);
        }
        protected override void EndProcessing()
        {
            _logger.Log(PsesLogLevel.Diagnostic, "Beginning EndProcessing block");

            try
            {
                // First try to remove PSReadLine to decomplicate startup
                // If PSReadLine is enabled, it will be re-imported later
                RemovePSReadLineForStartup();

                // Create the configuration from parameters
                EditorServicesConfig editorServicesConfig = CreateConfigObject();

                var sessionFileWriter = new SessionFileWriter(_logger, SessionDetailsPath);
                _logger.Log(PsesLogLevel.Diagnostic, "Session file writer created");

                using (var psesLoader = EditorServicesLoader.Create(_logger, editorServicesConfig, sessionFileWriter, _loggerUnsubscribers))
                {
                    _logger.Log(PsesLogLevel.Verbose, "Loading EditorServices");
                    psesLoader.LoadAndRunEditorServicesAsync().Wait();
                }
            }
            catch (Exception e)
            {
                _logger.LogException("Exception encountered starting EditorServices", e);

                // Give the user a chance to read the message if they have a console
                if (!Stdio)
                {
                    Host.UI.WriteLine("\n== Press any key to close terminal ==");
                    Console.ReadKey();
                }

                ThrowTerminatingError(new ErrorRecord(e, "PowerShellEditorServicesError", ErrorCategory.NotSpecified, this));
            }
            finally
            {
                foreach (IDisposable disposableResource in _disposableResources)
                {
                    disposableResource.Dispose();
                }
            }
        }