• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Cmdlet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: WarnAboutUnsupportedActionPreferences

        private static void WarnAboutUnsupportedActionPreferences(
            Cmdlet cmdlet,
            ActionPreference effectiveActionPreference,
            string nameOfCommandLineParameter,
            Func<string> inquireMessageGetter,
            Func<string> stopMessageGetter)
        {
            string message;
            switch (effectiveActionPreference)
            {
                case ActionPreference.Stop:
                    message = stopMessageGetter();
                    break;

                case ActionPreference.Inquire:
                    message = inquireMessageGetter();
                    break;

                default:
                    return; // we can handle everything that is not Stop or Inquire
            }

            bool actionPreferenceComesFromCommandLineParameter = cmdlet.MyInvocation.BoundParameters.ContainsKey(nameOfCommandLineParameter);
            if (actionPreferenceComesFromCommandLineParameter)
            {
                Exception exception = new ArgumentException(message);
                ErrorRecord errorRecord = new ErrorRecord(exception, "ActionPreferenceNotSupportedByCimCmdletAdapter", ErrorCategory.NotImplemented, null);
                cmdlet.ThrowTerminatingError(errorRecord);
            }
        }
开发者ID:40a,项目名称:PowerShell,代码行数:30,代码来源:cimCmdletInvocationContext.cs


示例2: CmdletParameterBinderController

 internal CmdletParameterBinderController(Cmdlet cmdlet, CommandMetadata commandMetadata, ParameterBinderBase parameterBinder)
     : base(cmdlet.MyInvocation, cmdlet.Context, parameterBinder)
 {
     this._warningSet = new HashSet<string>();
     this._useDefaultParameterBinding = true;
     this._delayBindScriptBlocks = new Dictionary<MergedCompiledCommandParameter, DelayedScriptBlockArgument>();
     this._defaultParameterValues = new Dictionary<string, CommandParameterInternal>(StringComparer.OrdinalIgnoreCase);
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     if (commandMetadata == null)
     {
         throw PSTraceSource.NewArgumentNullException("commandMetadata");
     }
     this.Command = cmdlet;
     this._commandRuntime = (MshCommandRuntime)cmdlet.CommandRuntime;
     this._commandMetadata = commandMetadata;
     if (commandMetadata.ImplementsDynamicParameters)
     {
         base.UnboundParameters = base.BindableParameters.ReplaceMetadata(commandMetadata.StaticCommandParameterMetadata);
         base.BindableParameters.GenerateParameterSetMappingFromMetadata(commandMetadata.DefaultParameterSetName);
     }
     else
     {
         base._bindableParameters = commandMetadata.StaticCommandParameterMetadata;
         base.UnboundParameters = new List<MergedCompiledCommandParameter>(base._bindableParameters.BindableParameters.Values);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:29,代码来源:CmdletParameterBinderController.cs


示例3: Write

 public void Write(Cmdlet cmd, string response)
 {
     foreach (var writer in Writers)
     {
         writer.Write(cmd, response);
     }
 }
开发者ID:brianhartsock,项目名称:powershell-rackspaceapps,代码行数:7,代码来源:MacroOutputWriter.cs


示例4: CmdletProviderContext

 internal CmdletProviderContext(CmdletProviderContext contextToCopyFrom)
 {
     this.credentials = PSCredential.Empty;
     this._origin = CommandOrigin.Internal;
     this.accumulatedObjects = new Collection<PSObject>();
     this.accumulatedErrorObjects = new Collection<ErrorRecord>();
     this.stopReferrals = new Collection<CmdletProviderContext>();
     if (contextToCopyFrom == null)
     {
         throw PSTraceSource.NewArgumentNullException("contextToCopyFrom");
     }
     this.executionContext = contextToCopyFrom.ExecutionContext;
     this.command = contextToCopyFrom.command;
     if (contextToCopyFrom.Credential != null)
     {
         this.credentials = contextToCopyFrom.Credential;
     }
     this.drive = contextToCopyFrom.Drive;
     this.force = (bool) contextToCopyFrom.Force;
     this.CopyFilters(contextToCopyFrom);
     this.suppressWildcardExpansion = contextToCopyFrom.SuppressWildcardExpansion;
     this.dynamicParameters = contextToCopyFrom.DynamicParameters;
     this._origin = contextToCopyFrom._origin;
     this.stopping = contextToCopyFrom.Stopping;
     contextToCopyFrom.StopReferrals.Add(this);
     this.copiedContext = contextToCopyFrom;
 }
开发者ID:nickchal,项目名称:pash,代码行数:27,代码来源:CmdletProviderContext.cs


示例5: WriteErrorDetails

        /// <summary>
        /// Process the exception that was thrown and write the error details.
        /// </summary>
        /// <param name="cmdlet">The cmdlet for which to write the error output.</param>
        /// <param name="clientRequestId">The unique id for this request.</param>
        /// <param name="exception">The exception that was thrown.</param>
        public static void WriteErrorDetails(
            Cmdlet cmdlet,
            string clientRequestId,
            Exception exception)
        {
            string requestId;
            ErrorRecord errorRecord = RetrieveExceptionDetails(exception, out requestId);

            // Write the request Id as a warning
            if (requestId != null)
            {
                // requestId was availiable from the server response, write that as warning to the
                // console.
                cmdlet.WriteWarning(string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.ExceptionRequestId,
                    requestId));
            }
            else
            {
                // requestId was not availiable from the server response, write the client Ids that
                // was sent.
                cmdlet.WriteWarning(string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.ExceptionClientSessionId,
                    SqlDatabaseCmdletBase.clientSessionId));
                cmdlet.WriteWarning(string.Format(
                    CultureInfo.InvariantCulture,
                    Resources.ExceptionClientRequestId,
                    clientRequestId));
            }

            // Write the actual errorRecord containing the exception details
            cmdlet.WriteError(errorRecord);
        }
开发者ID:hovsepm,项目名称:azure-sdk-tools,代码行数:41,代码来源:SqlDatabaseExceptionHandler.cs


示例6: BuildMessage

 private string BuildMessage(Cmdlet cmdlet, string baseName, string resourceId, params object[] args)
 {
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     if (string.IsNullOrEmpty(baseName))
     {
         throw PSTraceSource.NewArgumentNullException("baseName");
     }
     if (string.IsNullOrEmpty(resourceId))
     {
         throw PSTraceSource.NewArgumentNullException("resourceId");
     }
     string template = "";
     try
     {
         template = cmdlet.GetResourceString(baseName, resourceId);
     }
     catch (MissingManifestResourceException exception)
     {
         this._textLookupError = exception;
         return "";
     }
     catch (ArgumentException exception2)
     {
         this._textLookupError = exception2;
         return "";
     }
     return this.BuildMessage(template, baseName, resourceId, args);
 }
开发者ID:nickchal,项目名称:pash,代码行数:31,代码来源:ErrorDetails.cs


示例7: Write

        public void Write(Cmdlet cmd, string response)
        {
            var doc = new XmlDocument();
            doc.LoadXml(response);

            cmd.WriteObject(doc.DocumentElement);
        }
开发者ID:brianhartsock,项目名称:powershell-rackspaceapps,代码行数:7,代码来源:XmlOutputWriter.cs


示例8: ReflectionParameterBinder

 /// <summary>
 /// Constructs the parameter binder with the specified type metadata. The binder is only valid
 /// for a single instance of a bindable object and only for the duration of a command.
 /// </summary>
 /// 
 /// <param name="target">
 /// The target object that the parameter values will be bound to.
 /// </param>
 /// 
 /// <param name="command">
 /// An instance of the command so that attributes can access the context.
 /// </param>
 /// 
 /// <param name="commandLineParameters">
 /// The dictionary to use to record the parameters set by this object...
 /// </param>
 /// 
 internal ReflectionParameterBinder(
     object target,
     Cmdlet command,
     CommandLineParameters commandLineParameters)
     : base(target, command.MyInvocation, command.Context, command)
 {
     this.CommandLineParameters = commandLineParameters;
 }
开发者ID:40a,项目名称:PowerShell,代码行数:25,代码来源:ReflectionParameterBinder.cs


示例9: WmiAsyncCmdletHelper

 /// <summary>
 /// Internal Constructor
 /// </summary>
 /// <param name="childJob">Job associated with this operation</param>
 /// <param name="wmiObject">object associated with this operation</param>
 /// <param name="computerName"> computer on which the operation is invoked </param>
 /// <param name="results"> sink to get wmi objects </param>
 internal WmiAsyncCmdletHelper(PSWmiChildJob childJob, Cmdlet wmiObject, string computerName, ManagementOperationObserver results)
 {
     _wmiObject = wmiObject;
     _computerName = computerName;
     _results = results;
     this.State = WmiState.NotStarted;
     _job = childJob;
 }
开发者ID:dfinke,项目名称:powershell,代码行数:15,代码来源:WMIHelper.cs


示例10: Convert

 internal static Encoding Convert(Cmdlet cmdlet, string encoding)
 {
     if (string.IsNullOrEmpty(encoding)
         || (string.Equals(encoding, "unknown", StringComparison.OrdinalIgnoreCase)
             || string.Equals(encoding, "string", StringComparison.OrdinalIgnoreCase))
         || string.Equals(encoding, "unicode", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.Unicode;
     }
     if (string.Equals(encoding, "bigendianunicode", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.BigEndianUnicode;
     }
     if (string.Equals(encoding, "ascii", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.ASCII;
     }
     if (string.Equals(encoding, "utf8", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.UTF8;
     }
     if (string.Equals(encoding, "utf7", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.UTF7;
     }
     if (string.Equals(encoding, "utf32", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.UTF32;
     }
     if (string.Equals(encoding, "default", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.Default;
     }
     if (string.Equals(encoding, "oem", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.GetEncoding((int) NativeMethods.GetOEMCP());
     }
     var str = string.Join(
         ", ",
         "unknown",
         "string",
         "unicode",
         "bigendianunicode",
         "ascii",
         "utf8",
         "utf7",
         "utf32",
         "default",
         "oem");
     var message = StringUtil.Format(PathUtilStrings.OutFile_WriteToFileEncodingUnknown, encoding, str);
     cmdlet.ThrowTerminatingError(
         new ErrorRecord(
             ExceptionUtils.NewArgumentException("Encoding"),
             "WriteToFileEncodingUnknown",
             ErrorCategory.InvalidArgument,
             null) {ErrorDetails = new ErrorDetails(message)});
     return null;
 }
开发者ID:powercode,项目名称:PSPlastic,代码行数:58,代码来源:EncodingConversion.cs


示例11: ChildItemCmdletProviderIntrinsics

 internal ChildItemCmdletProviderIntrinsics(Cmdlet cmdlet)
 {
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     this.cmdlet = cmdlet;
     this.sessionState = cmdlet.Context.EngineSessionState;
 }
开发者ID:nickchal,项目名称:pash,代码行数:9,代码来源:ChildItemCmdletProviderIntrinsics.cs


示例12: CmdletLogger

        public CmdletLogger(Cmdlet cmdlet)
        {
            _cmdlet = cmdlet;

            _name = (from attr in _cmdlet.GetType().GetCustomAttributes(true)
                     let cmdletattr = attr as CmdletAttribute
                     where null != cmdletattr
                     select cmdletattr.NounName + "-" + cmdletattr.VerbName).FirstOrDefault()
                     ?? "Unknown Cmdlet";
        }
开发者ID:modulexcite,项目名称:scriptcs-powershell-module,代码行数:10,代码来源:CmdletLogger.cs


示例13: ContentCmdletProviderIntrinsics

        } // CmdletProviderIntrinsics private


        /// <summary>
        /// Constructs a facade over the "real" session state API
        /// </summary>
        ///
        /// <param name="cmdlet">
        /// An instance of the cmdlet.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="cmdlet"/> is null.
        /// </exception>
        /// 
        internal ContentCmdletProviderIntrinsics(Cmdlet cmdlet)
        {
            if (cmdlet == null)
            {
                throw PSTraceSource.NewArgumentNullException("cmdlet");
            }

            _cmdlet = cmdlet;
            _sessionState = cmdlet.Context.EngineSessionState;
        } // ContentCmdletProviderIntrinsics internal
开发者ID:40a,项目名称:PowerShell,代码行数:25,代码来源:ContentCmdletProviderInterfaces.cs


示例14: Prepare

 /// <summary>
 /// First phase of cmdlet lifecycle: "Binding Parameters that Take Command-Line Input"
 /// </summary>
 public override void Prepare()
 {
     Cmdlet cmdlet = (Cmdlet)Activator.CreateInstance(_cmdletInfo.ImplementingType);
     cmdlet.CommandInfo = _cmdletInfo;
     cmdlet.ExecutionContext = base.ExecutionContext;
     cmdlet.CommandRuntime = CommandRuntime;
     Command = cmdlet;
     MergeParameters();
     _argumentBinder = new CmdletParameterBinder(_cmdletInfo, Command);
     _argumentBinder.BindCommandLineParameters(Parameters);
 }
开发者ID:Ventero,项目名称:Pash,代码行数:14,代码来源:CommandProcessor.cs


示例15: Convert

 internal static Encoding Convert(Cmdlet cmdlet, string encoding)
 {
     if ((encoding == null) || (encoding.Length == 0))
     {
         return Encoding.Unicode;
     }
     if (string.Equals(encoding, "unknown", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.Unicode;
     }
     if (string.Equals(encoding, "string", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.Unicode;
     }
     if (string.Equals(encoding, "unicode", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.Unicode;
     }
     if (string.Equals(encoding, "bigendianunicode", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.BigEndianUnicode;
     }
     if (string.Equals(encoding, "ascii", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.ASCII;
     }
     if (string.Equals(encoding, "utf8", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.UTF8;
     }
     if (string.Equals(encoding, "utf7", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.UTF7;
     }
     if (string.Equals(encoding, "utf32", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.UTF32;
     }
     if (string.Equals(encoding, "default", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.Default;
     }
     if (string.Equals(encoding, "oem", StringComparison.OrdinalIgnoreCase))
     {
         return Encoding.GetEncoding((int) NativeMethods.GetOEMCP());
     }
     string str = string.Join(", ", new string[] { "unknown", "string", "unicode", "bigendianunicode", "ascii", "utf8", "utf7", "utf32", "default", "oem" });
     string message = StringUtil.Format(PathUtilsStrings.OutFile_WriteToFileEncodingUnknown, encoding, str);
     ErrorRecord errorRecord = new ErrorRecord(PSTraceSource.NewArgumentException("Encoding"), "WriteToFileEncodingUnknown", ErrorCategory.InvalidArgument, null) {
         ErrorDetails = new ErrorDetails(message)
     };
     cmdlet.ThrowTerminatingError(errorRecord);
     return null;
 }
开发者ID:nickchal,项目名称:pash,代码行数:54,代码来源:EncodingConversion.cs


示例16: GetOrCreate

        public IScriptCSSession GetOrCreate( string name, Cmdlet cmdlet )
        {
            var session = Get(name);
            if (null == session)
            {
                session = ScriptCSSession.Create(cmdlet);
                _map.Add( name, session );
            }

            return session;
        }
开发者ID:modulexcite,项目名称:scriptcs-powershell-module,代码行数:11,代码来源:ScriptCSSessionManager.cs


示例17: AddChildJobAndPotentiallyBlock

 internal void AddChildJobAndPotentiallyBlock(Cmdlet cmdlet, StartableJob childJob, ChildJobFlags flags)
 {
     using (CancellationTokenSource source = new CancellationTokenSource())
     {
         if (childJob == null)
         {
             throw new ArgumentNullException("childJob");
         }
         this.AddChildJobWithoutBlocking(childJob, flags, new Action(source.Cancel));
         this.ForwardAllResultsToCmdlet(cmdlet, new CancellationToken?(source.Token));
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:12,代码来源:ThrottlingJob.cs


示例18: CmdletParameterBinder

 public CmdletParameterBinder(CmdletInfo cmdletInfo, Cmdlet cmdlet)
 {
     _cmdletInfo = cmdletInfo;
     _cmdlet = cmdlet;
     _defaultValues = new Dictionary<MemberInfo, object>();
     _boundParameters = new Collection<MemberInfo>();
     _candidateParameterSets = new Collection<CommandParameterSetInfo>();
     _commandLineValuesBackup = new Dictionary<MemberInfo, object>();
     _activeSet = null;
     _defaultSet = null;
     _hasDefaultSet = true;
 }
开发者ID:Ventero,项目名称:Pash,代码行数:12,代码来源:CmdletParameterBinder.cs


示例19: ProviderIntrinsics

 internal ProviderIntrinsics(Cmdlet cmdlet)
 {
     if (cmdlet == null)
     {
         throw PSTraceSource.NewArgumentNullException("cmdlet");
     }
     this.cmdlet = cmdlet;
     this.item = new ItemCmdletProviderIntrinsics(cmdlet);
     this.childItem = new ChildItemCmdletProviderIntrinsics(cmdlet);
     this.content = new ContentCmdletProviderIntrinsics(cmdlet);
     this.property = new PropertyCmdletProviderIntrinsics(cmdlet);
     this.securityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(cmdlet);
 }
开发者ID:nickchal,项目名称:pash,代码行数:13,代码来源:ProviderIntrinsics.cs


示例20: ProviderIntrinsics

        internal ProviderIntrinsics(Cmdlet cmdlet)
        {
            if (cmdlet == null)
            {
                throw new NullReferenceException("Cmdlet can't be null.");
            }

            _cmdlet = cmdlet;
            ChildItem = new ChildItemCmdletProviderIntrinsics(_cmdlet);
            Content = new ContentCmdletProviderIntrinsics(_cmdlet);
            Item = new ItemCmdletProviderIntrinsics(_cmdlet);
            Property = new PropertyCmdletProviderIntrinsics(_cmdlet);
            SecurityDescriptor = new SecurityDescriptorCmdletProviderIntrinsics(_cmdlet);
        }
开发者ID:mauve,项目名称:Pash,代码行数:14,代码来源:ProviderIntrinsics.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CmsAttributeTableGenerator类代码示例发布时间:2022-05-24
下一篇:
C# CmdTrigger类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap