Permalink
Browse files

Merge pull request #894 from kendallb/master

Lower overhead ADO extension wrapping
  • Loading branch information...
avanderhoorn committed Jun 16, 2015
2 parents 0f01bb3 + 7902e23 commit 61857be49fdab5af887d70cc9d85ff4a4a3a7358
@@ -1,6 +1,8 @@
using System;
using System.Data.Common;
using System.Reflection;
using System.Reflection;
using Glimpse.Core.Extensibility;
using Glimpse.Core.Framework;

namespace Glimpse.Ado.AlternateType
{
@@ -10,7 +12,7 @@ public abstract class GlimpseDbProviderFactory : DbProviderFactory

public class GlimpseDbProviderFactory<TProviderFactory> : GlimpseDbProviderFactory, IServiceProvider
where TProviderFactory : DbProviderFactory
{
{
public static readonly GlimpseDbProviderFactory<TProviderFactory> Instance = new GlimpseDbProviderFactory<TProviderFactory>();

public GlimpseDbProviderFactory()
@@ -32,8 +34,13 @@ public override bool CanCreateDataSourceEnumerator
private TProviderFactory InnerFactory { get; set; }

public override DbCommand CreateCommand()
{
return new GlimpseDbCommand(InnerFactory.CreateCommand());
{
var command = InnerFactory.CreateCommand();
if (IsAdoMonitoringNeeded())
{
return new GlimpseDbCommand(command);
}
return command;
}

public override DbCommandBuilder CreateCommandBuilder()
@@ -42,8 +49,13 @@ public override DbCommandBuilder CreateCommandBuilder()
}

public override DbConnection CreateConnection()
{
return new GlimpseDbConnection(InnerFactory.CreateConnection(), this);
{
var connection = InnerFactory.CreateConnection();
if (IsAdoMonitoringNeeded())
{
return new GlimpseDbConnection(connection, this);
}
return connection;
}

public override DbConnectionStringBuilder CreateConnectionStringBuilder()
@@ -53,7 +65,12 @@ public override DbConnectionStringBuilder CreateConnectionStringBuilder()

public override DbDataAdapter CreateDataAdapter()
{
return new GlimpseDbDataAdapter(InnerFactory.CreateDataAdapter());
var adapter = InnerFactory.CreateDataAdapter();
if (IsAdoMonitoringNeeded())
{
return new GlimpseDbDataAdapter(adapter);
}
return adapter;
}

public override DbDataSourceEnumerator CreateDataSourceEnumerator()
@@ -104,5 +121,12 @@ public object GetService(Type serviceType)

return service;
}

private static bool IsAdoMonitoringNeeded()
{
return GlimpseConfiguration.GetConfiguredMessageBroker() != null &&
GlimpseConfiguration.GetDefaultRuntimePolicy() != RuntimePolicy.Off &&
GlimpseConfiguration.GetRuntimePolicyStategy()() != RuntimePolicy.Off;
}
}
}
@@ -30,7 +30,8 @@ public class GlimpseConfiguration : IGlimpseConfiguration
private ISerializer serializer;
private ICollection<ITab> tabs;
private ICollection<IDisplay> displays;
private Func<RuntimePolicy> runtimePolicyStrategy;
private static RuntimePolicy defaultRuntimePolicy;
private static Func<RuntimePolicy> runtimePolicyStrategy;
private string hash;

/// <summary>
@@ -239,7 +240,18 @@ public IResource DefaultResource
/// <value>
/// The default runtime policy.
/// </value>
public RuntimePolicy DefaultRuntimePolicy { get; set; }
public RuntimePolicy DefaultRuntimePolicy
{
get
{
return defaultRuntimePolicy;
}

set
{
defaultRuntimePolicy = value;
}
}

/// <summary>
/// Gets or sets the endpoint base URI.
@@ -704,5 +716,17 @@ public static IMessageBroker GetConfiguredMessageBroker()
{
return messageBroker;
}

[Obsolete("HACK: To prevent unnecessary wrapping of SQL connections, commands etc")]
public static RuntimePolicy GetDefaultRuntimePolicy()
{
return defaultRuntimePolicy;
}

[Obsolete("HACK: To prevent unnecessary wrapping of SQL connections, commands etc")]
public static Func<RuntimePolicy> GetRuntimePolicyStategy()
{
return runtimePolicyStrategy;
}
}
}

0 comments on commit 61857be

Please sign in to comment.