Browse Source

Merge remote-tracking branch 'origin/dev'

Former-commit-id: 412def30749a89c6d6686f830a218809c8271f38
af/merge-core
James South 13 years ago
parent
commit
c37359ee99
  1. 12
      src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs
  2. 4
      src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs
  3. 1
      src/Nuget/ImageProcessor.Web.2.3.0.1.nupkg.REMOVED.git-id
  4. 2
      src/packages/sqlite-net.1.0.7/content/SQLite.cs.REMOVED.git-id
  5. 839
      src/packages/sqlite-net.1.0.7/content/SQLiteAsync.cs

12
src/ImageProcessor.Web/NET45/HttpModules/ImageProcessingModule.cs

@ -167,7 +167,9 @@ namespace ImageProcessor.Web.HttpModules
private async Task ProcessImageAsync(HttpContext context) private async Task ProcessImageAsync(HttpContext context)
{ {
HttpRequest request = context.Request; HttpRequest request = context.Request;
bool isRemote = request.Path.Equals(RemotePrefix, StringComparison.OrdinalIgnoreCase);
// Fixes issue 10.
bool isRemote = request.Path.EndsWith(RemotePrefix, StringComparison.OrdinalIgnoreCase);
string requestPath = string.Empty; string requestPath = string.Empty;
string queryString = string.Empty; string queryString = string.Empty;
@ -176,8 +178,14 @@ namespace ImageProcessor.Web.HttpModules
// We need to split the querystring to get the actual values we want. // We need to split the querystring to get the actual values we want.
string urlDecode = HttpUtility.UrlDecode(request.QueryString.ToString()); string urlDecode = HttpUtility.UrlDecode(request.QueryString.ToString());
if (urlDecode != null) if (!string.IsNullOrWhiteSpace(urlDecode))
{ {
// UrlDecode seems to mess up in some circumstance.
if (urlDecode.IndexOf("://", StringComparison.OrdinalIgnoreCase) == -1)
{
urlDecode = urlDecode.Replace(":/", "://");
}
string[] paths = urlDecode.Split('?'); string[] paths = urlDecode.Split('?');
requestPath = paths[0]; requestPath = paths[0];

4
src/ImageProcessor.Web/NET45/Properties/AssemblyInfo.cs

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("2.3.0.0")] [assembly: AssemblyVersion("2.3.0.1")]
[assembly: AssemblyFileVersion("2.3.0.0")] [assembly: AssemblyFileVersion("2.3.0.1")]

1
src/Nuget/ImageProcessor.Web.2.3.0.1.nupkg.REMOVED.git-id

@ -0,0 +1 @@
8a839fc32a168bcddd1bd9043d64e9502bab4e99

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

@ -1 +1 @@
86139d135bd91c43d8ffe8808f0f04975fd22a82 d2856e3733eb6c7d85057c37ae415e54c8bf2386

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

@ -30,126 +30,115 @@ using System.Threading.Tasks;
namespace SQLite namespace SQLite
{ {
public partial class SQLiteAsyncConnection public partial class SQLiteAsyncConnection
{ {
SQLiteConnectionString _connectionString; SQLiteConnectionString _connectionString;
public SQLiteAsyncConnection(string databasePath, bool storeDateTimeAsTicks = false) public SQLiteAsyncConnection (string databasePath, bool storeDateTimeAsTicks = false)
{ {
_connectionString = new SQLiteConnectionString(databasePath, storeDateTimeAsTicks); _connectionString = new SQLiteConnectionString (databasePath, storeDateTimeAsTicks);
} }
SQLiteConnectionWithLock GetConnection() SQLiteConnectionWithLock GetConnection ()
{ {
return SQLiteConnectionPool.Shared.GetConnection(_connectionString); return SQLiteConnectionPool.Shared.GetConnection (_connectionString);
} }
public Task<CreateTablesResult> CreateTableAsync<T>() public Task<CreateTablesResult> CreateTableAsync<T> ()
where T : new() where T : new ()
{ {
return CreateTablesAsync(typeof(T)); return CreateTablesAsync (typeof (T));
} }
public Task<CreateTablesResult> CreateTablesAsync<T, T2>() public Task<CreateTablesResult> CreateTablesAsync<T, T2> ()
where T : new() where T : new ()
where T2 : new() where T2 : new ()
{ {
return CreateTablesAsync(typeof(T), typeof(T2)); return CreateTablesAsync (typeof (T), typeof (T2));
} }
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3>() public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3> ()
where T : new() where T : new ()
where T2 : new() where T2 : new ()
where T3 : new() where T3 : new ()
{ {
return CreateTablesAsync(typeof(T), typeof(T2), typeof(T3)); return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3));
} }
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4>() public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4> ()
where T : new() where T : new ()
where T2 : new() where T2 : new ()
where T3 : new() where T3 : new ()
where T4 : new() where T4 : new ()
{ {
return CreateTablesAsync(typeof(T), typeof(T2), typeof(T3), typeof(T4)); return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3), typeof (T4));
} }
public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5>() public Task<CreateTablesResult> CreateTablesAsync<T, T2, T3, T4, T5> ()
where T : new() where T : new ()
where T2 : new() where T2 : new ()
where T3 : new() where T3 : new ()
where T4 : new() where T4 : new ()
where T5 : new() where T5 : new ()
{ {
return CreateTablesAsync(typeof(T), typeof(T2), typeof(T3), typeof(T4), typeof(T5)); return CreateTablesAsync (typeof (T), typeof (T2), typeof (T3), typeof (T4), typeof (T5));
} }
public Task<CreateTablesResult> CreateTablesAsync(params Type[] types) public Task<CreateTablesResult> CreateTablesAsync (params Type[] types)
{ {
return Task.Factory.StartNew(() => return Task.Factory.StartNew (() => {
{ CreateTablesResult result = new CreateTablesResult ();
CreateTablesResult result = new CreateTablesResult(); var conn = GetConnection ();
var conn = GetConnection(); using (conn.Lock ()) {
using (conn.Lock()) foreach (Type type in types) {
{ int aResult = conn.CreateTable (type);
foreach (Type type in types) result.Results[type] = aResult;
{ }
int aResult = conn.CreateTable(type); }
result.Results[type] = aResult; return result;
} });
} }
return result;
}); public Task<int> DropTableAsync<T> ()
} where T : new ()
{
public Task<int> DropTableAsync<T>() return Task.Factory.StartNew (() => {
where T : new() var conn = GetConnection ();
{ using (conn.Lock ()) {
return Task.Factory.StartNew(() => return conn.DropTable<T> ();
{ }
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 ()) {
public Task<int> InsertAsync(object item) return conn.Insert (item);
{ }
return Task.Factory.StartNew(() => });
{ }
var conn = GetConnection();
using (conn.Lock()) public Task<int> UpdateAsync (object item)
{ {
return conn.Insert(item); return Task.Factory.StartNew (() => {
} var conn = GetConnection ();
}); using (conn.Lock ()) {
} return conn.Update (item);
}
public Task<int> UpdateAsync(object item) });
{ }
return Task.Factory.StartNew(() =>
{ public Task<int> DeleteAsync (object item)
var conn = GetConnection(); {
using (conn.Lock()) return Task.Factory.StartNew (() => {
{ var conn = GetConnection ();
return conn.Update(item); using (conn.Lock ()) {
} return conn.Delete (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) public Task<T> GetAsync<T>(object pk)
where T : new() where T : new()
@ -164,20 +153,18 @@ namespace SQLite
}); });
} }
public Task<T> FindAsync<T>(object pk) public Task<T> FindAsync<T> (object pk)
where T : new() where T : new ()
{ {
return Task.Factory.StartNew(() => return Task.Factory.StartNew (() => {
{ var conn = GetConnection ();
var conn = GetConnection(); using (conn.Lock ()) {
using (conn.Lock()) return conn.Find<T> (pk);
{ }
return conn.Find<T>(pk); });
} }
});
}
public Task<T> GetAsync<T>(Expression<Func<T, bool>> predicate) public Task<T> GetAsync<T> (Expression<Func<T, bool>> predicate)
where T : new() where T : new()
{ {
return Task.Factory.StartNew(() => return Task.Factory.StartNew(() =>
@ -185,70 +172,60 @@ namespace SQLite
var conn = GetConnection(); var conn = GetConnection();
using (conn.Lock()) using (conn.Lock())
{ {
return conn.Get<T>(predicate); return conn.Get<T> (predicate);
} }
}); });
} }
public Task<T> FindAsync<T>(Expression<Func<T, bool>> predicate) public Task<T> FindAsync<T> (Expression<Func<T, bool>> predicate)
where T : new() where T : new ()
{ {
return Task.Factory.StartNew(() => return Task.Factory.StartNew (() => {
{ var conn = GetConnection ();
var conn = GetConnection(); using (conn.Lock ()) {
using (conn.Lock()) return conn.Find<T> (predicate);
{ }
return conn.Find<T>(predicate); });
} }
});
} public Task<int> ExecuteAsync (string query, params object[] args)
{
public Task<int> ExecuteAsync(string query, params object[] args) return Task<int>.Factory.StartNew (() => {
{ var conn = GetConnection ();
return Task<int>.Factory.StartNew(() => using (conn.Lock ()) {
{ return conn.Execute (query, args);
var conn = GetConnection(); }
using (conn.Lock()) });
{ }
return conn.Execute(query, args);
} public Task<int> InsertAllAsync (IEnumerable items)
}); {
} return Task.Factory.StartNew (() => {
var conn = GetConnection ();
public Task<int> InsertAllAsync(IEnumerable items) using (conn.Lock ()) {
{ return conn.InsertAll (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.")] [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) public Task RunInTransactionAsync (Action<SQLiteAsyncConnection> action)
{ {
return Task.Factory.StartNew(() => return Task.Factory.StartNew (() => {
{ var conn = this.GetConnection ();
var conn = this.GetConnection(); using (conn.Lock ()) {
using (conn.Lock()) conn.BeginTransaction ();
{ try {
conn.BeginTransaction(); action (this);
try conn.Commit ();
{ }
action(this); catch (Exception) {
conn.Commit(); conn.Rollback ();
} throw;
catch (Exception) }
{ }
conn.Rollback(); });
throw; }
}
}
});
}
public Task RunInTransactionAsync(Action<SQLiteConnection> action) public Task RunInTransactionAsync(Action<SQLiteConnection> action)
{ {
@ -272,256 +249,238 @@ namespace SQLite
}); });
} }
public AsyncTableQuery<T> Table<T>() public AsyncTableQuery<T> Table<T> ()
where T : new() where T : new ()
{ {
// //
// This isn't async as the underlying connection doesn't go out to the database // 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. // until the query is performed. The Async methods are on the query iteself.
// //
var conn = GetConnection(); var conn = GetConnection ();
return new AsyncTableQuery<T>(conn.Table<T>()); return new AsyncTableQuery<T> (conn.Table<T> ());
} }
public Task<T> ExecuteScalarAsync<T>(string sql, params object[] args) public Task<T> ExecuteScalarAsync<T> (string sql, params object[] args)
{ {
return Task<T>.Factory.StartNew(() => return Task<T>.Factory.StartNew (() => {
{ var conn = GetConnection ();
var conn = GetConnection(); using (conn.Lock ()) {
using (conn.Lock()) var command = conn.CreateCommand (sql, args);
{ return command.ExecuteScalar<T> ();
var command = conn.CreateCommand(sql, args); }
return command.ExecuteScalar<T>(); });
} }
});
} public Task<List<T>> QueryAsync<T> (string sql, params object[] args)
where T : new ()
public Task<List<T>> QueryAsync<T>(string sql, params object[] args) {
where T : new() return Task<List<T>>.Factory.StartNew (() => {
{ var conn = GetConnection ();
return Task<List<T>>.Factory.StartNew(() => using (conn.Lock ()) {
{ return conn.Query<T> (sql, args);
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
// TODO: Bind to AsyncConnection.GetConnection instead so that delayed {
// execution can still work after a Pool.Reset. public Dictionary<Type, int> Results { get; private set; }
//
public class AsyncTableQuery<T> internal CreateTablesResult ()
where T : new() {
{ this.Results = new Dictionary<Type, int> ();
TableQuery<T> _innerQuery; }
}
public AsyncTableQuery(TableQuery<T> innerQuery)
{ class SQLiteConnectionPool
_innerQuery = innerQuery; {
} class Entry
{
public AsyncTableQuery<T> Where(Expression<Func<T, bool>> predExpr) public SQLiteConnectionString ConnectionString { get; private set; }
{ public SQLiteConnectionWithLock Connection { get; private set; }
return new AsyncTableQuery<T>(_innerQuery.Where(predExpr));
} public Entry (SQLiteConnectionString connectionString)
{
public AsyncTableQuery<T> Skip(int n) ConnectionString = connectionString;
{ Connection = new SQLiteConnectionWithLock (connectionString);
return new AsyncTableQuery<T>(_innerQuery.Skip(n)); }
}
public void OnApplicationSuspended ()
public AsyncTableQuery<T> Take(int n) {
{ Connection.Dispose ();
return new AsyncTableQuery<T>(_innerQuery.Take(n)); Connection = null;
} }
}
public AsyncTableQuery<T> OrderBy<U>(Expression<Func<T, U>> orderExpr)
{ readonly Dictionary<string, Entry> _entries = new Dictionary<string, Entry> ();
return new AsyncTableQuery<T>(_innerQuery.OrderBy<U>(orderExpr)); readonly object _entriesLock = new object ();
}
static readonly SQLiteConnectionPool _shared = new SQLiteConnectionPool ();
public AsyncTableQuery<T> OrderByDescending<U>(Expression<Func<T, U>> orderExpr)
{ /// <summary>
return new AsyncTableQuery<T>(_innerQuery.OrderByDescending<U>(orderExpr)); /// Gets the singleton instance of the connection tool.
} /// </summary>
public static SQLiteConnectionPool Shared
public Task<List<T>> ToListAsync() {
{ get
return Task.Factory.StartNew(() => {
{ return _shared;
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock()) }
{ }
return _innerQuery.ToList();
} public SQLiteConnectionWithLock GetConnection (SQLiteConnectionString connectionString)
}); {
} lock (_entriesLock) {
Entry entry;
public Task<int> CountAsync() string key = connectionString.ConnectionString;
{
return Task.Factory.StartNew(() => if (!_entries.TryGetValue (key, out entry)) {
{ entry = new Entry (connectionString);
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock()) _entries[key] = entry;
{ }
return _innerQuery.Count();
} return entry.Connection;
}); }
} }
public Task<T> ElementAtAsync(int index) /// <summary>
{ /// Closes all connections managed by this pool.
return Task.Factory.StartNew(() => /// </summary>
{ public void Reset ()
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock()) {
{ lock (_entriesLock) {
return _innerQuery.ElementAt(index); foreach (var entry in _entries.Values) {
} entry.OnApplicationSuspended ();
}); }
} _entries.Clear ();
}
public Task<T> FirstAsync() }
{
return Task<T>.Factory.StartNew(() => /// <summary>
{ /// Call this method when the application is suspended.
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock()) /// </summary>
{ /// <remarks>Behaviour here is to close any open connections.</remarks>
return _innerQuery.First(); public void ApplicationSuspended ()
} {
}); Reset ();
} }
}
public Task<T> FirstOrDefaultAsync()
{ class SQLiteConnectionWithLock : SQLiteConnection
return Task<T>.Factory.StartNew(() => {
{ readonly object _lockPoint = new object ();
using (((SQLiteConnectionWithLock)_innerQuery.Connection).Lock())
{ public SQLiteConnectionWithLock (SQLiteConnectionString connectionString)
return _innerQuery.FirstOrDefault(); : base (connectionString.DatabasePath, connectionString.StoreDateTimeAsTicks)
} {
}); }
}
} public IDisposable Lock ()
{
public class CreateTablesResult return new LockWrapper (_lockPoint);
{ }
public Dictionary<Type, int> Results { get; private set; }
private class LockWrapper : IDisposable
internal CreateTablesResult() {
{ object _lockPoint;
this.Results = new Dictionary<Type, int>();
} public LockWrapper (object lockPoint)
} {
_lockPoint = lockPoint;
class SQLiteConnectionPool Monitor.Enter (_lockPoint);
{ }
class Entry
{ public void Dispose ()
public SQLiteConnectionString ConnectionString { get; private set; } {
public SQLiteConnectionWithLock Connection { get; private set; } Monitor.Exit (_lockPoint);
}
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);
}
}
}
} }

Loading…
Cancel
Save