Skip to content

Commit daf5080

Browse files
committed
Added a configuration changed event handler
1 parent 3992d60 commit daf5080

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

Source/Shared/Configuration/ExceptionlessConfiguration.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public string ServerUrl {
7676
_validationResult = null;
7777
_serverUrl = value;
7878
_heartbeatServerUrl = value;
79+
OnChanged();
7980
}
8081
}
8182

@@ -93,6 +94,7 @@ public string HeartbeatServerUrl {
9394

9495
_validationResult = null;
9596
_heartbeatServerUrl = value;
97+
OnChanged();
9698
}
9799
}
98100

@@ -115,6 +117,7 @@ public string ApiKey {
115117

116118
_validationResult = null;
117119
_apiKey = value;
120+
OnChanged();
118121
}
119122
}
120123

@@ -160,12 +163,17 @@ public string ApiKey {
160163
public TimeSpan UpdateSettingsWhenIdleInterval {
161164
get { return _updateSettingsWhenIdleInterval; }
162165
set {
166+
if (_updateSettingsWhenIdleInterval == value)
167+
return;
168+
163169
if (value > TimeSpan.Zero && value < TimeSpan.FromSeconds(15))
164170
_updateSettingsWhenIdleInterval = TimeSpan.FromSeconds(15);
165171
else if (value <= TimeSpan.Zero)
166172
_updateSettingsWhenIdleInterval = TimeSpan.FromMilliseconds(-1);
167173
else
168174
_updateSettingsWhenIdleInterval = value;
175+
176+
OnChanged();
169177
}
170178
}
171179

@@ -460,5 +468,12 @@ public void Dispose() {
460468
disposable.Dispose();
461469
}
462470
}
471+
472+
public event EventHandler Changed;
473+
474+
protected virtual void OnChanged() {
475+
if (Changed != null)
476+
Changed.Invoke(this, EventArgs.Empty);
477+
}
463478
}
464479
}

Source/Shared/ExceptionlessClient.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ public ExceptionlessClient(string apiKey) : this(new ExceptionlessConfiguration(
2525
}
2626

2727
public ExceptionlessClient(Action<ExceptionlessConfiguration> configure) : this(new ExceptionlessConfiguration(DependencyResolver.CreateDefault())) {
28-
if (configure == null)
29-
return;
30-
31-
configure(Configuration);
32-
_updateSettingsTimer.Change(GetInitialSettingsDelay(), Configuration.UpdateSettingsWhenIdleInterval);
28+
if (configure != null)
29+
configure(Configuration);
3330
}
3431

3532
public ExceptionlessClient(ExceptionlessConfiguration configuration) {
3633
if (configuration == null)
3734
throw new ArgumentNullException("configuration");
3835

3936
Configuration = configuration;
37+
Configuration.Changed += OnConfigurationChanged;
4038
Configuration.Resolver.Register(typeof(ExceptionlessConfiguration), () => Configuration);
39+
4140
_log = new Lazy<IExceptionlessLog>(() => Configuration.Resolver.GetLog());
4241
_queue = new Lazy<IEventQueue>(() => {
4342
// config can't be changed after the queue starts up.
@@ -60,7 +59,11 @@ private TimeSpan GetInitialSettingsDelay() {
6059
private void OnQueueEventsPosted(object sender, EventsPostedEventArgs args) {
6160
_updateSettingsTimer.Change(Configuration.UpdateSettingsWhenIdleInterval, Configuration.UpdateSettingsWhenIdleInterval);
6261
}
63-
62+
63+
private void OnConfigurationChanged(object sender, EventArgs e) {
64+
_updateSettingsTimer.Change(!_queue.IsValueCreated ? GetInitialSettingsDelay() : Configuration.UpdateSettingsWhenIdleInterval, Configuration.UpdateSettingsWhenIdleInterval);
65+
}
66+
6467
public ExceptionlessConfiguration Configuration { get; private set; }
6568

6669
/// <summary>
@@ -268,6 +271,7 @@ protected void OnSubmittedEvent(EventSubmittedEventArgs e) {
268271
}
269272

270273
void IDisposable.Dispose() {
274+
Configuration.Changed -= OnConfigurationChanged;
271275
if (_queue.IsValueCreated)
272276
_queue.Value.EventsPosted -= OnQueueEventsPosted;
273277

0 commit comments

Comments
 (0)