Browse Source

initial commit

Former-commit-id: 78afc616b46416cac5bc8bab9024b386039f944d
af/merge-core
JimBobSquarePants 13 years ago
parent
commit
4334aa1389
  1. 29
      src/ImageProcessor.Web/Caching/CachedImage.cs
  2. 10
      src/ImageProcessor.Web/Caching/DiskCache.cs
  3. 2
      src/ImageProcessor.Web/Caching/PersistantDictionary.cs
  4. 139
      src/ImageProcessor.Web/Caching/SQLContext.cs
  5. 14
      src/ImageProcessor.Web/ImageProcessor.Web.csproj
  6. 1
      src/ImageProcessor.Web/SQLite.cs.REMOVED.git-id
  7. 486
      src/ImageProcessor.Web/SQLiteAsync.cs
  8. 3
      src/ImageProcessor.Web/packages.config
  9. 160
      src/Test/Test/Web.config
  10. 1
      src/packages/Csharp-Sqlite.3.7.7.1/Csharp-Sqlite.3.7.7.1.nupkg.REMOVED.git-id
  11. 21
      src/packages/Csharp-Sqlite.3.7.7.1/Csharp-Sqlite.3.7.7.1.nuspec
  12. BIN
      src/packages/Csharp-Sqlite.3.7.7.1/lib/net20/Community.CsharpSqlite.SQLiteClient.dll
  13. 1
      src/packages/Csharp-Sqlite.3.7.7.1/lib/net20/Community.CsharpSqlite.dll.REMOVED.git-id
  14. BIN
      src/packages/Csharp-Sqlite.3.7.7.1/lib/net35/Community.CsharpSqlite.SQLiteClient.dll
  15. 1
      src/packages/Csharp-Sqlite.3.7.7.1/lib/net35/Community.CsharpSqlite.dll.REMOVED.git-id
  16. BIN
      src/packages/Csharp-Sqlite.3.7.7.1/lib/net40/Community.CsharpSqlite.SQLiteClient.dll
  17. 1
      src/packages/Csharp-Sqlite.3.7.7.1/lib/net40/Community.CsharpSqlite.dll.REMOVED.git-id
  18. 1
      src/packages/SQLitex64.1.0.66/SQLitex64.1.0.66.nupkg.REMOVED.git-id
  19. 23
      src/packages/SQLitex64.1.0.66/SQLitex64.1.0.66.nuspec
  20. 1
      src/packages/SQLitex64.1.0.66/lib/32/System.Data.SQLite.DLL.REMOVED.git-id
  21. 1
      src/packages/SQLitex64.1.0.66/lib/64/System.Data.SQLite.DLL.REMOVED.git-id
  22. 1
      src/packages/SQLitex64.1.0.66/lib/System.Data.SQLite.DLL.REMOVED.git-id
  23. 1
      src/packages/sqlite-net.1.0.7/content/SQLite.cs.REMOVED.git-id
  24. 486
      src/packages/sqlite-net.1.0.7/content/SQLiteAsync.cs
  25. BIN
      src/packages/sqlite-net.1.0.7/sqlite-net.1.0.7.nupkg
  26. 20
      src/packages/sqlite-net.1.0.7/sqlite-net.1.0.7.nuspec

29
src/ImageProcessor.Web/Caching/CachedImage.cs

@ -9,6 +9,9 @@ namespace ImageProcessor.Web.Caching
{
#region Using
using System;
using SQLite;
#endregion
/// <summary>
@ -16,28 +19,14 @@ namespace ImageProcessor.Web.Caching
/// </summary>
internal sealed class CachedImage
{
//[PrimaryKey, AutoIncrement]
//public int Id { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="CachedImage"/> class.
/// Gets or sets the key identifying the cached image.
/// </summary>
/// <param name="path">
/// The value of the cached image.
/// </param>
/// <param name="maxAge">
/// The max age of the cached image.
/// </param>
/// <param name="lastWriteTimeUtc">
/// The last write time of the cached image.
/// </param>
/// <param name="expiresTimeUtc">
/// The expires time.
/// </param>
public CachedImage(string path, int maxAge, DateTime lastWriteTimeUtc, DateTime expiresTimeUtc)
{
this.Path = path;
this.MaxAge = maxAge;
this.LastWriteTimeUtc = lastWriteTimeUtc;
this.ExpiresUtc = expiresTimeUtc;
}
[PrimaryKey]
internal string Key { get; set; }
/// <summary>
/// Gets or sets the value of the cached image.

10
src/ImageProcessor.Web/Caching/DiskCache.cs

@ -227,7 +227,15 @@ namespace ImageProcessor.Web.Caching
{
string key = Path.GetFileNameWithoutExtension(this.CachedPath);
DateTime expires = DateTime.UtcNow.AddDays(MaxFileCachedDuration).ToUniversalTime();
CachedImage cachedImage = new CachedImage(this.CachedPath, MaxFileCachedDuration, lastWriteTimeUtc, expires);
CachedImage cachedImage = new CachedImage
{
Key = key,
Path = this.CachedPath,
MaxAge = MaxFileCachedDuration,
LastWriteTimeUtc = lastWriteTimeUtc,
ExpiresUtc = expires
};
await PersistantDictionary.Instance.AddAsync(key, cachedImage);
}

2
src/ImageProcessor.Web/Caching/PersistantDictionary.cs

@ -130,7 +130,7 @@ namespace ImageProcessor.Web.Caching
return await SQLContext.RemoveImageAsync(key);
}
return await SQLContext.AddImageAsync(key, cachedImage);
return await SQLContext.AddImageAsync(cachedImage);
}
catch
{

139
src/ImageProcessor.Web/Caching/SQLContext.cs

@ -8,14 +8,17 @@
namespace ImageProcessor.Web.Caching
{
#region Using
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;
using System.Threading.Tasks;
using System.Web.Hosting;
using ImageProcessor.Web.Config;
using ImageProcessor.Web.Helpers;
using SQLite;
#endregion
/// <summary>
@ -37,57 +40,44 @@ namespace ImageProcessor.Web.Caching
/// <summary>
/// The connection string.
/// </summary>
private static readonly string ConnectionString = string.Format("Data Source={0};Version=3;", IndexLocation);
private static readonly string ConnectionString = IndexLocation;
#endregion
#region Methods
#region Internal
/// <summary>
/// Creates the database if it doesn't already exist.
/// </summary>
internal static void CreateDatabase()
{
if (!File.Exists(IndexLocation))
try
{
string absolutePath = HostingEnvironment.MapPath(VirtualCachePath);
if (absolutePath != null)
if (!File.Exists(IndexLocation))
{
DirectoryInfo directoryInfo = new DirectoryInfo(absolutePath);
string absolutePath = HostingEnvironment.MapPath(VirtualCachePath);
if (!directoryInfo.Exists)
if (absolutePath != null)
{
// Create the directory.
Directory.CreateDirectory(absolutePath);
}
}
SQLiteConnection.CreateFile(IndexLocation);
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
{
connection.Open();
DirectoryInfo directoryInfo = new DirectoryInfo(absolutePath);
using (SQLiteTransaction transaction = connection.BeginTransaction())
{
using (SQLiteCommand command = new SQLiteCommand(connection))
if (!directoryInfo.Exists)
{
command.CommandText = @"CREATE TABLE names
(Key TEXT,
Path TEXT,
MaxAge INTEGER,
LastWriteTimeUtc TEXT,
ExpiresUtc TEXT,
PRIMARY KEY (Key),
UNIQUE (Path));";
command.ExecuteNonQuery();
// Create the directory.
Directory.CreateDirectory(absolutePath);
}
}
transaction.Commit();
using (SQLiteConnection connection = new SQLiteConnection(IndexLocation))
{
connection.CreateTable<CachedImage>();
}
}
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
@ -104,25 +94,11 @@ namespace ImageProcessor.Web.Caching
{
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
{
connection.Open();
List<CachedImage> images = connection.Query<CachedImage>("SELECT * FROM CachedImage");
using (SQLiteCommand command = new SQLiteCommand(connection))
foreach (CachedImage cachedImage in images)
{
command.CommandText = "SELECT * FROM names;";
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string key = reader["Key"].ToString();
CachedImage image = new CachedImage(
reader["Path"].ToString(),
int.Parse(reader["MaxAge"].ToString()),
DateTime.Parse(reader["LastWriteTimeUtc"].ToString()).ToUniversalTime(),
DateTime.Parse(reader["ExpiresUtc"].ToString()).ToUniversalTime());
dictionary.Add(key, image);
}
dictionary.Add(cachedImage.Key, cachedImage);
}
}
@ -137,19 +113,16 @@ namespace ImageProcessor.Web.Caching
/// <summary>
/// Adds a cached image to the database.
/// </summary>
/// <param name="key">
/// The key for the cached image.
/// </param>
/// <param name="image">
/// The cached image to add.
/// </param>
/// <returns>
/// The true if the addition of the cached image is added; otherwise, false.
/// </returns>
internal static async Task<bool> AddImageAsync(string key, CachedImage image)
internal static async Task<bool> AddImageAsync(CachedImage image)
{
// Create Action delegate for AddImage.
return await TaskHelpers.Run(() => AddImage(key, image));
return await TaskHelpers.Run(() => AddImage(image));
}
/// <summary>
@ -169,48 +142,28 @@ namespace ImageProcessor.Web.Caching
#endregion
#region Private
/// <summary>
/// Adds a cached image to the database.
/// </summary>
/// <param name="key">
/// The key for the cached image.
/// </param>
/// <param name="image">
/// The cached image to add.
/// </param>
/// <returns>
/// The true if the addition of the cached image is added; otherwise, false.
/// </returns>
private static bool AddImage(string key, CachedImage image)
private static bool AddImage(CachedImage image)
{
try
{
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
{
connection.Open();
SQLiteConnection connection = new SQLiteConnection(ConnectionString);
using (SQLiteTransaction transaction = connection.BeginTransaction())
connection.RunInTransaction(() =>
{
using (SQLiteCommand command = new SQLiteCommand(connection))
{
command.CommandText = "INSERT INTO names VALUES(?, ?, ?, ?, ?)";
SQLiteParameter[] parameters = new[]
{
new SQLiteParameter("Key", key),
new SQLiteParameter("Path", image.Path),
new SQLiteParameter("MaxAge", image.MaxAge),
new SQLiteParameter("LastWriteTimeUtc", image.LastWriteTimeUtc),
new SQLiteParameter("ExpiresUtc", image.ExpiresUtc)
};
command.Parameters.AddRange(parameters);
command.ExecuteNonQuery();
}
transaction.Commit();
}
}
// Database calls inside the transaction
connection.Insert(image);
connection.Dispose();
});
return true;
}
@ -233,22 +186,14 @@ namespace ImageProcessor.Web.Caching
{
try
{
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString))
{
connection.Open();
SQLiteConnection connection = new SQLiteConnection(ConnectionString);
using (SQLiteTransaction transaction = connection.BeginTransaction())
{
using (SQLiteCommand command = new SQLiteCommand(connection))
{
command.CommandText = "DELETE FROM names WHERE key = @searchParam;";
command.Parameters.Add(new SQLiteParameter("searchParam", key));
command.ExecuteNonQuery();
}
transaction.Commit();
}
}
connection.RunInTransaction(() =>
{
// Database calls inside the transaction
connection.Delete<CachedImage>(key);
connection.Dispose();
});
return true;
}

14
src/ImageProcessor.Web/ImageProcessor.Web.csproj

@ -18,7 +18,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DefineConstants>TRACE;DEBUG;USE_CSHARP_SQLITE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@ -66,6 +66,12 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Community.CsharpSqlite">
<HintPath>..\packages\Csharp-Sqlite.3.7.7.1\lib\net40\Community.CsharpSqlite.dll</HintPath>
</Reference>
<Reference Include="Community.CsharpSqlite.SQLiteClient">
<HintPath>..\packages\Csharp-Sqlite.3.7.7.1\lib\net40\Community.CsharpSqlite.SQLiteClient.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Threading.Tasks">
<HintPath>..\packages\Microsoft.Bcl.Async.1.0.14-rc\lib\net40\Microsoft.Threading.Tasks.dll</HintPath>
</Reference>
@ -78,10 +84,6 @@
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SQLitex64.1.0.66\lib\32\System.Data.SQLite.DLL</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime">
@ -108,6 +110,8 @@
<Compile Include="HttpModules\ImageProcessingModule.cs" />
<Compile Include="ImageFactoryExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SQLite.cs" />
<Compile Include="SQLiteAsync.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ImageProcessor\ImageProcessor.csproj">

1
src/ImageProcessor.Web/SQLite.cs.REMOVED.git-id

@ -0,0 +1 @@
ce0491dcbe39702bf25fb616f76e1b149f670688

486
src/ImageProcessor.Web/SQLiteAsync.cs

@ -0,0 +1,486 @@
//
// Copyright (c) 2012 Krueger Systems, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace SQLite
{
public partial class SQLiteAsyncConnection
{
SQLiteConnectionString _connectionString;
public SQLiteAsyncConnection (string databasePath, bool storeDateTimeAsTicks = false)
{
_connectionString = new SQLiteConnectionString (databasePath, storeDateTimeAsTicks);
}
SQLiteConnectionWithLock GetConnection ()
{
return SQLiteConnectionPool.Shared.GetConnection (_connectionString);
}
public Task<CreateTablesResult> CreateTableAsync<T> ()
where T : new ()
{
return CreateTablesAsync (typeof (T));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2> ()
where T : new ()
where T2 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3> ()
where T : new ()
where T2 : new ()
where T3 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4> ()
where T : new ()
where T2 : new ()
where T3 : new ()
where T4 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3), typeof (T4));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> ()
where T : new ()
where T2 : new ()
where T3 : new ()
where T4 : new ()
where T5 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3), typeof (T4), typeof (T5));
}
public Task<CreateTablesResult> CreateTablesAsync (params Type[] types)
{
return Task.Factory.StartNew (() => {
CreateTablesResult result = new CreateTablesResult ();
var conn = GetConnection ();
using (conn.Lock ()) {
foreach (Type type in types) {
int aResult = conn.CreateTable (type);
result.Results[type] = aResult;
}
}
return result;
});
}
public Task<int> DropTableAsync<T> ()
where T : new ()
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.DropTable<T> ();
}
});
}
public Task<int> InsertAsync (object item)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Insert (item);
}
});
}
public Task<int> UpdateAsync (object item)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Update (item);
}
});
}
public Task<int> DeleteAsync (object item)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Delete (item);
}
});
}
public Task<T> GetAsync<T>(object pk)
where T : new()
{
return Task.Factory.StartNew(() =>
{
var conn = GetConnection();
using (conn.Lock())
{
return conn.Get<T>(pk);
}
});
}
public Task<T> FindAsync<T> (object pk)
where T : new ()
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Find<T> (pk);
}
});
}
public Task<T> GetAsync<T> (Expression<Func<T, bool>> predicate)
where T : new()
{
return Task.Factory.StartNew(() =>
{
var conn = GetConnection();
using (conn.Lock())
{
return conn.Get<T> (predicate);
}
});
}
public Task<T> FindAsync<T> (Expression<Func<T, bool>> predicate)
where T : new ()
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Find<T> (predicate);
}
});
}
public Task<int> ExecuteAsync (string query, params object[] args)
{
return Task<int>.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Execute (query, args);
}
});
}
public Task<int> InsertAllAsync (IEnumerable items)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.InsertAll (items);
}
});
}
[Obsolete("Will cause a deadlock if any call in action ends up in a different thread. Use RunInTransactionAsync(Action<SQLiteConnection>) instead.")]
public Task RunInTransactionAsync (Action<SQLiteAsyncConnection> action)
{
return Task.Factory.StartNew (() => {
var conn = this.GetConnection ();
using (conn.Lock ()) {
conn.BeginTransaction ();
try {
action (this);
conn.Commit ();
}
catch (Exception) {
conn.Rollback ();
throw;
}
}
});
}
public Task RunInTransactionAsync(Action<SQLiteConnection> action)
{
return Task.Factory.StartNew(() =>
{
var conn = this.GetConnection();
using (conn.Lock())
{
conn.BeginTransaction();
try
{
action(conn);
conn.Commit();
}
catch (Exception)
{
conn.Rollback();
throw;
}
}
});
}
public AsyncTableQuery<T> Table<T> ()
where T : new ()
{
//
// This isn't async as the underlying connection doesn't go out to the database
// until the query is performed. The Async methods are on the query iteself.
//
var conn = GetConnection ();
return new AsyncTableQuery<T> (conn.Table<T> ());
}
public Task<T> ExecuteScalarAsync<T> (string sql, params object[] args)
{
return Task<T>.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
var command = conn.CreateCommand (sql, args);
return command.ExecuteScalar<T> ();
}
});
}
public Task<List<T>> QueryAsync<T> (string sql, params object[] args)
where T : new ()
{
return Task<List<T>>.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Query<T> (sql, args);
}
});
}
}
//
// TODO: Bind to AsyncConnection.GetConnection instead so that delayed
// execution can still work after a Pool.Reset.
//
public class AsyncTableQuery<T>
where T : new ()
{
TableQuery<T> _innerQuery;
public AsyncTableQuery (TableQuery<T> innerQuery)
{
_innerQuery = innerQuery;
}
public AsyncTableQuery<T> Where (Expression<Func<T, bool>> predExpr)
{
return new AsyncTableQuery<T> (_innerQuery.Where (predExpr));
}
public AsyncTableQuery<T> Skip (int n)
{
return new AsyncTableQuery<T> (_innerQuery.Skip (n));
}
public AsyncTableQuery<T> Take (int n)
{
return new AsyncTableQuery<T> (_innerQuery.Take (n));
}
public AsyncTableQuery<T> OrderBy<U> (Expression<Func<T, U>> orderExpr)
{
return new AsyncTableQuery<T> (_innerQuery.OrderBy<U> (orderExpr));
}
public AsyncTableQuery<T> OrderByDescending<U> (Expression<Func<T, U>> orderExpr)
{
return new AsyncTableQuery<T> (_innerQuery.OrderByDescending<U> (orderExpr));
}
public Task<List<T>> ToListAsync ()
{
return Task.Factory.StartNew (() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.ToList ();
}
});
}
public Task<int> CountAsync ()
{
return Task.Factory.StartNew (() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.Count ();
}
});
}
public Task<T> ElementAtAsync (int index)
{
return Task.Factory.StartNew (() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.ElementAt (index);
}
});
}
public Task<T> FirstAsync ()
{
return Task<T>.Factory.StartNew(() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.First ();
}
});
}
public Task<T> FirstOrDefaultAsync ()
{
return Task<T>.Factory.StartNew(() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.FirstOrDefault ();
}
});
}
}
public class CreateTablesResult
{
public Dictionary<Type, int> Results { get; private set; }
internal CreateTablesResult ()
{
this.Results = new Dictionary<Type, int> ();
}
}
class SQLiteConnectionPool
{
class Entry
{
public SQLiteConnectionString ConnectionString { get; private set; }
public SQLiteConnectionWithLock Connection { get; private set; }
public Entry (SQLiteConnectionString connectionString)
{
ConnectionString = connectionString;
Connection = new SQLiteConnectionWithLock (connectionString);
}
public void OnApplicationSuspended ()
{
Connection.Dispose ();
Connection = null;
}
}
readonly Dictionary<string, Entry> _entries = new Dictionary<string, Entry> ();
readonly object _entriesLock = new object ();
static readonly SQLiteConnectionPool _shared = new SQLiteConnectionPool ();
/// <summary>
/// Gets the singleton instance of the connection tool.
/// </summary>
public static SQLiteConnectionPool Shared
{
get
{
return _shared;
}
}
public SQLiteConnectionWithLock GetConnection (SQLiteConnectionString connectionString)
{
lock (_entriesLock) {
Entry entry;
string key = connectionString.ConnectionString;
if (!_entries.TryGetValue (key, out entry)) {
entry = new Entry (connectionString);
_entries[key] = entry;
}
return entry.Connection;
}
}
/// <summary>
/// Closes all connections managed by this pool.
/// </summary>
public void Reset ()
{
lock (_entriesLock) {
foreach (var entry in _entries.Values) {
entry.OnApplicationSuspended ();
}
_entries.Clear ();
}
}
/// <summary>
/// Call this method when the application is suspended.
/// </summary>
/// <remarks>Behaviour here is to close any open connections.</remarks>
public void ApplicationSuspended ()
{
Reset ();
}
}
class SQLiteConnectionWithLock : SQLiteConnection
{
readonly object _lockPoint = new object ();
public SQLiteConnectionWithLock (SQLiteConnectionString connectionString)
: base (connectionString.DatabasePath, connectionString.StoreDateTimeAsTicks)
{
}
public IDisposable Lock ()
{
return new LockWrapper (_lockPoint);
}
private class LockWrapper : IDisposable
{
object _lockPoint;
public LockWrapper (object lockPoint)
{
_lockPoint = lockPoint;
Monitor.Enter (_lockPoint);
}
public void Dispose ()
{
Monitor.Exit (_lockPoint);
}
}
}
}

3
src/ImageProcessor.Web/packages.config

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Csharp-Sqlite" version="3.7.7.1" targetFramework="net40" />
<package id="Microsoft.Bcl" version="1.0.16-rc" targetFramework="net40" />
<package id="Microsoft.Bcl.Async" version="1.0.14-rc" targetFramework="net40" />
<package id="Microsoft.Bcl.Build" version="1.0.0-rc" targetFramework="net40" />
<package id="SQLitex64" version="1.0.66" targetFramework="net40" />
<package id="sqlite-net" version="1.0.7" targetFramework="net40" />
</packages>

160
src/Test/Test/Web.config

@ -4,84 +4,84 @@
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<!-- Configuration section-handler declaration area. -->
<configSections>
<sectionGroup name="imageProcessor">
<section name="security" requirePermission="false" type="ImageProcessor.Web.Config.ImageSecuritySection, ImageProcessor.Web" />
<section name="processing" requirePermission="false" type="ImageProcessor.Web.Config.ImageProcessingSection, ImageProcessor.Web" />
<section name="cache" requirePermission="false" type="ImageProcessor.Web.Config.ImageCacheSection, ImageProcessor.Web" />
</sectionGroup>
</configSections>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpModules>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web" />
</httpModules>
<!--Set the trust level.-->
<!--<trust level="Medium"/>-->
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<imageProcessor>
<security allowRemoteDownloads="true" timeout="300000" maxBytes="524288" remotePrefix="/remote.axd">
<whiteList>
<add url="http://images.mymovies.net" />
</whiteList>
</security>
<cache virtualPath="~/cache" maxDays="56" />
<processing>
<plugins>
<plugin name="Resize">
<settings>
<setting key="MaxWidth" value="1024" />
<setting key="MaxHeight" value="768" />
</settings>
</plugin>
</plugins>
</processing>
</imageProcessor>
<!-- Configuration section-handler declaration area. -->
<configSections>
<sectionGroup name="imageProcessor">
<section name="security" requirePermission="false" type="ImageProcessor.Web.Config.ImageSecuritySection, ImageProcessor.Web" />
<section name="processing" requirePermission="false" type="ImageProcessor.Web.Config.ImageProcessingSection, ImageProcessor.Web" />
<section name="cache" requirePermission="false" type="ImageProcessor.Web.Config.ImageCacheSection, ImageProcessor.Web" />
</sectionGroup>
</configSections>
<appSettings>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<httpModules>
<add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web" />
</httpModules>
<!--Set the trust level.-->
<!--<trust level="Medium"/>-->
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.5.16.0" newVersion="2.5.16.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<imageProcessor>
<security allowRemoteDownloads="true" timeout="300000" maxBytes="524288" remotePrefix="/remote.axd">
<whiteList>
<add url="http://images.mymovies.net" />
</whiteList>
</security>
<cache virtualPath="~/cache" maxDays="56" />
<processing>
<plugins>
<plugin name="Resize">
<settings>
<setting key="MaxWidth" value="1024" />
<setting key="MaxHeight" value="768" />
</settings>
</plugin>
</plugins>
</processing>
</imageProcessor>
</configuration>

1
src/packages/Csharp-Sqlite.3.7.7.1/Csharp-Sqlite.3.7.7.1.nupkg.REMOVED.git-id

@ -0,0 +1 @@
81fffff68e71d82a09d8c6a345ce69410f351786

21
src/packages/Csharp-Sqlite.3.7.7.1/Csharp-Sqlite.3.7.7.1.nuspec

@ -0,0 +1,21 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>Csharp-Sqlite</id>
<version>3.7.7.1</version>
<title>C#-SqLite Unofficial Package</title>
<authors>noah.hart</authors>
<owners>noah.hart</owners>
<projectUrl>http://code.google.com/p/csharp-sqlite/</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>C#-SQLite is an independent reimplementation of the SQLite software library version 3.7.7.1.</description>
<releaseNotes />
<copyright />
<language />
<tags>Sqlite</tags>
<references>
<reference file="Community.CsharpSqlite.dll" />
<reference file="Community.CsharpSqlite.SQLiteClient.dll" />
</references>
</metadata>
</package>

BIN
src/packages/Csharp-Sqlite.3.7.7.1/lib/net20/Community.CsharpSqlite.SQLiteClient.dll

Binary file not shown.

1
src/packages/Csharp-Sqlite.3.7.7.1/lib/net20/Community.CsharpSqlite.dll.REMOVED.git-id

@ -0,0 +1 @@
703605507a2c2a90fa7b826aaf2cf7c78a7243b7

BIN
src/packages/Csharp-Sqlite.3.7.7.1/lib/net35/Community.CsharpSqlite.SQLiteClient.dll

Binary file not shown.

1
src/packages/Csharp-Sqlite.3.7.7.1/lib/net35/Community.CsharpSqlite.dll.REMOVED.git-id

@ -0,0 +1 @@
2e6a85ddf4ce868ed48de14c2be21ee94f689b78

BIN
src/packages/Csharp-Sqlite.3.7.7.1/lib/net40/Community.CsharpSqlite.SQLiteClient.dll

Binary file not shown.

1
src/packages/Csharp-Sqlite.3.7.7.1/lib/net40/Community.CsharpSqlite.dll.REMOVED.git-id

@ -0,0 +1 @@
ab181a987d0059a31c26ee3891a01c40d43019a0

1
src/packages/SQLitex64.1.0.66/SQLitex64.1.0.66.nupkg.REMOVED.git-id

@ -1 +0,0 @@
aff828512d1afca48fa5d6824429359562199078

23
src/packages/SQLitex64.1.0.66/SQLitex64.1.0.66.nuspec

@ -1,23 +0,0 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>SQLitex64</id>
<version>1.0.66</version>
<title>SQLitex64</title>
<authors>Amir Barylko</authors>
<owners>Amir Barylko</owners>
<projectUrl>http://www.sqlite.org/</projectUrl>
<iconUrl>http://www.sqlite.org/images/sqlite370_banner.gif</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Provides both (32 and 64 bit) assemblies needed to use SQLite.
The current package only provides 32 bit.</description>
<summary>SQLite 64 bit and 32 bit assemblies</summary>
<releaseNotes />
<copyright />
<language />
<tags>SQLite</tags>
<references>
<reference file="System.Data.SQLite.DLL" />
</references>
</metadata>
</package>

1
src/packages/SQLitex64.1.0.66/lib/32/System.Data.SQLite.DLL.REMOVED.git-id

@ -1 +0,0 @@
aa398bbec1a567de55f984959d200900b794372a

1
src/packages/SQLitex64.1.0.66/lib/64/System.Data.SQLite.DLL.REMOVED.git-id

@ -1 +0,0 @@
6f07d5e7ab41a0f791f07d5407f10edb4b716a02

1
src/packages/SQLitex64.1.0.66/lib/System.Data.SQLite.DLL.REMOVED.git-id

@ -1 +0,0 @@
aa398bbec1a567de55f984959d200900b794372a

1
src/packages/sqlite-net.1.0.7/content/SQLite.cs.REMOVED.git-id

@ -0,0 +1 @@
d2856e3733eb6c7d85057c37ae415e54c8bf2386

486
src/packages/sqlite-net.1.0.7/content/SQLiteAsync.cs

@ -0,0 +1,486 @@
//
// Copyright (c) 2012 Krueger Systems, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
namespace SQLite
{
public partial class SQLiteAsyncConnection
{
SQLiteConnectionString _connectionString;
public SQLiteAsyncConnection (string databasePath, bool storeDateTimeAsTicks = false)
{
_connectionString = new SQLiteConnectionString (databasePath, storeDateTimeAsTicks);
}
SQLiteConnectionWithLock GetConnection ()
{
return SQLiteConnectionPool.Shared.GetConnection (_connectionString);
}
public Task<CreateTablesResult> CreateTableAsync<T> ()
where T : new ()
{
return CreateTablesAsync (typeof (T));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2> ()
where T : new ()
where T2 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3> ()
where T : new ()
where T2 : new ()
where T3 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4> ()
where T : new ()
where T2 : new ()
where T3 : new ()
where T4 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3), typeof (T4));
}
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> ()
where T : new ()
where T2 : new ()
where T3 : new ()
where T4 : new ()
where T5 : new ()
{
return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3), typeof (T4), typeof (T5));
}
public Task<CreateTablesResult> CreateTablesAsync (params Type[] types)
{
return Task.Factory.StartNew (() => {
CreateTablesResult result = new CreateTablesResult ();
var conn = GetConnection ();
using (conn.Lock ()) {
foreach (Type type in types) {
int aResult = conn.CreateTable (type);
result.Results[type] = aResult;
}
}
return result;
});
}
public Task<int> DropTableAsync<T> ()
where T : new ()
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.DropTable<T> ();
}
});
}
public Task<int> InsertAsync (object item)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Insert (item);
}
});
}
public Task<int> UpdateAsync (object item)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Update (item);
}
});
}
public Task<int> DeleteAsync (object item)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Delete (item);
}
});
}
public Task<T> GetAsync<T>(object pk)
where T : new()
{
return Task.Factory.StartNew(() =>
{
var conn = GetConnection();
using (conn.Lock())
{
return conn.Get<T>(pk);
}
});
}
public Task<T> FindAsync<T> (object pk)
where T : new ()
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Find<T> (pk);
}
});
}
public Task<T> GetAsync<T> (Expression<Func<T, bool>> predicate)
where T : new()
{
return Task.Factory.StartNew(() =>
{
var conn = GetConnection();
using (conn.Lock())
{
return conn.Get<T> (predicate);
}
});
}
public Task<T> FindAsync<T> (Expression<Func<T, bool>> predicate)
where T : new ()
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Find<T> (predicate);
}
});
}
public Task<int> ExecuteAsync (string query, params object[] args)
{
return Task<int>.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Execute (query, args);
}
});
}
public Task<int> InsertAllAsync (IEnumerable items)
{
return Task.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.InsertAll (items);
}
});
}
[Obsolete("Will cause a deadlock if any call in action ends up in a different thread. Use RunInTransactionAsync(Action<SQLiteConnection>) instead.")]
public Task RunInTransactionAsync (Action<SQLiteAsyncConnection> action)
{
return Task.Factory.StartNew (() => {
var conn = this.GetConnection ();
using (conn.Lock ()) {
conn.BeginTransaction ();
try {
action (this);
conn.Commit ();
}
catch (Exception) {
conn.Rollback ();
throw;
}
}
});
}
public Task RunInTransactionAsync(Action<SQLiteConnection> action)
{
return Task.Factory.StartNew(() =>
{
var conn = this.GetConnection();
using (conn.Lock())
{
conn.BeginTransaction();
try
{
action(conn);
conn.Commit();
}
catch (Exception)
{
conn.Rollback();
throw;
}
}
});
}
public AsyncTableQuery<T> Table<T> ()
where T : new ()
{
//
// This isn't async as the underlying connection doesn't go out to the database
// until the query is performed. The Async methods are on the query iteself.
//
var conn = GetConnection ();
return new AsyncTableQuery<T> (conn.Table<T> ());
}
public Task<T> ExecuteScalarAsync<T> (string sql, params object[] args)
{
return Task<T>.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
var command = conn.CreateCommand (sql, args);
return command.ExecuteScalar<T> ();
}
});
}
public Task<List<T>> QueryAsync<T> (string sql, params object[] args)
where T : new ()
{
return Task<List<T>>.Factory.StartNew (() => {
var conn = GetConnection ();
using (conn.Lock ()) {
return conn.Query<T> (sql, args);
}
});
}
}
//
// TODO: Bind to AsyncConnection.GetConnection instead so that delayed
// execution can still work after a Pool.Reset.
//
public class AsyncTableQuery<T>
where T : new ()
{
TableQuery<T> _innerQuery;
public AsyncTableQuery (TableQuery<T> innerQuery)
{
_innerQuery = innerQuery;
}
public AsyncTableQuery<T> Where (Expression<Func<T, bool>> predExpr)
{
return new AsyncTableQuery<T> (_innerQuery.Where (predExpr));
}
public AsyncTableQuery<T> Skip (int n)
{
return new AsyncTableQuery<T> (_innerQuery.Skip (n));
}
public AsyncTableQuery<T> Take (int n)
{
return new AsyncTableQuery<T> (_innerQuery.Take (n));
}
public AsyncTableQuery<T> OrderBy<U> (Expression<Func<T, U>> orderExpr)
{
return new AsyncTableQuery<T> (_innerQuery.OrderBy<U> (orderExpr));
}
public AsyncTableQuery<T> OrderByDescending<U> (Expression<Func<T, U>> orderExpr)
{
return new AsyncTableQuery<T> (_innerQuery.OrderByDescending<U> (orderExpr));
}
public Task<List<T>> ToListAsync ()
{
return Task.Factory.StartNew (() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.ToList ();
}
});
}
public Task<int> CountAsync ()
{
return Task.Factory.StartNew (() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.Count ();
}
});
}
public Task<T> ElementAtAsync (int index)
{
return Task.Factory.StartNew (() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.ElementAt (index);
}
});
}
public Task<T> FirstAsync ()
{
return Task<T>.Factory.StartNew(() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.First ();
}
});
}
public Task<T> FirstOrDefaultAsync ()
{
return Task<T>.Factory.StartNew(() => {
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock ()) {
return _innerQuery.FirstOrDefault ();
}
});
}
}
public class CreateTablesResult
{
public Dictionary<Type, int> Results { get; private set; }
internal CreateTablesResult ()
{
this.Results = new Dictionary<Type, int> ();
}
}
class SQLiteConnectionPool
{
class Entry
{
public SQLiteConnectionString ConnectionString { get; private set; }
public SQLiteConnectionWithLock Connection { get; private set; }
public Entry (SQLiteConnectionString connectionString)
{
ConnectionString = connectionString;
Connection = new SQLiteConnectionWithLock (connectionString);
}
public void OnApplicationSuspended ()
{
Connection.Dispose ();
Connection = null;
}
}
readonly Dictionary<string, Entry> _entries = new Dictionary<string, Entry> ();
readonly object _entriesLock = new object ();
static readonly SQLiteConnectionPool _shared = new SQLiteConnectionPool ();
/// <summary>
/// Gets the singleton instance of the connection tool.
/// </summary>
public static SQLiteConnectionPool Shared
{
get
{
return _shared;
}
}
public SQLiteConnectionWithLock GetConnection (SQLiteConnectionString connectionString)
{
lock (_entriesLock) {
Entry entry;
string key = connectionString.ConnectionString;
if (!_entries.TryGetValue (key, out entry)) {
entry = new Entry (connectionString);
_entries[key] = entry;
}
return entry.Connection;
}
}
/// <summary>
/// Closes all connections managed by this pool.
/// </summary>
public void Reset ()
{
lock (_entriesLock) {
foreach (var entry in _entries.Values) {
entry.OnApplicationSuspended ();
}
_entries.Clear ();
}
}
/// <summary>
/// Call this method when the application is suspended.
/// </summary>
/// <remarks>Behaviour here is to close any open connections.</remarks>
public void ApplicationSuspended ()
{
Reset ();
}
}
class SQLiteConnectionWithLock : SQLiteConnection
{
readonly object _lockPoint = new object ();
public SQLiteConnectionWithLock (SQLiteConnectionString connectionString)
: base (connectionString.DatabasePath, connectionString.StoreDateTimeAsTicks)
{
}
public IDisposable Lock ()
{
return new LockWrapper (_lockPoint);
}
private class LockWrapper : IDisposable
{
object _lockPoint;
public LockWrapper (object lockPoint)
{
_lockPoint = lockPoint;
Monitor.Enter (_lockPoint);
}
public void Dispose ()
{
Monitor.Exit (_lockPoint);
}
}
}
}

BIN
src/packages/sqlite-net.1.0.7/sqlite-net.1.0.7.nupkg

Binary file not shown.

20
src/packages/sqlite-net.1.0.7/sqlite-net.1.0.7.nuspec

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>sqlite-net</id>
<version>1.0.7</version>
<title>sqlite-net</title>
<authors>Frank Krueger</authors>
<owners>Frank Krueger</owners>
<licenseUrl>https://github.com/praeclarum/sqlite-net/blob/master/license.md</licenseUrl>
<projectUrl>https://github.com/praeclarum/sqlite-net</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>sqlite-net is an open source, minimal library to allow .NET and Mono applications to store data in SQLite databases. It is written in C# 3.0 and is meant to be simply compiled in with your projects. It was first designed to work with MonoTouch on the iPhone, but should work in any other CLI environment.</description>
<summary>A .NET client library to access SQLite embedded database files in a LINQ manner.</summary>
<releaseNotes>v1.0.7: Update with commits through 06-FEB-2013.</releaseNotes>
<copyright />
<language />
<tags>sqlite sql monotouch database metro winrt</tags>
<references />
</metadata>
</package>
Loading…
Cancel
Save