Skip to content

Commit fd92f35

Browse files
authored
Merge pull request #603 from WideSpectrumComputing/master
Addressing SonarCloud suggestions
2 parents 11b7841 + da1a170 commit fd92f35

File tree

108 files changed

+1165
-1489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1165
-1489
lines changed

Rollbar.App.Config/AppConfigUtility.cs

+71-82
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class AppConfigUtility
1818
/// </summary>
1919
/// <param name="config">The configuration.</param>
2020
/// <returns>false when the configuration was not found, otherwise true.</returns>
21+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S4136:Method overloads should be grouped together", Justification = "Intentionally split by settings kind.")]
2122
public static bool LoadAppSettings(RollbarInfrastructureConfig config)
2223
{
2324
return AppConfigUtility.LoadAppSettings(config, RollbarConfigSection.GetConfiguration());
@@ -36,191 +37,179 @@ public static bool LoadAppSettings(RollbarInfrastructureConfig config, RollbarCo
3637
return false;
3738
}
3839

39-
// infrastructure options:
40-
//////////////////////////
41-
42-
RollbarInfrastructureOptions infrastructureOptions = new RollbarInfrastructureOptions();
40+
LoadInfrastructureOptions(config, rollbarConfigSection);
41+
LoadOfflinePayloadStoreOptions(config, rollbarConfigSection);
42+
LoadDestinationOptions(config, rollbarConfigSection);
43+
LoadDeveloperOptions(config, rollbarConfigSection);
44+
LoadHttpProxyOptions(config, rollbarConfigSection);
45+
LoadDataSecurityOptions(config, rollbarConfigSection);
46+
LoadTelemetryOptions(config);
4347

44-
if(rollbarConfigSection.MaxReportsPerMinute.HasValue)
48+
var validationResults = config.Validate();
49+
bool configLoadingResult =
50+
(validationResults == null) || (validationResults.Count == 0);
51+
Debug.Assert(configLoadingResult);
52+
return configLoadingResult;
53+
}
54+
55+
private static void LoadInfrastructureOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
56+
{
57+
RollbarInfrastructureOptions infrastructureOptions = new();
58+
59+
if (rollbarConfigSection.MaxReportsPerMinute.HasValue)
4560
{
4661
infrastructureOptions.MaxReportsPerMinute = rollbarConfigSection.MaxReportsPerMinute.Value;
4762
}
4863

49-
if(rollbarConfigSection.ReportingQueueDepth.HasValue)
64+
if (rollbarConfigSection.ReportingQueueDepth.HasValue)
5065
{
5166
infrastructureOptions.ReportingQueueDepth = rollbarConfigSection.ReportingQueueDepth.Value;
5267
}
5368

54-
if(rollbarConfigSection.MaxItems.HasValue)
69+
if (rollbarConfigSection.MaxItems.HasValue)
5570
{
5671
infrastructureOptions.MaxItems = rollbarConfigSection.MaxItems.Value;
5772
}
5873

59-
if(rollbarConfigSection.CaptureUncaughtExceptions.HasValue)
74+
if (rollbarConfigSection.CaptureUncaughtExceptions.HasValue)
6075
{
6176
infrastructureOptions.CaptureUncaughtExceptions = rollbarConfigSection.CaptureUncaughtExceptions.Value;
6277
}
6378

64-
if(rollbarConfigSection.PayloadPostTimeout.HasValue)
79+
if (rollbarConfigSection.PayloadPostTimeout.HasValue)
6580
{
6681
infrastructureOptions.PayloadPostTimeout = rollbarConfigSection.PayloadPostTimeout.Value;
6782
}
6883

6984
config.RollbarInfrastructureOptions.Reconfigure(infrastructureOptions);
85+
}
7086

71-
// telemetry options:
72-
/////////////////////
73-
74-
RollbarTelemetryOptions telemetryOptions = new RollbarTelemetryOptions();
75-
if(AppConfigUtility.LoadAppSettings(telemetryOptions))
76-
{
77-
config.RollbarTelemetryOptions.Reconfigure(telemetryOptions);
78-
}
87+
private static void LoadOfflinePayloadStoreOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
88+
{
89+
RollbarOfflineStoreOptions offlineStoreOptions = new();
7990

80-
//if(telemetryConfigSection.TelemetryEnabled.HasValue)
81-
//{
82-
// telemetryOptions.TelemetryEnabled = telemetryConfigSection.TelemetryEnabled.Value;
83-
//}
84-
//if(telemetryConfigSection.TelemetryQueueDepth.HasValue)
85-
//{
86-
// telemetryOptions.TelemetryQueueDepth = telemetryConfigSection.TelemetryQueueDepth.Value;
87-
//}
88-
//if(telemetryConfigSection.TelemetryAutoCollectionTypes.HasValue)
89-
//{
90-
// telemetryOptions.TelemetryAutoCollectionTypes = telemetryConfigSection.TelemetryAutoCollectionTypes.Value;
91-
//}
92-
//if(telemetryConfigSection.TelemetryAutoCollectionInterval.HasValue)
93-
//{
94-
// telemetryOptions.TelemetryAutoCollectionInterval = telemetryConfigSection.TelemetryAutoCollectionInterval.Value;
95-
//}
96-
97-
//config.RollbarTelemetryOptions.Reconfigure(telemetryOptions);
98-
99-
// offline payload store options:
100-
/////////////////////////////////
101-
102-
RollbarOfflineStoreOptions offlineStoreOptions = new RollbarOfflineStoreOptions();
103-
104-
if(rollbarConfigSection.EnableLocalPayloadStore.HasValue)
91+
if (rollbarConfigSection.EnableLocalPayloadStore.HasValue)
10592
{
10693
offlineStoreOptions.EnableLocalPayloadStore = rollbarConfigSection.EnableLocalPayloadStore.Value;
10794
}
10895

109-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.LocalPayloadStoreFileName))
96+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.LocalPayloadStoreFileName))
11097
{
11198
offlineStoreOptions.LocalPayloadStoreFileName = rollbarConfigSection.LocalPayloadStoreFileName;
11299
}
113100

114-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.LocalPayloadStoreLocationPath))
101+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.LocalPayloadStoreLocationPath))
115102
{
116103
offlineStoreOptions.LocalPayloadStoreLocationPath = rollbarConfigSection.LocalPayloadStoreLocationPath;
117104
}
118105

119106
config.RollbarOfflineStoreOptions.Reconfigure(offlineStoreOptions);
107+
}
120108

121-
// logger destination options:
122-
//////////////////////////////
123-
124-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.AccessToken))
109+
private static void LoadDestinationOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
110+
{
111+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.AccessToken))
125112
{
126-
RollbarDestinationOptions destinationOptions =
127-
new RollbarDestinationOptions(rollbarConfigSection.AccessToken);
113+
RollbarDestinationOptions destinationOptions = new(rollbarConfigSection.AccessToken);
128114

129-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.Environment))
115+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.Environment))
130116
{
131117
destinationOptions.Environment = rollbarConfigSection.Environment;
132118
}
133119

134-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.EndPoint))
120+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.EndPoint))
135121
{
136122
destinationOptions.EndPoint = rollbarConfigSection.EndPoint;
137123
}
138124

139125
config.RollbarLoggerConfig.RollbarDestinationOptions.Reconfigure(destinationOptions);
140126
}
127+
}
141128

142-
// logger developer options:
143-
////////////////////////////
144-
145-
if(rollbarConfigSection.Enabled.HasValue)
129+
private static void LoadDeveloperOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
130+
{
131+
if (rollbarConfigSection.Enabled.HasValue)
146132
{
147133
config.RollbarLoggerConfig.RollbarDeveloperOptions.Enabled = rollbarConfigSection.Enabled.Value;
148134
}
149135

150-
if(rollbarConfigSection.Transmit.HasValue)
136+
if (rollbarConfigSection.Transmit.HasValue)
151137
{
152138
config.RollbarLoggerConfig.RollbarDeveloperOptions.Transmit = rollbarConfigSection.Transmit.Value;
153139
}
154140

155-
if(rollbarConfigSection.RethrowExceptionsAfterReporting.HasValue)
141+
if (rollbarConfigSection.RethrowExceptionsAfterReporting.HasValue)
156142
{
157143
config.RollbarLoggerConfig.RollbarDeveloperOptions.RethrowExceptionsAfterReporting = rollbarConfigSection.RethrowExceptionsAfterReporting.Value;
158144
}
159145

160-
if(rollbarConfigSection.LogLevel.HasValue)
146+
if (rollbarConfigSection.LogLevel.HasValue)
161147
{
162148
config.RollbarLoggerConfig.RollbarDeveloperOptions.LogLevel = rollbarConfigSection.LogLevel.Value;
163149
}
150+
}
164151

165-
// logger HTTP proxy options:
166-
/////////////////////////////
167-
168-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyAddress))
152+
private static void LoadHttpProxyOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
153+
{
154+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyAddress))
169155
{
170-
HttpProxyOptions httpProxyOptions = new HttpProxyOptions(rollbarConfigSection.ProxyAddress);
156+
HttpProxyOptions httpProxyOptions = new(rollbarConfigSection.ProxyAddress);
171157

172-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyUsername))
158+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyUsername))
173159
{
174160
httpProxyOptions.ProxyUsername = rollbarConfigSection.ProxyUsername;
175161
}
176162

177-
if(!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyPassword))
163+
if (!string.IsNullOrWhiteSpace(rollbarConfigSection.ProxyPassword))
178164
{
179165
httpProxyOptions.ProxyPassword = rollbarConfigSection.ProxyPassword;
180166
}
181167

182168
config.RollbarLoggerConfig.HttpProxyOptions.Reconfigure(httpProxyOptions);
183169
}
170+
}
184171

185-
// logger data security options:
186-
////////////////////////////////
187-
188-
RollbarDataSecurityOptions dataSecurityOptions = new RollbarDataSecurityOptions();
172+
private static void LoadDataSecurityOptions(RollbarInfrastructureConfig config, RollbarConfigSection rollbarConfigSection)
173+
{
174+
RollbarDataSecurityOptions dataSecurityOptions = new();
189175

190-
if(rollbarConfigSection.ScrubFields != null && rollbarConfigSection.ScrubFields.Length > 0)
176+
if (rollbarConfigSection.ScrubFields != null && rollbarConfigSection.ScrubFields.Length > 0)
191177
{
192178
dataSecurityOptions.ScrubFields =
193-
string.IsNullOrEmpty(rollbarConfigSection.ScrubFields) ? new string[0]
179+
string.IsNullOrEmpty(rollbarConfigSection.ScrubFields) ? Array.Empty<string>()
194180
: rollbarConfigSection.ScrubFields.Split(listValueSplitters, StringSplitOptions.RemoveEmptyEntries);
195181
}
196182

197-
if(rollbarConfigSection.ScrubSafelistFields != null && rollbarConfigSection.ScrubSafelistFields.Length > 0)
183+
if (rollbarConfigSection.ScrubSafelistFields != null && rollbarConfigSection.ScrubSafelistFields.Length > 0)
198184
{
199185
dataSecurityOptions.ScrubSafelistFields =
200-
string.IsNullOrEmpty(rollbarConfigSection.ScrubSafelistFields) ? new string[0]
186+
string.IsNullOrEmpty(rollbarConfigSection.ScrubSafelistFields) ? Array.Empty<string>()
201187
: rollbarConfigSection.ScrubSafelistFields.Split(listValueSplitters, StringSplitOptions.RemoveEmptyEntries);
202188
}
203189

204-
if(rollbarConfigSection.PersonDataCollectionPolicies.HasValue)
190+
if (rollbarConfigSection.PersonDataCollectionPolicies.HasValue)
205191
{
206192
dataSecurityOptions.PersonDataCollectionPolicies = rollbarConfigSection.PersonDataCollectionPolicies.Value;
207193
}
208194

209-
if(rollbarConfigSection.IpAddressCollectionPolicy.HasValue)
195+
if (rollbarConfigSection.IpAddressCollectionPolicy.HasValue)
210196
{
211197
dataSecurityOptions.IpAddressCollectionPolicy = rollbarConfigSection.IpAddressCollectionPolicy.Value;
212198
}
213199

214200
config.RollbarLoggerConfig.RollbarDataSecurityOptions.Reconfigure(dataSecurityOptions);
201+
}
215202

216-
217-
var validationResults = config.Validate();
218-
bool configLoadingResult =
219-
(validationResults == null) || (validationResults.Count == 0);
220-
Debug.Assert(configLoadingResult);
221-
return configLoadingResult;
203+
private static void LoadTelemetryOptions(RollbarInfrastructureConfig config)
204+
{
205+
RollbarTelemetryOptions telemetryOptions = new();
206+
if (AppConfigUtility.LoadAppSettings(telemetryOptions))
207+
{
208+
config.RollbarTelemetryOptions.Reconfigure(telemetryOptions);
209+
}
222210
}
223211

212+
224213
#endregion RollbarConfig
225214

226215
#region TelemetryConfig

Rollbar.App.Config/RollbarConfigSection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public class RollbarConfigSection
1717
: ConfigurationSection
1818
{
19-
private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarConfigSection).FullName);
19+
private static readonly TraceSource traceSource = new(typeof(RollbarConfigSection).FullName);
2020

2121
/// <summary>
2222
/// Gets the configuration.

Rollbar.App.Config/RollbarTelemetryConfigSection.cs

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class RollbarTelemetryConfigSection
1818
: ConfigurationSection
1919
{
20-
private static readonly TraceSource traceSource = new TraceSource(typeof(RollbarTelemetryConfigSection).FullName);
20+
private static readonly TraceSource traceSource = new(typeof(RollbarTelemetryConfigSection).FullName);
2121

2222
/// <summary>
2323
/// Gets the configuration.
@@ -34,11 +34,10 @@ public class RollbarTelemetryConfigSection
3434
}
3535
catch (System.Exception ex)
3636
{
37+
string msg = $"Error while attempting to get RollbarTelemetryConfigSection:{Environment.NewLine}{ex}";
3738
//let's just trace it for now:
38-
System.Diagnostics.Trace.TraceError(
39-
"Error while attempting to get RollbarTelemetryConfigSection:" + System.Environment.NewLine + ex
40-
);
41-
traceSource.TraceEvent(TraceEventType.Warning, 0, $"Error while attempting to get RollbarTelemetryConfigSection:{Environment.NewLine}{ex}");
39+
System.Diagnostics.Trace.TraceError(msg);
40+
traceSource.TraceEvent(TraceEventType.Warning, 0, msg);
4241
return null;
4342
}
4443
}

Rollbar.AppSettings.Json/AppSettingsUtility.cs

+2-14
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ public static bool LoadAppSettings(RollbarTelemetryOptions config, IConfiguratio
208208
string fileFullName = Path.Combine(folderPath, appSettingsFileName);
209209
if (!File.Exists(fileFullName))
210210
{
211-
//NOTE: the following line causes the RollbarTraceListener into infinite creation loop and subsequent stck overflow:
212-
//Debug.WriteLine($"File: {fileFullName} does not exist...");
211+
//NOTE: Do not Trace/Debug anything here,
212+
// sinse it would cause the RollbarTraceListener into infinite creation loop and subsequent stack overflow!
213213

214214
return null;
215215
}
@@ -222,18 +222,6 @@ public static bool LoadAppSettings(RollbarTelemetryOptions config, IConfiguratio
222222
return appConfiguration;
223223
}
224224

225-
/// <summary>
226-
/// Loads the application settings.
227-
/// </summary>
228-
/// <typeparam name="TSection">The type of the t section.</typeparam>
229-
/// <param name="sectionName">Name of the section.</param>
230-
/// <param name="appSettings">The application settings.</param>
231-
/// <returns>TSection.</returns>
232-
private static TSection LoadAppSettings<TSection>(string sectionName, IConfiguration appSettings)
233-
{
234-
return appSettings.GetSection(sectionName).Get<TSection>();
235-
}
236-
237225
/// <summary>
238226
/// Loads the application settings.
239227
/// </summary>

Rollbar.AppSettings.Json/RollbarConfigurationUtil.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ public static class RollbarConfigurationUtil
1616
/// <returns></returns>
1717
public static IRollbarInfrastructureConfig DeduceRollbarConfig(IConfiguration configuration)
1818
{
19-
//if (RollbarLocator.RollbarInstance.Config.RollbarDestinationOptions.AccessToken != null)
2019
if (RollbarInfrastructure.Instance.Config?.RollbarLoggerConfig?.RollbarDestinationOptions?.AccessToken != null)
2120
{
22-
//return RollbarLocator.RollbarInstance.Config;
2321
return RollbarInfrastructure.Instance.Config;
2422
}
2523

@@ -30,7 +28,7 @@ public static IRollbarInfrastructureConfig DeduceRollbarConfig(IConfiguration co
3028
Assumption.AssertNotNull(configuration, nameof(configuration));
3129

3230
const string defaultAccessToken = "none";
33-
RollbarInfrastructureConfig rollbarConfig = new RollbarInfrastructureConfig(defaultAccessToken);
31+
RollbarInfrastructureConfig rollbarConfig = new(defaultAccessToken);
3432
AppSettingsUtility.LoadAppSettings(rollbarConfig, configuration);
3533

3634
if (rollbarConfig.RollbarLoggerConfig.RollbarDestinationOptions.AccessToken == defaultAccessToken)
@@ -61,7 +59,7 @@ public static IRollbarInfrastructureConfig DeduceRollbarConfig(IConfiguration co
6159
/// <returns></returns>
6260
public static IRollbarTelemetryOptions DeduceRollbarTelemetryConfig(IConfiguration configuration)
6361
{
64-
RollbarTelemetryOptions config = new RollbarTelemetryOptions();
62+
RollbarTelemetryOptions config = new();
6563
AppSettingsUtility.LoadAppSettings(config, configuration);
6664

6765
RollbarTelemetryCollector.Instance?.Config?.Reconfigure(config);

Rollbar.Deploys/Internal/Deployment.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@
55
/// <summary>
66
/// Models data used for registering a deployment instance.
77
/// </summary>
8-
/// [TODO] Eventually, make this class internal AND remove all the [Obsolete] attributes ...
9-
[Obsolete("This type is obsolete. Instead, use Rollbar.Deploys.IDeployment.", false)]
10-
#pragma warning disable CA1724 // The type name conflicts with the namespace
11-
public class Deployment
8+
internal class Deployment
129
: IDeployment
13-
#pragma warning restore CA1724 // The type name conflicts with the namespace
1410
{
1511
/// <summary>
1612
/// Prevents a default instance of the <see cref="Deployment"/> class from being created.
@@ -25,7 +21,6 @@ private Deployment()
2521
/// </summary>
2622
/// <param name="environment">The environment.</param>
2723
/// <param name="revision">The revision.</param>
28-
[Obsolete("This constructor is obsolete. Instead, use Rollbar.Deploys.DeploymentFactory.CreateDeployment(...)", false)]
2924
public Deployment(string environment, string revision)
3025
: this(null, environment, revision)
3126
{
@@ -38,7 +33,6 @@ public Deployment(string environment, string revision)
3833
/// <param name="writeAccessToken">The write access token.</param>
3934
/// <param name="environment">The environment.</param>
4035
/// <param name="revision">The revision.</param>
41-
[Obsolete("This constructor is obsolete. Instead, use Rollbar.Deploys.DeploymentFactory.CreateDeployment(...)", false)]
4236
public Deployment(string? writeAccessToken, string? environment, string? revision)
4337
{
4438
this.WriteAccessToken = writeAccessToken;

0 commit comments

Comments
 (0)