1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace AspectSharpExample
18 using System
.Collections
;
21 using AspectSharp
.Builder
;
23 using AspectSharp
.Example
;
24 using AspectSharp
.Example
.Views
;
25 using AspectSharp
.Example
.ContentProviders
;
28 /// Summary description for Application.
30 public class Application
32 public static void Main()
34 // First we're going to execute two content providers and
35 // display the contents using the PlainTextView
38 // Now we're going to execute adding a security
39 // mixin to content providers and security checking through
41 MixinAndInterceptorExecution();
43 // Altering the Hashtable
46 Console
.WriteLine("\r\nPress any key to exit." );
50 private static void SimpleExecution()
52 Console
.Out
.WriteLine( " o0o First execution o0o " );
54 RequestPipeline pipeline
= new RequestPipeline();
55 pipeline
.Context
["username"] = "Billy Paul Mckinsky";
56 pipeline
.AddContentProvider( new StaticContentProvider() );
57 pipeline
.AddContentProvider( new DynamicContentProvider() );
58 pipeline
.View
= new PlainTextView();
59 pipeline
.ProcessRequest( Console
.Out
);
61 Console
.Out
.WriteLine();
64 private static void MixinAndInterceptorExecution()
66 Console
.Out
.WriteLine( " o0o Within security checking o0o " );
68 // For the sake of readability we're keep the aspect code here:
70 " import AspectSharp.Example.Aop.Interceptors " +
71 " import AspectSharp.Example.Aop.Mixins " +
73 " aspect sample for [ AspectSharp.Example.ContentProviders ] " +
74 " include SecurityMixin " +
76 " pointcut method(* RetrieveContent())" +
77 " advice(SecurityCheckInterceptor)" +
82 AspectLanguageEngineBuilder builder
= new AspectLanguageEngineBuilder( contents
);
83 AspectEngine engine
= builder
.Build();
85 RequestPipeline pipeline
= new RequestPipeline();
86 pipeline
.Context
["username"] = "Billy Paul Mckinsky";
87 pipeline
.AddContentProvider( engine
.WrapClass( typeof(StaticContentProvider
) ) as IContentProvider
);
88 pipeline
.AddContentProvider( engine
.WrapClass( typeof(DynamicContentProvider
) ) as IContentProvider
);
89 pipeline
.View
= new PlainTextView();
90 pipeline
.ProcessRequest( Console
.Out
);
92 Console
.Out
.WriteLine();
95 private static void HashtableTest()
97 Console
.Out
.WriteLine( " o0o Changing default hashtable value o0o " );
99 // For the sake of readability we're keep the aspect code here:
101 " import System.Collections " +
103 " aspect sample for Hashtable " +
105 " pointcut propertyread(* Item(*))" +
106 " advice(HashcodeDefaultValueInterceptor)" +
111 AspectLanguageEngineBuilder builder
= new AspectLanguageEngineBuilder( contents
);
112 AspectEngine engine
= builder
.Build();
114 IDictionary myHashTable
= engine
.WrapClass( typeof(Hashtable
) ) as IDictionary
;
116 String
value = myHashTable
["item"] as String
;
117 Console
.Out
.WriteLine( "Default value is {0}", value );
119 Console
.Out
.WriteLine();