|
|
|
@ -11,13 +11,17 @@ using System.Data.SQLite; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Globalization; |
|
|
|
using System.Globalization; |
|
|
|
using System.IO; |
|
|
|
using System.IO; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
using System.Reflection; |
|
|
|
using System.Reflection; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Runtime.Serialization; |
|
|
|
using System.Runtime.Serialization; |
|
|
|
using System.Security; |
|
|
|
using System.Security; |
|
|
|
|
|
|
|
using System.Security.Permissions; |
|
|
|
using System.Text; |
|
|
|
using System.Text; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using ICSharpCode.UsageDataCollector.Contracts; |
|
|
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.UsageDataCollector |
|
|
|
namespace ICSharpCode.UsageDataCollector |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
@ -25,7 +29,7 @@ namespace ICSharpCode.UsageDataCollector |
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This class is thread-safe.
|
|
|
|
/// This class is thread-safe.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class UsageDataSessionWriter : IDisposable |
|
|
|
public sealed class UsageDataSessionWriter : IDisposable |
|
|
|
{ |
|
|
|
{ |
|
|
|
readonly object lockObj = new object(); |
|
|
|
readonly object lockObj = new object(); |
|
|
|
SQLiteConnection connection; |
|
|
|
SQLiteConnection connection; |
|
|
|
@ -153,6 +157,19 @@ namespace ICSharpCode.UsageDataCollector |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Gets the default environment data.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public static UsageDataEnvironmentProperty[] GetDefaultEnvironmentData() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return new [] { |
|
|
|
|
|
|
|
new UsageDataEnvironmentProperty { Name = "platform", Value = Environment.OSVersion.Platform.ToString() }, |
|
|
|
|
|
|
|
new UsageDataEnvironmentProperty { Name = "osVersion", Value = Environment.OSVersion.Version.ToString() }, |
|
|
|
|
|
|
|
new UsageDataEnvironmentProperty { Name = "processorCount", Value = Environment.ProcessorCount.ToString() }, |
|
|
|
|
|
|
|
new UsageDataEnvironmentProperty { Name = "dotnetRuntime", Value = Environment.Version.ToString() } |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void StartSession() |
|
|
|
void StartSession() |
|
|
|
{ |
|
|
|
{ |
|
|
|
using (SQLiteTransaction transaction = this.connection.BeginTransaction()) { |
|
|
|
using (SQLiteTransaction transaction = this.connection.BeginTransaction()) { |
|
|
|
@ -161,10 +178,7 @@ namespace ICSharpCode.UsageDataCollector |
|
|
|
"SELECT last_insert_rowid();"; |
|
|
|
"SELECT last_insert_rowid();"; |
|
|
|
sessionID = (long)cmd.ExecuteScalar(); |
|
|
|
sessionID = (long)cmd.ExecuteScalar(); |
|
|
|
} |
|
|
|
} |
|
|
|
AddEnvironmentData("platform", Environment.OSVersion.Platform.ToString()); |
|
|
|
AddEnvironmentData(GetDefaultEnvironmentData()); |
|
|
|
AddEnvironmentData("osVersion", Environment.OSVersion.Version.ToString()); |
|
|
|
|
|
|
|
AddEnvironmentData("processorCount", Environment.ProcessorCount.ToString()); |
|
|
|
|
|
|
|
AddEnvironmentData("dotnetRuntime", Environment.Version.ToString()); |
|
|
|
|
|
|
|
transaction.Commit(); |
|
|
|
transaction.Commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -185,22 +199,26 @@ namespace ICSharpCode.UsageDataCollector |
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Adds environment data to the current session.
|
|
|
|
/// Adds environment data to the current session.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="name">Name of the data entry.</param>
|
|
|
|
public void AddEnvironmentData(IEnumerable<UsageDataEnvironmentProperty> properties) |
|
|
|
/// <param name="value">Value of the data entry.</param>
|
|
|
|
|
|
|
|
public void AddEnvironmentData(string name, string value) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
if (name == null) |
|
|
|
if (properties == null) |
|
|
|
throw new ArgumentNullException("name"); |
|
|
|
throw new ArgumentNullException("properties"); |
|
|
|
|
|
|
|
UsageDataEnvironmentProperty[] pArray = properties.ToArray(); |
|
|
|
lock (lockObj) { |
|
|
|
lock (lockObj) { |
|
|
|
if (isDisposed) |
|
|
|
if (isDisposed) |
|
|
|
throw new ObjectDisposedException(GetType().Name); |
|
|
|
throw new ObjectDisposedException(GetType().Name); |
|
|
|
using (SQLiteCommand cmd = this.connection.CreateCommand()) { |
|
|
|
using (SQLiteTransaction transaction = this.connection.BeginTransaction()) { |
|
|
|
cmd.CommandText = "INSERT INTO Environment (session, name, value)" + |
|
|
|
foreach (UsageDataEnvironmentProperty p in pArray) { |
|
|
|
" VALUES (?, ?, ?);"; |
|
|
|
using (SQLiteCommand cmd = this.connection.CreateCommand()) { |
|
|
|
cmd.Parameters.Add(new SQLiteParameter { Value = sessionID }); |
|
|
|
cmd.CommandText = "INSERT INTO Environment (session, name, value)" + |
|
|
|
cmd.Parameters.Add(new SQLiteParameter { Value = name }); |
|
|
|
" VALUES (?, ?, ?);"; |
|
|
|
cmd.Parameters.Add(new SQLiteParameter { Value = value }); |
|
|
|
cmd.Parameters.Add(new SQLiteParameter { Value = sessionID }); |
|
|
|
cmd.ExecuteNonQuery(); |
|
|
|
cmd.Parameters.Add(new SQLiteParameter { Value = p.Name }); |
|
|
|
|
|
|
|
cmd.Parameters.Add(new SQLiteParameter { Value = p.Value }); |
|
|
|
|
|
|
|
cmd.ExecuteNonQuery(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
transaction.Commit(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -482,6 +500,16 @@ namespace ICSharpCode.UsageDataCollector |
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public IncompatibleDatabaseException() {} |
|
|
|
public IncompatibleDatabaseException() {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creates a new IncompatibleDatabaseException instance.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public IncompatibleDatabaseException(string message) : base(message) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creates a new IncompatibleDatabaseException instance.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public IncompatibleDatabaseException(string message, Exception innerException) : base(message, innerException) {} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new IncompatibleDatabaseException instance.
|
|
|
|
/// Creates a new IncompatibleDatabaseException instance.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
@ -504,6 +532,7 @@ namespace ICSharpCode.UsageDataCollector |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
|
|
|
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] |
|
|
|
public override void GetObjectData(SerializationInfo info, StreamingContext context) |
|
|
|
public override void GetObjectData(SerializationInfo info, StreamingContext context) |
|
|
|
{ |
|
|
|
{ |
|
|
|
base.GetObjectData(info, context); |
|
|
|
base.GetObjectData(info, context); |
|
|
|
|