Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes308downloads
UserFeedbackParameters.cs214 linesDownload Raw Back to engine
1// Copyright (c) Microsoft Corporation.2// Licensed under the MIT License.3 4using System.Globalization;5using System.Management.Automation.Language;6 7namespace System.Management.Automation8{9    /// <summary>10    /// The parameters for the paging support enabled by <see cref="CmdletCommonMetadataAttribute.SupportsPaging"/>.11    /// Includes: -IncludeTotalCount, -Skip [int], -First [int]12    /// </summary>13    public sealed class PagingParameters14    {15        #region ctor16 17        internal PagingParameters(MshCommandRuntime commandRuntime)18        {19            if (commandRuntime == null)20            {21                throw PSTraceSource.NewArgumentNullException(nameof(commandRuntime));22            }23 24            commandRuntime.PagingParameters = this;25        }26 27        #endregion ctor28 29        #region parameters30 31        /// <summary>32        /// Gets or sets the value of the -IncludeTotalCount parameter for all cmdlets that support paging.33        /// </summary>34        [Parameter]35        public SwitchParameter IncludeTotalCount { get; set; }36 37        /// <summary>38        /// Gets or sets the value of the -Skip parameter for all cmdlets that support paging.39        /// If the user doesn't specify anything, the default is <c>0</c>.40        /// </summary>41        [Parameter]42        public UInt64 Skip { get; set; }43 44        /// <summary>45        /// Gets or sets the value of the -First parameter for all cmdlets that support paging.46        /// If the user doesn't specify anything, the default is <see cref="System.UInt64.MaxValue"/>.47        /// </summary>48        [Parameter]49        public UInt64 First { get; set; } = UInt64.MaxValue;50 51        #endregion parameters52 53        #region emitting total count54 55        /// <summary>56        /// A helper method for creating an object that represents a total count57        /// of objects that the cmdlet would return without paging58        /// (this can be more than the size of the page specified in the <see cref="First"/> cmdlet parameter).59        /// </summary>60        /// <param name="totalCount">A total count of objects that the cmdlet would return without paging.</param>61        /// <param name="accuracy">62        /// accuracy of the <paramref name="totalCount"/> parameter.63        /// <c>1.0</c> means 100% accurate;64        /// <c>0.0</c> means that total count is unknown;65        /// anything in-between means that total count is estimated66        /// </param>67        /// <returns>An object that represents a total count of objects that the cmdlet would return without paging.</returns>68        public PSObject NewTotalCount(UInt64 totalCount, double accuracy)69        {70            PSObject result = new PSObject(totalCount);71 72            string toStringMethodBody = string.Format(73                CultureInfo.CurrentCulture,74                @"75                    $totalCount = $this.PSObject.BaseObject76                    switch ($this.Accuracy) {{77                        {{ $_ -ge 1.0 }} {{ '{0}' -f $totalCount }}78                        {{ $_ -le 0.0 }} {{ '{1}' -f $totalCount }}79                        default          {{ '{2}' -f $totalCount }}80                    }}81                ",82                CodeGeneration.EscapeSingleQuotedStringContent(CommandBaseStrings.PagingSupportAccurateTotalCountTemplate),83                CodeGeneration.EscapeSingleQuotedStringContent(CommandBaseStrings.PagingSupportUnknownTotalCountTemplate),84                CodeGeneration.EscapeSingleQuotedStringContent(CommandBaseStrings.PagingSupportEstimatedTotalCountTemplate));85            PSScriptMethod toStringMethod = new PSScriptMethod("ToString", ScriptBlock.Create(toStringMethodBody));86            result.Members.Add(toStringMethod);87 88            accuracy = Math.Max(0.0, Math.Min(1.0, accuracy));89            PSNoteProperty statusProperty = new PSNoteProperty("Accuracy", accuracy);90            result.Members.Add(statusProperty);91 92            return result;93        }94 95        #endregion emitting total count96    }97}98 99namespace System.Management.Automation.Internal100{101    /// <summary>102    /// The declaration of parameters for the ShouldProcess mechanisms. -Whatif, and -Confirm.103    /// </summary>104    public sealed class ShouldProcessParameters105    {106        #region ctor107 108        /// <summary>109        /// Constructs an instance with the specified command instance.110        /// </summary>111        /// <param name="commandRuntime">112        /// The instance of the command that the parameters should set the113        /// user feedback properties on when the parameters get bound.114        /// </param>115        internal ShouldProcessParameters(MshCommandRuntime commandRuntime)116        {117            if (commandRuntime == null)118            {119                throw PSTraceSource.NewArgumentNullException(nameof(commandRuntime));120            }121 122            _commandRuntime = commandRuntime;123        }124        #endregion ctor125 126        #region parameters127 128        /// <summary>129        /// Gets or sets the value of the -Whatif parameter for all cmdlets.130        /// </summary>131        [Parameter]132        [Alias("wi")]133        public SwitchParameter WhatIf134        {135            get136            {137                return _commandRuntime.WhatIf;138            }139 140            set141            {142                _commandRuntime.WhatIf = value;143            }144        }145 146        /// <summary>147        /// Gets or sets the value of the -Confirm parameter for all cmdlets.148        /// </summary>149        [Parameter]150        [Alias("cf")]151        public SwitchParameter Confirm152        {153            get154            {155                return _commandRuntime.Confirm;156            }157 158            set159            {160                _commandRuntime.Confirm = value;161            }162        }163        #endregion parameters164 165        private readonly MshCommandRuntime _commandRuntime;166    }167 168    /// <summary>169    /// The declaration of parameters for the Transactions mechanisms. -UseTransaction, and -BypassTransaction.170    /// </summary>171    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes", Justification = "These are only exposed by way of the PowerShell cmdlets that surface them.")]172    public sealed class TransactionParameters173    {174        #region ctor175 176        /// <summary>177        /// Constructs an instance with the specified command instance.178        /// </summary>179        /// <param name="commandRuntime">180        /// The instance of the command that the parameters should set the181        /// user feedback properties on when the parameters get bound.182        /// </param>183        internal TransactionParameters(MshCommandRuntime commandRuntime)184        {185            _commandRuntime = commandRuntime;186        }187        #endregion ctor188 189        #region parameters190 191        /// <summary>192        /// Gets or sets the value of the -UseTransaction parameter for all cmdlets.193        /// </summary>194        [Parameter]195        [Alias("usetx")]196        public SwitchParameter UseTransaction197        {198            get199            {200                return _commandRuntime.UseTransaction;201            }202 203            set204            {205                _commandRuntime.UseTransaction = value;206            }207        }208 209        #endregion parameters210 211        private readonly MshCommandRuntime _commandRuntime;212    }213}214