Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public CimSessionBase()
{
this.sessionState = cimSessions.GetOrAdd(
CurrentRunspaceId,
delegate (Guid instanceId)
(Guid instanceId) =>
{
if (Runspace.DefaultRunspace != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ private StartableJob DoCreateQueryJob(TSession sessionForJob, QueryBuilder query
discardNonPipelineResults,
actionAgainstResults == null
? (Action<PSObject>)null
: delegate (PSObject pso)
{
var objectInstance =
(TObjectInstance)
LanguagePrimitives.ConvertTo(pso, typeof(TObjectInstance),
CultureInfo.InvariantCulture);
actionAgainstResults(sessionForJob, objectInstance);
});
: ((PSObject pso) =>
{
var objectInstance =
(TObjectInstance)LanguagePrimitives.ConvertTo(
pso,
typeof(TObjectInstance),
CultureInfo.InvariantCulture);
actionAgainstResults(sessionForJob, objectInstance);
}));
}

return queryJob;
Expand Down Expand Up @@ -239,7 +240,7 @@ private StartableJob DoCreateStaticMethodInvocationJob(TSession sessionForJob, M
private void HandleJobOutput(Job job, TSession sessionForJob, bool discardNonPipelineResults, Action<PSObject> outputAction)
{
Action<PSObject> processOutput =
delegate (PSObject pso)
(PSObject pso) =>
{
if (pso == null)
{
Expand All @@ -250,7 +251,7 @@ private void HandleJobOutput(Job job, TSession sessionForJob, bool discardNonPip
};

job.Output.DataAdded +=
delegate (object sender, DataAddedEventArgs eventArgs)
(object sender, DataAddedEventArgs eventArgs) =>
{
var dataCollection = (PSDataCollection<PSObject>)sender;

Expand Down Expand Up @@ -300,7 +301,7 @@ internal virtual TSession GetSessionOfOriginFromInstance(TObjectInstance instanc
private static void DiscardJobOutputs<T>(PSDataCollection<T> psDataCollection)
{
psDataCollection.DataAdded +=
delegate (object sender, DataAddedEventArgs e)
(object sender, DataAddedEventArgs e) =>
{
var localDataCollection = (PSDataCollection<T>)sender;
localDataCollection.Clear();
Expand Down Expand Up @@ -409,7 +410,7 @@ public override void ProcessRecord(QueryBuilder query, MethodInvocationInfo meth
StartableJob queryJob = this.DoCreateQueryJob(
sessionForJob,
query,
delegate (TSession sessionForMethodInvocationJob, TObjectInstance objectInstance)
(TSession sessionForMethodInvocationJob, TObjectInstance objectInstance) =>
{
StartableJob methodInvocationJob = this.DoCreateInstanceMethodInvocationJob(
sessionForMethodInvocationJob,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ internal void MarkSessionAsTerminated(CimSession terminatedSession, out bool ses
key: terminatedSession,
addValue: true,
updateValueFactory:
delegate (CimSession key, bool isTerminatedValueInDictionary)
{
closureSafeSessionWasAlreadyTerminated = isTerminatedValueInDictionary;
return true;
});
(CimSession key, bool isTerminatedValueInDictionary) =>
{
closureSafeSessionWasAlreadyTerminated = isTerminatedValueInDictionary;
return true;
});

sessionWasAlreadyTerminated = closureSafeSessionWasAlreadyTerminated;
}
Expand All @@ -198,20 +198,20 @@ internal CmdletMethodInvoker<bool> GetErrorReportingDelegate(ErrorRecord errorRe
{
ManualResetEventSlim manualResetEventSlim = new ManualResetEventSlim();
object lockObject = new object();
Func<Cmdlet, bool> action = delegate (Cmdlet cmdlet)
{
_numberOfReportedSessionTerminatingErrors++;
if (_numberOfReportedSessionTerminatingErrors >= _numberOfSessions)
{
cmdlet.ThrowTerminatingError(errorRecord);
}
else
{
cmdlet.WriteError(errorRecord);
}

return false; // not really needed here, but required by CmdletMethodInvoker
};
Func<Cmdlet, bool> action = (Cmdlet cmdlet) =>
{
_numberOfReportedSessionTerminatingErrors++;
if (_numberOfReportedSessionTerminatingErrors >= _numberOfSessions)
{
cmdlet.ThrowTerminatingError(errorRecord);
}
else
{
cmdlet.WriteError(errorRecord);
}

return false; // not really needed here, but required by CmdletMethodInvoker
};

return new CmdletMethodInvoker<bool>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,21 @@ internal static object ConvertFromCimToDotNet(object cimObject, Type expectedDot
return dotNetObject;
}

Func<Func<object>, object> exceptionSafeReturn = delegate (Func<object> innerAction)
{
try
{
return innerAction();
}
catch (Exception e)
{
throw CimValueConverter.GetInvalidCastException(
e,
"InvalidCimToDotNetCast",
cimObject,
expectedDotNetType.FullName);
}
};
Func<Func<object>, object> exceptionSafeReturn = (Func<object> innerAction) =>
{
try
{
return innerAction();
}
catch (Exception e)
{
throw CimValueConverter.GetInvalidCastException(
e,
"InvalidCimToDotNetCast",
cimObject,
expectedDotNetType.FullName);
}
};

if (typeof(ObjectSecurity).IsAssignableFrom(expectedDotNetType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,14 @@ protected override void ProcessRecord()
breakpoints = Filter(
breakpoints,
Id,
delegate (Breakpoint breakpoint, int id)
{
return breakpoint.Id == id;
}
);
(Breakpoint breakpoint, int id) => breakpoint.Id == id);
}
else if (ParameterSetName.Equals(CommandParameterSetName, StringComparison.OrdinalIgnoreCase))
{
breakpoints = Filter(
breakpoints,
Command,
delegate (Breakpoint breakpoint, string command)
(Breakpoint breakpoint, string command) =>
{
CommandBreakpoint commandBreakpoint = breakpoint as CommandBreakpoint;

Expand All @@ -135,7 +131,7 @@ protected override void ProcessRecord()
breakpoints = Filter(
breakpoints,
Variable,
delegate (Breakpoint breakpoint, string variable)
(Breakpoint breakpoint, string variable) =>
{
VariableBreakpoint variableBreakpoint = breakpoint as VariableBreakpoint;

Expand All @@ -152,7 +148,7 @@ protected override void ProcessRecord()
breakpoints = Filter(
breakpoints,
Type,
delegate (Breakpoint breakpoint, BreakpointType type)
(Breakpoint breakpoint, BreakpointType type) =>
{
switch (type)
{
Expand Down Expand Up @@ -195,7 +191,7 @@ protected override void ProcessRecord()
breakpoints = Filter(
breakpoints,
Script,
delegate (Breakpoint breakpoint, string script)
(Breakpoint breakpoint, string script) =>
{
if (breakpoint.Script == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,7 @@ private void WriteMatches(string value, string parametersetname)
}

results.Sort(
delegate (AliasInfo left, AliasInfo right)
{
return StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name);
});
(AliasInfo left, AliasInfo right) => StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name));
foreach (AliasInfo alias in results)
{
this.WriteObject(alias);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ private List<T> RehydrateList<T>(string commandName, object deserializedList, Fu
{
if (itemRehydrator == null)
{
itemRehydrator = delegate (PSObject pso) { return ConvertTo<T>(commandName, pso); };
itemRehydrator = (PSObject pso) => ConvertTo<T>(commandName, pso);
}

List<T> result = null;
Expand All @@ -1073,7 +1073,7 @@ private Dictionary<K, V> RehydrateDictionary<K, V>(string commandName, PSObject

if (valueRehydrator == null)
{
valueRehydrator = delegate (PSObject pso) { return ConvertTo<V>(commandName, pso); };
valueRehydrator = (PSObject pso) => ConvertTo<V>(commandName, pso);
}

Dictionary<K, V> result = new Dictionary<K, V>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,7 @@ protected override void ProcessRecord()
GetMatchingVariables(varName, Scope, out wasFiltered, /*quiet*/ false);

matchingVariables.Sort(
delegate (PSVariable left, PSVariable right)
{
return StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name);
});
(PSVariable left, PSVariable right) => StringComparer.CurrentCultureIgnoreCase.Compare(left.Name, right.Name));

bool matchFound = false;
foreach (PSVariable matchingVariable in matchingVariables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1137,11 +1137,11 @@ private static List<PathItemAndConvertedPath> PSv2FindMatches(PowerShellExecutio
return null;
}

result.Sort(delegate (PathItemAndConvertedPath x, PathItemAndConvertedPath y)
{
Diagnostics.Assert(x.Path != null && y.Path != null, "SafeToString always returns a non-null string");
return string.Compare(x.Path, y.Path, StringComparison.CurrentCultureIgnoreCase);
});
result.Sort((PathItemAndConvertedPath x, PathItemAndConvertedPath y) =>
{
Diagnostics.Assert(x.Path != null && y.Path != null, "SafeToString always returns a non-null string");
return string.Compare(x.Path, y.Path, StringComparison.CurrentCultureIgnoreCase);
});

return result;
}
Expand Down
28 changes: 14 additions & 14 deletions src/System.Management.Automation/engine/ErrorPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,21 +1204,21 @@ internal void ToPSObjectForRemoting(PSObject dest)

private void ToPSObjectForRemoting(PSObject dest, bool serializeExtInfo)
{
RemotingEncoder.AddNoteProperty<Exception>(dest, "Exception", delegate () { return Exception; });
RemotingEncoder.AddNoteProperty<object>(dest, "TargetObject", delegate () { return TargetObject; });
RemotingEncoder.AddNoteProperty<string>(dest, "FullyQualifiedErrorId", delegate () { return FullyQualifiedErrorId; });
RemotingEncoder.AddNoteProperty<InvocationInfo>(dest, "InvocationInfo", delegate () { return InvocationInfo; });
RemotingEncoder.AddNoteProperty<int>(dest, "ErrorCategory_Category", delegate () { return (int)CategoryInfo.Category; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Activity", delegate () { return CategoryInfo.Activity; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Reason", delegate () { return CategoryInfo.Reason; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_TargetName", delegate () { return CategoryInfo.TargetName; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_TargetType", delegate () { return CategoryInfo.TargetType; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Message", delegate () { return CategoryInfo.GetMessage(CultureInfo.CurrentCulture); });
RemotingEncoder.AddNoteProperty<Exception>(dest, "Exception", () => Exception);
RemotingEncoder.AddNoteProperty<object>(dest, "TargetObject", () => TargetObject);
RemotingEncoder.AddNoteProperty<string>(dest, "FullyQualifiedErrorId", () => FullyQualifiedErrorId);
RemotingEncoder.AddNoteProperty<InvocationInfo>(dest, "InvocationInfo", () => InvocationInfo);
RemotingEncoder.AddNoteProperty<int>(dest, "ErrorCategory_Category", () => (int)CategoryInfo.Category);
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Activity", () => CategoryInfo.Activity);
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Reason", () => CategoryInfo.Reason);
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_TargetName", () => CategoryInfo.TargetName);
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_TargetType", () => CategoryInfo.TargetType);
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorCategory_Message", () => CategoryInfo.GetMessage(CultureInfo.CurrentCulture));

if (ErrorDetails != null)
{
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorDetails_Message", delegate () { return ErrorDetails.Message; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorDetails_RecommendedAction", delegate () { return ErrorDetails.RecommendedAction; });
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorDetails_Message", () => ErrorDetails.Message);
RemotingEncoder.AddNoteProperty<string>(dest, "ErrorDetails_RecommendedAction", () => ErrorDetails.RecommendedAction);
}

if (!serializeExtInfo || this.InvocationInfo == null)
Expand All @@ -1229,12 +1229,12 @@ private void ToPSObjectForRemoting(PSObject dest, bool serializeExtInfo)
{
RemotingEncoder.AddNoteProperty(dest, "SerializeExtendedInfo", () => true);
this.InvocationInfo.ToPSObjectForRemoting(dest);
RemotingEncoder.AddNoteProperty<object>(dest, "PipelineIterationInfo", delegate () { return PipelineIterationInfo; });
RemotingEncoder.AddNoteProperty<object>(dest, "PipelineIterationInfo", () => PipelineIterationInfo);
}

if (!string.IsNullOrEmpty(this.ScriptStackTrace))
{
RemotingEncoder.AddNoteProperty(dest, "ErrorDetails_ScriptStackTrace", delegate () { return this.ScriptStackTrace; });
RemotingEncoder.AddNoteProperty(dest, "ErrorDetails_ScriptStackTrace", () => this.ScriptStackTrace);
}
}

Expand Down
8 changes: 2 additions & 6 deletions src/System.Management.Automation/engine/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -953,11 +953,7 @@ protected internal override void ProcessNewEvent(PSEventArgs newEvent,
}
else
{
ThreadPool.QueueUserWorkItem(new WaitCallback(
delegate (object unused)
{
ProcessNewEventImplementation(newEvent, false);
}));
ThreadPool.QueueUserWorkItem(new WaitCallback((_) => ProcessNewEventImplementation(newEvent, false)));
}
}

Expand Down Expand Up @@ -1137,7 +1133,7 @@ private void ProcessPendingActionsImpl()
// teardown event. That can result in starvation of
// foreground threads that also want to use the runspace.
ThreadPool.QueueUserWorkItem(new WaitCallback(
delegate (object unused)
(_) =>
{
System.Threading.Thread.Sleep(100);
this.PulseEngine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ internal static void Init()
// We shouldn't create too many tasks.
#if !UNIX
// Amsi initialize can be a little slow
Task.Run(() =>
{
AmsiUtils.WinScanContent(content: string.Empty, sourceMetadata: string.Empty, warmUp: true);
});
Task.Run(() => AmsiUtils.WinScanContent(content: string.Empty, sourceMetadata: string.Empty, warmUp: true));
#endif

// One other task for other stuff that's faster, but still a little slow.
Expand Down
5 changes: 1 addition & 4 deletions src/System.Management.Automation/engine/InternalCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,7 @@ private void InitParallelParameterSet()
_taskCollection = new PSDataCollection<System.Management.Automation.PSTasks.PSTask>();
_taskDataStreamWriter = new PSTaskDataStreamWriter(this);
_taskPool = new PSTaskPool(ThrottleLimit, UseNewRunspace);
_taskPool.PoolComplete += (sender, args) =>
{
_taskDataStreamWriter.Close();
};
_taskPool.PoolComplete += (sender, args) => _taskDataStreamWriter.Close();

// Create timeout timer if requested.
if (TimeoutSeconds != 0)
Expand Down
Loading