/********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System.Globalization; using System.Management.Automation.Language; namespace System.Management.Automation { /// /// The parameters for the paging support enabled by . /// Includes: -IncludeTotalCount, -Skip [int], -First [int] /// public sealed class PagingParameters { #region ctor internal PagingParameters(MshCommandRuntime commandRuntime) { if (commandRuntime == null) { throw PSTraceSource.NewArgumentNullException ("commandRuntime"); } commandRuntime.PagingParameters = this; } #endregion ctor #region parameters /// /// Gets or sets the value of the -IncludeTotalCount parameter for all cmdlets that support paging. /// [Parameter] public SwitchParameter IncludeTotalCount { get; set; } /// /// Gets or sets the value of the -Skip parameter for all cmdlets that support paging. /// If the user doesn't specify anything, the default is 0. /// [Parameter] public UInt64 Skip { get; set; } /// /// Gets or sets the value of the -First parameter for all cmdlets that support paging. /// If the user doesn't specify anything, the default is . /// [Parameter] public UInt64 First { get { return psFirst; } set { psFirst = value; } } private ulong psFirst = UInt64.MaxValue; #endregion parameters #region emitting total count /// /// A helper method for creating an object that represents a total count /// of objects that the cmdlet would return without paging /// (this can be more than the size of the page specified in the cmdlet parameter). /// /// a total count of objects that the cmdlet would return without paging /// /// accuracy of the parameter. /// 1.0 means 100% accurate; /// 0.0 means that total count is unknown; /// anything in-between means that total count is estimated /// /// An object that represents a total count of objects that the cmdlet would return without paging public PSObject NewTotalCount(UInt64 totalCount, double accuracy) { PSObject result = new PSObject(totalCount); string toStringMethodBody = string.Format( CultureInfo.CurrentCulture, @" $totalCount = $this.PSObject.BaseObject switch ($this.Accuracy) {{ {{ $_ -ge 1.0 }} {{ '{0}' -f $totalCount }} {{ $_ -le 0.0 }} {{ '{1}' -f $totalCount }} default {{ '{2}' -f $totalCount }} }} ", CodeGeneration.EscapeSingleQuotedStringContent(CommandBaseStrings.PagingSupportAccurateTotalCountTemplate), CodeGeneration.EscapeSingleQuotedStringContent(CommandBaseStrings.PagingSupportUnknownTotalCountTemplate), CodeGeneration.EscapeSingleQuotedStringContent(CommandBaseStrings.PagingSupportEstimatedTotalCountTemplate)); PSScriptMethod toStringMethod = new PSScriptMethod("ToString", ScriptBlock.Create(toStringMethodBody)); result.Members.Add(toStringMethod); accuracy = Math.Max(0.0, Math.Min(1.0, accuracy)); PSNoteProperty statusProperty = new PSNoteProperty("Accuracy", accuracy); result.Members.Add(statusProperty); return result; } #endregion emitting total count } } namespace System.Management.Automation.Internal { /// /// The declaration of parameters for the ShouldProcess mechanisms. -Whatif, and -Confirm. /// public sealed class ShouldProcessParameters { #region ctor /// /// Constructs an instance with the specified command instance /// /// /// /// The instance of the command that the parameters should set the /// user feedback properties on when the parameters get bound. /// /// internal ShouldProcessParameters (MshCommandRuntime commandRuntime) { if (commandRuntime == null) { throw PSTraceSource.NewArgumentNullException ("commandRuntime"); } this.commandRuntime = commandRuntime; } // ctor #endregion ctor #region parameters /// /// Gets or sets the value of the -Whatif parameter for all cmdlets. /// [Parameter] [Alias("wi")] public SwitchParameter WhatIf { get { return this.commandRuntime.WhatIf; } set { this.commandRuntime.WhatIf = value; } } /// /// Gets or sets the value of the -Confirm parameter for all cmdlets. /// [Parameter] [Alias("cf")] public SwitchParameter Confirm { get { return this.commandRuntime.Confirm; } set { this.commandRuntime.Confirm = value; } } #endregion parameters private MshCommandRuntime commandRuntime; } /// /// The declaration of parameters for the Transactions mechanisms. -UseTransaction, and -BypassTransaction. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.MSInternal", "CA903:InternalNamespaceShouldNotContainPublicTypes", Justification="These are only exposed by way of the PowerShell core cmdlets that surface them.")] public sealed class TransactionParameters { #region ctor /// /// Constructs an instance with the specified command instance /// /// /// /// The instance of the command that the parameters should set the /// user feedback properties on when the parameters get bound. /// /// internal TransactionParameters (MshCommandRuntime commandRuntime) { this.commandRuntime = commandRuntime; } // ctor #endregion ctor #region parameters /// /// Gets or sets the value of the -UseTransaction parameter for all cmdlets. /// /// [Parameter] [Alias("usetx")] public SwitchParameter UseTransaction { get { return this.commandRuntime.UseTransaction; } set { this.commandRuntime.UseTransaction = value; } } #endregion parameters private MshCommandRuntime commandRuntime; } }