Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
EngineIntrinsics.cs114 linesDownload Raw Back to engine
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Management.Automation.Host;5 6using Dbg = System.Management.Automation;7 8namespace System.Management.Automation9{10    /// <summary>11    /// Exposes the Engine APIs for a particular instance of the engine.12    /// </summary>13    public class EngineIntrinsics14    {15        #region Constructors16 17        /// <summary>18        /// Hide the default constructor since we always require an instance of ExecutionContext.19        /// </summary>20        private EngineIntrinsics()21        {22            Dbg.Diagnostics.Assert(23                false,24                "This constructor should never be called. Only the constructor that takes an instance of ExecutionContext should be called.");25        }26 27        /// <summary>28        /// The internal constructor for this object. It should be the only one that gets called.29        /// </summary>30        /// <param name="context">31        /// An instance of ExecutionContext that the APIs should work against.32        /// </param>33        /// <exception cref="ArgumentNullException">34        /// If <paramref name="context"/> is null.35        /// </exception>36        internal EngineIntrinsics(ExecutionContext context)37        {38            ArgumentNullException.ThrowIfNull(context);39 40            _context = context;41            _host = context.EngineHostInterface;42        }43 44        #endregion Constructors45 46        #region Public methods47 48        /// <summary>49        /// Gets engine APIs to access the host.50        /// </summary>51        public PSHost Host52        {53            get54            {55                Dbg.Diagnostics.Assert(56                    _host != null,57                    "The only constructor for this class should always set the host field");58 59                return _host;60            }61        }62 63        /// <summary>64        /// Gets engine APIs to access the event manager.65        /// </summary>66        public PSEventManager Events67        {68            get69            {70                return _context.Events;71            }72        }73 74        /// <summary>75        /// Gets the engine APIs to access providers.76        /// </summary>77        public ProviderIntrinsics InvokeProvider78        {79            get80            {81                return _context.EngineSessionState.InvokeProvider;82            }83        }84 85        /// <summary>86        /// Gets the engine APIs to access session state.87        /// </summary>88        public SessionState SessionState89        {90            get91            {92                return _context.EngineSessionState.PublicSessionState;93            }94        }95 96        /// <summary>97        /// Gets the engine APIs to invoke a command.98        /// </summary>99        public CommandInvocationIntrinsics InvokeCommand100        {101            get { return _invokeCommand ??= new CommandInvocationIntrinsics(_context); }102        }103 104        #endregion Public methods105 106        #region private data107 108        private readonly ExecutionContext _context;109        private readonly PSHost _host;110        private CommandInvocationIntrinsics _invokeCommand;111        #endregion private data112    }113}114