mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Use nameof() in bound parameters.contains key() (#7908)
Replace code like BoundParameters.ContainsKey("Delimiter") with BoundParameters.ContainsKey(nameof(Delimiter)). Old pattern come from old C# (<6.0) without nameof().
This commit is contained in:
@@ -98,7 +98,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
ErrorRecord errorRecord = new ErrorRecord(exception, "CannotSpecifyIncludeTypeInformationAndNoTypeInformation", ErrorCategory.InvalidData, null);
|
||||
this.ThrowTerminatingError(errorRecord);
|
||||
}
|
||||
if (this.MyInvocation.BoundParameters.ContainsKey("IncludeTypeInformation"))
|
||||
if (this.MyInvocation.BoundParameters.ContainsKey(nameof(IncludeTypeInformation)))
|
||||
{
|
||||
NoTypeInformation = !IncludeTypeInformation;
|
||||
}
|
||||
|
||||
+1
-1
@@ -389,7 +389,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Enable debugging by preserving debug stop events.
|
||||
debugger.UnhandledBreakpointMode = UnhandledBreakpointProcessingMode.Wait;
|
||||
|
||||
if (this.MyInvocation.BoundParameters.ContainsKey("BreakAll"))
|
||||
if (this.MyInvocation.BoundParameters.ContainsKey(nameof(BreakAll)))
|
||||
{
|
||||
if (BreakAll)
|
||||
{
|
||||
|
||||
+6
-6
@@ -115,7 +115,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Throw out terminating error if this is the case.
|
||||
if (IsModuleSpecified && IsFullyQualifiedModuleSpecified)
|
||||
{
|
||||
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "Module", "FullyQualifiedModule");
|
||||
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, nameof(Module), nameof(FullyQualifiedModule));
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "ModuleAndFullyQualifiedModuleCannotBeSpecifiedTogether", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(error);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
// Throw out terminating error if this is the case.
|
||||
if (IsModuleSpecified && IsFullyQualifiedModuleSpecified)
|
||||
{
|
||||
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, "Module", "FullyQualifiedModule");
|
||||
string errMsg = StringUtil.Format(SessionStateStrings.GetContent_TailAndHeadCannotCoexist, nameof(Module), nameof(FullyQualifiedModule));
|
||||
ErrorRecord error = new ErrorRecord(new InvalidOperationException(errMsg), "ModuleAndFullyQualifiedModuleCannotBeSpecifiedTogether", ErrorCategory.InvalidOperation, null);
|
||||
ThrowTerminatingError(error);
|
||||
}
|
||||
@@ -1643,10 +1643,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
powerShell.AddParameter("Name", this.CommandName);
|
||||
}
|
||||
powerShell.AddParameter("Module", this.Module);
|
||||
powerShell.AddParameter(nameof(Module), this.Module);
|
||||
if (IsFullyQualifiedModuleSpecified)
|
||||
{
|
||||
powerShell.AddParameter("FullyQualifiedModule", this.FullyQualifiedModule);
|
||||
powerShell.AddParameter(nameof(FullyQualifiedModule), this.FullyQualifiedModule);
|
||||
}
|
||||
powerShell.AddParameter("ArgumentList", this.ArgumentList);
|
||||
|
||||
@@ -2405,9 +2405,9 @@ function Get-PSImplicitRemotingSession
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
if (_invocationInfo.BoundParameters.ContainsKey("Module"))
|
||||
if (_invocationInfo.BoundParameters.ContainsKey(nameof(Module)))
|
||||
{
|
||||
string[] moduleNames = (string[])_invocationInfo.BoundParameters["Module"];
|
||||
string[] moduleNames = (string[])_invocationInfo.BoundParameters[nameof(Module)];
|
||||
foreach (string moduleName in moduleNames)
|
||||
{
|
||||
result.AppendFormat(
|
||||
|
||||
@@ -272,22 +272,22 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
{
|
||||
TimeSpan? repInterval = null;
|
||||
TimeSpan? repDuration = null;
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RepetitionInterval") || MyInvocation.BoundParameters.ContainsKey("RepetitionDuration") ||
|
||||
MyInvocation.BoundParameters.ContainsKey("RepeatIndefinitely"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) || MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(nameof(RepeatIndefinitely)))
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RepeatIndefinitely"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepeatIndefinitely)))
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RepetitionDuration"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)))
|
||||
{
|
||||
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidRepeatIndefinitelyParams);
|
||||
}
|
||||
if (!MyInvocation.BoundParameters.ContainsKey("RepetitionInterval"))
|
||||
if (!MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)))
|
||||
{
|
||||
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidRepetitionRepeatParams);
|
||||
}
|
||||
_repDuration = TimeSpan.MaxValue;
|
||||
}
|
||||
else if (!MyInvocation.BoundParameters.ContainsKey("RepetitionInterval") || !MyInvocation.BoundParameters.ContainsKey("RepetitionDuration"))
|
||||
else if (!MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) || !MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)))
|
||||
{
|
||||
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidRepetitionParams);
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
if (definition != null)
|
||||
{
|
||||
// Set the MaxCount value if available.
|
||||
if (MyInvocation.BoundParameters.ContainsKey("MaxResultCount"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(MaxResultCount)))
|
||||
{
|
||||
if (MaxResultCount < 1)
|
||||
{
|
||||
@@ -245,7 +245,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
{
|
||||
// If RunEvery parameter is specified then create a job trigger for the definition that
|
||||
// runs the job at the requested interval.
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RunEvery"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RunEvery)))
|
||||
{
|
||||
AddRepetitionJobTriggerToDefinition(
|
||||
definition,
|
||||
|
||||
@@ -175,13 +175,13 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
protected override void BeginProcessing()
|
||||
{
|
||||
// Validate parameters.
|
||||
if (MyInvocation.BoundParameters.ContainsKey("IdleTimeout") &&
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(IdleTimeout)) &&
|
||||
_idleTimeout < TimeSpan.Zero)
|
||||
{
|
||||
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidIdleTimeout);
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("IdleDuration") &&
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(IdleDuration)) &&
|
||||
_idleDuration < TimeSpan.Zero)
|
||||
{
|
||||
throw new PSArgumentException(ScheduledJobErrorStrings.InvalidIdleDuration);
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
// If RunEvery parameter is specified then create a job trigger for the definition that
|
||||
// runs the job at the requested interval.
|
||||
bool addedTrigger = false;
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RunEvery"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RunEvery)))
|
||||
{
|
||||
AddRepetitionJobTriggerToDefinition(
|
||||
_definition,
|
||||
@@ -340,7 +340,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
UpdateJobInvocationInfo();
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("MaxResultCount"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(MaxResultCount)))
|
||||
{
|
||||
_definition.SetExecutionHistoryLength(MaxResultCount, false);
|
||||
}
|
||||
@@ -406,7 +406,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
}
|
||||
|
||||
// RunAs32
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RunAs32"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RunAs32)))
|
||||
{
|
||||
if (newParameters.ContainsKey(ScheduledJobInvocationInfo.RunAs32Parameter))
|
||||
{
|
||||
@@ -419,7 +419,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
}
|
||||
|
||||
// Authentication
|
||||
if (MyInvocation.BoundParameters.ContainsKey("Authentication"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(Authentication)))
|
||||
{
|
||||
if (newParameters.ContainsKey(ScheduledJobInvocationInfo.AuthenticationParameter))
|
||||
{
|
||||
|
||||
@@ -272,23 +272,23 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
{
|
||||
// First see if a switch parameter was set.
|
||||
List<TriggerFrequency> switchParamList = new List<TriggerFrequency>();
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramAtStartup))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(AtStartup)))
|
||||
{
|
||||
switchParamList.Add(TriggerFrequency.AtStartup);
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramAtLogon))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(AtLogon)))
|
||||
{
|
||||
switchParamList.Add(TriggerFrequency.AtLogon);
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramOnce))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(Once)))
|
||||
{
|
||||
switchParamList.Add(TriggerFrequency.Once);
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaily))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(Daily)))
|
||||
{
|
||||
switchParamList.Add(TriggerFrequency.Daily);
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramWeekly))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(Weekly)))
|
||||
{
|
||||
switchParamList.Add(TriggerFrequency.Weekly);
|
||||
}
|
||||
@@ -338,38 +338,38 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private bool ValidateStartupParams()
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysInterval, ScheduledJobErrorStrings.TriggerStartUpType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(WeeksInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidWeeksInterval, ScheduledJobErrorStrings.TriggerStartUpType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidAtTime, ScheduledJobErrorStrings.TriggerStartUpType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramUser))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(User)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidUser, ScheduledJobErrorStrings.TriggerStartUpType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysOfWeek)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysOfWeek, ScheduledJobErrorStrings.TriggerStartUpType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval) || MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) || MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInfiniteDuration)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidSetTriggerRepetition, ScheduledJobErrorStrings.TriggerStartUpType);
|
||||
WriteValidationError(msg);
|
||||
@@ -381,32 +381,32 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private bool ValidateLogonParams()
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysInterval, ScheduledJobErrorStrings.TriggerLogonType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(WeeksInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidWeeksInterval, ScheduledJobErrorStrings.TriggerLogonType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidAtTime, ScheduledJobErrorStrings.TriggerLogonType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysOfWeek)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysOfWeek, ScheduledJobErrorStrings.TriggerLogonType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval) || MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) || MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInfiniteDuration)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidSetTriggerRepetition, ScheduledJobErrorStrings.TriggerLogonType);
|
||||
WriteValidationError(msg);
|
||||
@@ -418,38 +418,38 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private bool ValidateOnceParams(ScheduledJobTrigger trigger = null)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysInterval, ScheduledJobErrorStrings.TriggerOnceType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(WeeksInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidWeeksInterval, ScheduledJobErrorStrings.TriggerOnceType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramUser))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(User)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidUser, ScheduledJobErrorStrings.TriggerOnceType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysOfWeek)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysOfWeek, ScheduledJobErrorStrings.TriggerOnceType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInfiniteDuration)))
|
||||
{
|
||||
_repDuration = TimeSpan.MaxValue;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval) || MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) || MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInfiniteDuration)))
|
||||
{
|
||||
// Validate Once trigger repetition parameters.
|
||||
try
|
||||
@@ -465,7 +465,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
if (trigger != null)
|
||||
{
|
||||
if (trigger.At == null && !MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (trigger.At == null && !MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.MissingAtTime, ScheduledJobErrorStrings.TriggerOnceType);
|
||||
WriteValidationError(msg);
|
||||
@@ -478,32 +478,32 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private bool ValidateDailyParams(ScheduledJobTrigger trigger = null)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval) &&
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysInterval)) &&
|
||||
_daysInterval < 1)
|
||||
{
|
||||
WriteValidationError(ScheduledJobErrorStrings.InvalidDaysIntervalParam);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(WeeksInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidWeeksInterval, ScheduledJobErrorStrings.TriggerDailyType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramUser))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(User)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidUser, ScheduledJobErrorStrings.TriggerDailyType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysOfWeek)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysOfWeek, ScheduledJobErrorStrings.TriggerDailyType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval) || MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) || MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInfiniteDuration)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidSetTriggerRepetition, ScheduledJobErrorStrings.TriggerDailyType);
|
||||
WriteValidationError(msg);
|
||||
@@ -512,7 +512,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
if (trigger != null)
|
||||
{
|
||||
if (trigger.At == null && !MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (trigger.At == null && !MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.MissingAtTime, ScheduledJobErrorStrings.TriggerDailyType);
|
||||
WriteValidationError(msg);
|
||||
@@ -525,26 +525,26 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private bool ValidateWeeklyParams(ScheduledJobTrigger trigger = null)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysInterval)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidDaysInterval, ScheduledJobErrorStrings.TriggerWeeklyType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval) &&
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(WeeksInterval)) &&
|
||||
_weeksInterval < 1)
|
||||
{
|
||||
WriteValidationError(ScheduledJobErrorStrings.InvalidWeeksIntervalParam);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramUser))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(User)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidUser, ScheduledJobErrorStrings.TriggerWeeklyType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval) || MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInfiniteDuration))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) || MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)) ||
|
||||
MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInfiniteDuration)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.InvalidSetTriggerRepetition, ScheduledJobErrorStrings.TriggerWeeklyType);
|
||||
WriteValidationError(msg);
|
||||
@@ -553,14 +553,14 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
if (trigger != null)
|
||||
{
|
||||
if (trigger.At == null && !MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (trigger.At == null && !MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.MissingAtTime, ScheduledJobErrorStrings.TriggerDailyType);
|
||||
WriteValidationError(msg);
|
||||
return false;
|
||||
}
|
||||
if ((trigger.DaysOfWeek == null || trigger.DaysOfWeek.Count == 0) &&
|
||||
!MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek))
|
||||
!MyInvocation.BoundParameters.ContainsKey(nameof(DaysOfWeek)))
|
||||
{
|
||||
string msg = StringUtil.Format(ScheduledJobErrorStrings.MissingDaysOfWeek, ScheduledJobErrorStrings.TriggerDailyType);
|
||||
WriteValidationError(msg);
|
||||
@@ -696,7 +696,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private void ModifyStartupTrigger(ScheduledJobTrigger trigger)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)))
|
||||
{
|
||||
trigger.RandomDelay = _randomDelay;
|
||||
}
|
||||
@@ -704,12 +704,12 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private void ModifyLogonTrigger(ScheduledJobTrigger trigger)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)))
|
||||
{
|
||||
trigger.RandomDelay = _randomDelay;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramUser))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(User)))
|
||||
{
|
||||
trigger.User = string.IsNullOrEmpty(_user) ? ScheduledJobTrigger.AllUsers : _user;
|
||||
}
|
||||
@@ -717,22 +717,22 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private void ModifyOnceTrigger(ScheduledJobTrigger trigger)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)))
|
||||
{
|
||||
trigger.RandomDelay = _randomDelay;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)))
|
||||
{
|
||||
trigger.RepetitionInterval = _repInterval;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)))
|
||||
{
|
||||
trigger.RepetitionDuration = _repDuration;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
trigger.At = _atTime;
|
||||
}
|
||||
@@ -740,17 +740,17 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private void ModifyDailyTrigger(ScheduledJobTrigger trigger)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)))
|
||||
{
|
||||
trigger.RandomDelay = _randomDelay;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
trigger.At = _atTime;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysInterval)))
|
||||
{
|
||||
trigger.Interval = _daysInterval;
|
||||
}
|
||||
@@ -758,22 +758,22 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
|
||||
private void ModifyWeeklyTrigger(ScheduledJobTrigger trigger)
|
||||
{
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)))
|
||||
{
|
||||
trigger.RandomDelay = _randomDelay;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramAt))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(At)))
|
||||
{
|
||||
trigger.At = _atTime;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(WeeksInterval)))
|
||||
{
|
||||
trigger.Interval = _weeksInterval;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DaysOfWeek)))
|
||||
{
|
||||
trigger.DaysOfWeek = new List<DayOfWeek>(_daysOfWeek);
|
||||
}
|
||||
@@ -791,8 +791,8 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
trigger.Enabled = enabled;
|
||||
trigger.Id = id;
|
||||
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay) ? _randomDelay : randomDelay;
|
||||
trigger.User = MyInvocation.BoundParameters.ContainsKey(_paramUser) ? _user : user;
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)) ? _randomDelay : randomDelay;
|
||||
trigger.User = MyInvocation.BoundParameters.ContainsKey(nameof(User)) ? _user : user;
|
||||
}
|
||||
|
||||
private void CreateAtStartupTrigger(ScheduledJobTrigger trigger)
|
||||
@@ -806,7 +806,7 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
trigger.Enabled = enabled;
|
||||
trigger.Id = id;
|
||||
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay) ? _randomDelay : randomDelay;
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)) ? _randomDelay : randomDelay;
|
||||
}
|
||||
|
||||
private void CreateOnceTrigger(ScheduledJobTrigger trigger)
|
||||
@@ -823,10 +823,10 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
trigger.Enabled = enabled;
|
||||
trigger.Id = id;
|
||||
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay) ? _randomDelay : randomDelay;
|
||||
trigger.At = MyInvocation.BoundParameters.ContainsKey(_paramAt) ? _atTime : atTime;
|
||||
trigger.RepetitionInterval = MyInvocation.BoundParameters.ContainsKey(_paramRepetitionInterval) ? _repInterval : repInterval;
|
||||
trigger.RepetitionDuration = MyInvocation.BoundParameters.ContainsKey(_paramRepetitionDuration) ? _repDuration : repDuration;
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)) ? _randomDelay : randomDelay;
|
||||
trigger.At = MyInvocation.BoundParameters.ContainsKey(nameof(At)) ? _atTime : atTime;
|
||||
trigger.RepetitionInterval = MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionInterval)) ? _repInterval : repInterval;
|
||||
trigger.RepetitionDuration = MyInvocation.BoundParameters.ContainsKey(nameof(RepetitionDuration)) ? _repDuration : repDuration;
|
||||
}
|
||||
|
||||
private void CreateDailyTrigger(ScheduledJobTrigger trigger)
|
||||
@@ -842,9 +842,9 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
trigger.Enabled = enabled;
|
||||
trigger.Id = id;
|
||||
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay) ? _randomDelay : randomDelay;
|
||||
trigger.At = MyInvocation.BoundParameters.ContainsKey(_paramAt) ? _atTime : atTime;
|
||||
trigger.Interval = MyInvocation.BoundParameters.ContainsKey(_paramDaysInterval) ? _daysInterval : interval;
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)) ? _randomDelay : randomDelay;
|
||||
trigger.At = MyInvocation.BoundParameters.ContainsKey(nameof(At)) ? _atTime : atTime;
|
||||
trigger.Interval = MyInvocation.BoundParameters.ContainsKey(nameof(DaysInterval)) ? _daysInterval : interval;
|
||||
}
|
||||
|
||||
private void CreateWeeklyTrigger(ScheduledJobTrigger trigger)
|
||||
@@ -861,10 +861,10 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
trigger.Enabled = enabled;
|
||||
trigger.Id = id;
|
||||
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(_paramRandomDelay) ? _randomDelay : randomDelay;
|
||||
trigger.At = MyInvocation.BoundParameters.ContainsKey(_paramAt) ? _atTime : atTime;
|
||||
trigger.Interval = MyInvocation.BoundParameters.ContainsKey(_paramWeeksInterval) ? _weeksInterval : interval;
|
||||
trigger.DaysOfWeek = MyInvocation.BoundParameters.ContainsKey(_paramDaysOfWeek) ? new List<DayOfWeek>(_daysOfWeek) : daysOfWeek;
|
||||
trigger.RandomDelay = MyInvocation.BoundParameters.ContainsKey(nameof(RandomDelay)) ? _randomDelay : randomDelay;
|
||||
trigger.At = MyInvocation.BoundParameters.ContainsKey(nameof(At)) ? _atTime : atTime;
|
||||
trigger.Interval = MyInvocation.BoundParameters.ContainsKey(nameof(WeeksInterval)) ? _weeksInterval : interval;
|
||||
trigger.DaysOfWeek = MyInvocation.BoundParameters.ContainsKey(nameof(DaysOfWeek)) ? new List<DayOfWeek>(_daysOfWeek) : daysOfWeek;
|
||||
}
|
||||
|
||||
private void WriteValidationError(string msg)
|
||||
@@ -875,25 +875,5 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Members
|
||||
|
||||
private string _paramAtStartup = "AtStartup";
|
||||
private string _paramAtLogon = "AtLogon";
|
||||
private string _paramOnce = "Once";
|
||||
private string _paramDaily = "Daily";
|
||||
private string _paramWeekly = "Weekly";
|
||||
//
|
||||
private string _paramDaysInterval = "DaysInterval";
|
||||
private string _paramWeeksInterval = "WeeksInterval";
|
||||
private string _paramRandomDelay = "RandomDelay";
|
||||
private string _paramRepetitionInterval = "RepetitionInterval";
|
||||
private string _paramRepetitionDuration = "RepetitionDuration";
|
||||
private string _paramRepetitionInfiniteDuration = "RepeatIndefinitely";
|
||||
private string _paramAt = "At";
|
||||
private string _paramUser = "User";
|
||||
private string _paramDaysOfWeek = "DaysOfWeek";
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,67 +53,67 @@ namespace Microsoft.PowerShell.ScheduledJob
|
||||
// Update ScheduledJobOptions object with current parameters.
|
||||
// Update switch parameters only if they were selected.
|
||||
// Also update the ScheduledJobDefinition object associated with this options object.
|
||||
if (MyInvocation.BoundParameters.ContainsKey("StartIfOnBattery"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(StartIfOnBattery)))
|
||||
{
|
||||
_jobOptions.StartIfOnBatteries = StartIfOnBattery;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("ContinueIfGoingOnBattery"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(ContinueIfGoingOnBattery)))
|
||||
{
|
||||
_jobOptions.StopIfGoingOnBatteries = !ContinueIfGoingOnBattery;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("WakeToRun"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(WakeToRun)))
|
||||
{
|
||||
_jobOptions.WakeToRun = WakeToRun;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("StartIfIdle"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(StartIfIdle)))
|
||||
{
|
||||
_jobOptions.StartIfNotIdle = !StartIfIdle;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("StopIfGoingOffIdle"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(StopIfGoingOffIdle)))
|
||||
{
|
||||
_jobOptions.StopIfGoingOffIdle = StopIfGoingOffIdle;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RestartOnIdleResume"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RestartOnIdleResume)))
|
||||
{
|
||||
_jobOptions.RestartOnIdleResume = RestartOnIdleResume;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("HideInTaskScheduler"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(HideInTaskScheduler)))
|
||||
{
|
||||
_jobOptions.ShowInTaskScheduler = !HideInTaskScheduler;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RunElevated"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RunElevated)))
|
||||
{
|
||||
_jobOptions.RunElevated = RunElevated;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("RequireNetwork"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(RequireNetwork)))
|
||||
{
|
||||
_jobOptions.RunWithoutNetwork = !RequireNetwork;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("DoNotAllowDemandStart"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(DoNotAllowDemandStart)))
|
||||
{
|
||||
_jobOptions.DoNotAllowDemandStart = DoNotAllowDemandStart;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("IdleDuration"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(IdleDuration)))
|
||||
{
|
||||
_jobOptions.IdleDuration = IdleDuration;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("IdleTimeout"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(IdleTimeout)))
|
||||
{
|
||||
_jobOptions.IdleTimeout = IdleTimeout;
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("MultipleInstancePolicy"))
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(MultipleInstancePolicy)))
|
||||
{
|
||||
_jobOptions.MultipleInstancePolicy = MultipleInstancePolicy;
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns>return the list of jobs after applying HasMoreData filter</returns>
|
||||
private List<Job> ApplyHasMoreDataFiltering(List<Job> jobList)
|
||||
{
|
||||
bool hasMoreDataParameter = MyInvocation.BoundParameters.ContainsKey("HasMoreData");
|
||||
bool hasMoreDataParameter = MyInvocation.BoundParameters.ContainsKey(nameof(HasMoreData));
|
||||
|
||||
if (!hasMoreDataParameter)
|
||||
{
|
||||
@@ -221,8 +221,8 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns>returns job list including all child jobs with ChildJobState or all if IncludeChildJob is specified</returns>
|
||||
private List<Job> FindChildJobs(List<Job> jobList)
|
||||
{
|
||||
bool childJobStateParameter = MyInvocation.BoundParameters.ContainsKey("ChildJobState");
|
||||
bool includeChildJobParameter = MyInvocation.BoundParameters.ContainsKey("IncludeChildJob");
|
||||
bool childJobStateParameter = MyInvocation.BoundParameters.ContainsKey(nameof(ChildJobState));
|
||||
bool includeChildJobParameter = MyInvocation.BoundParameters.ContainsKey(nameof(IncludeChildJob));
|
||||
|
||||
List<Job> matches = new List<Job>();
|
||||
|
||||
@@ -267,9 +267,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// <returns></returns>
|
||||
private List<Job> ApplyTimeFiltering(List<Job> jobList)
|
||||
{
|
||||
bool beforeParameter = MyInvocation.BoundParameters.ContainsKey("Before");
|
||||
bool afterParameter = MyInvocation.BoundParameters.ContainsKey("After");
|
||||
bool newestParameter = MyInvocation.BoundParameters.ContainsKey("Newest");
|
||||
bool beforeParameter = MyInvocation.BoundParameters.ContainsKey(nameof(Before));
|
||||
bool afterParameter = MyInvocation.BoundParameters.ContainsKey(nameof(After));
|
||||
bool newestParameter = MyInvocation.BoundParameters.ContainsKey(nameof(Newest));
|
||||
|
||||
if (!beforeParameter && !afterParameter && !newestParameter)
|
||||
{
|
||||
|
||||
@@ -782,7 +782,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
throw new InvalidOperationException(RemotingErrorIdStrings.AsJobAndDisconnectedError);
|
||||
}
|
||||
|
||||
if (MyInvocation.BoundParameters.ContainsKey("SessionName") && !this.InvokeAndDisconnect)
|
||||
if (MyInvocation.BoundParameters.ContainsKey(nameof(SessionName)) && !this.InvokeAndDisconnect)
|
||||
{
|
||||
throw new InvalidOperationException(RemotingErrorIdStrings.SessionNameWithoutInvokeDisconnected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user