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


C# Automation.PSCmdlet类代码示例

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


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

示例1: UpdatableHelpSystemDrive

 internal UpdatableHelpSystemDrive(PSCmdlet cmdlet, string path, PSCredential credential)
 {
     for (int i = 0; i < 6; i++)
     {
         this._driveName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
         this._cmdlet = cmdlet;
         if (path.EndsWith(@"\", StringComparison.OrdinalIgnoreCase) || path.EndsWith("/", StringComparison.OrdinalIgnoreCase))
         {
             path = path.Remove(path.Length - 1);
         }
         PSDriveInfo atScope = cmdlet.SessionState.Drive.GetAtScope(this._driveName, "local");
         if (atScope != null)
         {
             if (atScope.Root.Equals(path))
             {
                 return;
             }
             if (i < 5)
             {
                 continue;
             }
             cmdlet.SessionState.Drive.Remove(this._driveName, true, "local");
         }
         atScope = new PSDriveInfo(this._driveName, cmdlet.SessionState.Internal.GetSingleProvider("FileSystem"), path, string.Empty, credential);
         cmdlet.SessionState.Drive.New(atScope, "local");
         return;
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:28,代码来源:UpdatableHelpSystemDrive.cs

示例2: AliasDefinitionsTypeValidationCallback

 private static bool AliasDefinitionsTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
 {
     Hashtable[] hashtableArray = DISCPowerShellConfiguration.TryGetHashtableArray(obj);
     if (hashtableArray == null)
     {
         cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeHashtableArray, key, path));
         return false;
     }
     foreach (Hashtable hashtable in hashtableArray)
     {
         if (!hashtable.ContainsKey(AliasNameToken))
         {
             cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustContainKey, new object[] { key, AliasNameToken, path }));
             return false;
         }
         if (!hashtable.ContainsKey(AliasValueToken))
         {
             cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustContainKey, new object[] { key, AliasValueToken, path }));
             return false;
         }
         foreach (string str in hashtable.Keys)
         {
             if ((!string.Equals(str, AliasNameToken, StringComparison.OrdinalIgnoreCase) && !string.Equals(str, AliasValueToken, StringComparison.OrdinalIgnoreCase)) && (!string.Equals(str, AliasDescriptionToken, StringComparison.OrdinalIgnoreCase) && !string.Equals(str, AliasOptionsToken, StringComparison.OrdinalIgnoreCase)))
             {
                 cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeContainsInvalidKey, new object[] { str, key, path }));
                 return false;
             }
         }
     }
     return true;
 }
开发者ID:nickchal,项目名称:pash,代码行数:31,代码来源:ConfigFileContants.cs

示例3: SetDelimiter

        internal static char SetDelimiter(PSCmdlet Cmdlet, string ParameterSetName, char Delimiter, bool UseCulture)
        {
            switch (ParameterSetName)
            {
                case "Delimiter":
                    if (Delimiter == '\0')
                    {
                        Delimiter = ',';
                    }
                    return Delimiter;

                case "UseCulture":
                    if (UseCulture)
                    {
                        string str = Registry.CurrentUser.OpenSubKey(@"Control Panel\International").GetValue("sList").ToString();
                        if (string.IsNullOrEmpty(str))
                        {
                            Delimiter = ',';
                            return Delimiter;
                        }
                        Delimiter = str[0];
                    }
                    return Delimiter;
            }
            Delimiter = ',';
            return Delimiter;
        }
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:ImportExportCSVHelper.cs

示例4: WriteToPs1Xml

        /// <summary>
        /// Writes a collection of format view definitions to XML file
        /// </summary>
        /// <param name="typeDefinitions">collection of PSTypeDefinition</param>
        /// <param name="filepath">path to XML file</param>
        /// <param name="cmdlet">cmdlet from which this si used</param>
        /// <param name="force">true - to force write the file</param>
        /// <param name="writeScriptBlock">true - to export scriptblocks</param>
        /// <param name="noclobber">true - do not overwrite the file</param>
        /// <param name="isLiteralPath">true - bypass wildcard expansion on the file name</param>
        internal static void WriteToPs1Xml(PSCmdlet cmdlet, List<ExtendedTypeDefinition> typeDefinitions,
            string filepath, bool force, bool noclobber, bool writeScriptBlock, bool isLiteralPath)
        {
            StreamWriter streamWriter;
            FileStream fileStream;
            FileInfo fileInfo;
            PathUtils.MasterStreamOpen(cmdlet, filepath, "ascii", true, false, force, noclobber,
                out fileStream, out streamWriter, out fileInfo, isLiteralPath);

            try
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(streamWriter))
                {
                    var writer = new FormatXmlWriter
                    {
                        _writer = xmlWriter,
                        _exportScriptBlock = writeScriptBlock
                    };
                    writer.WriteToXml(typeDefinitions);
                }
            }
            finally
            {
                streamWriter.Dispose();
                fileStream.Dispose();
            }
        }
开发者ID:dfinke,项目名称:powershell,代码行数:37,代码来源:FormatXMLWriter.cs

示例5: CheckForSevereException

        // Keep in sync:
        // S.M.A.CommandProcessorBase.CheckForSevereException
        // S.M.A.Internal.ConsoleHost.CheckForSevereException
        // S.M.A.Commands.CommandsCommon.CheckForSevereException
        // S.M.A.Commands.UtilityCommon.CheckForSevereException
        /// <summary>
        /// Checks whether the exception is a severe exception which should
        /// cause immediate process failure.
        /// </summary>
        /// <param name="cmdlet">can be null</param>
        /// <param name="e"></param>
        /// <remarks>
        /// CB says 02/23/2005: I personally would err on the side
        /// of treating OOM like an application exception, rather than
        /// a critical system failure.I think this will be easier to justify
        /// in Orcas, if we tease apart the two cases of OOM better.
        /// But even in Whidbey, how likely is it that we couldnt JIT
        /// some backout code?  At that point, the process or possibly
        /// the machine is likely to stop executing soon no matter
        /// what you do in this routine.  So I would just consider
        /// AccessViolationException.  (I understand why you have SO here,
        /// at least temporarily).
        /// </remarks>
        internal static void CheckForSevereException(PSCmdlet cmdlet, Exception e)
        {
            if (e is AccessViolationException || e is StackOverflowException)
            {
                try
                {
                    if (!alreadyFailing)
                    {
                        alreadyFailing = true;

                        // Get the ExecutionContext from the thread.
                        ExecutionContext context =
                            (null != cmdlet)
                                ? cmdlet.Context
                                : LocalPipeline.GetExecutionContextFromTLS();

                        // Log a command health event for this critical error.
                        MshLog.LogCommandHealthEvent(context, e, Severity.Critical);
                    }
                }
                finally
                {
                    if (!designForTestability_SkipFailFast)
                        WindowsErrorReporting.FailFast(e);
                }
            }
        }
开发者ID:40a,项目名称:PowerShell,代码行数:50,代码来源:UtilityCommon.cs

示例6: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            ManagementService client = CreateManagementServiceClient();
            var relyingParties = client.RelyingParties;

            List<string> relyingPartyRelayAddresses = new List<string>();

            long relyingPartyId = -1;

            foreach (var relyingParty in relyingParties)
            {
                string name = relyingParty.Name;

                if (name == RelyingParty)
                {
                    relyingPartyId = relyingParty.Id;
                }
            }

            foreach (RelyingPartyAddress address in client.RelyingPartyAddresses)
            {
                if (address.RelyingPartyId == relyingPartyId)
                {
                    relyingPartyRelayAddresses.Add(address.Address);
                }
            }

            callingCmdlet.WriteObject(relyingPartyRelayAddresses, true); ;
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:29,代码来源:Get_ACSRelyingPartyRelayAddressesBase.cs

示例7: MasterStreamOpen

        internal static void MasterStreamOpen(
			PSCmdlet cmdlet,
			string filePath,
			string encoding,
			bool defaultEncoding,
			bool append,
			bool force,
			bool noClobber,
			out FileStream fileStream,
			out StreamWriter streamWriter,
			out FileInfo readOnlyFileInfo,
			bool isLiteralPath)
        {
            var resolvedEncoding = EncodingConversion.Convert(cmdlet, encoding);
            MasterStreamOpen(
                cmdlet,
                filePath,
                resolvedEncoding,
                defaultEncoding,
                append,
                force,
                noClobber,
                out fileStream,
                out streamWriter,
                out readOnlyFileInfo,
                isLiteralPath);
        }
开发者ID:powercode,项目名称:PSPlastic,代码行数:27,代码来源:PathUtils.cs

示例8: ExecuteCmdletBase

        public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
        {
            ManagementService client = CreateManagementServiceClient();
            var relyingParties = client.RelyingParties;

            if (relyingParties != null)
            {
                foreach (var relyingParty in relyingParties)
                {
                    string name = relyingParty.Name;

                    if (name == RelyingParty)
                    {
                        RelyingPartyAddress address = new RelyingPartyAddress();
                        address.Address = RelyingPartyRelayAddress;
                        address.EndpointType = "Reply";

                        client.AddRelatedObject(relyingParty, "RelyingPartyAddresses", address);
                        client.SaveChanges(SaveChangesOptions.Batch);
                    }
                }
            }
            else
            {
                throw new Exception("Failed to get the Relying Parties list from the ACS Management Service.");
            }
        }
开发者ID:chris-tomich,项目名称:Glyma,代码行数:27,代码来源:Add_ACSRelyingPartyRelayAddressBase.cs

示例9: ShowHelpWindow

        private static void ShowHelpWindow(PSObject helpObj, PSCmdlet cmdlet)
        {
            Window ownerWindow = ShowCommandHelper.GetHostWindow(cmdlet);
            if (ownerWindow != null)
            {
                ownerWindow.Dispatcher.Invoke(
                    new SendOrPostCallback(
                        delegate(object ignored)
                        {
                            HelpWindow helpWindow = new HelpWindow(helpObj);
                            helpWindow.Owner = ownerWindow;
                            helpWindow.Show();

                            helpWindow.Closed += new EventHandler(delegate(object sender, EventArgs e) { ownerWindow.Focus(); });
                        }),
                        String.Empty);
                return;
            }

            Thread guiThread = new Thread(
            (ThreadStart)delegate
            {
                HelpWindow helpWindow = new HelpWindow(helpObj);
                helpWindow.ShowDialog();
            });
            guiThread.SetApartmentState(ApartmentState.STA);
            guiThread.Start();
        }
开发者ID:40a,项目名称:PowerShell,代码行数:28,代码来源:HelpWindowHelper.cs

示例10: Glob

        /// <summary>
        /// 
        /// </summary>
        /// <param name="files"></param>
        /// <param name="errorId"></param>
        /// <param name="cmdlet"></param>
        /// <returns></returns>
        internal static Collection<string> Glob(string[] files, string errorId, PSCmdlet cmdlet)
        {
            Collection<string> retValue = new Collection<string>();
            foreach (string file in files)
            {
                Collection<string> providerPaths;
                ProviderInfo provider = null;
                try
                {
                    providerPaths = cmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(file, out provider);
                }
                catch (SessionStateException e)
                {
                    cmdlet.WriteError(new ErrorRecord(e, errorId, ErrorCategory.InvalidOperation, file));
                    continue;
                }
                if (!provider.NameEquals(cmdlet.Context.ProviderNames.FileSystem))
                {
                    ReportWrongProviderType(provider.FullName, errorId, cmdlet);
                    continue;
                }
                foreach (string providerPath in providerPaths)
                {
                    if (!providerPath.EndsWith(".ps1xml", StringComparison.OrdinalIgnoreCase))
                    {
                        ReportWrongExtension(providerPath, "WrongExtension", cmdlet);
                        continue;
                    }
                    retValue.Add(providerPath);
                }
            }

            return retValue;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:41,代码来源:Update-Data.cs

示例11: DomainDispatcher

        public DomainDispatcher(PSCmdlet cmdlet)
        {
            Contract.Requires(cmdlet != null);

            _cmdlet = cmdlet;
            _dte = (DTE)cmdlet.GetVariableValue("DTE");
        }
开发者ID:jimmy00784,项目名称:entityframework,代码行数:7,代码来源:DomainDispatcher.cs

示例12: TerminatingErrorContext

 internal TerminatingErrorContext(PSCmdlet command)
 {
     if (command == null)
     {
         throw PSTraceSource.NewArgumentNullException("command");
     }
     this._command = command;
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:TerminatingErrorContext.cs

示例13: ImportCsvHelper

 internal ImportCsvHelper(PSCmdlet cmdlet, char delimiter, IList<string> header, string typeName, StreamReader streamReader)
 {
     this._cmdlet = cmdlet;
     this._delimiter = delimiter;
     this._header = header;
     this._typeName = typeName;
     this._sr = streamReader;
 }
开发者ID:nickchal,项目名称:pash,代码行数:8,代码来源:ImportCsvHelper.cs

示例14: ReportWrongExtension

 private static void ReportWrongExtension(string file, string errorId, PSCmdlet cmdlet)
 {
     ErrorRecord errorRecord = new ErrorRecord(
         PSTraceSource.NewInvalidOperationException(UpdateDataStrings.UpdateData_WrongExtension, file, "ps1xml"),
         errorId,
         ErrorCategory.InvalidArgument,
         null);
     cmdlet.WriteError(errorRecord);
 }
开发者ID:40a,项目名称:PowerShell,代码行数:9,代码来源:Update-Data.cs

示例15: PSHostTraceListener

 internal PSHostTraceListener(PSCmdlet cmdlet) : base("")
 {
     this.cachedWrite = new StringBuilder();
     if (cmdlet == null)
     {
         throw new PSArgumentNullException("cmdlet");
     }
     this.ui = cmdlet.Host.UI as InternalHostUserInterface;
 }
开发者ID:nickchal,项目名称:pash,代码行数:9,代码来源:PSHostTraceListener.cs


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