mirror of https://github.com/SixLabors/ImageSharp
26 changed files with 733 additions and 126 deletions
@ -0,0 +1,101 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
|||
<PropertyGroup> |
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
|||
<ProjectGuid>{39911A38-CA06-413C-80AA-39EF60CE984F}</ProjectGuid> |
|||
<OutputType>Library</OutputType> |
|||
<AppDesignerFolder>Properties</AppDesignerFolder> |
|||
<RootNamespace>ImageProcessor.Tests</RootNamespace> |
|||
<AssemblyName>ImageProcessor.Tests</AssemblyName> |
|||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
|||
<FileAlignment>512</FileAlignment> |
|||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> |
|||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> |
|||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> |
|||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> |
|||
<IsCodedUITest>False</IsCodedUITest> |
|||
<TestProjectType>UnitTest</TestProjectType> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<DebugType>full</DebugType> |
|||
<Optimize>false</Optimize> |
|||
<OutputPath>bin\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
|||
<DebugType>pdbonly</DebugType> |
|||
<Optimize>true</Optimize> |
|||
<OutputPath>bin\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<WarningLevel>4</WarningLevel> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> |
|||
<DebugSymbols>true</DebugSymbols> |
|||
<OutputPath>bin\x86\Debug\</OutputPath> |
|||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
|||
<DebugType>full</DebugType> |
|||
<PlatformTarget>x86</PlatformTarget> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
|||
</PropertyGroup> |
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> |
|||
<OutputPath>bin\x86\Release\</OutputPath> |
|||
<DefineConstants>TRACE</DefineConstants> |
|||
<Optimize>true</Optimize> |
|||
<DebugType>pdbonly</DebugType> |
|||
<PlatformTarget>x86</PlatformTarget> |
|||
<ErrorReport>prompt</ErrorReport> |
|||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
|||
</PropertyGroup> |
|||
<ItemGroup> |
|||
<Reference Include="System" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> |
|||
</ItemGroup> |
|||
</When> |
|||
<Otherwise> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" /> |
|||
</ItemGroup> |
|||
</Otherwise> |
|||
</Choose> |
|||
<ItemGroup> |
|||
<Compile Include="UnitTest1.cs" /> |
|||
<Compile Include="Properties\AssemblyInfo.cs" /> |
|||
</ItemGroup> |
|||
<Choose> |
|||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> |
|||
<ItemGroup> |
|||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|||
<Private>False</Private> |
|||
</Reference> |
|||
</ItemGroup> |
|||
</When> |
|||
</Choose> |
|||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> |
|||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
|||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
|||
Other similar extension points exist, see Microsoft.Common.targets. |
|||
<Target Name="BeforeBuild"> |
|||
</Target> |
|||
<Target Name="AfterBuild"> |
|||
</Target> |
|||
--> |
|||
</Project> |
|||
@ -0,0 +1,36 @@ |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
// General Information about an assembly is controlled through the following
|
|||
// set of attributes. Change these attribute values to modify the information
|
|||
// associated with an assembly.
|
|||
[assembly: AssemblyTitle("ImageProcessor.Tests")] |
|||
[assembly: AssemblyDescription("")] |
|||
[assembly: AssemblyConfiguration("")] |
|||
[assembly: AssemblyCompany("")] |
|||
[assembly: AssemblyProduct("ImageProcessor.Tests")] |
|||
[assembly: AssemblyCopyright("Copyright © 2013")] |
|||
[assembly: AssemblyTrademark("")] |
|||
[assembly: AssemblyCulture("")] |
|||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible
|
|||
// to COM components. If you need to access a type in this assembly from
|
|||
// COM, set the ComVisible attribute to true on that type.
|
|||
[assembly: ComVisible(false)] |
|||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|||
[assembly: Guid("ab617b65-7259-4dc5-9dad-81a7c6537a4f")] |
|||
|
|||
// Version information for an assembly consists of the following four values:
|
|||
//
|
|||
// Major Version
|
|||
// Minor Version
|
|||
// Build Number
|
|||
// Revision
|
|||
//
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
|||
// by using the '*' as shown below:
|
|||
// [assembly: AssemblyVersion("1.0.*")]
|
|||
[assembly: AssemblyVersion("1.0.0.0")] |
|||
[assembly: AssemblyFileVersion("1.0.0.0")] |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using Microsoft.VisualStudio.TestTools.UnitTesting; |
|||
|
|||
namespace ImageProcessor.Tests |
|||
{ |
|||
using System.IO; |
|||
|
|||
[TestClass] |
|||
public class UnitTest1 |
|||
{ |
|||
[TestMethod] |
|||
public void TestMethod1() |
|||
{ |
|||
|
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,216 @@ |
|||
// -----------------------------------------------------------------------
|
|||
// <copyright file="SQLContext.cs" company="James South">
|
|||
// Copyright (c) James South.
|
|||
// Dual licensed under the MIT or GPL Version 2 licenses.
|
|||
// </copyright>
|
|||
// -----------------------------------------------------------------------
|
|||
|
|||
namespace ImageProcessor.Web.Caching |
|||
{ |
|||
#region Using
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Data.SQLite; |
|||
using System.IO; |
|||
using System.Web.Hosting; |
|||
using ImageProcessor.Web.Config; |
|||
#endregion
|
|||
|
|||
/// <summary>
|
|||
/// Provides a wrapper for the SQLite functionality.
|
|||
/// </summary>
|
|||
internal sealed class SQLContext |
|||
{ |
|||
/// <summary>
|
|||
/// The default path for cached folders on the server.
|
|||
/// </summary>
|
|||
private static readonly string VirtualCachePath = ImageProcessorConfig.Instance.VirtualCachePath; |
|||
|
|||
/// <summary>
|
|||
/// The cached index location.
|
|||
/// </summary>
|
|||
private static readonly string IndexLocation = Path.Combine(HostingEnvironment.MapPath(VirtualCachePath), "imagecache.sqlite"); |
|||
|
|||
/// <summary>
|
|||
/// The connection string.
|
|||
/// </summary>
|
|||
private static readonly string ConnectionString = string.Format("Data Source={0};Version=3;", IndexLocation); |
|||
|
|||
/// <summary>
|
|||
/// Creates the database if it doesn't already exist.
|
|||
/// </summary>
|
|||
public static void CreateDatabase() |
|||
{ |
|||
if (!File.Exists(IndexLocation)) |
|||
{ |
|||
string absolutePath = HostingEnvironment.MapPath(VirtualCachePath); |
|||
|
|||
if (absolutePath != null) |
|||
{ |
|||
DirectoryInfo directoryInfo = new DirectoryInfo(absolutePath); |
|||
|
|||
if (!directoryInfo.Exists) |
|||
{ |
|||
// Create the directory.
|
|||
Directory.CreateDirectory(absolutePath); |
|||
} |
|||
} |
|||
|
|||
SQLiteConnection.CreateFile(IndexLocation); |
|||
|
|||
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) |
|||
{ |
|||
connection.Open(); |
|||
|
|||
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|||
{ |
|||
using (SQLiteCommand command = new SQLiteCommand(connection)) |
|||
{ |
|||
command.CommandText = @"CREATE TABLE names
|
|||
(Key TEXT, |
|||
Path TEXT, |
|||
LastWriteTimeUtc TEXT, |
|||
ExpiresUtc TEXT, |
|||
PRIMARY KEY (Key), |
|||
UNIQUE (Value));";
|
|||
|
|||
command.ExecuteNonQuery(); |
|||
} |
|||
|
|||
transaction.Commit(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <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>
|
|||
public static bool AddImage(string key, CachedImage image) |
|||
{ |
|||
try |
|||
{ |
|||
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) |
|||
{ |
|||
connection.Open(); |
|||
|
|||
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|||
{ |
|||
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("LastWriteTimeUtc", image.LastWriteTimeUtc), |
|||
new SQLiteParameter("ExpiresUtc", image.ExpiresUtc) |
|||
}; |
|||
|
|||
command.Parameters.AddRange(parameters); |
|||
command.ExecuteNonQuery(); |
|||
} |
|||
|
|||
transaction.Commit(); |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Removes a cached image from the database.
|
|||
/// </summary>
|
|||
/// <param name="key">
|
|||
/// The key for the cached image.
|
|||
/// </param>
|
|||
/// <returns>
|
|||
/// The true if the addition of the cached image is removed; otherwise, false.
|
|||
/// </returns>
|
|||
public static bool RemoveImage(string key) |
|||
{ |
|||
try |
|||
{ |
|||
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) |
|||
{ |
|||
connection.Open(); |
|||
|
|||
using (SQLiteTransaction transaction = connection.BeginTransaction()) |
|||
{ |
|||
using (SQLiteCommand command = new SQLiteCommand(connection)) |
|||
{ |
|||
command.CommandText = string.Format("DELETE FROM names WHERE key = '{0}';", key); |
|||
command.ExecuteNonQuery(); |
|||
} |
|||
|
|||
transaction.Commit(); |
|||
} |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Gets all the images from the database.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// The <see cref="System.Collections.Generic.Dictionary{TKey,TVal}"/>.
|
|||
/// </returns>
|
|||
public static Dictionary<string, CachedImage> GetImages() |
|||
{ |
|||
Dictionary<string, CachedImage> dictionary = new Dictionary<string, CachedImage>(); |
|||
|
|||
try |
|||
{ |
|||
using (SQLiteConnection connection = new SQLiteConnection(ConnectionString)) |
|||
{ |
|||
connection.Open(); |
|||
|
|||
using (SQLiteCommand command = new SQLiteCommand(connection)) |
|||
{ |
|||
command.CommandText = "SELECT * FROM names;"; |
|||
|
|||
SQLiteDataReader reader = command.ExecuteReader(); |
|||
|
|||
while (reader.Read()) |
|||
{ |
|||
string key = reader["Key"].ToString(); |
|||
CachedImage image = new CachedImage( |
|||
reader["Path"].ToString(), |
|||
DateTime.Parse(reader["LastWriteTimeUtc"].ToString()).ToUniversalTime(), |
|||
DateTime.Parse(reader["LastWriteTimeUtc"].ToString()).ToUniversalTime()); |
|||
|
|||
dictionary.Add(key, image); |
|||
} |
|||
} |
|||
} |
|||
|
|||
return dictionary; |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return new Dictionary<string, CachedImage>(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<packages> |
|||
<package id="System.Data.SQLite.x86" version="1.0.84.0" targetFramework="net40" /> |
|||
</packages> |
|||
@ -0,0 +1,20 @@ |
|||
@model TimeSpan |
|||
@{ |
|||
Layout = null; |
|||
|
|||
double s = Model.TotalMilliseconds; |
|||
} |
|||
|
|||
<!DOCTYPE html> |
|||
|
|||
<html> |
|||
<head> |
|||
<title>@s</title> |
|||
</head> |
|||
<body> |
|||
<div> |
|||
Speed In Milliseconds: @s<br/> |
|||
Dictionary Count: @ViewBag.Count |
|||
</div> |
|||
</body> |
|||
</html> |
|||
@ -0,0 +1 @@ |
|||
2db1579b36b2d81adf041533845e9a72ea6c2393 |
|||
@ -0,0 +1,23 @@ |
|||
<?xml version="1.0"?> |
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> |
|||
<metadata> |
|||
<id>System.Data.SQLite.x86</id> |
|||
<version>1.0.84.0</version> |
|||
<title>System.Data.SQLite.x86</title> |
|||
<authors>SQLite Development Team</authors> |
|||
<owners>SQLite Development Team</owners> |
|||
<licenseUrl>http://www.sqlite.org/copyright.html</licenseUrl> |
|||
<projectUrl>http://system.data.sqlite.org/</projectUrl> |
|||
<iconUrl>http://system.data.sqlite.org/images/sqlite32.png</iconUrl> |
|||
<requireLicenseAcceptance>false</requireLicenseAcceptance> |
|||
<description>The official SQLite database engine combined with a complete ADO.NET provider all rolled into a single mixed-mode assembly for x86.</description> |
|||
<releaseNotes /> |
|||
<copyright>Public Domain</copyright> |
|||
<language>en-US</language> |
|||
<tags>sqlite database ado.net provider interop</tags> |
|||
<references> |
|||
<reference file="System.Data.SQLite.dll" /> |
|||
<reference file="System.Data.SQLite.Linq.dll" /> |
|||
</references> |
|||
</metadata> |
|||
</package> |
|||
@ -0,0 +1 @@ |
|||
91d583cc0540c5252c68278bea13a48045548a20 |
|||
@ -0,0 +1 @@ |
|||
168e4329b21098e36b1c1af6e0c8728d5e9c589e |
|||
@ -0,0 +1 @@ |
|||
31c463596b575043d8559b8a10cb25ad3bc15090 |
|||
@ -0,0 +1 @@ |
|||
f60b588d3ff22ae8b1f51d710a44a037683ce81d |
|||
@ -0,0 +1 @@ |
|||
71a4551ce7011a6caeeadb73aea687ec586a5d87 |
|||
@ -0,0 +1 @@ |
|||
c62d000052745e37933833a3b764eb47ece9673f |
|||
@ -0,0 +1,4 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<repositories> |
|||
<repository path="..\ImageProcessor.Web\packages.config" /> |
|||
</repositories> |
|||
Loading…
Reference in new issue