Skip to content

Commit

Permalink
1. Removed unncessary components.
Browse files Browse the repository at this point in the history
2. Refactoring
  • Loading branch information
rohan3usturge committed Jul 3, 2017
1 parent e9caec3 commit 362f3d9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 33 deletions.
5 changes: 5 additions & 0 deletions ProxyMapper.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26430.6
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProxyMapper", "ProxyMapper\ProxyMapper.csproj", "{4551806A-2756-4F17-B78B-E835B7CF5CC1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{35FCAB98-D5FF-4CEF-B718-F796CE675E9A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -19,4 +21,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4551806A-2756-4F17-B78B-E835B7CF5CC1} = {35FCAB98-D5FF-4CEF-B718-F796CE675E9A}
EndGlobalSection
EndGlobal
14 changes: 1 addition & 13 deletions ProxyMapper/Core/DbCallInterceptor.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Reflection;
using Castle.Core.Internal;
using Castle.DynamicProxy;
Expand All @@ -20,7 +18,6 @@ internal class DbCallInterceptor : IInterceptor

private readonly IValidatorChain<CallInfo> _validatorChain;


public DbCallInterceptor(string connectionString, IDataProcessor dataProcessor)
{
this._connectionString = connectionString;
Expand All @@ -34,8 +31,6 @@ public DbCallInterceptor(string connectionString, IDataProcessor dataProcessor)
public void Intercept(IInvocation invocation)
{
SqlConnection conn = null;
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
try
{
MethodInfo methodInfo = invocation.Method;
Expand Down Expand Up @@ -94,16 +89,9 @@ public void Intercept(IInvocation invocation)
}
}
}
catch (Exception ex)
{
//this._logger.LogError($"Db Call Processing Failed for - {callInfo}");
throw new Exception(ex.Message, ex);
}
finally
{
conn?.Close();
stopwatch.Stop();
//this._logger.LogInformation($"Db Call Processing completed in {stopwatch.ElapsedMilliseconds} ms for - {callInfo}");
}
}

Expand Down
25 changes: 13 additions & 12 deletions ProxyMapper/Core/ProxyFactory.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
using Castle.DynamicProxy;
using Microsoft.Extensions.Logging;
using System;
using System.Reflection;
using Castle.DynamicProxy;

namespace ProxyMapper.Core
{
public class ProxyFactory
public static class ProxyFactory
{
private readonly ILogger _logger;
private static readonly ProxyGenerator ProxyGenerator = new ProxyGenerator();

public ProxyFactory(ILogger logger)
public static T CreateRepoProxy<T>(string connectionString, IDataProcessor dataProcessor = null) where T : class
{
this._logger = logger;
}

public T CreateProxy<T>(string connectionString, IDataProcessor dataProcessor = null) where T : class
{
ProxyGenerator proxyGenerator = new ProxyGenerator();
object proxy = proxyGenerator.CreateInterfaceProxyWithoutTarget(typeof(T), new DbCallInterceptor(connectionString, GetDataProcessor(dataProcessor)));
if (!typeof(T).GetTypeInfo().IsInterface)
{
throw new InvalidOperationException(
"Proxies can be generated only for interfaces. Please provide a proper interface.");
}
object proxy = ProxyGenerator.CreateInterfaceProxyWithoutTarget(typeof(T),
new DbCallInterceptor(connectionString, GetDataProcessor(dataProcessor)));
return (T) proxy;
}

Expand Down
6 changes: 1 addition & 5 deletions ProxyMapper/Enums/CallType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
public enum CallType
{
Procedure,
Function,
Select,
Delete,
Update,
Insert
Text
}
}
4 changes: 1 addition & 3 deletions ProxyMapper/ProxyMapper.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;netcoreapp1.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net46;netcoreapp1.1</TargetFrameworks>
<PackageId>ProxyMapper</PackageId>
<PackageVersion>0.1.1</PackageVersion>
<Authors>Rohan Usturge</Authors>
Expand All @@ -14,9 +14,7 @@

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
<PackageReference Include="protobuf-net" Version="2.2.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.3.1" />
</ItemGroup>

Expand Down

0 comments on commit 362f3d9

Please sign in to comment.