当前位置: 首页>>代码示例>>C#>>正文


C# Host.PSHost类代码示例

本文整理汇总了C#中System.Management.Automation.Host.PSHost的典型用法代码示例。如果您正苦于以下问题:C# PSHost类的具体用法?C# PSHost怎么用?C# PSHost使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PSHost类属于System.Management.Automation.Host命名空间,在下文中一共展示了PSHost类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InstantiateSPOnlineConnection

        internal static SPOnlineConnection InstantiateSPOnlineConnection(Uri url, string realm, string clientId, string clientSecret, PSHost host, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false)
        {
            Core.AuthenticationManager authManager = new Core.AuthenticationManager();
            if (realm == null)
            {
                realm = GetRealmFromTargetUrl(url);
            }

            var context = authManager.GetAppOnlyAuthenticatedContext(url.ToString(), realm, clientId, clientSecret);
            context.ApplicationName = Properties.Resources.ApplicationName;
            context.RequestTimeout = requestTimeout;

            var connectionType = ConnectionType.OnPrem;
            if (url.Host.ToUpperInvariant().EndsWith("SHAREPOINT.COM"))
            {
                connectionType = ConnectionType.O365;
            }
            if (skipAdminCheck == false)
            {
                if (IsTenantAdminSite(context))
                {
                    connectionType = ConnectionType.TenantAdmin;
                }
            }
            return new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString());
        }
开发者ID:ivanvagunin,项目名称:PnP,代码行数:26,代码来源:SPOnlineConnectionHelper.cs

示例2: RemoteRunspacePoolInternal

        /// <summary>
        /// Constructor which creates a RunspacePool using the
        /// supplied <paramref name="connectionInfo"/>, <paramref name="minRunspaces"/> 
        /// and <paramref name="maxRunspaces"/>
        /// </summary>
        /// <param name="maxRunspaces">
        /// The maximum number of Runspaces that can exist in this pool. 
        /// Should be greater than or equal to 1.
        /// </param>
        /// <param name="minRunspaces">
        /// The minimum number of Runspaces that can exist in this pool.
        /// Should be greater than or equal to 1.
        /// </param>
        /// <param name="typeTable">
        /// The TypeTable to use while deserializing/serializing remote objects.
        /// TypeTable has the following information used by serializer:
        ///   1. SerializationMethod
        ///   2. SerializationDepth
        ///   3. SpecificSerializationProperties
        /// TypeTable has the following information used by deserializer:
        ///   1. TargetTypeForDeserialization
        ///   2. TypeConverter
        /// </param>
        /// <param name="host">Host associated with this runspacepool</param>
        /// <param name="applicationArguments">
        /// Application arguments the server can see in <see cref="System.Management.Automation.Remoting.PSSenderInfo.ApplicationArguments"/>
        /// </param>
        /// <param name="connectionInfo">The RunspaceConnectionInfo object
        /// which identifies this runspace pools connection to the server
        /// </param>
        /// <param name="name">Session name.</param>
        /// <exception cref="ArgumentException">
        /// Maximum runspaces is less than 1.
        /// Minimum runspaces is less than 1.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// ConnectionInfo specified is null
        /// </exception>
        internal RemoteRunspacePoolInternal(int minRunspaces,
            int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo, string name = null)
            : base(minRunspaces, maxRunspaces)
        {
            if (connectionInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("WSManConnectionInfo");
            }

            PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolConstructor,
                    PSOpcode.Constructor, PSTask.CreateRunspace,
                    PSKeyword.UseAlwaysOperational,
                    instanceId.ToString(),
                    minPoolSz.ToString(CultureInfo.InvariantCulture),
                    maxPoolSz.ToString(CultureInfo.InvariantCulture));

            _connectionInfo = connectionInfo.InternalCopy();

            this.host = host;
            ApplicationArguments = applicationArguments;
            AvailableForConnection = false;
            DispatchTable = new DispatchTable<object>();
            _runningPowerShells = new System.Collections.Concurrent.ConcurrentStack<PowerShell>();

            if (!string.IsNullOrEmpty(name))
            {
                this.Name = name;
            }

            CreateDSHandler(typeTable);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:69,代码来源:RemoteRunspacePoolInternal.cs

示例3: Dispatch

 internal static void Dispatch(BaseClientTransportManager transportManager, PSHost clientHost, PSDataCollectionStream<ErrorRecord> errorStream, ObjectStream methodExecutorStream, bool isMethodExecutorStreamEnabled, RemoteRunspacePoolInternal runspacePool, Guid clientPowerShellId, System.Management.Automation.Remoting.RemoteHostCall remoteHostCall)
 {
     ClientMethodExecutor executor = new ClientMethodExecutor(transportManager, clientHost, runspacePool.InstanceId, clientPowerShellId, remoteHostCall);
     if (clientPowerShellId == Guid.Empty)
     {
         executor.Execute(errorStream);
     }
     else
     {
         bool flag = false;
         if (clientHost != null)
         {
             PSObject privateData = clientHost.PrivateData;
             if (privateData != null)
             {
                 PSNoteProperty property = privateData.Properties["AllowSetShouldExitFromRemote"] as PSNoteProperty;
                 flag = ((property != null) && (property.Value is bool)) ? ((bool) property.Value) : false;
             }
         }
         if ((remoteHostCall.IsSetShouldExit && isMethodExecutorStreamEnabled) && !flag)
         {
             runspacePool.Close();
         }
         else if (isMethodExecutorStreamEnabled)
         {
             methodExecutorStream.Write(executor);
         }
         else
         {
             executor.Execute(errorStream);
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:33,代码来源:ClientMethodExecutor.cs

示例4: RemoteRunspace

        internal RemoteRunspace(TypeTable typeTable, RunspaceConnectionInfo connectionInfo, PSHost host, PSPrimitiveDictionary applicationArguments, string name = null, int id = -1)
        {
            this._runningPipelines = new ArrayList();
            this._syncRoot = new object();
            this._runspaceStateInfo = new System.Management.Automation.Runspaces.RunspaceStateInfo(RunspaceState.BeforeOpen);
            this._version = PSVersionInfo.PSVersion;
            this._runspaceEventQueue = new Queue<RunspaceEventQueueItem>();
            this.id = -1;
            PSEtwLog.SetActivityIdForCurrentThread(base.InstanceId);
			this._applicationArguments = applicationArguments;
            PSEtwLog.LogOperationalVerbose(PSEventId.RunspaceConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, new object[] { base.InstanceId.ToString() });
            if (connectionInfo is WSManConnectionInfo)
            {
                this._connectionInfo = ((WSManConnectionInfo) connectionInfo).Copy();
                this._originalConnectionInfo = ((WSManConnectionInfo) connectionInfo).Copy();
            }
            else if (connectionInfo is NewProcessConnectionInfo)
            {
                this._connectionInfo = ((NewProcessConnectionInfo) connectionInfo).Copy();
                this._originalConnectionInfo = ((NewProcessConnectionInfo) connectionInfo).Copy();
            }
            this._runspacePool = new System.Management.Automation.Runspaces.RunspacePool(1, 1, typeTable, host, applicationArguments, connectionInfo, name);
            this.Id = id;
            this.SetEventHandlers();
        }
开发者ID:nickchal,项目名称:pash,代码行数:25,代码来源:RemoteRunspace.cs

示例5: RemoteRunspacePoolInternal

 internal RemoteRunspacePoolInternal(int minRunspaces, int maxRunspaces, TypeTable typeTable, PSHost host, PSPrimitiveDictionary applicationArguments, RunspaceConnectionInfo connectionInfo, string name = null) : base(minRunspaces, maxRunspaces)
 {
     this.applicationPrivateDataReceived = new ManualResetEvent(false);
     this.friendlyName = string.Empty;
     if (connectionInfo == null)
     {
         throw PSTraceSource.NewArgumentNullException("WSManConnectionInfo");
     }
     PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolConstructor, PSOpcode.Constructor, PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational, new object[] { this.instanceId.ToString(), this.minPoolSz.ToString(CultureInfo.InvariantCulture), this.maxPoolSz.ToString(CultureInfo.InvariantCulture) });
     if (connectionInfo is WSManConnectionInfo)
     {
         this.connectionInfo = ((WSManConnectionInfo) connectionInfo).Copy();
     }
     else if (connectionInfo is NewProcessConnectionInfo)
     {
         this.connectionInfo = ((NewProcessConnectionInfo) connectionInfo).Copy();
     }
     base.host = host;
     this.applicationArguments = applicationArguments;
     this.availableForConnection = false;
     this.dispatchTable = new DispatchTable<object>();
     if (!string.IsNullOrEmpty(name))
     {
         this.Name = name;
     }
     this.CreateDSHandler(typeTable);
 }
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:RemoteRunspacePoolInternal.cs

示例6: TypeInfoDataBaseManager

 internal TypeInfoDataBaseManager(IEnumerable<string> formatFiles, bool isShared, AuthorizationManager authorizationManager, PSHost host)
 {
     this.databaseLock = new object();
     this.updateDatabaseLock = new object();
     this.formatFileList = new List<string>();
     Collection<PSSnapInTypeAndFormatErrors> files = new Collection<PSSnapInTypeAndFormatErrors>();
     Collection<string> loadErrors = new Collection<string>();
     foreach (string str in formatFiles)
     {
         if (string.IsNullOrEmpty(str) || !Path.IsPathRooted(str))
         {
             throw PSTraceSource.NewArgumentException("formatFiles", "FormatAndOutXmlLoadingStrings", "FormatFileNotRooted", new object[] { str });
         }
         PSSnapInTypeAndFormatErrors item = new PSSnapInTypeAndFormatErrors(string.Empty, str) {
             Errors = loadErrors
         };
         files.Add(item);
         this.formatFileList.Add(str);
     }
     MshExpressionFactory expressionFactory = new MshExpressionFactory();
     List<XmlLoaderLoggerEntry> logEntries = null;
     this.LoadFromFile(files, expressionFactory, true, authorizationManager, host, false, out logEntries);
     this.isShared = isShared;
     if (loadErrors.Count > 0)
     {
         throw new FormatTableLoadException(loadErrors);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:28,代码来源:TypeInfoDataBaseManager.cs

示例7: Restore

        public void Restore(PSHost host = null)
        {
            // Delete environment variables that are in the current
            // environment but not in the one being restored.
            var currentVars = Environment.GetEnvironmentVariables();
            foreach (DictionaryEntry entry in currentVars)
            {
                if (!Variables.Contains(entry.Key))
                {
                    Environment.SetEnvironmentVariable((string)entry.Key, null);
                }
            }

            // Now set all the environment variables defined in this frame
            foreach (DictionaryEntry entry in Variables)
            {
                var name = (string)entry.Key;
                var value = (string)entry.Value;
                Environment.SetEnvironmentVariable(name, value);
            }

            if (host != null)
            {
                host.UI.RawUI.WindowTitle = WindowTitle;
                host.UI.RawUI.BackgroundColor = BackgroundColor;
                host.UI.RawUI.ForegroundColor = ForegroundColor;
            }
        }
开发者ID:jen20,项目名称:powershell-environment-vars,代码行数:28,代码来源:EnvironmentFrame.cs

示例8: AutomationEngine

        /// <summary>
        /// The principal constructor that most hosts will use when creating
        /// an instance of the automation engine. It allows you to pass in an
        /// instance of PSHost that provides the host-specific I/O routines, etc.
        /// </summary>
        internal AutomationEngine(PSHost hostInterface, RunspaceConfiguration runspaceConfiguration, InitialSessionState iss)
        {
#if !CORECLR// There is no control panel items in CSS
            // Update the env variable PathEXT to contain .CPL
            var pathext = Environment.GetEnvironmentVariable("PathEXT");
            pathext = pathext ?? string.Empty;
            bool cplExist = false;
            if (pathext != string.Empty)
            {
                string[] entries = pathext.Split(Utils.Separators.Semicolon);
                foreach (string entry in entries)
                {
                    string ext = entry.Trim();
                    if (ext.Equals(".CPL", StringComparison.OrdinalIgnoreCase))
                    {
                        cplExist = true;
                        break;
                    }
                }
            }
            if (!cplExist)
            {
                pathext = (pathext == string.Empty) ? ".CPL" :
                    pathext.EndsWith(";", StringComparison.OrdinalIgnoreCase)
                    ? (pathext + ".CPL") : (pathext + ";.CPL");
                Environment.SetEnvironmentVariable("PathEXT", pathext);
            }
#endif
            if (runspaceConfiguration != null)
            {
                Context = new ExecutionContext(this, hostInterface, runspaceConfiguration);
            }
            else
            {
                Context = new ExecutionContext(this, hostInterface, iss);
            }

            EngineParser = new Language.Parser();
            CommandDiscovery = new CommandDiscovery(Context);

            // Initialize providers before loading types so that any ScriptBlocks in the
            // types.ps1xml file can be parsed.

            // Bind the execution context with RunspaceConfiguration. 
            // This has the side effect of initializing cmdlet cache and providers from runspace configuration.
            if (runspaceConfiguration != null)
            {
                runspaceConfiguration.Bind(Context);
            }
            else
            {
                // Load the iss, resetting everything to it's defaults...
                iss.Bind(Context, /*updateOnly*/ false);
            }

            InitialSessionState.SetSessionStateDrive(Context, true);

            InitialSessionState.CreateQuestionVariable(Context);
        }
开发者ID:dfinke,项目名称:powershell,代码行数:64,代码来源:AutomationEngine.cs

示例9: FormatTable

 internal FormatTable(IEnumerable<string> formatFiles, AuthorizationManager authorizationManager, PSHost host)
 {
     if (formatFiles == null)
     {
         throw PSTraceSource.NewArgumentNullException("formatFiles");
     }
     this.formatDBMgr = new TypeInfoDataBaseManager(formatFiles, true, authorizationManager, host);
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:FormatTable.cs

示例10: ClientMethodExecutor

 private ClientMethodExecutor(BaseClientTransportManager transportManager, PSHost clientHost, Guid clientRunspacePoolId, Guid clientPowerShellId, System.Management.Automation.Remoting.RemoteHostCall remoteHostCall)
 {
     this._transportManager = transportManager;
     this._remoteHostCall = remoteHostCall;
     this._clientHost = clientHost;
     this._clientRunspacePoolId = clientRunspacePoolId;
     this._clientPowerShellId = clientPowerShellId;
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:ClientMethodExecutor.cs

示例11: LocalRunspace

 // TODO: make sure to implement a Singleton DefaultRunspace pattern
 //internal static LocalRunspace DefaultRunspace { get; private set; }
 public LocalRunspace(PSHost host, RunspaceConfiguration configuration)
 {
     DefaultRunspace = this;
     PSHost = host;
     _runspaceConfiguration = configuration;
     ExecutionContext = new ExecutionContext(host, configuration);
     ExecutionContext.CurrentRunspace = this;
 }
开发者ID:JamesTryand,项目名称:pash,代码行数:10,代码来源:LocalRunspace.cs

示例12: CreateRunspace

 public static Runspace CreateRunspace(PSHost host)
 {
     if (host == null)
     {
         throw PSTraceSource.NewArgumentNullException("host");
     }
     return CreateRunspace(host, RunspaceConfiguration.Create());
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:RunspaceFactory.cs

示例13: HostInfo

 internal HostInfo(PSHost host)
 {
     CheckHostChain(host, ref this._isHostNull, ref this._isHostUINull, ref this._isHostRawUINull);
     if (!this._isHostUINull && !this._isHostRawUINull)
     {
         this._hostDefaultData = System.Management.Automation.Remoting.HostDefaultData.Create(host.UI.RawUI);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:HostInfo.cs

示例14: ExecutionContext

 public ExecutionContext(PSHost host, RunspaceConfiguration config)
     : this()
 {
     RunspaceConfiguration = config;
     LocalHost = host;
     SessionStateGlobal = new SessionStateGlobal(this);
     SessionState = new SessionState(SessionStateGlobal);
 }
开发者ID:Pash-Project,项目名称:Pash,代码行数:8,代码来源:ExecutionContext.cs

示例15: ToPool

 internal RunspacePool ToPool(PSHost Host)
 {
     RunspacePool pool = RunspaceFactory.CreateRunspacePool(1, this.PoolSize, this.InitialSessionState, Host);
     //RunspacePool pool = RunspaceFactory.CreateRunspacePool(1, this.PoolSize);
     pool.ApartmentState = this.ApartmentState;
     pool.CleanupInterval = this.CleanupInterval;
     pool.ThreadOptions = this.ThreadOptions;
     return pool;
 }
开发者ID:GoodOlClint,项目名称:PSAsync,代码行数:9,代码来源:RunspaceSettings.cs


注:本文中的System.Management.Automation.Host.PSHost类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。