Clean up CodeFactor style issues coming in commits for the last month (#10591)

Only reformatting changes.
This commit is contained in:
Ilya
2019-09-28 12:47:09 +05:00
committed by GitHub
parent 72187d5d13
commit eb2220632c
9 changed files with 107 additions and 66 deletions
@@ -809,11 +809,11 @@ namespace System.Management.Automation
private static readonly Dictionary<string, string> WindowsPowershellGroupPolicyKeys = new Dictionary<string, string>
{
{nameof(ScriptExecution), @"Software\Policies\Microsoft\Windows\PowerShell"},
{nameof(ScriptBlockLogging), @"Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging"},
{nameof(ModuleLogging), @"Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging"},
{nameof(Transcription), @"Software\Policies\Microsoft\Windows\PowerShell\Transcription"},
{nameof(UpdatableHelp), @"Software\Policies\Microsoft\Windows\PowerShell\UpdatableHelp"},
{ nameof(ScriptExecution), @"Software\Policies\Microsoft\Windows\PowerShell" },
{ nameof(ScriptBlockLogging), @"Software\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging" },
{ nameof(ModuleLogging), @"Software\Policies\Microsoft\Windows\PowerShell\ModuleLogging" },
{ nameof(Transcription), @"Software\Policies\Microsoft\Windows\PowerShell\Transcription" },
{ nameof(UpdatableHelp), @"Software\Policies\Microsoft\Windows\PowerShell\UpdatableHelp" },
};
private const string PolicySettingFallbackKey = "UseWindowsPowerShellPolicySetting";
@@ -858,7 +858,10 @@ namespace System.Management.Automation
{
using (RegistryKey subKey = gpoKey.OpenSubKey(settingName))
{
if (subKey != null) { rawRegistryValue = subKey.GetValueNames(); }
if (subKey != null)
{
rawRegistryValue = subKey.GetValueNames();
}
}
}
@@ -874,8 +877,14 @@ namespace System.Management.Automation
case var _ when propertyType == typeof(bool?):
if (rawRegistryValue is int rawIntValue)
{
if (rawIntValue == 1) { propertyValue = true; }
else if (rawIntValue == 0) { propertyValue = false; }
if (rawIntValue == 1)
{
propertyValue = true;
}
else if (rawIntValue == 0)
{
propertyValue = false;
}
}
break;
@@ -40,7 +40,7 @@ namespace System.Management.Automation.PSTasks
ScriptBlock scriptBlock,
Dictionary<string, object> usingValuesMap,
object dollarUnderbar,
PSTaskDataStreamWriter dataStreamWriter)
PSTaskDataStreamWriter dataStreamWriter)
: base(
scriptBlock,
usingValuesMap,
@@ -127,7 +127,7 @@ namespace System.Management.Automation.PSTasks
new PSStreamObject(PSStreamObjectType.Information, item));
}
}
#endregion
#region Event handlers
@@ -361,8 +361,8 @@ namespace System.Management.Automation.PSTasks
#region Constructor
private PSTaskBase()
{
private PSTaskBase()
{
_id = Interlocked.Increment(ref s_taskId);
}
@@ -422,7 +422,7 @@ namespace System.Management.Automation.PSTasks
// Create and open Runspace for this task to run in
var iss = InitialSessionState.CreateDefault2();
iss.LanguageMode = (SystemPolicy.GetSystemLockdownPolicy() == SystemEnforcementMode.Enforce)
iss.LanguageMode = (SystemPolicy.GetSystemLockdownPolicy() == SystemEnforcementMode.Enforce)
? PSLanguageMode.ConstrainedLanguage : PSLanguageMode.FullLanguage;
_runspace = RunspaceFactory.CreateRunspace(iss);
_runspace.Name = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", RunspaceName, s_taskId);
@@ -475,7 +475,7 @@ namespace System.Management.Automation.PSTasks
private readonly PSCmdlet _cmdlet;
private readonly PSDataCollection<PSStreamObject> _dataStream;
private readonly int _cmdletThreadId;
#endregion
#region Properties
@@ -711,6 +711,7 @@ namespace System.Management.Automation.PSTasks
task.Start();
}
return true;
case Stop:
@@ -739,7 +740,7 @@ namespace System.Management.Automation.PSTasks
// Accept no more input
Close();
_stopAll.Set();
// Stop all running tasks
lock (_syncObject)
{
@@ -764,7 +765,7 @@ namespace System.Management.Automation.PSTasks
#region Private Methods
private void HandleTaskStateChangedDelegate(object sender, PSInvocationStateChangedEventArgs args) => HandleTaskStateChanged(sender, args);
private void HandleTaskStateChanged(object sender, PSInvocationStateChangedEventArgs args)
{
var task = sender as PSTaskBase;
@@ -805,10 +806,10 @@ namespace System.Management.Automation.PSTasks
try
{
PoolComplete.SafeInvoke(
this,
this,
new EventArgs());
}
catch
catch
{
Dbg.Assert(false, "Exceptions should not be thrown on event thread");
}
@@ -872,8 +873,8 @@ namespace System.Management.Automation.PSTasks
/// </summary>
public override bool HasMoreData
{
get
{
get
{
foreach (var childJob in ChildJobs)
{
if (childJob.HasMoreData)
@@ -901,7 +902,7 @@ namespace System.Management.Automation.PSTasks
{
_stopSignaled = true;
SetJobState(JobState.Stopping);
_taskPool.StopAll();
SetJobState(JobState.Stopped);
}
@@ -953,7 +954,7 @@ namespace System.Management.Automation.PSTasks
// This thread will end once all jobs reach a finished state by either running
// to completion, terminating with error, or stopped.
System.Threading.ThreadPool.QueueUserWorkItem(
(_) =>
(_) =>
{
foreach (var childJob in ChildJobs)
{
@@ -991,7 +992,7 @@ namespace System.Management.Automation.PSTasks
SetJobState(finalState);
}
catch (ObjectDisposedException)
catch (ObjectDisposedException)
{ }
}
@@ -6621,14 +6621,16 @@ namespace System.Management.Automation.Language
if (expr == null)
{
// ErrorRecovery: create an error expression to fill out the ast and keep parsing.
IScriptExtent extent = After(token);
// Use token.Text, not token.Kind.Text() b/c the kind might not match the actual operator used
// when a case insensitive operator is used.
ReportIncompleteInput(extent,
ReportIncompleteInput(
extent,
nameof(ParserStrings.ExpectedValueExpression),
ParserStrings.ExpectedValueExpression,
token.Text);
expr = new ErrorExpressionAst(extent);
}
@@ -6652,7 +6654,9 @@ namespace System.Management.Automation.Language
Token op = operatorStack.Pop();
operandStack.Push(new BinaryExpressionAst(ExtentOf(lhs, rhs), lhs, op.Kind, rhs, op.Extent));
if (operatorStack.Count == 0)
{
break;
}
precedence = operatorStack.Peek().Kind.GetBinaryPrecedence();
}
@@ -6710,7 +6714,6 @@ namespace System.Management.Automation.Language
// G array-literal-expression:
// G unary-expression
// G unary-expression ',' new-lines:opt array-literal-expression
ExpressionAst lastExpr = UnaryExpressionRule(endNumberOnTernaryOpChars);
if (lastExpr == null)
{
@@ -6737,7 +6740,6 @@ namespace System.Management.Automation.Language
if (lastExpr == null)
{
// ErrorRecovery: create an error expression for the ast and break.
ReportIncompleteInput(After(commaToken),
nameof(ParserStrings.MissingExpressionAfterToken),
ParserStrings.MissingExpressionAfterToken,
@@ -6851,13 +6853,15 @@ namespace System.Management.Automation.Language
{
// ErrorRecovery: don't bother constructing a unary expression, but we know we must have
// some sort of expression, so return an error expression.
//
// Use token.Text, not token.Kind.Text() b/c the kind might not match the actual operator used
// when a case insensitive operator is used.
ReportIncompleteInput(After(token),
ReportIncompleteInput(
After(token),
nameof(ParserStrings.MissingExpressionAfterOperator),
ParserStrings.MissingExpressionAfterOperator,
token.Text);
return new ErrorExpressionAst(token.Extent);
}
}
@@ -6881,11 +6885,12 @@ namespace System.Management.Automation.Language
{
// ErrorRecovery: We have a list of attributes, and we know it's not before a param statement,
// so we know we must have some sort of expression. Return an error expression then.
ReportIncompleteInput(lastAttribute.Extent,
ReportIncompleteInput(
lastAttribute.Extent,
nameof(ParserStrings.UnexpectedAttribute),
ParserStrings.UnexpectedAttribute,
lastAttribute.TypeName.FullName);
return new ErrorExpressionAst(ExtentOf(token, lastAttribute));
}
@@ -6893,16 +6898,18 @@ namespace System.Management.Automation.Language
}
else
{
Diagnostics.Assert(_ungotToken == null || ErrorList.Count > 0,
"Unexpected lookahead from AttributeListRule.");
Diagnostics.Assert(
_ungotToken == null || ErrorList.Count > 0,
"Unexpected lookahead from AttributeListRule.");
// If we've looked ahead, don't go looking for a member access token, we've already issued an error,
// just assume we're not trying to access a member.
var memberAccessToken = _ungotToken != null ? null : NextMemberAccessToken(false);
if (memberAccessToken != null)
{
expr = CheckPostPrimaryExpressionOperators(memberAccessToken,
new TypeExpressionAst(lastAttribute.Extent,
lastAttribute.TypeName));
expr = CheckPostPrimaryExpressionOperators(
memberAccessToken,
new TypeExpressionAst(lastAttribute.Extent, lastAttribute.TypeName));
}
else
{
@@ -6913,8 +6920,9 @@ namespace System.Management.Automation.Language
child = UnaryExpressionRule(endNumberOnTernaryOpChars: true);
if (child != null)
{
expr = new ConvertExpressionAst(ExtentOf(lastAttribute, child),
(TypeConstraintAst)lastAttribute, child);
expr = new ConvertExpressionAst(
ExtentOf(lastAttribute, child),
(TypeConstraintAst)lastAttribute, child);
}
}
}
@@ -7104,7 +7104,7 @@ namespace System.Management.Automation.Language
public class TernaryExpressionAst : ExpressionAst
{
/// <summary>
/// Construct a binary expression.
/// Initializes a new instance of the a ternary expression.
/// </summary>
/// <param name="extent">The extent of the expression.</param>
/// <param name="condition">The condition operand.</param>
@@ -7123,23 +7123,26 @@ namespace System.Management.Automation.Language
}
/// <summary>
/// The ast for the condition of the ternary expression. The property is never null.
/// Gets the ast for the condition of the ternary expression. The property is never null.
/// </summary>
public ExpressionAst Condition { get; }
/// <summary>
/// The ast for the if-operand of the ternary expression. The property is never null.
/// Gets the ast for the if-operand of the ternary expression. The property is never null.
/// </summary>
public ExpressionAst IfTrue { get; }
/// <summary>
/// The ast for the else-operand of the ternary expression. The property is never null.
/// Gets the ast for the else-operand of the ternary expression. The property is never null.
/// </summary>
public ExpressionAst IfFalse { get; }
/// <summary>
/// Copy the TernaryExpressionAst instance.
/// </summary>
/// <return>
/// Retirns a copy of the ast.
/// </return>
public override Ast Copy()
{
ExpressionAst newCondition = CopyElement(this.Condition);
@@ -7199,7 +7202,7 @@ namespace System.Management.Automation.Language
public class BinaryExpressionAst : ExpressionAst
{
/// <summary>
/// Construct a binary expression.
/// Initializes a new instance of the binary expression.
/// </summary>
/// <param name="extent">The extent of the expression.</param>
/// <param name="left">The left hand operand.</param>
@@ -386,7 +386,9 @@ namespace System.Management.Automation.Remoting.Server
catch (Exception e)
{
PSEtwLog.LogOperationalError(
PSEventId.TransportError, PSOpcode.Open, PSTask.None,
PSEventId.TransportError,
PSOpcode.Open,
PSTask.None,
PSKeyword.UseAlwaysOperational,
Guid.Empty.ToString(),
Guid.Empty.ToString(),
@@ -395,7 +397,9 @@ namespace System.Management.Automation.Remoting.Server
e.StackTrace);
PSEtwLog.LogAnalyticError(
PSEventId.TransportError_Analytic, PSOpcode.Open, PSTask.None,
PSEventId.TransportError_Analytic,
PSOpcode.Open,
PSTask.None,
PSKeyword.Transport | PSKeyword.UseAlwaysAnalytic,
Guid.Empty.ToString(),
Guid.Empty.ToString(),
@@ -483,7 +487,7 @@ namespace System.Management.Automation.Remoting.Server
#region Static Methods
/// <summary>
/// Starts the out-of-process powershell server instance.
/// Starts the out-of-process powershell server instance.
/// </summary>
/// <param name="initialCommand">Specifies the initialization script.</param>
/// <param name="workingDirectory">Specifies the initial working directory. The working directory is set before the initial command.</param>
@@ -44,6 +44,9 @@ namespace System.Management.Automation
// local runspace pool at the server
// Optional initial location of the PowerShell session
private readonly string _initialLocation;
// Script to run after a RunspacePool/Runspace is created in this session.
private ConfigurationDataFromXML _configData;
@@ -87,9 +90,6 @@ namespace System.Management.Automation
// Results in a configured remote runspace pushed onto driver host.
private string _configurationName;
// Optional initial location of the PowerShell session
private readonly string _initialLocation;
/// <summary>
/// Event that get raised when the RunspacePool is closed.
/// </summary>
@@ -100,18 +100,17 @@ namespace System.Management.Automation
#region Constructors
/// <summary>
/// Creates the runspace pool driver.
/// Initializes a new instance of the runspace pool driver.
/// </summary>
/// <param name="clientRunspacePoolId">Client runspace pool id to associate.</param>
/// <param name="transportManager">transport manager associated with this
/// runspace pool driver</param>
/// <param name="transportManager">Transport manager associated with this
/// runspace pool driver.</param>
/// <param name="maxRunspaces">Maximum runspaces to open.</param>
/// <param name="minRunspaces">Minimum runspaces to open.</param>
/// <param name="threadOptions">Threading options for the runspaces in the pool.</param>
/// <param name="apartmentState">Apartment state for the runspaces in the pool.</param>
/// <param name="hostInfo">Host information about client side host.</param>
/// <param name="configData">
/// Contains:
/// <param name="configData">Contains:
/// 1. Script to run after a RunspacePool/Runspace is created in this session.
/// For RunspacePool case, every newly created Runspace (in the pool) will run
/// this script.
@@ -192,7 +192,8 @@ namespace System.Management.Automation.Remoting
...
</InitializationParameters>
*/
internal static ServerRemoteSession CreateServerRemoteSession(PSSenderInfo senderInfo,
internal static ServerRemoteSession CreateServerRemoteSession(
PSSenderInfo senderInfo,
string configurationProviderId,
string initializationParameters,
AbstractServerSessionTransportManager transportManager,
@@ -472,8 +472,7 @@ namespace Microsoft.PowerShell.Commands
{
chars[i] = buf[j];
}
}
);
});
long currentBlock = 0;
string lastDelimiterMatch = null;
@@ -572,18 +571,25 @@ namespace Microsoft.PowerShell.Commands
{
WaitForChanges(_path, _mode, _access, _share, _reader.CurrentEncoding);
line = _reader.ReadLine();
} while ((line == null) && (!_provider.Stopping));
}
while ((line == null) && (!_provider.Stopping));
}
}
if (line != null)
{
blocks.Add(line);
}
int peekResult = readBackward ? _backReader.Peek() : _reader.Peek();
if (peekResult == -1)
{
return false;
}
else
{
return true;
}
}
private bool ReadDelimited(bool waitChanges, List<object> blocks, bool readBackward, string actualDelimiter)
@@ -636,7 +642,7 @@ namespace Microsoft.PowerShell.Commands
// We only wait for changes when read forwards, so here we don't need to check if 'readBackward' is
// true or false, we only use 'reader'. The member 'reader' will be updated by WaitForChanges.
WaitForChanges(_path, _mode, _access, _share, _reader.CurrentEncoding);
numRead += _reader.Read(readBuffer.Slice(0, (currentOffset - numRead)));
numRead += _reader.Read(readBuffer.Slice(0, currentOffset - numRead));
}
}
}
@@ -679,7 +685,8 @@ namespace Microsoft.PowerShell.Commands
}
}
}
} while (delimiterNotFound && (numRead != 0));
}
while (delimiterNotFound && (numRead != 0));
// We've reached the end of file or end of line.
if (_currentLineContent.Length > 0)
@@ -692,13 +699,14 @@ namespace Microsoft.PowerShell.Commands
blocks.Add(
!readBackward && !delimiterNotFound
? _currentLineContent.ToString(0, _currentLineContent.Length - actualDelimiter.Length)
: _currentLineContent.ToString()
);
: _currentLineContent.ToString());
}
int peekResult = readBackward ? _backReader.Peek() : _reader.Peek();
if (peekResult != -1)
{
return true;
}
else
{
if (readBackward && _currentLineContent.Length > 0)
@@ -726,7 +734,9 @@ namespace Microsoft.PowerShell.Commands
// Break when the end of the file is reached.
if (n == 0)
{
break;
}
numBytesRead += n;
numBytesToRead -= n;
@@ -778,7 +788,9 @@ namespace Microsoft.PowerShell.Commands
return true;
}
else
{
return false;
}
}
private void CreateStreams(string filePath, string streamName, FileMode fileMode, FileAccess fileAccess, FileShare fileShare, Encoding fileEncoding)
@@ -104,12 +104,14 @@ namespace Microsoft.PowerShell.Telemetry
{
s_telemetryClient = new TelemetryClient();
TelemetryConfiguration.Active.InstrumentationKey = _psCoreTelemetryKey;
// Set this to true to reduce latency during development
TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = false;
s_sessionId = Guid.NewGuid().ToString();
// use a hashset when looking for module names, it should be quicker than a string comparison
s_knownModules = new HashSet<string>(StringComparer.OrdinalIgnoreCase) {
s_knownModules = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"Microsoft.PowerShell.Archive",
"Microsoft.PowerShell.Host",
"Microsoft.PowerShell.Management",
@@ -122,6 +124,7 @@ namespace Microsoft.PowerShell.Telemetry
"PSReadLine",
"ThreadJob",
};
s_uniqueUserIdentifier = GetUniqueIdentifier().ToString();
}
}
@@ -193,7 +196,6 @@ namespace Microsoft.PowerShell.Telemetry
// do nothing, telemetry can't be sent
// don't send the panic telemetry as if we have failed above, it will likely fail here.
}
}
// Get the experimental feature name. If we can report it, we'll return the name of the feature, otherwise, we'll return "anonymous"
@@ -233,7 +235,9 @@ namespace Microsoft.PowerShell.Telemetry
{
return;
}
var properties = new Dictionary<string, string>();
// The variable POWERSHELL_DISTRIBUTION_CHANNEL is set in our docker images.
// This allows us to track the actual docker OS as OSDescription provides only "linuxkit"
// which has limited usefulness
@@ -354,7 +358,7 @@ namespace Microsoft.PowerShell.Telemetry
/// <returns>A guid which represents the unique identifier.</returns>
private static Guid GetUniqueIdentifier()
{
// Try to get the unique id. If this returns false, we'll
// Try to get the unique id. If this returns false, we'll
// create/recreate the telemetry.uuid file to persist for next startup.
Guid id = Guid.Empty;
string uuidPath = Path.Join(Platform.CacheDirectory, "telemetry.uuid");
@@ -363,7 +367,7 @@ namespace Microsoft.PowerShell.Telemetry
return id;
}
// Multiple processes may start simultaneously so we need a system wide
// Multiple processes may start simultaneously so we need a system wide
// way to control access to the file in the case (although remote) when we have
// simulataneous shell starts without the persisted file which attempt to create the file.
using (var m = new Mutex(true, "CreateUniqueUserId"))