Skip to content

Commit

Permalink
An initial infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Feb 22, 2013
1 parent 4cf115e commit 230fb5d
Show file tree
Hide file tree
Showing 17 changed files with 828 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2013 Antya Dev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
20 changes: 20 additions & 0 deletions src/VS 2010/KingAOP.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KingAOP", "KingAOP\KingAOP.csproj", "{ED8B42DC-F376-42A7-9281-452A026AA864}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED8B42DC-F376-42A7-9281-452A026AA864}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED8B42DC-F376-42A7-9281-452A026AA864}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED8B42DC-F376-42A7-9281-452A026AA864}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED8B42DC-F376-42A7-9281-452A026AA864}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
49 changes: 49 additions & 0 deletions src/VS 2010/KingAOP/Aspects/Arguments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System.Collections.Generic;
using System.Dynamic;

namespace KingAOP.Aspects
{
/// <summary>
/// Encapsulation of method arguments.
/// </summary>
public class Arguments
{
private readonly List<object> _objects = new List<object>();

public Arguments(IEnumerable<DynamicMetaObject> objects)
{
foreach (var obj in objects)
{
_objects.Add(obj.Value);
}
}

public object this[int index]
{
get { return _objects[index]; }
}

public int Count
{
get { return _objects.Count; }
}
}
}
33 changes: 33 additions & 0 deletions src/VS 2010/KingAOP/Aspects/Aspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;

namespace KingAOP.Aspects
{
/// <summary>
/// Base class for all aspects that are declared
/// </summary>
public abstract class Aspect : Attribute, IAspect
{
/// <summary>
/// Gets or sets the weaving priority of the aspect.
/// </summary>
public int AspectPriority { get; set; }
}
}
32 changes: 32 additions & 0 deletions src/VS 2010/KingAOP/Aspects/FlowBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

namespace KingAOP.Aspects
{
/// <summary>
/// Enumerates the possible behaviors of the calling method after the calling method has returned.
/// </summary>
public enum FlowBehavior
{
Default,
Continue,
RethrowException,
Return,
ThrowException,
}
}
26 changes: 26 additions & 0 deletions src/VS 2010/KingAOP/Aspects/IAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

namespace KingAOP.Aspects
{
/// <summary>
/// Base interface for all aspects that are declared
/// </summary>
interface IAspect
{ }
}
26 changes: 26 additions & 0 deletions src/VS 2010/KingAOP/Aspects/IMethodAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

namespace KingAOP.Aspects
{
/// <summary>
/// Base interface for all aspects which should applied to methods.
/// </summary>
interface IMethodAspect : IAspect
{ }
}
66 changes: 66 additions & 0 deletions src/VS 2010/KingAOP/Aspects/MethodExecutionArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.Reflection;

namespace KingAOP.Aspects
{
/// <summary>
/// Arguments of aspect which in executing
/// </summary>
public sealed class MethodExecutionArgs
{
public MethodExecutionArgs(object instance, MethodInfo method, Arguments arguments)
{
Instance = instance;
Method = method;
Arguments = arguments;
}

/// <summary>
/// Gets the object instance on which the method is being executed.
/// </summary>
public object Instance { get; private set; }

/// <summary>
/// Gets the method being executed.
/// </summary>
public MethodInfo Method { get; private set; }

/// <summary>
/// Determines the control flow of the target method once the advice is exited.
/// </summary>
public FlowBehavior FlowBehavior { get; set; }

/// <summary>
/// Gets the arguments with which the method has been invoked.
/// </summary>
public Arguments Arguments { get; set; }

/// <summary>
/// Gets or sets the method return value.
/// </summary>
public object ReturnValue { get; set; }

/// <summary>
/// Gets the exception currently flying.
/// </summary>
public Exception Exception { get; set; }
}
}
56 changes: 56 additions & 0 deletions src/VS 2010/KingAOP/Aspects/OnMethodBoundaryAspect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

namespace KingAOP.Aspects
{
/// <summary>
/// Represents a class that can wrap itself around any given method call.
/// </summary>
public abstract class OnMethodBoundaryAspect : Aspect
{
/// <summary>
/// Method executed before the body of method to which this aspect is applied.
/// </summary>
/// <param name="args">Method arguments including return value and all necessary info.</param>
public virtual void OnEntry(MethodExecutionArgs args)
{ }

/// <summary>
/// Method executed after the body of method to which this aspect is applied
/// (this method is invoked from the finally block, it's mean that this method will be invoked in any way)
/// </summary>
/// <param name="args">Method arguments including return value and all necessary info.</param>
public virtual void OnExit(MethodExecutionArgs args)
{ }

/// <summary>
/// Method executed after the body of method to which this aspect is applied,
/// but only when the method successfully returns
/// </summary>
/// <param name="args">Method arguments including return value and all necessary info.</param>
public virtual void OnSuccess(MethodExecutionArgs args)
{ }

/// <summary>
/// When an exception is happened then this method will be called.
/// </summary>
/// <param name="args">Method arguments including return value and all necessary info.</param>
public virtual void OnException(MethodExecutionArgs args)
{ }
}
}
42 changes: 42 additions & 0 deletions src/VS 2010/KingAOP/Core/AspectCacheFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2013 Antya Dev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections;

namespace KingAOP.Core
{
/// <summary>
/// Represent a global aspect cache factory.
/// </summary>
internal class AspectCacheFactory
{
private static readonly Hashtable Cache = new Hashtable();

public static object GetAspect(Type aspectType)
{
var aspect = Cache[aspectType];
if (aspect == null)
{
aspect = Activator.CreateInstance(aspectType);
Cache[aspectType] = aspect;
}
return aspect;
}
}
}
Loading

0 comments on commit 230fb5d

Please sign in to comment.