Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fxcop to version 2.9.8 #1499

Merged
merged 18 commits into from
Dec 18, 2019
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
10 changes: 4 additions & 6 deletions .rulesets/ApplicationInsightsSDKRules.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<Rule Id="CA1049" Action="Warning" />
<Rule Id="CA1060" Action="Warning" />
<Rule Id="CA1061" Action="Warning" />
<!-- Disabling this check "CA1063: Implement IDisposable correctly".
This analyzer has a bug which fails the build, https://github.com/dotnet/roslyn-analyzers/issues/1815 -->
<Rule Id="CA1063" Action="None" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<!-- Suppressing Message "Do not pass literals as localized parameters" because we do not localize our SDK -->
<Rule Id="CA1303" Action="None" />
<Rule Id="CA1304" Action="Warning" />
<Rule Id="CA1305" Action="Warning" />
<Rule Id="CA1307" Action="Warning" />
Expand Down Expand Up @@ -85,9 +85,7 @@
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2210" Action="None" />
<Rule Id="CA2212" Action="Warning" />
<!-- Disabling this check "CA2213:DisposableFieldsShouldBeDisposed".
This analyzer has a bug which fails the build, https://github.com/dotnet/roslyn-analyzers/issues/1815 -->
<Rule Id="CA2213" Action="None" />
<Rule Id="CA2213" Action="Warning" />
<Rule Id="CA2214" Action="Warning" />
<Rule Id="CA2216" Action="Warning" />
<Rule Id="CA2219" Action="Warning" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal class InMemoryTransmitter : IDisposable
/// A lock object to serialize the sending calls from Flush, OnFull event and the Runner.
/// </summary>
private object sendingLockObj = new object();

[SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", Justification = "Object is disposed within the using statement of the " + nameof(Runner) + " method.")]
private AutoResetEvent startRunnerEvent;
private bool enabled = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public static double GetSamplingScore(string value)
/// <returns>Item sampling score.</returns>
public static double GetSamplingScore(ITelemetry telemetry)
{
if (telemetry == null)
{
throw new ArgumentNullException(nameof(telemetry));
}

double samplingScore = 0;

if (telemetry.Context.Operation.Id != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ public virtual async Task<HttpWebResponseWrapper> SendAsync()
/// </returns>
public virtual Tuple<Transmission, Transmission> Split(Func<int, int> calculateLength)
{
if (calculateLength == null)
{
throw new ArgumentNullException(nameof(calculateLength));
}

Transmission transmissionA = this;
Transmission transmissionB = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ public ITelemetry DeepClone()
/// <inheritdoc/>
public void SerializeData(ISerializationWriter serializationWriter)
{
if (serializationWriter == null)
{
throw new ArgumentNullException(nameof(serializationWriter));
}

serializationWriter.WriteProperty(this.Data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ void ITelemetry.Sanitize()
/// <inheritdoc/>
public void SerializeData(ISerializationWriter serializationWriter)
{
if (serializationWriter == null)
{
throw new ArgumentNullException(nameof(serializationWriter));
}

serializationWriter.WriteProperty(this.Data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ public ITelemetry DeepClone()
/// <inheritdoc/>
public void SerializeData(ISerializationWriter serializationWriter)
{
if (serializationWriter == null)
{
throw new ArgumentNullException(nameof(serializationWriter));
}

serializationWriter.WriteProperty(this.Data.Data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ public ITelemetry DeepClone()
/// <inheritdoc/>
public void SerializeData(ISerializationWriter serializationWriter)
{
if (serializationWriter == null)
{
throw new ArgumentNullException(nameof(serializationWriter));
}

serializationWriter.WriteProperty(this.Data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ void ITelemetry.Sanitize()
/// <inheritdoc/>
public void SerializeData(ISerializationWriter serializationWriter)
{
if (serializationWriter == null)
{
throw new ArgumentNullException(nameof(serializationWriter));
}

serializationWriter.WriteProperty(this.Data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ public ITelemetry DeepClone()
/// <inheritdoc/>
public void SerializeData(ISerializationWriter serializationWriter)
{
if (serializationWriter == null)
{
throw new ArgumentNullException(nameof(serializationWriter));
}

serializationWriter.WriteProperty(this.Data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public ITelemetry DeepClone()
/// <inheritdoc/>
public void SerializeData(ISerializationWriter serializationWriter)
{
if (serializationWriter == null)
{
throw new ArgumentNullException(nameof(serializationWriter));
}

serializationWriter.WriteProperty(this.Data);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public static class ExperimentalFeaturesExtension
[EditorBrowsable(EditorBrowsableState.Never)]
public static bool EvaluateExperimentalFeature(this TelemetryConfiguration telemetryConfiguration, string featureName)
{
if (telemetryConfiguration == null)
{
throw new ArgumentNullException(nameof(telemetryConfiguration));
}

return telemetryConfiguration.ExperimentalFeatures.Any(x => x.Equals(featureName, StringComparison.OrdinalIgnoreCase));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static string ContentType
[SuppressMessage("Microsoft.Usage", "CA2202:Do not dispose objects multiple times", Justification = "Disposing a MemoryStream multiple times is harmless.")]
public static byte[] Serialize(IEnumerable<ITelemetry> telemetryItems, bool compress = true)
{
if (telemetryItems == null)
{
throw new ArgumentNullException(nameof(telemetryItems));
}

var memoryStream = new MemoryStream();
using (Stream compressedStream = compress ? CreateCompressedStream(memoryStream) : memoryStream)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Microsoft.ApplicationInsights.Extensibility.Implementation
{
using System;
using System.ComponentModel;
using Microsoft.ApplicationInsights.DataContracts;

Expand All @@ -14,6 +15,11 @@ public static class TelemetryConfigurationExtensions
/// </summary>
public static double GetLastObservedSamplingPercentage(this TelemetryConfiguration configuration, SamplingTelemetryItemTypes samplingItemType)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

return configuration.LastKnownSampleRateStore.GetLastObservedSamplingPercentage(samplingItemType);
}

Expand All @@ -22,6 +28,11 @@ public static double GetLastObservedSamplingPercentage(this TelemetryConfigurati
/// </summary>
public static void SetLastObservedSamplingPercentage(this TelemetryConfiguration configuration, SamplingTelemetryItemTypes samplingItemType, double value)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

configuration.LastKnownSampleRateStore.SetLastObservedSamplingPercentage(samplingItemType, value);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -50,6 +51,7 @@ public static TelemetryConfigurationFactory Instance
set { instance = value; }
}

[SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "We want objects created in this method to live for the life of the application.")]
public virtual void Initialize(TelemetryConfiguration configuration, TelemetryModules modules, string serializedConfiguration)
{
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Microsoft.ApplicationInsights.Extensibility.Implementation
{
using System;
using System.ComponentModel;
using Microsoft.ApplicationInsights.DataContracts;

Expand All @@ -16,6 +17,11 @@ public static class TelemetryContextExtensions
/// <returns>Internal context for TelemetryContext.</returns>
public static InternalContext GetInternalContext(this TelemetryContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

return context.Internal;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class TelemetryDebugWriter : IDebugOutput
/// <param name="filteredBy">If specified, indicates the telemetry item was filtered out and not sent to the API.</param>
public static void WriteTelemetry(ITelemetry telemetry, string filteredBy = null)
{
if (telemetry == null)
{
throw new ArgumentNullException(nameof(telemetry));
}

var output = PlatformSingleton.Current.GetDebugOutput();
if (output.IsAttached() && output.IsLogging())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ public static class Extensions
/// </summary>
public static string ToInvariantString(this Exception exception)
{
#if !NETSTANDARD1_3
if (exception == null)
{
return string.Empty;
}

#if NETSTANDARD1_3
return exception.ToString();
#else
CultureInfo originalUICulture = Thread.CurrentThread.CurrentUICulture;
try
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
#endif
return exception.ToString();
#if !NETSTANDARD1_3
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Microsoft.ApplicationInsights.Extensibility
{
using System;
using System.Diagnostics;

using Microsoft.ApplicationInsights;
Expand All @@ -22,6 +23,11 @@ public class OperationCorrelationTelemetryInitializer : ITelemetryInitializer
/// <param name="telemetryItem">Target telemetry item to add operation context.</param>
public void Initialize(ITelemetry telemetryItem)
{
if (telemetryItem == null)
{
throw new ArgumentNullException(nameof(telemetryItem));
}

var itemOperationContext = telemetryItem.Context.Operation;
var telemetryProp = telemetryItem as ISupportProperties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public sealed class SequencePropertyInitializer : ITelemetryInitializer
/// </summary>
public void Initialize(ITelemetry telemetry)
{
if (telemetry == null)
{
throw new ArgumentNullException(nameof(telemetry));
}

if (string.IsNullOrEmpty(telemetry.Sequence))
{
telemetry.Sequence = this.stablePrefix + Interlocked.Increment(ref this.currentNumber).ToString(CultureInfo.InvariantCulture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public static Activity UpdateContextOnActivity(this Activity activity)
[Obsolete("Activity from System.Diagnostics.DiagnosticSource 4.6.0 onwards natively support W3C.")]
public static string GetTraceparent(this Activity activity)
{
if (activity == null)
{
throw new ArgumentNullException(nameof(activity));
}

// Activity.ID is the trasceparent header.
return activity.Id;
}
Expand All @@ -90,6 +95,11 @@ public static void SetTraceparent(this Activity activity, string value)
[Obsolete("Activity from System.Diagnostics.DiagnosticSource 4.6.0 onwards natively support W3C.")]
public static string GetTracestate(this Activity activity)
{
if (activity == null)
{
throw new ArgumentNullException(nameof(activity));
}

return activity.TraceStateString;
}

Expand All @@ -102,6 +112,11 @@ public static string GetTracestate(this Activity activity)
[Obsolete("Activity from System.Diagnostics.DiagnosticSource 4.6.0 onwards natively support W3C.")]
public static void SetTracestate(this Activity activity, string value)
{
if (activity == null)
{
throw new ArgumentNullException(nameof(activity));
}

activity.TraceStateString = value;
}

Expand All @@ -114,6 +129,11 @@ public static void SetTracestate(this Activity activity, string value)
[Obsolete("Activity from System.Diagnostics.DiagnosticSource 4.6.0 onwards natively support W3C. Use Activity.TraceId to get Trace ID")]
public static string GetTraceId(this Activity activity)
{
if (activity == null)
{
throw new ArgumentNullException(nameof(activity));
}

return activity.TraceId.ToHexString();
}

Expand All @@ -126,6 +146,11 @@ public static string GetTraceId(this Activity activity)
[Obsolete("Activity from System.Diagnostics.DiagnosticSource 4.6.0 onwards natively support W3C. Use Activity.SpanId to get Span ID")]
public static string GetSpanId(this Activity activity)
{
if (activity == null)
{
throw new ArgumentNullException(nameof(activity));
}

return activity.SpanId.ToHexString();
}

Expand All @@ -138,6 +163,11 @@ public static string GetSpanId(this Activity activity)
[Obsolete("Activity from System.Diagnostics.DiagnosticSource 4.6.0 onwards natively support W3C. Use Activity.ParentSpanId to get ParentSpan ID")]
public static string GetParentSpanId(this Activity activity)
{
if (activity == null)
{
throw new ArgumentNullException(nameof(activity));
}

return activity.ParentSpanId.ToHexString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public static class MetricExtensions
/// <returns>The configuration of the metric.</returns>
public static MetricConfiguration GetConfiguration(this Metric metric)
{
if (metric == null)
{
throw new ArgumentNullException(nameof(metric));
}

return metric.configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public static class MetricSeriesExtensions
/// <returns>Configuration of the specified series.</returns>
public static IMetricSeriesConfiguration GetConfiguration(this MetricSeries metricSeries)
{
if (metricSeries == null)
{
throw new ArgumentNullException(nameof(metricSeries));
}

return metricSeries.configuration;
}
}
Expand Down
Loading