本文整理汇总了C#中Spring.Aop.Framework.ProxyFactory.AddAdvice方法的典型用法代码示例。如果您正苦于以下问题:C# ProxyFactory.AddAdvice方法的具体用法?C# ProxyFactory.AddAdvice怎么用?C# ProxyFactory.AddAdvice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Aop.Framework.ProxyFactory
的用法示例。
在下文中一共展示了ProxyFactory.AddAdvice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
try
{
// Create AOP proxy programmatically.
ProxyFactory factory = new ProxyFactory(new ServiceCommand());
factory.AddAdvice(new ConsoleLoggingBeforeAdvice());
factory.AddAdvice(new ConsoleLoggingAfterAdvice());
factory.AddAdvice(new ConsoleLoggingThrowsAdvice());
ICommand command = (ICommand)factory.GetProxy();
command.Execute();
if (command.IsUndoCapable)
{
command.UnExecute();
}
}
catch (Exception ex)
{
Console.Out.WriteLine();
Console.Out.WriteLine(ex);
}
finally
{
Console.Out.WriteLine();
Console.Out.WriteLine("--- hit <return> to quit ---");
Console.ReadLine();
}
}
示例2: Main
private static void Main(string[] args)
{
ProxyFactory factory = new ProxyFactory(new ServiceCommand());
factory.AddAdvice(new ConsoleLoggingAroundAdvice());
ICommand command = (ICommand)factory.GetProxy();
command.Execute("This is the argument");
}
示例3: GetEntity
public static IXMLMailUtil GetEntity()
{
if (entity == null)
{
ProxyFactory factory = new ProxyFactory(new XMLMailUtil());
factory.AddAdvice(new AroundAdvice());
entity = (IXMLMailUtil)factory.GetProxy();
}
return entity;
}
示例4: AddPersistenceExceptionTranslation
protected override void AddPersistenceExceptionTranslation(ProxyFactory pf, IPersistenceExceptionTranslator pet)
{
if (AttributeUtils.FindAttribute(pf.TargetType, typeof(RepositoryAttribute)) != null)
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
of.RegisterObjectDefinition("peti", new RootObjectDefinition(typeof(PersistenceExceptionTranslationInterceptor)));
of.RegisterSingleton("pet", pet);
pf.AddAdvice((PersistenceExceptionTranslationInterceptor) of.GetObject("peti"));
}
}
示例5: Advised
protected override object Advised(object target, IPlatformTransactionManager ptm,
ITransactionAttributeSource tas)
{
TransactionInterceptor ti = new TransactionInterceptor();
ti.TransactionManager = ptm;
Assert.AreEqual(ptm, ti.TransactionManager);
ti.TransactionAttributeSource = tas;
Assert.AreEqual(tas, ti.TransactionAttributeSource);
ProxyFactory pf = new ProxyFactory(target);
pf.AddAdvice(0, ti);
return pf.GetProxy();
}
示例6: Main
static void Main(string[] args)
{
ProxyFactory factory = new ProxyFactory(new ServiceCommand());
factory.AddAdvice(new ExceptionAdvice());
ICommand cc = (ICommand)factory.GetProxy();
cc.Execute();
//cc.DoExecute();
//var ctx = ContextRegistry.GetContext();
//ICommand command = (ICommand)ctx.GetObject("myAfterAdvice");
//command.Execute();
//command.DoExecute();
Console.ReadLine();
}
示例7: Main
static void Main(string[] args)
{
//Person p=new Person();
// p.Pen=new Pen();
// p.Write();
ProxyFactory proxy = new ProxyFactory(new Pen());
//proxy.AddAdvice(new BeforeAdvice());
proxy.AddAdvice(new AroundAdvice());
IWrite p = proxy.GetProxy() as IWrite;
p.Write();
Console.ReadKey();
}
示例8: GetServiceProxy
public object GetServiceProxy(Assembly webServiceAssembly, string serviceName)
{
object proxy = webServiceAssembly.CreateInstance(serviceName);
if (proxy == null)
throw new Exception("Cannot create proxy instance");
if (_modifier == null)
return proxy;
var factory = new ProxyFactory(proxy) { ProxyTargetType = true };
factory.AddAdvice(new WebRequestModifyInterceptor(_modifier));
var result = factory.GetProxy();
SetUpMissingValues(proxy, result);
return result;
}
示例9: IntegrationTest
public void IntegrationTest()
{
ProxyFactory pf = new ProxyFactory(new TestTarget());
ILog log = (ILog)mocks.CreateMock(typeof(ILog));
SimpleLoggingAdvice loggingAdvice = new SimpleLoggingAdvice(log);
pf.AddAdvice(loggingAdvice);
Expect.Call(log.IsTraceEnabled).Return(true).Repeat.Any();
log.Trace("Entering DoSomething");
log.Trace("Exiting DoSomething");
mocks.ReplayAll();
object proxy = pf.GetProxy();
ITestTarget ptt = (ITestTarget)proxy;
ptt.DoSomething();
mocks.VerifyAll();
}
示例10: AddAndRemoveEventHandlerThroughInterceptor
public void AddAndRemoveEventHandlerThroughInterceptor()
{
TestObject target = new TestObject();
NopInterceptor nopInterceptor = new NopInterceptor();
CountingBeforeAdvice countingBeforeAdvice = new CountingBeforeAdvice();
target.Name = "SOME-NAME";
ProxyFactory pf = new ProxyFactory(target);
pf.AddAdvice(nopInterceptor);
pf.AddAdvisor(new DefaultPointcutAdvisor(countingBeforeAdvice));
object proxy = pf.GetProxy();
ITestObject to = proxy as ITestObject;
// add event handler through proxy
to.Click += new EventHandler(OnClick);
OnClickWasCalled = false;
to.OnClick();
Assert.IsTrue(OnClickWasCalled);
Assert.AreEqual(2, countingBeforeAdvice.GetCalls());
// remove event handler through proxy
to.Click -= new EventHandler(OnClick);
OnClickWasCalled = false;
to.OnClick();
Assert.IsFalse(OnClickWasCalled);
Assert.AreEqual(4, countingBeforeAdvice.GetCalls());
}
示例11: AdvisedSupportListenerMethodsAreCalledAppropriately
public void AdvisedSupportListenerMethodsAreCalledAppropriately()
{
IAdvisedSupportListener listener = MockRepository.GenerateMock<IAdvisedSupportListener>();
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
// must fire the Activated callback...
factory.GetProxy();
// must fire the AdviceChanged callback...
factory.AddAdvice(new NopInterceptor());
// must fire the InterfacesChanged callback...
factory.AddInterface(typeof(ISerializable));
listener.AssertWasCalled(x => x.Activated(Arg<AdvisedSupport>.Is.NotNull));
listener.AssertWasCalled(x => x.AdviceChanged(Arg<AdvisedSupport>.Is.NotNull));
listener.AssertWasCalled(x => x.InterfacesChanged(Arg<AdvisedSupport>.Is.NotNull));
}
示例12: CreateProxy
private ITestObject CreateProxy()
{
exceptionHandlerAdvice.AfterPropertiesSet();
ProxyFactory pf = new ProxyFactory(new TestObject());
pf.AddAdvice(exceptionHandlerAdvice);
return (ITestObject)pf.GetProxy();
}
示例13: CreateProxy
private ITestObject CreateProxy(object target, IAdvice interceptor, bool exposeProxy)
{
ProxyFactory pf = new ProxyFactory(target);
pf.ExposeProxy = exposeProxy;
// pf.Target = target;
pf.AddAdvice(interceptor);
return pf.GetProxy() as ITestObject;
}
示例14: ReplaceAdvisor
public void ReplaceAdvisor()
{
TestObject target = new TestObject();
ProxyFactory pf = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
CountingBeforeAdvice cba1 = new CountingBeforeAdvice();
CountingBeforeAdvice cba2 = new CountingBeforeAdvice();
IAdvisor advisor1 = new DefaultPointcutAdvisor(cba1);
IAdvisor advisor2 = new DefaultPointcutAdvisor(cba2);
pf.AddAdvisor(advisor1);
pf.AddAdvice(nop);
ITestObject proxied = (ITestObject)pf.GetProxy();
// Use the type cast feature
// Replace etc methods on advised should be same as on ProxyFactory
IAdvised advised = (IAdvised)proxied;
proxied.Age = 5;
Assert.AreEqual(1, cba1.GetCalls());
Assert.AreEqual(0, cba2.GetCalls());
Assert.AreEqual(1, nop.Count);
Assert.IsFalse(advised.ReplaceAdvisor(null, null));
Assert.IsFalse(advised.ReplaceAdvisor(null, advisor2));
Assert.IsFalse(advised.ReplaceAdvisor(advisor1, null));
Assert.IsTrue(advised.ReplaceAdvisor(advisor1, advisor2));
Assert.AreEqual(advisor2, pf.Advisors[0]);
Assert.AreEqual(5, proxied.Age);
Assert.AreEqual(1, cba1.GetCalls());
Assert.AreEqual(2, nop.Count);
Assert.AreEqual(1, cba2.GetCalls());
Assert.IsFalse(pf.ReplaceAdvisor(new DefaultPointcutAdvisor(null), advisor1));
}
示例15: LoggingTest
public void LoggingTest()
{
LogExceptionHandler logHandler = new LogExceptionHandler();
logHandler.LogName = "adviceHandler";
string testText =
@"'Hello World, exception message = ' + #e.Message + ', target method = ' + #method.Name";
logHandler.SourceExceptionNames.Add("ArithmeticException");
logHandler.ActionExpressionText = testText;
exceptionHandlerAdvice.ExceptionHandlers.Add(logHandler);
exceptionHandlerAdvice.AfterPropertiesSet();
ProxyFactory pf = new ProxyFactory(new TestObject());
pf.AddAdvice(exceptionHandlerAdvice);
ITestObject to = (ITestObject)pf.GetProxy();
try
{
to.Exceptional(new ArithmeticException());
Assert.Fail("Should have thrown exception when only logging");
}
catch (ArithmeticException)
{
bool found = false;
foreach (string message in loggerFactoryAdapter.LogMessages)
{
if (message.IndexOf("Hello World") >= 0)
{
found = true;
}
}
Assert.IsTrue(found, "did not find logging output");
}
}