@@ -18,6 +18,7 @@ public static class AppConfigUtility
18
18
/// </summary>
19
19
/// <param name="config">The configuration.</param>
20
20
/// <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." ) ]
21
22
public static bool LoadAppSettings ( RollbarInfrastructureConfig config )
22
23
{
23
24
return AppConfigUtility . LoadAppSettings ( config , RollbarConfigSection . GetConfiguration ( ) ) ;
@@ -36,191 +37,179 @@ public static bool LoadAppSettings(RollbarInfrastructureConfig config, RollbarCo
36
37
return false ;
37
38
}
38
39
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 ) ;
43
47
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 )
45
60
{
46
61
infrastructureOptions . MaxReportsPerMinute = rollbarConfigSection . MaxReportsPerMinute . Value ;
47
62
}
48
63
49
- if ( rollbarConfigSection . ReportingQueueDepth . HasValue )
64
+ if ( rollbarConfigSection . ReportingQueueDepth . HasValue )
50
65
{
51
66
infrastructureOptions . ReportingQueueDepth = rollbarConfigSection . ReportingQueueDepth . Value ;
52
67
}
53
68
54
- if ( rollbarConfigSection . MaxItems . HasValue )
69
+ if ( rollbarConfigSection . MaxItems . HasValue )
55
70
{
56
71
infrastructureOptions . MaxItems = rollbarConfigSection . MaxItems . Value ;
57
72
}
58
73
59
- if ( rollbarConfigSection . CaptureUncaughtExceptions . HasValue )
74
+ if ( rollbarConfigSection . CaptureUncaughtExceptions . HasValue )
60
75
{
61
76
infrastructureOptions . CaptureUncaughtExceptions = rollbarConfigSection . CaptureUncaughtExceptions . Value ;
62
77
}
63
78
64
- if ( rollbarConfigSection . PayloadPostTimeout . HasValue )
79
+ if ( rollbarConfigSection . PayloadPostTimeout . HasValue )
65
80
{
66
81
infrastructureOptions . PayloadPostTimeout = rollbarConfigSection . PayloadPostTimeout . Value ;
67
82
}
68
83
69
84
config . RollbarInfrastructureOptions . Reconfigure ( infrastructureOptions ) ;
85
+ }
70
86
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 ( ) ;
79
90
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 )
105
92
{
106
93
offlineStoreOptions . EnableLocalPayloadStore = rollbarConfigSection . EnableLocalPayloadStore . Value ;
107
94
}
108
95
109
- if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . LocalPayloadStoreFileName ) )
96
+ if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . LocalPayloadStoreFileName ) )
110
97
{
111
98
offlineStoreOptions . LocalPayloadStoreFileName = rollbarConfigSection . LocalPayloadStoreFileName ;
112
99
}
113
100
114
- if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . LocalPayloadStoreLocationPath ) )
101
+ if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . LocalPayloadStoreLocationPath ) )
115
102
{
116
103
offlineStoreOptions . LocalPayloadStoreLocationPath = rollbarConfigSection . LocalPayloadStoreLocationPath ;
117
104
}
118
105
119
106
config . RollbarOfflineStoreOptions . Reconfigure ( offlineStoreOptions ) ;
107
+ }
120
108
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 ) )
125
112
{
126
- RollbarDestinationOptions destinationOptions =
127
- new RollbarDestinationOptions ( rollbarConfigSection . AccessToken ) ;
113
+ RollbarDestinationOptions destinationOptions = new ( rollbarConfigSection . AccessToken ) ;
128
114
129
- if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . Environment ) )
115
+ if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . Environment ) )
130
116
{
131
117
destinationOptions . Environment = rollbarConfigSection . Environment ;
132
118
}
133
119
134
- if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . EndPoint ) )
120
+ if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . EndPoint ) )
135
121
{
136
122
destinationOptions . EndPoint = rollbarConfigSection . EndPoint ;
137
123
}
138
124
139
125
config . RollbarLoggerConfig . RollbarDestinationOptions . Reconfigure ( destinationOptions ) ;
140
126
}
127
+ }
141
128
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 )
146
132
{
147
133
config . RollbarLoggerConfig . RollbarDeveloperOptions . Enabled = rollbarConfigSection . Enabled . Value ;
148
134
}
149
135
150
- if ( rollbarConfigSection . Transmit . HasValue )
136
+ if ( rollbarConfigSection . Transmit . HasValue )
151
137
{
152
138
config . RollbarLoggerConfig . RollbarDeveloperOptions . Transmit = rollbarConfigSection . Transmit . Value ;
153
139
}
154
140
155
- if ( rollbarConfigSection . RethrowExceptionsAfterReporting . HasValue )
141
+ if ( rollbarConfigSection . RethrowExceptionsAfterReporting . HasValue )
156
142
{
157
143
config . RollbarLoggerConfig . RollbarDeveloperOptions . RethrowExceptionsAfterReporting = rollbarConfigSection . RethrowExceptionsAfterReporting . Value ;
158
144
}
159
145
160
- if ( rollbarConfigSection . LogLevel . HasValue )
146
+ if ( rollbarConfigSection . LogLevel . HasValue )
161
147
{
162
148
config . RollbarLoggerConfig . RollbarDeveloperOptions . LogLevel = rollbarConfigSection . LogLevel . Value ;
163
149
}
150
+ }
164
151
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 ) )
169
155
{
170
- HttpProxyOptions httpProxyOptions = new HttpProxyOptions ( rollbarConfigSection . ProxyAddress ) ;
156
+ HttpProxyOptions httpProxyOptions = new ( rollbarConfigSection . ProxyAddress ) ;
171
157
172
- if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . ProxyUsername ) )
158
+ if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . ProxyUsername ) )
173
159
{
174
160
httpProxyOptions . ProxyUsername = rollbarConfigSection . ProxyUsername ;
175
161
}
176
162
177
- if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . ProxyPassword ) )
163
+ if ( ! string . IsNullOrWhiteSpace ( rollbarConfigSection . ProxyPassword ) )
178
164
{
179
165
httpProxyOptions . ProxyPassword = rollbarConfigSection . ProxyPassword ;
180
166
}
181
167
182
168
config . RollbarLoggerConfig . HttpProxyOptions . Reconfigure ( httpProxyOptions ) ;
183
169
}
170
+ }
184
171
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 ( ) ;
189
175
190
- if ( rollbarConfigSection . ScrubFields != null && rollbarConfigSection . ScrubFields . Length > 0 )
176
+ if ( rollbarConfigSection . ScrubFields != null && rollbarConfigSection . ScrubFields . Length > 0 )
191
177
{
192
178
dataSecurityOptions . ScrubFields =
193
- string . IsNullOrEmpty ( rollbarConfigSection . ScrubFields ) ? new string [ 0 ]
179
+ string . IsNullOrEmpty ( rollbarConfigSection . ScrubFields ) ? Array . Empty < string > ( )
194
180
: rollbarConfigSection . ScrubFields . Split ( listValueSplitters , StringSplitOptions . RemoveEmptyEntries ) ;
195
181
}
196
182
197
- if ( rollbarConfigSection . ScrubSafelistFields != null && rollbarConfigSection . ScrubSafelistFields . Length > 0 )
183
+ if ( rollbarConfigSection . ScrubSafelistFields != null && rollbarConfigSection . ScrubSafelistFields . Length > 0 )
198
184
{
199
185
dataSecurityOptions . ScrubSafelistFields =
200
- string . IsNullOrEmpty ( rollbarConfigSection . ScrubSafelistFields ) ? new string [ 0 ]
186
+ string . IsNullOrEmpty ( rollbarConfigSection . ScrubSafelistFields ) ? Array . Empty < string > ( )
201
187
: rollbarConfigSection . ScrubSafelistFields . Split ( listValueSplitters , StringSplitOptions . RemoveEmptyEntries ) ;
202
188
}
203
189
204
- if ( rollbarConfigSection . PersonDataCollectionPolicies . HasValue )
190
+ if ( rollbarConfigSection . PersonDataCollectionPolicies . HasValue )
205
191
{
206
192
dataSecurityOptions . PersonDataCollectionPolicies = rollbarConfigSection . PersonDataCollectionPolicies . Value ;
207
193
}
208
194
209
- if ( rollbarConfigSection . IpAddressCollectionPolicy . HasValue )
195
+ if ( rollbarConfigSection . IpAddressCollectionPolicy . HasValue )
210
196
{
211
197
dataSecurityOptions . IpAddressCollectionPolicy = rollbarConfigSection . IpAddressCollectionPolicy . Value ;
212
198
}
213
199
214
200
config . RollbarLoggerConfig . RollbarDataSecurityOptions . Reconfigure ( dataSecurityOptions ) ;
201
+ }
215
202
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
+ }
222
210
}
223
211
212
+
224
213
#endregion RollbarConfig
225
214
226
215
#region TelemetryConfig
0 commit comments