summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-12-21 18:04:59 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2009-12-21 18:04:59 -0800
commitb7e82ab5eaf22d52b684a3264a6158d1f7d4a684 (patch)
tree2c596de91e03606c6e4365031637e612e7f99126 /src
parentb59b4c0ccb8869cc9d896c9b944498b0a9b7174b (diff)
downloadDotNetOpenAuth-b7e82ab5eaf22d52b684a3264a6158d1f7d4a684.zip
DotNetOpenAuth-b7e82ab5eaf22d52b684a3264a6158d1f7d4a684.tar.gz
DotNetOpenAuth-b7e82ab5eaf22d52b684a3264a6158d1f7d4a684.tar.bz2
Sending reports now resets counters.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth/Reporting.cs49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/DotNetOpenAuth/Reporting.cs b/src/DotNetOpenAuth/Reporting.cs
index 3002415..88556ff 100644
--- a/src/DotNetOpenAuth/Reporting.cs
+++ b/src/DotNetOpenAuth/Reporting.cs
@@ -57,7 +57,7 @@ namespace DotNetOpenAuth {
/// <summary>
/// The recipient of collected reports.
/// </summary>
- private static Uri wellKnownPostLocation = new Uri("http://reports.dotnetopenauth.net/ReportingPost.aspx");
+ private static Uri wellKnownPostLocation = new Uri("http://reports.dotnetopenauth.net/ReportingPost.ashx");
/// <summary>
/// The outgoing HTTP request handler to use for publishing reports.
@@ -315,14 +315,24 @@ namespace DotNetOpenAuth {
request.UserAgent = Util.LibraryVersion;
request.AllowAutoRedirect = false;
request.Method = "POST";
- var report = GetReport();
+ Stream report = GetReport();
request.ContentLength = report.Length;
using (var requestStream = webRequestHandler.GetRequestStream(request)) {
report.CopyTo(requestStream);
}
- var response = webRequestHandler.GetResponse(request);
- response.Dispose();
+ using (var response = webRequestHandler.GetResponse(request)) {
+ // Currently we have no interest in the response stream content.
+ }
+
+ // Report submission was successful. Reset all counters.
+ lock (events) {
+ foreach (PersistentCounter counter in events.Values) {
+ counter.Reset();
+ counter.Flush();
+ }
+ }
+
return true;
} catch (ProtocolException ex) {
Logger.Library.Error("Unable to submit report due to an HTTP error.", ex);
@@ -342,15 +352,29 @@ namespace DotNetOpenAuth {
lock (publishingConsiderationLock) {
if (DateTime.Now - lastPublished > minimumReportingInterval) {
lastPublished = DateTime.Now;
-
- // Do it on a background thread since it could take a while and we
- // don't want to slow down this request we're borrowing.
- ThreadPool.QueueUserWorkItem(state => SendStats());
+ SendStatsAsync();
}
}
}
/// <summary>
+ /// Sends the stats report asynchronously, and careful to not throw any unhandled exceptions.
+ /// </summary>
+ private static void SendStatsAsync() {
+ // Do it on a background thread since it could take a while and we
+ // don't want to slow down this request we're borrowing.
+ ThreadPool.QueueUserWorkItem(state => {
+ try {
+ SendStats();
+ } catch (Exception ex) {
+ // Something bad and unexpected happened. Just deactivate to avoid more trouble.
+ Logger.Library.Error("Error while trying to submit statistical report.", ex);
+ Enabled = false;
+ }
+ });
+ }
+
+ /// <summary>
/// Gets the isolated storage to use for reporting.
/// </summary>
/// <returns>An isolated storage location appropriate for our host.</returns>
@@ -720,6 +744,15 @@ namespace DotNetOpenAuth {
}
/// <summary>
+ /// Resets all counters.
+ /// </summary>
+ internal void Reset() {
+ lock (this) {
+ this.counters.Clear();
+ }
+ }
+
+ /// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>