#164 add working metadata caching

This commit is contained in:
Marko Lahma
2018-10-21 14:12:29 +03:00
parent 1fdb0622b7
commit 13fb3c74b8
70 changed files with 1405 additions and 1256 deletions

View File

@@ -18,15 +18,10 @@
#endregion
#region Imports
using System;
using System.Reflection;
using Spring.Aop;
#endregion
namespace Spring.AopQuickStart.Aspects
{
/// <summary>
@@ -39,8 +34,7 @@ namespace Spring.AopQuickStart.Aspects
{
public void AfterThrowing(Exception ex)
{
Console.Error.WriteLine(
String.Format("Advised method threw this exception : {0}", ex.Message));
Console.Error.WriteLine($"Advised method threw this exception : {ex.Message}");
}
}
}

View File

@@ -18,16 +18,10 @@
#endregion
#region Imports
using System;
using AopAlliance.Intercept;
using Spring.AopQuickStart.Attributes;
#endregion
namespace Spring.AopQuickStart.Aspects
{
/// <summary>

View File

@@ -1,29 +1,27 @@
using System;
using System.Reflection;
using AopAlliance.Intercept;
using Spring.Aop.Framework;
namespace Spring.AopQuickStart
{
public class ModificationAdvice : IMethodInterceptor
{
public virtual Object Invoke(IMethodInvocation invocation)
public virtual object Invoke(IMethodInvocation invocation)
{
MethodInfo method = invocation.Method;
object proxy = invocation.Proxy;
if (proxy is IIsModified)
if (proxy is IIsModified obj)
{
IIsModified obj = (IIsModified) proxy;
if (IsSetter(method))
{
obj.IsModified = HasModificationOccured(method, invocation.This, invocation.Arguments);
}
}
return invocation.Proceed();
}
private bool HasModificationOccured(MethodInfo setter, Object target, Object[] args)
private bool HasModificationOccured(MethodInfo setter, object target, object[] args)
{
PropertyInfo property = target.GetType().GetProperty(setter.Name.Substring(4));
@@ -31,25 +29,25 @@ namespace Spring.AopQuickStart
{
// modification check is unimportant
// for write only methods
Object newVal = args[0];
Object oldVal = property.GetValue(target, null);
object newVal = args[0];
object oldVal = property.GetValue(target, null);
if ((newVal == null) && (oldVal == null))
if (newVal == null && (oldVal == null))
{
return false;
}
else if ((newVal == null) && (oldVal != null))
if (newVal == null && (oldVal != null))
{
return true;
}
else if ((newVal != null) && (oldVal == null))
if ((oldVal == null))
{
return true;
}
else
{
return (!newVal.Equals(oldVal));
}
return (!newVal.Equals(oldVal));
}
return false;
@@ -57,8 +55,7 @@ namespace Spring.AopQuickStart
private bool IsSetter(MethodInfo method)
{
return (method.Name.StartsWith("set_")) && (method.GetParameters().Length == 1);
return method.Name.StartsWith("set_") && method.GetParameters().Length == 1;
}
}
}
}

View File

@@ -18,18 +18,12 @@
#endregion
#region Imports
using System;
using System.Collections.Generic;
using Spring.Context;
using Spring.Context.Support;
using Spring.AopQuickStart.Commands;
#endregion
namespace Spring.AopQuickStart
{
/// <summary>
@@ -47,7 +41,7 @@ namespace Spring.AopQuickStart
{
// Create AOP proxy using Spring.NET IoC container.
IApplicationContext ctx = ContextRegistry.GetContext();
IDictionary<string, ICommand> commands = ctx.GetObjects<ICommand>();
var commands = ctx.GetObjects<ICommand>();
foreach (ICommand command in commands.Values)
{

View File

@@ -18,10 +18,7 @@
#endregion
#region Imports
using System;
using System.Collections.Generic;
using System.Data;
using NUnit.Framework;
using Spring.Aop.Config;
@@ -34,8 +31,6 @@ using Spring.Objects.Factory.Xml;
using Spring.Transaction.Config;
using Spring.TxQuickStart.Services;
#endregion
namespace Spring.TxQuickStart
{
[TestFixture]
@@ -54,7 +49,6 @@ namespace Spring.TxQuickStart
NamespaceParserRegistry.RegisterParser(typeof(TxNamespaceParser));
NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser));
IApplicationContext context = CreateContextFromXml();
IDictionary<string, IAccountManager> dict = context.GetObjects<IAccountManager>();
accountManager = context["accountManager"] as IAccountManager;
CleanDb(context);
}