summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-12-21 08:47:09 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2009-12-21 08:47:09 -0800
commit976b5be557476b6bfda7258071042ab148d4be1d (patch)
tree433bb1f107537362c8531b16e547c0391867d702 /src
parentdb20f139cf8b050f3ccfb85cf4da4acceaabd6b7 (diff)
downloadDotNetOpenAuth-976b5be557476b6bfda7258071042ab148d4be1d.zip
DotNetOpenAuth-976b5be557476b6bfda7258071042ab148d4be1d.tar.gz
DotNetOpenAuth-976b5be557476b6bfda7258071042ab148d4be1d.tar.bz2
Report origin pseudonymous identity.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth/Reporting.cs41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth/Reporting.cs b/src/DotNetOpenAuth/Reporting.cs
index 79451b8..f5ba6fc 100644
--- a/src/DotNetOpenAuth/Reporting.cs
+++ b/src/DotNetOpenAuth/Reporting.cs
@@ -50,9 +50,9 @@ namespace DotNetOpenAuth {
private static IsolatedStorageFile file;
/// <summary>
- /// The name of this assembly.
+ /// The GUID that shows up at the top of all reports from this user/machine/domain.
/// </summary>
- private static AssemblyName assemblyName;
+ private static Guid reportOriginIdentity;
/// <summary>
/// The recipient of collected reports.
@@ -107,7 +107,8 @@ namespace DotNetOpenAuth {
if (Enabled) {
try {
file = GetIsolatedStorage();
- assemblyName = new AssemblyName(Assembly.GetExecutingAssembly().FullName);
+ reportOriginIdentity = GetOrCreateOriginIdentity();
+
webRequestHandler = new StandardWebRequestHandler();
observations.Add(observedRequests = new PersistentHashSet(file, "requests.txt", 3));
observations.Add(observedCultures = new PersistentHashSet(file, "cultures.txt", 20));
@@ -266,6 +267,7 @@ namespace DotNetOpenAuth {
private static Stream GetReport() {
var stream = new MemoryStream();
var writer = new StreamWriter(stream, Encoding.UTF8);
+ writer.WriteLine(reportOriginIdentity.ToString("B"));
writer.WriteLine(Util.LibraryVersion);
foreach (var observation in observations) {
@@ -375,6 +377,39 @@ namespace DotNetOpenAuth {
}
/// <summary>
+ /// Gets a unique, pseudonymous identifier for this particular web site or application.
+ /// </summary>
+ /// <returns>A GUID that will serve as the identifier.</returns>
+ /// <remarks>
+ /// The identifier is made persistent by storing the identifier in isolated storage.
+ /// If an existing identifier is not found, a new one is created, persisted, and returned.
+ /// </remarks>
+ private static Guid GetOrCreateOriginIdentity() {
+ Contract.Requires<InvalidOperationException>(file != null);
+ Contract.Ensures(Contract.Result<Guid>() != Guid.Empty);
+
+ Guid identityGuid = Guid.Empty;
+ const int GuidLength = 16;
+ using (var identityFileStream = new IsolatedStorageFileStream("identity.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read, file)) {
+ if (identityFileStream.Length == GuidLength) {
+ byte[] guidBytes = new byte[GuidLength];
+ if (identityFileStream.Read(guidBytes, 0, GuidLength) == GuidLength) {
+ identityGuid = new Guid(guidBytes);
+ }
+ }
+
+ if (identityGuid == Guid.Empty) {
+ identityGuid = Guid.NewGuid();
+ byte[] guidBytes = identityGuid.ToByteArray();
+ identityFileStream.SetLength(0);
+ identityFileStream.Write(guidBytes, 0, guidBytes.Length);
+ }
+
+ return identityGuid;
+ }
+ }
+
+ /// <summary>
/// Sanitizes the name of the file so it only includes valid filename characters.
/// </summary>
/// <param name="fileName">The filename to sanitize.</param>