Skip to content

Commit

Permalink
Add dapperextensions project, some work on install, and testrunner.
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesbetros committed Feb 2, 2017
1 parent d561610 commit cadc917
Show file tree
Hide file tree
Showing 66 changed files with 3,113 additions and 364 deletions.
7 changes: 7 additions & 0 deletions Cosmos.sln
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Cosmos.Build.MSBuild", "sou
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Cosmos.Debug.Hosts", "source\Cosmos.Debug.Hosts\Cosmos.Debug.Hosts.xproj", "{24AB9FAE-4021-4D76-99D3-07A3971DDBB7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "NASM", "source\NASM\NASM.xproj", "{1026BB74-575C-4A96-B36C-56E53914BE4D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -724,6 +726,10 @@ Global
{24AB9FAE-4021-4D76-99D3-07A3971DDBB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24AB9FAE-4021-4D76-99D3-07A3971DDBB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24AB9FAE-4021-4D76-99D3-07A3971DDBB7}.Release|Any CPU.Build.0 = Release|Any CPU
{1026BB74-575C-4A96-B36C-56E53914BE4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1026BB74-575C-4A96-B36C-56E53914BE4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1026BB74-575C-4A96-B36C-56E53914BE4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1026BB74-575C-4A96-B36C-56E53914BE4D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -854,5 +860,6 @@ Global
{0306438C-F94F-4D7D-9547-11B64EFD215A} = {B521E2A2-81E4-4B2D-A471-7AB550E9551E}
{FDA5D609-B634-4C02-89A6-74E68D9B2EBA} = {72617CB8-C572-4F39-A815-A2F6C21F4889}
{24AB9FAE-4021-4D76-99D3-07A3971DDBB7} = {36BC87BD-FAE2-4017-844A-17F440D9657F}
{1026BB74-575C-4A96-B36C-56E53914BE4D} = {D95021E1-A2C9-4829-819E-ED433AF13162}
EndGlobalSection
EndGlobal
9 changes: 9 additions & 0 deletions Cosmos.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Locals/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="x" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Parameters/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="a" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PublicFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="m" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer /&gt;</s:String></wpf:ResourceDictionary>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using DapperExtensions.Mapper;
using DapperExtensions.Sql;

namespace DapperExtensions
{
/// <summary>
///
/// </summary>
public interface IDapperAsyncImplementor : IDapperImplementor
{
/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.Get{T}"/>.
/// </summary>
Task<T> GetAsync<T>(IDbConnection connection, dynamic id, IDbTransaction transaction = null, int? commandTimeout = null) where T : class;
/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetList{T}"/>.
/// </summary>
Task<IEnumerable<T>> GetListAsync<T>(IDbConnection connection, object predicate = null, IList<ISort> sort = null, IDbTransaction transaction = null, int? commandTimeout = null) where T : class;
/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetPage{T}"/>.
/// </summary>
Task<IEnumerable<T>> GetPageAsync<T>(IDbConnection connection, object predicate = null, IList<ISort> sort = null, int page = 1, int resultsPerPage = 10, IDbTransaction transaction = null, int? commandTimeout = null) where T : class;
/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetSet{T}"/>.
/// </summary>
Task<IEnumerable<T>> GetSetAsync<T>(IDbConnection connection, object predicate = null, IList<ISort> sort = null, int firstResult = 1, int maxResults = 10, IDbTransaction transaction = null, int? commandTimeout = null) where T : class;
/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.Count{T}"/>.
/// </summary>
Task<int> CountAsync<T>(IDbConnection connection, object predicate = null, IDbTransaction transaction = null, int? commandTimeout = null) where T : class;
}

public class DapperAsyncImplementor : DapperImplementor, IDapperAsyncImplementor
{
/// <summary>
/// Initializes a new instance of the <see cref="DapperAsyncImplementor"/> class.
/// </summary>
/// <param name="sqlGenerator">The SQL generator.</param>
public DapperAsyncImplementor(ISqlGenerator sqlGenerator)
:base(sqlGenerator) { }

#region Implementation of IDapperAsyncImplementor

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.Get{T}"/>.
/// </summary>
public async Task<T> GetAsync<T>(IDbConnection connection, dynamic id, IDbTransaction transaction = null,
int? commandTimeout = null) where T : class
{
IClassMapper classMap = SqlGenerator.Configuration.GetMap<T>();
IPredicate predicate = GetIdPredicate(classMap, id);
return (await GetListAsync<T>(connection, classMap, predicate, null, transaction, commandTimeout)).SingleOrDefault();
}

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetList{T}"/>.
/// </summary>
public async Task<IEnumerable<T>> GetListAsync<T>(IDbConnection connection, object predicate = null, IList<ISort> sort = null,
IDbTransaction transaction = null, int? commandTimeout = null) where T : class
{
IClassMapper classMap = SqlGenerator.Configuration.GetMap<T>();
IPredicate wherePredicate = GetPredicate(classMap, predicate);
return await GetListAsync<T>(connection, classMap, wherePredicate, sort, transaction, commandTimeout);
}

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetPage{T}"/>.
/// </summary>
public async Task<IEnumerable<T>> GetPageAsync<T>(IDbConnection connection, object predicate = null, IList<ISort> sort = null, int page = 1,
int resultsPerPage = 10, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
{
IClassMapper classMap = SqlGenerator.Configuration.GetMap<T>();
IPredicate wherePredicate = GetPredicate(classMap, predicate);
return await GetPageAsync<T>(connection, classMap, wherePredicate, sort, page, resultsPerPage, transaction, commandTimeout);
}

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetSet{T}"/>.
/// </summary>
public async Task<IEnumerable<T>> GetSetAsync<T>(IDbConnection connection, object predicate = null, IList<ISort> sort = null, int firstResult = 1,
int maxResults = 10, IDbTransaction transaction = null, int? commandTimeout = null) where T : class
{
IClassMapper classMap = SqlGenerator.Configuration.GetMap<T>();
IPredicate wherePredicate = GetPredicate(classMap, predicate);
return await GetSetAsync<T>(connection, classMap, wherePredicate, sort, firstResult, maxResults, transaction, commandTimeout);
}

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.Count{T}"/>.
/// </summary>
public async Task<int> CountAsync<T>(IDbConnection connection, object predicate = null, IDbTransaction transaction = null,
int? commandTimeout = null) where T : class
{
IClassMapper classMap = SqlGenerator.Configuration.GetMap<T>();
IPredicate wherePredicate = GetPredicate(classMap, predicate);
Dictionary<string, object> parameters = new Dictionary<string, object>();
string sql = SqlGenerator.Count(classMap, wherePredicate, parameters);
DynamicParameters dynamicParameters = new DynamicParameters();
foreach (var parameter in parameters)
{
dynamicParameters.Add(parameter.Key, parameter.Value);
}

return (int)(await connection.QueryAsync(sql, dynamicParameters, transaction, commandTimeout, CommandType.Text)).Single().Total;
}

#endregion

#region Helpers

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetList{T}"/>.
/// </summary>
protected async Task<IEnumerable<T>> GetListAsync<T>(IDbConnection connection, IClassMapper classMap, IPredicate predicate, IList<ISort> sort, IDbTransaction transaction, int? commandTimeout) where T : class
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
string sql = SqlGenerator.Select(classMap, predicate, sort, parameters);
DynamicParameters dynamicParameters = new DynamicParameters();
foreach (var parameter in parameters)
{
dynamicParameters.Add(parameter.Key, parameter.Value);
}

return await connection.QueryAsync<T>(sql, dynamicParameters, transaction, commandTimeout, CommandType.Text);
}

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetPage{T}"/>.
/// </summary>
protected async Task<IEnumerable<T>> GetPageAsync<T>(IDbConnection connection, IClassMapper classMap, IPredicate predicate, IList<ISort> sort, int page, int resultsPerPage, IDbTransaction transaction, int? commandTimeout) where T : class
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
string sql = SqlGenerator.SelectPaged(classMap, predicate, sort, page, resultsPerPage, parameters);
DynamicParameters dynamicParameters = new DynamicParameters();
foreach (var parameter in parameters)
{
dynamicParameters.Add(parameter.Key, parameter.Value);
}

return await connection.QueryAsync<T>(sql, dynamicParameters, transaction, commandTimeout, CommandType.Text);
}

/// <summary>
/// The asynchronous counterpart to <see cref="IDapperImplementor.GetSet{T}"/>.
/// </summary>
protected async Task<IEnumerable<T>> GetSetAsync<T>(IDbConnection connection, IClassMapper classMap, IPredicate predicate, IList<ISort> sort, int firstResult, int maxResults, IDbTransaction transaction, int? commandTimeout) where T : class
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
string sql = SqlGenerator.SelectSet(classMap, predicate, sort, firstResult, maxResults, parameters);
DynamicParameters dynamicParameters = new DynamicParameters();
foreach (var parameter in parameters)
{
dynamicParameters.Add(parameter.Key, parameter.Value);
}

return await connection.QueryAsync<T>(sql, dynamicParameters, transaction, commandTimeout, CommandType.Text);
}

#endregion
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>caa1a673-6521-4954-bf05-37ffe016e5c3</ProjectGuid>
<RootNamespace>DapperExtensions</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
Loading

0 comments on commit cadc917

Please sign in to comment.