private static void HashtableTest()
		{
			Console.Out.WriteLine( " o0o Changing default hashtable value o0o " );

			// For the sake of readability we're keep the aspect code here:
			String contents = 
				" import System.Collections " + 
				" " +
				" aspect sample for Hashtable " + 
				"   " + 
				"   pointcut propertyread(* Item(*))" + 
				"     advice(HashcodeDefaultValueInterceptor)" + 
				"   end" + 
				"   " + 
				" end ";

			AspectLanguageEngineBuilder builder = new AspectLanguageEngineBuilder( contents );
			AspectEngine engine = builder.Build();

			IDictionary myHashTable = engine.WrapClass( typeof(Hashtable) ) as IDictionary;

			String value = myHashTable["item"] as String;
			Console.Out.WriteLine( "Default value is {0}", value );

			Console.Out.WriteLine();			
		}
Exemplo n.º 2
0
        public void InterfaceWrap()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for [ assignableFrom(IPartiallyComplex) ] " +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            IPartiallyComplex instance = null;

            instance = engine.WrapInterface(typeof(IPartiallyComplex), new ComplexClass()) as IPartiallyComplex;

            instance.DoNothing();
            instance.DoSomething();

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(2, messages.Length);
        }
		private static void MixinAndInterceptorExecution()
		{
			Console.Out.WriteLine( " o0o Within security checking o0o " );

			// For the sake of readability we're keep the aspect code here:
			String contents = 
				" import AspectSharp.Example.Aop.Interceptors " + 
				" import AspectSharp.Example.Aop.Mixins " + 
				" " +
				" aspect sample for [ AspectSharp.Example.ContentProviders ] " + 
				"   include SecurityMixin " + 
				"   " + 
				"   pointcut method(* RetrieveContent())" + 
				"     advice(SecurityCheckInterceptor)" + 
				"   end" + 
				"   " + 
				" end ";

			AspectLanguageEngineBuilder builder = new AspectLanguageEngineBuilder( contents );
			AspectEngine engine = builder.Build();

			RequestPipeline pipeline = new RequestPipeline();
			pipeline.Context["username"] = "******";
			pipeline.AddContentProvider( engine.WrapClass( typeof(StaticContentProvider) ) as IContentProvider );
			pipeline.AddContentProvider( engine.WrapClass( typeof(DynamicContentProvider) ) as IContentProvider );
			pipeline.View = new PlainTextView();
			pipeline.ProcessRequest( Console.Out );

			Console.Out.WriteLine();
		}
Exemplo n.º 4
0
        public void ClassWithConstructorArguments()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            ComplexClass instance = null;

            instance = engine.WrapClass(typeof(ComplexClass), "Eric Cartman") as ComplexClass;
            Assert.AreEqual("Eric Cartman", instance.Name);
            Assert.IsFalse(instance.Started);
            InvokeAndAssert(instance);

            instance = engine.WrapClass(typeof(ComplexClass), "Kenny McKormick", true) as ComplexClass;
            Assert.AreEqual("Kenny McKormick", instance.Name);
            Assert.IsTrue(instance.Started);
            InvokeAndAssert(instance);

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(20, messages.Length);
        }
Exemplo n.º 5
0
        public void ClassWithConstructorArgumentsAndNoAspects()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " interceptors [" +
                              " \"key\" : DummyInterceptor " +
                              " ]" +
                              " mixins [" +
                              " \"key\" : DummyMixin " +
                              " ]" +
                              " " +
                              " aspect McBrother for DummyCustomer " +
                              "   include \"key\"" +
                              "   " +
                              "   pointcut method(*)" +
                              "     advice(\"key\")" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            ComplexClass instance = null;

            instance = engine.WrapClass(typeof(ComplexClass), "Eric Cartman") as ComplexClass;
            Assert.AreEqual("Eric Cartman", instance.Name);
            Assert.IsFalse(instance.Started);
        }
Exemplo n.º 6
0
        public void InterceptWithComplexSignatures()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut method(* Do.*(*))" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              "   pointcut propertyread(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              "   pointcut propertywrite(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            WrapAndInvokeEverything(engine);
        }
Exemplo n.º 7
0
        public void BuildUsingLanguageWithDifferingKeys()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " interceptors [" +
                              " \"interceptor\" : DummyInterceptor " +
                              " ]" +
                              " mixins [" +
                              " \"mixin\" : DummyMixin " +
                              " ]" +
                              " " +
                              " aspect McBrother for DummyCustomer " +
                              "   include \"mixin\"" +
                              "   " +
                              "   pointcut method(*)" +
                              "     advice(\"interceptor\")" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);

            AspectEngine engine = builder.Build();

            AssertEngineConfiguration(engine);
        }
        public void ImplementLoggerProperty()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for Author " +
                              "   " +
                              "   include Loggeable" +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(LogInvocationsInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            Author author = engine.WrapClass(typeof(Author)) as Author;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ILoggeable);

            Assert.AreEqual(0, author.BooksPublished);
            author.MoreOneBook();
            Assert.AreEqual(1, author.BooksPublished);

            ILoggeable log      = author as ILoggeable;
            String     messages = log.GetLogMessages();

            // TODO: Correct compare
            Assert.AreEqual("Invoking get_BooksPublished;Invoking MoreOneBook;Invoking get_BooksPublished;", messages);
        }
        static void Main(string[] args)
        {
            String weavingRules =
                " import AOPServices.Aspects " +
                " " +
                " aspect AuthorizationAspect for [ AOPServices.Services ] " +
                "   " +
                "   pointcut method(* Start())" +
                "     advice(AuthorizationAdvice)" +
                "   end" +
                "   " +
                "   pointcut method(* Stop())" +
                "     advice(AuthorizationAdvice)" +
                "   end" +
                "   " +
                " end ";

            AspectLanguageEngineBuilder builder = new AspectLanguageEngineBuilder(weavingRules);
            AspectEngine engine = builder.Build();

            NASDAQHeartBeatService nasdaqService = engine.WrapClass(typeof(NASDAQHeartBeatService)) as NASDAQHeartBeatService;

            nasdaqService.Start();
            Console.ReadLine();
        }
        public void MakeAuthorAPersonAndACustomer()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for Author " +
                              "   " +
                              "   include DummyCustomer" +
                              "   include DummyPerson" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            Author author = engine.WrapClass(typeof(Author)) as Author;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ICustomer);
            Assert.IsNotNull(author as IPerson);

            ICustomer customer = author as ICustomer;

            customer.CustomerId = 10;
            Assert.AreEqual(10, customer.CustomerId);

            IPerson person = author as IPerson;

            person.Name = "Billy Paul McKinsky";
            Assert.AreEqual(10, customer.CustomerId);

            Assert.AreEqual(0, author.BooksPublished);
            author.MoreOneBook();
            Assert.AreEqual(1, author.BooksPublished);
        }
Exemplo n.º 11
0
        private void RegisterAspectEngine()
        {
            String contents = FacilityConfig.Value;

            // By now we're supporting only AspectLanguageEngineBuilder

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);

            ComponentModel model =
                new ComponentModel("aspectsharp.engine",
                                   typeof(AspectEngine), typeof(AspectEngine));

            model.ExtendedProperties.Add("builder", builder);
            model.CustomComponentActivator = typeof(AspectEngineActivator);

            Kernel.AddCustomComponent(model);
        }
        public void MixinProxyAware()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for LogEnabledAuthor " +
                              "   " +
                              "   include LogFactoryMixin" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            LogEnabledAuthor author = engine.WrapClass(typeof(LogEnabledAuthor)) as LogEnabledAuthor;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ILogEnabled);
            Assert.IsNotNull(author.Logger);
        }
        public void InterceptAllDoSMethods()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut method(* DoS.*(*))" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            WrapAndInvokeEverything(engine);

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(3, messages.Length);
        }
        public void InterceptAllProperties()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect MyAspect for ComplexClass " +
                              "   " +
                              "   pointcut property(*)" +
                              "     advice(AspectSharp.Tests.Classes.LogInvocationInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            WrapAndInvokeEverything(engine);

            String[] messages = LogInvocationInterceptor.Messages;
            Assert.AreEqual(4, messages.Length);
            // TODO: Assert messages in correct order
        }
        public void MixinMethodsMustBeIntercepted()
        {
            String contents = "import AspectSharp.Tests.Classes in AspectSharp.Tests " +
                              " " +
                              " aspect McBrother for Author " +
                              "   " +
                              "   include Loggeable" +
                              "   include DummyPerson" +
                              "   " +
                              "   pointcut method|property(*)" +
                              "     advice(LogInvocationsInterceptor)" +
                              "   end" +
                              "   " +
                              " end ";

            AspectEngineBuilder builder = new AspectLanguageEngineBuilder(contents);
            AspectEngine        engine  = builder.Build();

            Author author = engine.WrapClass(typeof(Author)) as Author;

            Assert.IsNotNull(author);
            Assert.IsNotNull(author as ILoggeable);
            Assert.IsNotNull(author as IPerson);

            IPerson person = author as IPerson;

            person.Name = "McBilly";
            Assert.AreEqual("McBilly", person.Name);

            ILoggeable log = author as ILoggeable;

            log.Log("Test");
            String messages = log.GetLogMessages();

            Assert.AreEqual("Invoking set_Name;Invoking get_Name;Test;", messages);
        }
Exemplo n.º 16
0
 private PlugInDynamicProxy()
 {
     builder = new AspectLanguageEngineBuilder(string.Empty);
     engine  = builder.Build();
 }