├── .gitignore
├── .gitmodules
├── Build
├── Build.cmd
├── Build.proj
├── BuildAndPackage.cmd
└── BuildAndTest.cmd
├── Common
├── AssemblyVersion.cs
└── CommonAssemblyInfo.cs
├── NugetTemplates
├── SharpArchContrib.Castle
│ └── SharpArchContrib.Castle.nuspec
├── SharpArchContrib.Core
│ └── SharpArchContrib.Core.nuspec
└── SharpArchContrib.Data
│ └── SharpArchContrib.Data.nuspec
├── README
├── ReferencedAssemblies
└── Microsoft
│ └── Microsoft.Practices.ServiceLocation.dll
├── Solutions
├── .nuget
│ ├── NuGet.Config
│ ├── NuGet.exe
│ └── NuGet.targets
├── Settings.StyleCop
├── SharpArchContrib.Castle
│ ├── AttributeControlledFacilityBase.cs
│ ├── CastleWindsor
│ │ ├── ComponentRegistrar.cs
│ │ ├── CoreComponentRegistrar.cs
│ │ └── NHibernateTransactionsComponentRegistrar.cs
│ ├── Logging
│ │ ├── ExceptionHandlerAttribute.cs
│ │ ├── ExceptionHandlerFacility.cs
│ │ ├── ExceptionHandlerInterceptor.cs
│ │ ├── LogAttribute.cs
│ │ ├── LogFacility.cs
│ │ └── LogInterceptor.cs
│ ├── NHibernate
│ │ ├── TransactionAttribute.cs
│ │ ├── TransactionFacility.cs
│ │ ├── TransactionInterceptor.cs
│ │ ├── UnitOfWorkAttribute.cs
│ │ ├── UnitOfWorkFacility.cs
│ │ └── UnitOfWorkInterceptor.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── SharpArchContrib.Castle.csproj
│ ├── SharpArchContrib.snk
│ └── packages.config
├── SharpArchContrib.Core
│ ├── Extensions
│ │ └── TypeExtensions.cs
│ ├── Logging
│ │ ├── ExceptionHandlerAttributeSettings.cs
│ │ ├── ExceptionLogger.cs
│ │ ├── IExceptionLogger.cs
│ │ ├── IMethodLogger.cs
│ │ ├── Log4NetHelper.cs
│ │ ├── LogAttributeSettings.cs
│ │ ├── LoggingLevel.cs
│ │ └── MethodLogger.cs
│ ├── MultiTenant
│ │ ├── IMultiTenantEntity.cs
│ │ ├── IMultiTenantQuery.cs
│ │ ├── IMultiTenantRepository.cs
│ │ └── ITenantContext.cs
│ ├── ParameterCheck.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── SharpArchContrib.Core.csproj
│ ├── SharpArchContrib.snk
│ └── packages.config
├── SharpArchContrib.Data
│ ├── NHibernate
│ │ ├── AbortTransactionException.cs
│ │ ├── IThreadSafeDictionary.cs
│ │ ├── ITransactionAttributeSettings.cs
│ │ ├── ITransactionManager.cs
│ │ ├── IUnitOfWorkSessionStorage.cs
│ │ ├── MultiTenantSessionFactoryKeyProvider.cs
│ │ ├── NHibernateTransactionManager.cs
│ │ ├── SystemTransactionManager.cs
│ │ ├── ThreadSafeDictionary.cs
│ │ ├── ThreadSessionStorage.cs
│ │ ├── TransactionAttributeSettings.cs
│ │ ├── TransactionManagerBase.cs
│ │ └── UnitOfWorkAttributeSettings.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── SharpArchContrib.Data.csproj
│ ├── SharpArchContrib.snk
│ └── packages.config
├── SharpArchContrib.PostSharp
│ ├── Logging
│ │ ├── ExceptionHandlerAttribute.cs
│ │ └── LogAttribute.cs
│ ├── NHibernate
│ │ ├── TransactionAttribute.cs
│ │ └── UnitOfWorkAttribute.cs
│ ├── PostSharp.license
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── SharpArchContrib.PostSharp.csproj
│ ├── SharpArchContrib.snk
│ └── packages.config
├── SharpArchContrib.Specifications
│ └── ServiceLocatorHelper.cs
├── SharpArchContrib.Tests
│ ├── App.config
│ ├── AssemblySetup.cs
│ ├── Configuration
│ │ └── Config.cs
│ ├── DomainModel
│ │ ├── AutoPersistenceModelGenerator.cs
│ │ ├── Conventions
│ │ │ ├── HasManyConvention.cs
│ │ │ ├── PrimaryKeyConvention.cs
│ │ │ ├── ReferenceConvention.cs
│ │ │ └── TableNameConvention.cs
│ │ ├── Entities
│ │ │ └── TestEntity.cs
│ │ └── NHibernateMaps
│ │ │ └── TestEntityMap.cs
│ ├── HibernateFile.cfg.xml
│ ├── NHibernateTests
│ │ ├── ITransactionTestProvider.cs
│ │ ├── TransactionTestProviderBase.cs
│ │ ├── TransactionTests.cs
│ │ └── TransactionTestsBase.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── ServiceLocatorInitializer.cs
│ ├── SharpArchContrib.Castle
│ │ ├── Logging
│ │ │ ├── ExceptionHandlerAttributeTests.cs
│ │ │ ├── ExceptionHandlerTestClass.cs
│ │ │ ├── IExceptionHandlerTestClass.cs
│ │ │ ├── ILogTestClass.cs
│ │ │ ├── LogTestClass.cs
│ │ │ └── LoggingTests.cs
│ │ └── NHibernate
│ │ │ ├── NHibernateTransactionTestProvider.cs
│ │ │ ├── NHibernateUnitOfWorkTestProvider.cs
│ │ │ ├── SystemTransactionTestProvider.cs
│ │ │ ├── SystemUnitOfWorkTestProvider.cs
│ │ │ └── TransactionAttributeTests.cs
│ ├── SharpArchContrib.Core
│ │ └── ParameterCheckTests.cs
│ ├── SharpArchContrib.Data
│ │ └── NHibernate
│ │ │ └── MultiTenantSessionFactoryKeyProviderTests.cs
│ ├── SharpArchContrib.PostSharp
│ │ ├── Logging
│ │ │ ├── DebugLevelTests.cs
│ │ │ └── ExceptionHandlerAttributeTests.cs
│ │ └── NHibernate
│ │ │ ├── NHibernateTransactionTestProvider.cs
│ │ │ ├── NHibernateUnitOfWorkTestProvider.cs
│ │ │ ├── SystemTransactionTestProvider.cs
│ │ │ └── SystemUnitOfWorkTestProvider.cs
│ ├── SharpArchContrib.Tests.csproj
│ ├── SyntaxHelper.cs
│ ├── TestCategories.cs
│ └── packages.config
├── SharpArchContrib.sln
└── nuget.config
├── VersionHistory.txt
├── license.txt
└── readme.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | #ignore outputs of project
2 | BuildOutput*/
3 | Drops/
4 | CommonAssemblyInfo.cs
5 | #ignore thumbnails created by windows
6 | Thumbs.db
7 | #Ignore files build by Visual Studio
8 | *.obj
9 | *.pdb
10 | *.user
11 | *.aps
12 | *.pch
13 | *.vspscc
14 | *_i.c
15 | *_p.c
16 | *.ncb
17 | *.suo
18 | *.tlb
19 | *.tlh
20 | *.bak
21 | *.cache
22 | *.ilk
23 | *.log
24 | [Bb]in
25 | !tools/**/*
26 | [Dd]ebug*/
27 | *.lib
28 | *.sbr
29 | obj/
30 | Solutions/**/[Rr]elease*/
31 | _ReSharper*/
32 | [Tt]est[Rr]esult*
33 | [Ss]pecification[Rr]eports
34 | [Pp]ackages
35 | NugetWorkspace
36 | StyleCop.Cache
37 | *.ReSharper
38 | *.dotCover
39 | *_mm_cache.bin
40 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "BuildSystem"]
2 | path = BuildSystem
3 | url = git://github.com/sharparchitecture/Sharp-Architecture-Build.git
4 |
--------------------------------------------------------------------------------
/Build/Build.cmd:
--------------------------------------------------------------------------------
1 | %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild Build.proj /t:Build /p:IsDesktopBuild=true
2 | pause
--------------------------------------------------------------------------------
/Build/Build.proj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SharpArchContrib
6 | $(MSBuildProjectDirectory)\..\Solutions
7 | $(MSBuildProjectDirectory)\..\BuildSystem
8 | $(BuildPath)\..\..
9 | 1
10 | 0
11 | 1
12 |
13 |
14 |
15 |
16 |
21 | $(DropsPath)\$(SemanticVersion)\$(PackageName).Source.v$(SemanticVersion).zip
22 | $(SolutionsPath)
23 | False
24 |
25 |
26 |
30 | $(DropsPath)\$(SemanticVersion)\$(PackageName).dlls.v$(SemanticVersion).zip
31 | $(SolutionsPath)
32 | True
33 |
34 |
35 |
36 |
37 |
39 | SharpArchContrib.Core
40 | SharpArchContrib.Core.nuspec
41 |
42 |
43 |
45 | SharpArchContrib.Data
46 | SharpArchContrib.Data.nuspec
47 |
48 |
49 |
51 | SharpArchContrib.Castle
52 | SharpArchContrib.Castle.nuspec
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
66 |
67 |
70 |
71 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/Build/BuildAndPackage.cmd:
--------------------------------------------------------------------------------
1 | %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild Build.proj /p:IsDesktopBuild=true
2 | pause
--------------------------------------------------------------------------------
/Build/BuildAndTest.cmd:
--------------------------------------------------------------------------------
1 | %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild Build.proj /t:RunTests /p:IsDesktopBuild=true
2 | pause
--------------------------------------------------------------------------------
/Common/AssemblyVersion.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.239
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | using System;
12 | using System.Reflection;
13 | using System.Runtime.CompilerServices;
14 | using System.Runtime.InteropServices;
15 |
16 | [assembly: AssemblyFileVersion("1.0.0.0")]
17 | [assembly: AssemblyInformationalVersion("1.0.0-RC-0")]
18 | [assembly: AssemblyVersion("1.0.0.0")]
19 |
20 |
21 |
--------------------------------------------------------------------------------
/Common/CommonAssemblyInfo.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/Common/CommonAssemblyInfo.cs
--------------------------------------------------------------------------------
/NugetTemplates/SharpArchContrib.Castle/SharpArchContrib.Castle.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SharpArchContrib.Castle
5 |
6 | Sharp Architecture Dev Team
7 | Sharp Architecture Dev Team
8 | https://github.com/sharparchitecture/Sharp-Architecture-Contrib/blob/master/license.txt
9 | https://github.com/sharparchitecture/Sharp-Architecture-Contrib/
10 | https://github.com/sharparchitecture/Sharp-Architecture/raw/master/Artefacts/Documentation/Logo_100x100.png
11 | false
12 | Provides logging, exception handling, transaction and unit of work attributes that use Castle DynamicProxy interceptors and facilities to provide AOP. Also contains SharpArchContrib component registrars for registering components required in Castle Windsor.
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/NugetTemplates/SharpArchContrib.Core/SharpArchContrib.Core.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SharpArchContrib.Core
5 |
6 | Sharp Architecture Dev Team
7 | Sharp Architecture Dev Team
8 | https://github.com/sharparchitecture/Sharp-Architecture-Contrib/blob/master/license.txt
9 | https://github.com/sharparchitecture/Sharp-Architecture-Contrib/
10 | https://github.com/sharparchitecture/Sharp-Architecture/raw/master/Artefacts/Documentation/Logo_100x100.png
11 | false
12 | Provides logging (using log4net) and exception handling classes used by SharpArchContrib.Castle and SharpArchContrib.Postsharp. Also contains interfaces for adding multi tenancy data access to a sharp architecture project.
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/NugetTemplates/SharpArchContrib.Data/SharpArchContrib.Data.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SharpArchContrib.Data
5 |
6 | Sharp Architecture Dev Team
7 | Sharp Architecture Dev Team
8 | https://github.com/sharparchitecture/Sharp-Architecture-Contrib/blob/master/license.txt
9 | https://github.com/sharparchitecture/Sharp-Architecture-Contrib/
10 | https://github.com/sharparchitecture/Sharp-Architecture/raw/master/Artefacts/Documentation/Logo_100x100.png
11 | false
12 | Provides a ThreadSafeSessionStorage that enables using SharpArchitecture outside a web project. Also provides classes for managing NHibernate transactions and units of work that are used by SharpArchContrib.Castle and SharpArchContrib.Postsharp attributes.
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/README
--------------------------------------------------------------------------------
/ReferencedAssemblies/Microsoft/Microsoft.Practices.ServiceLocation.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/ReferencedAssemblies/Microsoft/Microsoft.Practices.ServiceLocation.dll
--------------------------------------------------------------------------------
/Solutions/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Solutions/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/Solutions/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/Solutions/.nuget/NuGet.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildProjectDirectory)\..\
5 | $([System.IO.Path]::Combine($(SolutionDir), ".nuget"))
6 | $(NuGetToolsPath)\nuget.exe
7 | $([System.IO.Path]::Combine($(ProjectDir), "packages.config"))
8 | $([System.IO.Path]::Combine($(SolutionDir), "..\Packages"))
9 | $(TargetDir.Trim('\\'))
10 |
11 |
12 | ""
13 |
14 |
15 | false
16 |
17 |
18 | false
19 |
20 |
21 | "$(NuGetExePath)" install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"
22 | "$(NuGetExePath)" pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols
23 |
24 |
25 |
26 | RestorePackages;
27 | $(BuildDependsOn);
28 |
29 |
30 |
31 |
32 | $(BuildDependsOn);
33 | BuildPackage;
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
46 |
47 |
48 |
49 |
51 |
52 |
--------------------------------------------------------------------------------
/Solutions/Settings.StyleCop:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | False
8 |
9 |
10 |
11 |
12 | False
13 |
14 |
15 |
16 |
17 | False
18 |
19 |
20 |
21 |
22 | False
23 |
24 |
25 |
26 |
27 | False
28 |
29 |
30 |
31 |
32 | False
33 |
34 |
35 |
36 |
37 | False
38 |
39 |
40 |
41 |
42 | False
43 |
44 |
45 |
46 |
47 | False
48 |
49 |
50 |
51 |
52 | False
53 |
54 |
55 |
56 |
57 | False
58 |
59 |
60 |
61 |
62 | False
63 |
64 |
65 |
66 |
67 | False
68 |
69 |
70 |
71 |
72 | False
73 |
74 |
75 |
76 |
77 | False
78 |
79 |
80 |
81 |
82 | False
83 |
84 |
85 |
86 |
87 | False
88 |
89 |
90 |
91 |
92 | False
93 |
94 |
95 |
96 |
97 | False
98 |
99 |
100 |
101 |
102 | False
103 |
104 |
105 |
106 |
107 | False
108 |
109 |
110 |
111 |
112 | False
113 |
114 |
115 |
116 |
117 | False
118 |
119 |
120 |
121 |
122 | False
123 |
124 |
125 |
126 |
127 | False
128 |
129 |
130 |
131 |
132 | False
133 |
134 |
135 |
136 |
137 | False
138 |
139 |
140 |
141 |
142 | False
143 |
144 |
145 |
146 |
147 | False
148 |
149 |
150 |
151 |
152 | False
153 |
154 |
155 |
156 |
157 | False
158 |
159 |
160 |
161 |
162 | False
163 |
164 |
165 |
166 |
167 | False
168 |
169 |
170 |
171 |
172 | False
173 |
174 |
175 |
176 |
177 | False
178 |
179 |
180 |
181 |
182 | False
183 |
184 |
185 |
186 |
187 | False
188 |
189 |
190 |
191 |
192 | False
193 |
194 |
195 |
196 |
197 | False
198 |
199 |
200 |
201 |
202 | False
203 |
204 |
205 |
206 |
207 |
208 |
209 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/AttributeControlledFacilityBase.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | using global::Castle.Core;
7 | using global::Castle.DynamicProxy;
8 | using global::Castle.MicroKernel;
9 | using global::Castle.MicroKernel.Facilities;
10 | using global::Castle.MicroKernel.Registration;
11 |
12 | using SharpArchContrib.Core;
13 |
14 | public abstract class AttributeControlledFacilityBase : AbstractFacility
15 | {
16 | private readonly Type interceptorType;
17 |
18 | private readonly LifestyleType lifestyleType;
19 |
20 | public AttributeControlledFacilityBase(Type interceptorType, LifestyleType lifestyleType)
21 | {
22 | ParameterCheck.ParameterRequired(interceptorType, "interceptorType");
23 |
24 | this.interceptorType = interceptorType;
25 | this.lifestyleType = lifestyleType;
26 | }
27 |
28 | protected abstract List GetAttributes(IHandler handler);
29 |
30 | protected override void Init()
31 | {
32 | this.Kernel.Register(Component.For()
33 | .ImplementedBy(this.interceptorType)
34 | .LifeStyle.Is(this.lifestyleType)
35 | .Named(this.interceptorType.Name));
36 | this.Kernel.ComponentRegistered += this.KernelComponentRegistered;
37 | }
38 |
39 | private bool AddInterceptorIfNeeded(IHandler handler, List attributes)
40 | {
41 | foreach (var attribute in attributes)
42 | {
43 | handler.ComponentModel.Interceptors.Add(new InterceptorReference(this.interceptorType.Name));
44 | return true;
45 | }
46 |
47 | return false;
48 | }
49 |
50 | private void KernelComponentRegistered(string key, IHandler handler)
51 | {
52 | this.AddInterceptorIfNeeded(handler, this.GetAttributes(handler));
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/CastleWindsor/ComponentRegistrar.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.CastleWindsor
2 | {
3 | using System;
4 |
5 | using global::Castle.Windsor;
6 |
7 | using SharpArchContrib.Castle.Logging;
8 | using SharpArchContrib.Castle.NHibernate;
9 | using SharpArchContrib.Core;
10 | using SharpArchContrib.Data.NHibernate;
11 |
12 | public static class ComponentRegistrar
13 | {
14 | public static void AddComponentsTo(IWindsorContainer container)
15 | {
16 | AddComponentsTo(container, typeof(NHibernateTransactionManager));
17 | }
18 |
19 | public static void AddComponentsTo(IWindsorContainer container, Type transactionManagerType)
20 | {
21 | ParameterCheck.ParameterRequired(container, "container");
22 |
23 | if (!container.Kernel.HasComponent("LogInterceptor"))
24 | {
25 | Core.CastleWindsor.CoreComponentRegistrar.AddComponentsTo(container);
26 | Data.CastleWindsor.NHibernateTransactionsComponentRegistrar.AddComponentsTo(container, transactionManagerType);
27 | container.AddFacility("LogFacility", new LogFacility());
28 | container.AddFacility("ExceptionHandlerFacility", new ExceptionHandlerFacility());
29 | container.AddFacility("TransactionFacility", new TransactionFacility());
30 | container.AddFacility("UnitOfWorkFacility", new UnitOfWorkFacility());
31 | }
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/CastleWindsor/CoreComponentRegistrar.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.CastleWindsor
2 | {
3 | using global::Castle.MicroKernel.Registration;
4 |
5 | using global::Castle.Windsor;
6 |
7 | using SharpArchContrib.Core.Logging;
8 |
9 | public static class CoreComponentRegistrar
10 | {
11 | public static void AddComponentsTo(IWindsorContainer container)
12 | {
13 | ParameterCheck.ParameterRequired(container, "container");
14 |
15 | if (!container.Kernel.HasComponent("ExceptionLogger"))
16 | {
17 | container.Register(Component.For()
18 | .ImplementedBy()
19 | .Named("ExceptionLogger"));
20 | container.Register(Component.For()
21 | .ImplementedBy()
22 | .Named("MethodLogger"));
23 | }
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/CastleWindsor/NHibernateTransactionsComponentRegistrar.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.CastleWindsor
2 | {
3 | using System;
4 |
5 | using global::Castle.MicroKernel.Registration;
6 | using global::Castle.Windsor;
7 |
8 | using SharpArchContrib.Core;
9 | using SharpArchContrib.Data.NHibernate;
10 |
11 | public static class NHibernateTransactionsComponentRegistrar
12 | {
13 | public static void AddComponentsTo(IWindsorContainer container)
14 | {
15 | AddComponentsTo(container, typeof(NHibernateTransactionManager));
16 | }
17 |
18 | public static void AddComponentsTo(IWindsorContainer container, Type transactionManagerType)
19 | {
20 | ParameterCheck.ParameterRequired(container, "container");
21 | ParameterCheck.ParameterRequired(transactionManagerType, "transactionManagerType");
22 |
23 | if (!container.Kernel.HasComponent("TransactionManager"))
24 | {
25 | Core.CastleWindsor.CoreComponentRegistrar.AddComponentsTo(container);
26 | container.Register(Component.For()
27 | .ImplementedBy(transactionManagerType)
28 | .Named("TransactionManager"));
29 | }
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/Logging/ExceptionHandlerAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 |
5 | using SharpArchContrib.Core.Logging;
6 |
7 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false,
8 | Inherited = false)]
9 | public class ExceptionHandlerAttribute : Attribute
10 | {
11 | public ExceptionHandlerAttribute()
12 | {
13 | this.Settings = new ExceptionHandlerAttributeSettings();
14 | }
15 |
16 | public Type ExceptionType
17 | {
18 | get
19 | {
20 | return this.Settings.ExceptionType;
21 | }
22 |
23 | set
24 | {
25 | this.Settings.ExceptionType = value;
26 | }
27 | }
28 |
29 | public bool IsSilent
30 | {
31 | get
32 | {
33 | return this.Settings.IsSilent;
34 | }
35 |
36 | set
37 | {
38 | this.Settings.IsSilent = value;
39 | }
40 | }
41 |
42 | public object ReturnValue
43 | {
44 | get
45 | {
46 | return this.Settings.ReturnValue;
47 | }
48 |
49 | set
50 | {
51 | this.Settings.ReturnValue = value;
52 | }
53 | }
54 |
55 | public ExceptionHandlerAttributeSettings Settings { get; set; }
56 | }
57 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/Logging/ExceptionHandlerFacility.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | using global::Castle.Core;
7 | using global::Castle.MicroKernel;
8 |
9 | public class ExceptionHandlerFacility : AttributeControlledFacilityBase
10 | {
11 | public ExceptionHandlerFacility()
12 | : base(typeof(ExceptionHandlerInterceptor), LifestyleType.Singleton)
13 | {
14 | }
15 |
16 | protected override List GetAttributes(IHandler handler)
17 | {
18 | var attributes = new List();
19 | this.AddAssemblyLevelAttributes(attributes, handler);
20 | this.AddClassLevelAttributes(attributes, handler);
21 | this.AddMethodLevelAttributes(attributes, handler);
22 |
23 | return attributes;
24 | }
25 |
26 | private void AddAssemblyLevelAttributes(List attributes, IHandler handler)
27 | {
28 | attributes.AddRange(
29 | (Attribute[])
30 | handler.ComponentModel.Implementation.Assembly.GetCustomAttributes(
31 | typeof(ExceptionHandlerAttribute), false));
32 | }
33 |
34 | private void AddClassLevelAttributes(List attributes, IHandler handler)
35 | {
36 | attributes.AddRange(
37 | (Attribute[])
38 | handler.ComponentModel.Implementation.GetCustomAttributes(typeof(ExceptionHandlerAttribute), false));
39 | }
40 |
41 | private void AddMethodLevelAttributes(List attributes, IHandler handler)
42 | {
43 | foreach (var methodInfo in handler.ComponentModel.Implementation.GetMethods())
44 | {
45 | attributes.AddRange(
46 | (Attribute[])methodInfo.GetCustomAttributes(typeof(ExceptionHandlerAttribute), false));
47 | }
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/Logging/ExceptionHandlerInterceptor.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 |
5 | using global::Castle.DynamicProxy;
6 |
7 | using SharpArchContrib.Core;
8 | using SharpArchContrib.Core.Logging;
9 |
10 | public class ExceptionHandlerInterceptor : IInterceptor
11 | {
12 | private readonly IExceptionLogger exceptionLogger;
13 |
14 | public ExceptionHandlerInterceptor(IExceptionLogger exceptionLogger)
15 | {
16 | ParameterCheck.ParameterRequired(exceptionLogger, "exceptionLogger");
17 |
18 | this.exceptionLogger = exceptionLogger;
19 | }
20 |
21 | public void Intercept(IInvocation invocation)
22 | {
23 | var methodInfo = invocation.MethodInvocationTarget;
24 | if (methodInfo == null)
25 | {
26 | methodInfo = invocation.Method;
27 | }
28 |
29 | // we take the settings from the first attribute we find searching method first
30 | // If there is at least one attribute, the call gets wrapped with an exception handler
31 | var assemblyAttributes =
32 | (ExceptionHandlerAttribute[])
33 | methodInfo.ReflectedType.Assembly.GetCustomAttributes(typeof(ExceptionHandlerAttribute), false);
34 | var classAttributes =
35 | (ExceptionHandlerAttribute[])
36 | methodInfo.ReflectedType.GetCustomAttributes(typeof(ExceptionHandlerAttribute), false);
37 | var methodAttributes =
38 | (ExceptionHandlerAttribute[])methodInfo.GetCustomAttributes(typeof(ExceptionHandlerAttribute), false);
39 |
40 | if (assemblyAttributes.Length == 0 && classAttributes.Length == 0 && methodAttributes.Length == 0)
41 | {
42 | invocation.Proceed();
43 | }
44 | else
45 | {
46 | var exceptionHandlerAttributeSettings = this.GetExceptionHandlerSettings(
47 | assemblyAttributes, classAttributes, methodAttributes);
48 | try
49 | {
50 | invocation.Proceed();
51 | }
52 | catch (Exception err)
53 | {
54 | this.exceptionLogger.LogException(
55 | err, exceptionHandlerAttributeSettings.IsSilent, methodInfo.ReflectedType);
56 | if (exceptionHandlerAttributeSettings.IsSilent)
57 | {
58 | if (exceptionHandlerAttributeSettings.ExceptionType == null ||
59 | exceptionHandlerAttributeSettings.ExceptionType == err.GetType())
60 | {
61 | invocation.ReturnValue = exceptionHandlerAttributeSettings.ReturnValue;
62 | }
63 | else
64 | {
65 | throw;
66 | }
67 | }
68 | else
69 | {
70 | throw;
71 | }
72 | }
73 | }
74 | }
75 |
76 | private ExceptionHandlerAttributeSettings GetExceptionHandlerSettings(
77 | ExceptionHandlerAttribute[] assemblyAttributes,
78 | ExceptionHandlerAttribute[] classAttributes,
79 | ExceptionHandlerAttribute[] methodAttributes)
80 | {
81 | if (methodAttributes.Length > 0)
82 | {
83 | return methodAttributes[0].Settings;
84 | }
85 |
86 | if (classAttributes.Length > 0)
87 | {
88 | return classAttributes[0].Settings;
89 | }
90 |
91 | return assemblyAttributes[0].Settings;
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/Logging/LogAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 |
5 | using SharpArchContrib.Core.Logging;
6 |
7 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false,
8 | Inherited = false)]
9 | public class LogAttribute : Attribute
10 | {
11 | public LogAttribute()
12 | {
13 | this.Settings = new LogAttributeSettings(LoggingLevel.Debug, LoggingLevel.Debug, LoggingLevel.Error);
14 | }
15 |
16 | public LoggingLevel EntryLevel
17 | {
18 | get
19 | {
20 | return this.Settings.EntryLevel;
21 | }
22 |
23 | set
24 | {
25 | this.Settings.EntryLevel = value;
26 | }
27 | }
28 |
29 | public LoggingLevel ExceptionLevel
30 | {
31 | get
32 | {
33 | return this.Settings.ExceptionLevel;
34 | }
35 |
36 | set
37 | {
38 | this.Settings.ExceptionLevel = value;
39 | }
40 | }
41 |
42 | public LogAttributeSettings Settings { get; set; }
43 |
44 | public LoggingLevel SuccessLevel
45 | {
46 | get
47 | {
48 | return this.Settings.SuccessLevel;
49 | }
50 |
51 | set
52 | {
53 | this.Settings.SuccessLevel = value;
54 | }
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/Logging/LogFacility.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | using global::Castle.Core;
7 | using global::Castle.MicroKernel;
8 |
9 | public class LogFacility : AttributeControlledFacilityBase
10 | {
11 | public LogFacility()
12 | : base(typeof(LogInterceptor), LifestyleType.Singleton)
13 | {
14 | }
15 |
16 | protected override List GetAttributes(IHandler handler)
17 | {
18 | var attributes = new List();
19 | this.AddAssemblyLevelAttributes(attributes, handler);
20 | this.AddClassLevelAttributes(attributes, handler);
21 | this.AddMethodLevelAttributes(attributes, handler);
22 |
23 | return attributes;
24 | }
25 |
26 | private void AddAssemblyLevelAttributes(List attributes, IHandler handler)
27 | {
28 | attributes.AddRange(
29 | (Attribute[])
30 | handler.ComponentModel.Implementation.Assembly.GetCustomAttributes(typeof(LogAttribute), false));
31 | }
32 |
33 | private void AddClassLevelAttributes(List attributes, IHandler handler)
34 | {
35 | attributes.AddRange(
36 | (Attribute[])handler.ComponentModel.Implementation.GetCustomAttributes(typeof(LogAttribute), false));
37 | }
38 |
39 | private void AddMethodLevelAttributes(List attributes, IHandler handler)
40 | {
41 | foreach (var methodInfo in handler.ComponentModel.Implementation.GetMethods())
42 | {
43 | attributes.AddRange((Attribute[])methodInfo.GetCustomAttributes(typeof(LogAttribute), false));
44 | }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/Logging/LogInterceptor.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 |
5 | using global::Castle.DynamicProxy;
6 |
7 | using SharpArchContrib.Core;
8 | using SharpArchContrib.Core.Logging;
9 |
10 | public class LogInterceptor : IInterceptor
11 | {
12 | private readonly IMethodLogger methodLogger;
13 |
14 | public LogInterceptor(IMethodLogger methodLogger)
15 | {
16 | ParameterCheck.ParameterRequired(methodLogger, "methodLogger");
17 |
18 | this.methodLogger = methodLogger;
19 | }
20 |
21 | public void Intercept(IInvocation invocation)
22 | {
23 | var methodInfo = invocation.MethodInvocationTarget;
24 | if (methodInfo == null)
25 | {
26 | methodInfo = invocation.Method;
27 | }
28 |
29 | // we take the most permissive log settings from the attributes we find
30 | // If there is at least one attribute, the call gets wrapped with a transaction
31 | var assemblyLogAttributes =
32 | (LogAttribute[])methodInfo.ReflectedType.Assembly.GetCustomAttributes(typeof(LogAttribute), false);
33 | var classLogAttributes =
34 | (LogAttribute[])methodInfo.ReflectedType.GetCustomAttributes(typeof(LogAttribute), false);
35 | var methodLogAttributes = (LogAttribute[])methodInfo.GetCustomAttributes(typeof(LogAttribute), false);
36 |
37 | if (assemblyLogAttributes.Length == 0 && classLogAttributes.Length == 0 && methodLogAttributes.Length == 0)
38 | {
39 | invocation.Proceed();
40 | }
41 | else
42 | {
43 | var logAttributeSettings = this.GetLoggingLevels(
44 | assemblyLogAttributes, classLogAttributes, methodLogAttributes);
45 | this.methodLogger.LogEntry(methodInfo, invocation.Arguments, logAttributeSettings.EntryLevel);
46 | try
47 | {
48 | invocation.Proceed();
49 | }
50 | catch (Exception err)
51 | {
52 | this.methodLogger.LogException(methodInfo, err, logAttributeSettings.ExceptionLevel);
53 | throw;
54 | }
55 |
56 | this.methodLogger.LogSuccess(methodInfo, invocation.ReturnValue, logAttributeSettings.SuccessLevel);
57 | }
58 | }
59 |
60 | private LogAttributeSettings GetLoggingLevels(
61 | LogAttribute[] assemblyLogAttributes, LogAttribute[] classLogAttributes, LogAttribute[] methodLogAttributes)
62 | {
63 | var logAttributeSettings = new LogAttributeSettings();
64 | logAttributeSettings = this.GetLoggingLevels(assemblyLogAttributes, logAttributeSettings);
65 | logAttributeSettings = this.GetLoggingLevels(classLogAttributes, logAttributeSettings);
66 | logAttributeSettings = this.GetLoggingLevels(methodLogAttributes, logAttributeSettings);
67 |
68 | return logAttributeSettings;
69 | }
70 |
71 | private LogAttributeSettings GetLoggingLevels(
72 | LogAttribute[] logAttributes, LogAttributeSettings logAttributeSettings)
73 | {
74 | foreach (var logAttribute in logAttributes)
75 | {
76 | if (logAttribute.Settings.EntryLevel > logAttributeSettings.EntryLevel)
77 | {
78 | logAttributeSettings.EntryLevel = logAttribute.Settings.EntryLevel;
79 | }
80 |
81 | if (logAttribute.Settings.SuccessLevel > logAttributeSettings.SuccessLevel)
82 | {
83 | logAttributeSettings.SuccessLevel = logAttribute.Settings.SuccessLevel;
84 | }
85 |
86 | if (logAttribute.Settings.ExceptionLevel > logAttributeSettings.ExceptionLevel)
87 | {
88 | logAttributeSettings.ExceptionLevel = logAttribute.Settings.ExceptionLevel;
89 | }
90 | }
91 |
92 | return logAttributeSettings;
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/NHibernate/TransactionAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.NHibernate
2 | {
3 | using System;
4 |
5 | using SharpArch.Domain;
6 |
7 | using SharpArchContrib.Data.NHibernate;
8 |
9 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
10 | public class TransactionAttribute : Attribute, ITransactionAttributeSettings
11 | {
12 | private TransactionAttributeSettings settings;
13 |
14 | public TransactionAttribute()
15 | {
16 | this.settings = new TransactionAttributeSettings();
17 | }
18 |
19 | public string FactoryKey
20 | {
21 | get
22 | {
23 | return this.Settings.FactoryKey;
24 | }
25 |
26 | set
27 | {
28 | if (value == null)
29 | {
30 | throw new PreconditionException("FactoryKey cannot be null");
31 | }
32 |
33 | this.Settings.FactoryKey = value;
34 | }
35 | }
36 |
37 | public bool IsExceptionSilent
38 | {
39 | get
40 | {
41 | return this.Settings.IsExceptionSilent;
42 | }
43 |
44 | set
45 | {
46 | this.Settings.IsExceptionSilent = value;
47 | }
48 | }
49 |
50 | public object ReturnValue
51 | {
52 | get
53 | {
54 | return this.Settings.ReturnValue;
55 | }
56 |
57 | set
58 | {
59 | this.Settings.ReturnValue = value;
60 | }
61 | }
62 |
63 | public TransactionAttributeSettings Settings
64 | {
65 | get
66 | {
67 | return this.settings;
68 | }
69 |
70 | set
71 | {
72 | if (value == null)
73 | {
74 | throw new PreconditionException("Settings must not be null");
75 | }
76 |
77 | this.settings = value;
78 | }
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/NHibernate/TransactionFacility.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.NHibernate
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | using global::Castle.Core;
7 | using global::Castle.MicroKernel;
8 |
9 | public class TransactionFacility : AttributeControlledFacilityBase
10 | {
11 | public TransactionFacility()
12 | : base(typeof(TransactionInterceptor), LifestyleType.Transient)
13 | {
14 | }
15 |
16 | protected override List GetAttributes(IHandler handler)
17 | {
18 | var attributes = new List();
19 | this.AddClassLevelAttributes(attributes, handler);
20 | this.AddMethodLevelAttributes(attributes, handler);
21 |
22 | return attributes;
23 | }
24 |
25 | private void AddClassLevelAttributes(List attributes, IHandler handler)
26 | {
27 | attributes.AddRange(
28 | (Attribute[])
29 | handler.ComponentModel.Implementation.GetCustomAttributes(typeof(TransactionAttribute), false));
30 | }
31 |
32 | private void AddMethodLevelAttributes(List attributes, IHandler handler)
33 | {
34 | foreach (var methodInfo in handler.ComponentModel.Implementation.GetMethods())
35 | {
36 | attributes.AddRange((Attribute[])methodInfo.GetCustomAttributes(typeof(TransactionAttribute), false));
37 | }
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/NHibernate/TransactionInterceptor.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.NHibernate
2 | {
3 | using System;
4 |
5 | using SharpArch.NHibernate;
6 |
7 | using SharpArchContrib.Core;
8 | using SharpArchContrib.Core.Logging;
9 | using SharpArchContrib.Data.NHibernate;
10 |
11 | using global::Castle.DynamicProxy;
12 |
13 | public class TransactionInterceptor : IInterceptor
14 | {
15 | protected readonly IExceptionLogger exceptionLogger;
16 |
17 | protected readonly ITransactionManager transactionManager;
18 |
19 | public TransactionInterceptor(ITransactionManager transactionManager, IExceptionLogger exceptionLogger)
20 | {
21 | ParameterCheck.ParameterRequired(transactionManager, "transactionManager");
22 | ParameterCheck.ParameterRequired(exceptionLogger, "exceptionLogger");
23 |
24 | this.transactionManager = transactionManager;
25 | this.exceptionLogger = exceptionLogger;
26 | }
27 |
28 | public void Intercept(IInvocation invocation)
29 | {
30 | var methodInfo = invocation.MethodInvocationTarget;
31 | if (methodInfo == null)
32 | {
33 | methodInfo = invocation.Method;
34 | }
35 |
36 | // we take the settings from the first attribute we find searching method first
37 | // If there is at least one attribute, the call gets wrapped with a transaction
38 | var attributeType = this.GetAttributeType();
39 | var classAttributes =
40 | (ITransactionAttributeSettings[])methodInfo.ReflectedType.GetCustomAttributes(attributeType, false);
41 | var methodAttributes = (ITransactionAttributeSettings[])methodInfo.GetCustomAttributes(attributeType, false);
42 | if (classAttributes.Length == 0 && methodAttributes.Length == 0)
43 | {
44 | invocation.Proceed();
45 | }
46 | else
47 | {
48 | var transactionAttributeSettings = this.GetTransactionAttributeSettings(
49 | methodAttributes, classAttributes);
50 |
51 | var transactionState = this.OnEntry(transactionAttributeSettings, null);
52 | try
53 | {
54 | invocation.Proceed();
55 | }
56 | catch (Exception err)
57 | {
58 | this.CloseUnitOfWork(transactionAttributeSettings, transactionState, err);
59 | if (!(err is AbortTransactionException))
60 | {
61 | this.exceptionLogger.LogException(
62 | err, transactionAttributeSettings.IsExceptionSilent, methodInfo.ReflectedType);
63 | }
64 |
65 | if (this.transactionManager.TransactionDepth == 0 &&
66 | (transactionAttributeSettings.IsExceptionSilent || err is AbortTransactionException))
67 | {
68 | invocation.ReturnValue = transactionAttributeSettings.ReturnValue;
69 | return;
70 | }
71 |
72 | throw;
73 | }
74 |
75 | transactionState = this.OnSuccess(transactionAttributeSettings, transactionState);
76 | }
77 | }
78 |
79 | protected virtual object CloseUnitOfWork(
80 | TransactionAttributeSettings transactionAttributeSettings, object transactionState, Exception err)
81 | {
82 | var factoryKey = transactionAttributeSettings.FactoryKey;
83 | if (err == null)
84 | {
85 | try
86 | {
87 | NHibernateSession.CurrentFor(factoryKey).Flush();
88 | transactionState = this.transactionManager.CommitTransaction(factoryKey, transactionState);
89 | }
90 | catch (Exception)
91 | {
92 | transactionState = this.transactionManager.RollbackTransaction(factoryKey, transactionState);
93 | transactionState = this.transactionManager.PopTransaction(factoryKey, transactionState);
94 | throw;
95 | }
96 | }
97 | else
98 | {
99 | transactionState = this.transactionManager.RollbackTransaction(factoryKey, transactionState);
100 | }
101 |
102 | transactionState = this.transactionManager.PopTransaction(factoryKey, transactionState);
103 |
104 | return transactionState;
105 | }
106 |
107 | protected virtual Type GetAttributeType()
108 | {
109 | return typeof(TransactionAttribute);
110 | }
111 |
112 | private TransactionAttributeSettings GetTransactionAttributeSettings(
113 | ITransactionAttributeSettings[] methodAttributes, ITransactionAttributeSettings[] classAttributes)
114 | {
115 | var transactionAttributeSettings = new TransactionAttributeSettings();
116 | if (methodAttributes.Length > 0)
117 | {
118 | transactionAttributeSettings = methodAttributes[methodAttributes.Length - 1].Settings;
119 | }
120 | else if (classAttributes.Length > 0)
121 | {
122 | transactionAttributeSettings = classAttributes[classAttributes.Length - 1].Settings;
123 | }
124 |
125 | return transactionAttributeSettings;
126 | }
127 |
128 | private object OnEntry(TransactionAttributeSettings transactionAttributeSettings, object transactionState)
129 | {
130 | return this.transactionManager.PushTransaction(transactionAttributeSettings.FactoryKey, transactionState);
131 | }
132 |
133 | private object OnSuccess(TransactionAttributeSettings transactionAttributeSettings, object transactionState)
134 | {
135 | return this.CloseUnitOfWork(transactionAttributeSettings, transactionState, null);
136 | }
137 | }
138 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/NHibernate/UnitOfWorkAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.NHibernate
2 | {
3 | using System;
4 |
5 | using SharpArch.Domain;
6 |
7 | using SharpArchContrib.Data.NHibernate;
8 |
9 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
10 | public class UnitOfWorkAttribute : Attribute, ITransactionAttributeSettings
11 | {
12 | private TransactionAttributeSettings settings;
13 |
14 | public UnitOfWorkAttribute()
15 | {
16 | this.settings = new UnitOfWorkAttributeSettings();
17 | }
18 |
19 | public bool CloseSessions
20 | {
21 | get
22 | {
23 | return this.UnitOfWorkSettings.CloseSessions;
24 | }
25 |
26 | set
27 | {
28 | this.UnitOfWorkSettings.CloseSessions = value;
29 | }
30 | }
31 |
32 | public string FactoryKey
33 | {
34 | get
35 | {
36 | return this.Settings.FactoryKey;
37 | }
38 |
39 | set
40 | {
41 | if (value == null)
42 | {
43 | throw new PreconditionException("FactoryKey cannot be null");
44 | }
45 |
46 | this.Settings.FactoryKey = value;
47 | }
48 | }
49 |
50 | public bool IsExceptionSilent
51 | {
52 | get
53 | {
54 | return this.Settings.IsExceptionSilent;
55 | }
56 |
57 | set
58 | {
59 | this.Settings.IsExceptionSilent = value;
60 | }
61 | }
62 |
63 | public object ReturnValue
64 | {
65 | get
66 | {
67 | return this.Settings.ReturnValue;
68 | }
69 |
70 | set
71 | {
72 | this.Settings.ReturnValue = value;
73 | }
74 | }
75 |
76 | public TransactionAttributeSettings Settings
77 | {
78 | get
79 | {
80 | return this.settings;
81 | }
82 |
83 | set
84 | {
85 | if (value == null)
86 | {
87 | throw new PreconditionException("Settings must not be null");
88 | }
89 |
90 | this.settings = value;
91 | }
92 | }
93 |
94 | public UnitOfWorkAttributeSettings UnitOfWorkSettings
95 | {
96 | get
97 | {
98 | return (UnitOfWorkAttributeSettings)this.settings;
99 | }
100 |
101 | set
102 | {
103 | this.Settings = value;
104 | }
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/NHibernate/UnitOfWorkFacility.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.NHibernate
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 |
6 | using global::Castle.Core;
7 | using global::Castle.MicroKernel;
8 |
9 | public class UnitOfWorkFacility : AttributeControlledFacilityBase
10 | {
11 | public UnitOfWorkFacility()
12 | : base(typeof(UnitOfWorkInterceptor), LifestyleType.Transient)
13 | {
14 | }
15 |
16 | protected override List GetAttributes(IHandler handler)
17 | {
18 | var attributes = new List();
19 | this.AddClassLevelAttributes(attributes, handler);
20 | this.AddMethodLevelAttributes(attributes, handler);
21 |
22 | return attributes;
23 | }
24 |
25 | private void AddClassLevelAttributes(List attributes, IHandler handler)
26 | {
27 | attributes.AddRange(
28 | (Attribute[])
29 | handler.ComponentModel.Implementation.GetCustomAttributes(typeof(UnitOfWorkAttribute), false));
30 | }
31 |
32 | private void AddMethodLevelAttributes(List attributes, IHandler handler)
33 | {
34 | foreach (var methodInfo in handler.ComponentModel.Implementation.GetMethods())
35 | {
36 | attributes.AddRange((Attribute[])methodInfo.GetCustomAttributes(typeof(UnitOfWorkAttribute), false));
37 | }
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/NHibernate/UnitOfWorkInterceptor.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Castle.NHibernate
2 | {
3 | using System;
4 |
5 | using SharpArch.NHibernate;
6 |
7 | using SharpArchContrib.Core.Logging;
8 | using SharpArchContrib.Data.NHibernate;
9 |
10 | public class UnitOfWorkInterceptor : TransactionInterceptor
11 | {
12 | public UnitOfWorkInterceptor(ITransactionManager transactionManager, IExceptionLogger exceptionLogger)
13 | : base(transactionManager, exceptionLogger)
14 | {
15 | }
16 |
17 | protected override object CloseUnitOfWork(
18 | TransactionAttributeSettings transactionAttributeSettings, object transactionState, Exception err)
19 | {
20 | transactionState = base.CloseUnitOfWork(transactionAttributeSettings, transactionState, err);
21 | if (this.transactionManager.TransactionDepth == 0)
22 | {
23 | var sessionStorage = NHibernateSession.Storage as IUnitOfWorkSessionStorage;
24 | if (sessionStorage != null)
25 | {
26 | sessionStorage.EndUnitOfWork(
27 | ((UnitOfWorkAttributeSettings)transactionAttributeSettings).CloseSessions);
28 | }
29 | }
30 |
31 | return transactionState;
32 | }
33 |
34 | protected override Type GetAttributeType()
35 | {
36 | return typeof(UnitOfWorkAttribute);
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | [assembly: AssemblyTitle("SharpArchContrib.Castle")]
5 | [assembly: AssemblyDescription("")]
6 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/SharpArchContrib.Castle.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {557E1790-FBDD-4FDE-86B2-93E2AD0E9E24}
9 | Library
10 | Properties
11 | SharpArchContrib.Castle
12 | SharpArchContrib.Castle
13 | v4.0
14 | 512
15 | true
16 |
17 |
18 |
19 |
20 | 3.5
21 |
22 | publish\
23 | true
24 | Disk
25 | false
26 | Foreground
27 | 7
28 | Days
29 | false
30 | false
31 | true
32 | 0
33 | 1.0.0.%2a
34 | false
35 | false
36 | true
37 |
38 | ..\..\Solutions\
39 | true
40 |
41 |
42 | true
43 | full
44 | false
45 | bin\Debug\
46 | DEBUG;TRACE
47 | prompt
48 | 4
49 | AllRules.ruleset
50 |
51 |
52 | pdbonly
53 | true
54 | bin\Release\
55 | TRACE
56 | prompt
57 | 4
58 | AllRules.ruleset
59 |
60 |
61 |
62 | ..\..\Packages\Castle.Core.3.0.0.4001\lib\net40-client\Castle.Core.dll
63 |
64 |
65 | ..\..\Packages\Castle.Windsor.3.0.0.4001\lib\net40\Castle.Windsor.dll
66 |
67 |
68 | False
69 | ..\..\Packages\FluentNHibernate.1.3.0.727\lib\FluentNHibernate.dll
70 |
71 |
72 | ..\..\Packages\Iesi.Collections.3.2.0.4000\lib\Net35\Iesi.Collections.dll
73 |
74 |
75 | ..\..\Packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll
76 |
77 |
78 | False
79 | ..\..\Packages\Newtonsoft.Json.4.5.4\lib\net40\Newtonsoft.Json.dll
80 |
81 |
82 | False
83 | ..\..\Packages\NHibernate.3.3.0.4000\lib\Net35\NHibernate.dll
84 |
85 |
86 | ..\..\Packages\SharpArch.Domain.2.0.4\lib\NET40\SharpArch.Domain.dll
87 |
88 |
89 | ..\..\Packages\SharpArch.NHibernate.2.0.4\lib\NET40\SharpArch.NHibernate.dll
90 |
91 |
92 |
93 |
94 | 3.5
95 |
96 |
97 | 3.5
98 |
99 |
100 | 3.5
101 |
102 |
103 |
104 |
105 |
106 |
107 | Properties\AssemblyVersion.cs
108 |
109 |
110 | Properties\CommonAssemblyInfo.cs
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}
133 | SharpArchContrib.Core
134 |
135 |
136 | {E33E2468-B055-4F3D-83DB-8F991F600A47}
137 | SharpArchContrib.Data
138 |
139 |
140 |
141 |
142 | False
143 | .NET Framework 3.5 SP1 Client Profile
144 | false
145 |
146 |
147 | False
148 | .NET Framework 3.5 SP1
149 | true
150 |
151 |
152 | False
153 | Windows Installer 3.1
154 | true
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
169 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/SharpArchContrib.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/Solutions/SharpArchContrib.Castle/SharpArchContrib.snk
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Castle/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Extensions/TypeExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Extensions
2 | {
3 | using System;
4 | using System.Linq;
5 |
6 | public static class TypeExtensions
7 | {
8 | public static bool IsImplementationOf(this Type type)
9 | {
10 | return type.GetInterfaces().Any(x => x == typeof(T));
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/ExceptionHandlerAttributeSettings.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | using System;
4 |
5 | [Serializable]
6 | public class ExceptionHandlerAttributeSettings
7 | {
8 | public ExceptionHandlerAttributeSettings()
9 | {
10 | this.IsSilent = false;
11 | this.ReturnValue = null;
12 | }
13 |
14 | public Type ExceptionType { get; set; }
15 |
16 | public bool IsSilent { get; set; }
17 |
18 | public object ReturnValue { get; set; }
19 | }
20 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/ExceptionLogger.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | using System;
4 |
5 | using log4net;
6 |
7 | public class ExceptionLogger : IExceptionLogger
8 | {
9 | public void LogException(Exception err, bool isSilent, Type throwingType)
10 | {
11 | var logger = LogManager.GetLogger(throwingType);
12 | string message = null;
13 | if (isSilent)
14 | {
15 | message = "[SILENT]";
16 | }
17 |
18 | logger.Log(LoggingLevel.Error, message, err);
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/IExceptionLogger.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | using System;
4 |
5 | public interface IExceptionLogger
6 | {
7 | void LogException(Exception err, bool isSilent, Type throwingType);
8 | }
9 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/IMethodLogger.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | using System;
4 | using System.Reflection;
5 |
6 | public interface IMethodLogger
7 | {
8 | void LogEntry(MethodBase methodBase, object[] argumentValues, LoggingLevel entryLevel);
9 |
10 | void LogException(MethodBase methodBase, Exception err, LoggingLevel exceptionLevel);
11 |
12 | void LogSuccess(MethodBase methodBase, object returnValue, LoggingLevel successLevel);
13 | }
14 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/Log4NetHelper.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | using System;
4 |
5 | using log4net;
6 |
7 | public static class Log4NetHelper
8 | {
9 | public static bool IsEnabledFor(this ILog logger, LoggingLevel level)
10 | {
11 | switch (level)
12 | {
13 | case LoggingLevel.All:
14 | return true;
15 | case LoggingLevel.Debug:
16 | return logger.IsDebugEnabled;
17 | case LoggingLevel.Info:
18 | return logger.IsInfoEnabled;
19 | case LoggingLevel.Warn:
20 | return logger.IsWarnEnabled;
21 | case LoggingLevel.Error:
22 | return logger.IsErrorEnabled;
23 | case LoggingLevel.Fatal:
24 | return logger.IsFatalEnabled;
25 | }
26 |
27 | return false;
28 | }
29 |
30 | public static void Log(this ILog logger, LoggingLevel level, string message)
31 | {
32 | switch (level)
33 | {
34 | case LoggingLevel.All:
35 | case LoggingLevel.Debug:
36 | logger.Debug(message);
37 | break;
38 | case LoggingLevel.Info:
39 | logger.Info(message);
40 | break;
41 | case LoggingLevel.Warn:
42 | logger.Warn(message);
43 | break;
44 | case LoggingLevel.Error:
45 | logger.Error(message);
46 | break;
47 | case LoggingLevel.Fatal:
48 | logger.Fatal(message);
49 | break;
50 | }
51 | }
52 |
53 | public static void Log(this ILog logger, LoggingLevel level, string message, Exception err)
54 | {
55 | switch (level)
56 | {
57 | case LoggingLevel.All:
58 | case LoggingLevel.Debug:
59 | if (message == null)
60 | {
61 | logger.Debug(err);
62 | }
63 | else
64 | {
65 | logger.Debug(message, err);
66 | }
67 |
68 | break;
69 | case LoggingLevel.Info:
70 | if (message == null)
71 | {
72 | logger.Info(err);
73 | }
74 | else
75 | {
76 | logger.Info(message, err);
77 | }
78 |
79 | break;
80 | case LoggingLevel.Warn:
81 | if (message == null)
82 | {
83 | logger.Warn(err);
84 | }
85 | else
86 | {
87 | logger.Warn(message, err);
88 | }
89 |
90 | break;
91 | case LoggingLevel.Error:
92 | if (message == null)
93 | {
94 | logger.Error(err);
95 | }
96 | else
97 | {
98 | logger.Error(message, err);
99 | }
100 |
101 | break;
102 | case LoggingLevel.Fatal:
103 | if (message == null)
104 | {
105 | logger.Fatal(err);
106 | }
107 | else
108 | {
109 | logger.Fatal(message, err);
110 | }
111 |
112 | break;
113 | }
114 | }
115 | }
116 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/LogAttributeSettings.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | using System;
4 |
5 | [Serializable]
6 | public class LogAttributeSettings
7 | {
8 | public LogAttributeSettings()
9 | : this(LoggingLevel.Off, LoggingLevel.Off, LoggingLevel.Off)
10 | {
11 | }
12 |
13 | public LogAttributeSettings(LoggingLevel entryLevel, LoggingLevel successLevel, LoggingLevel exceptionLevel)
14 | {
15 | this.EntryLevel = entryLevel;
16 | this.SuccessLevel = successLevel;
17 | this.ExceptionLevel = exceptionLevel;
18 | }
19 |
20 | public LoggingLevel EntryLevel { get; set; }
21 |
22 | public LoggingLevel ExceptionLevel { get; set; }
23 |
24 | public LoggingLevel SuccessLevel { get; set; }
25 | }
26 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/LoggingLevel.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | public enum LoggingLevel
4 | {
5 | Off,
6 | Fatal,
7 | Error,
8 | Warn,
9 | Info,
10 | Debug,
11 | All
12 | }
13 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Logging/MethodLogger.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.Logging
2 | {
3 | using System;
4 | using System.Reflection;
5 | using System.Text;
6 |
7 | using log4net;
8 |
9 | public class MethodLogger : IMethodLogger
10 | {
11 | private readonly IExceptionLogger exceptionLogger;
12 |
13 | public MethodLogger(IExceptionLogger exceptionLogger)
14 | {
15 | ParameterCheck.ParameterRequired(exceptionLogger, "exceptionLogger");
16 |
17 | this.exceptionLogger = exceptionLogger;
18 | }
19 |
20 | public void LogEntry(MethodBase methodBase, object[] argumentValues, LoggingLevel entryLevel)
21 | {
22 | var logger = LogManager.GetLogger(methodBase.DeclaringType);
23 | if (this.ShouldLog(logger, entryLevel, methodBase))
24 | {
25 | var logMessage = new StringBuilder();
26 | logMessage.Append(string.Format("{0}(", methodBase.Name));
27 |
28 | var parameterInfos = methodBase.GetParameters();
29 | if (argumentValues != null && parameterInfos != null)
30 | {
31 | for (var i = 0; i < argumentValues.Length; i++)
32 | {
33 | if (i > 0)
34 | {
35 | logMessage.Append(" ");
36 | }
37 |
38 | logMessage.Append(string.Format("{0}:[{1}]", parameterInfos[i].Name, argumentValues[i]));
39 | }
40 | }
41 |
42 | logMessage.Append(")");
43 | logger.Log(entryLevel, logMessage.ToString());
44 | }
45 | }
46 |
47 | public void LogException(MethodBase methodBase, Exception err, LoggingLevel exceptionLevel)
48 | {
49 | var logger = LogManager.GetLogger(methodBase.DeclaringType);
50 | if (this.ShouldLog(logger, exceptionLevel, methodBase))
51 | {
52 | this.exceptionLogger.LogException(err, false, methodBase.DeclaringType);
53 | }
54 | }
55 |
56 | public void LogSuccess(MethodBase methodBase, object returnValue, LoggingLevel successLevel)
57 | {
58 | var logger = LogManager.GetLogger(methodBase.DeclaringType);
59 | if (this.ShouldLog(logger, successLevel, methodBase))
60 | {
61 | logger.Log(
62 | successLevel,
63 | string.Format("{0} Returns:[{1}]", methodBase.Name, returnValue != null ? returnValue.ToString() : string.Empty));
64 | }
65 | }
66 |
67 | private bool ShouldLog(ILog logger, LoggingLevel loggingLevel, MethodBase methodBase)
68 | {
69 | if (methodBase != null && methodBase.Name != null)
70 | {
71 | return logger.IsEnabledFor(loggingLevel);
72 | }
73 |
74 | return false;
75 | }
76 | }
77 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/MultiTenant/IMultiTenantEntity.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.MultiTenant
2 | {
3 | ///
4 | /// Marker interface for multi tenant entities.
5 | ///
6 | public interface IMultiTenantEntity
7 | {
8 | }
9 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/MultiTenant/IMultiTenantQuery.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.MultiTenant
2 | {
3 | public interface IMultiTenantQuery
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/MultiTenant/IMultiTenantRepository.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.MultiTenant
2 | {
3 | public interface IMultiTenantRepository
4 | {
5 | }
6 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/MultiTenant/ITenantContext.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core.MultiTenant
2 | {
3 | public interface ITenantContext
4 | {
5 | string Key { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/ParameterCheck.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Core
2 | {
3 | using System.Collections.Generic;
4 |
5 | using SharpArch.Domain;
6 |
7 | public static class ParameterCheck
8 | {
9 | public static void DictionaryContainsKey(
10 | IDictionary dictionary, string dictionaryName, string key)
11 | {
12 | ParameterRequired(dictionary, "dictionary");
13 | StringRequiredAndNotEmpty(key, "key");
14 | StringRequiredAndNotEmpty(dictionaryName, "dictionaryName");
15 |
16 | Check.Require(
17 | dictionary.ContainsKey(key),
18 | string.Format("Dictionary parameter {0} must contain an entry with key value {1}", dictionaryName, key));
19 | }
20 |
21 | public static void DictionaryContainsKey(
22 | IDictionary dictionary, string dictionaryName, string key)
23 | {
24 | ParameterRequired(dictionary, "dictionary");
25 | StringRequiredAndNotEmpty(key, "key");
26 | StringRequiredAndNotEmpty(dictionaryName, "dictionaryName");
27 |
28 | Check.Require(
29 | dictionary.ContainsKey(key),
30 | string.Format("Dictionary parameter {0} must contain an entry with key value {1}", dictionaryName, key));
31 | }
32 |
33 | public static void ParameterRequired(object parameter, string parameterName)
34 | {
35 | ParameterNameRequired(parameterName);
36 |
37 | Check.Require(parameter != null, GetParameterRequiredErrorMessage(parameterName));
38 | }
39 |
40 | public static void StringRequiredAndNotEmpty(string parameter, string parameterName)
41 | {
42 | ParameterNameRequired(parameterName);
43 |
44 | Check.Require(!string.IsNullOrEmpty(parameter), GetParameterRequiredErrorMessage(parameterName));
45 | }
46 |
47 | private static string GetParameterRequiredErrorMessage(string parameterName)
48 | {
49 | return string.Format("The parameter {0} is required.", parameterName);
50 | }
51 |
52 | private static void ParameterNameRequired(string parameterName)
53 | {
54 | Check.Require(!string.IsNullOrEmpty(parameterName), GetParameterRequiredErrorMessage("parameterName"));
55 | }
56 | }
57 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | [assembly: AssemblyTitle("SharpArchContrib.Core")]
5 | [assembly: AssemblyDescription("")]
6 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/SharpArchContrib.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}
9 | Library
10 | Properties
11 | SharpArchContrib.Core
12 | SharpArchContrib.Core
13 | v4.0
14 | 512
15 | true
16 |
17 |
18 |
19 |
20 | 3.5
21 |
22 | publish\
23 | true
24 | Disk
25 | false
26 | Foreground
27 | 7
28 | Days
29 | false
30 | false
31 | true
32 | 0
33 | 1.0.0.%2a
34 | false
35 | false
36 | true
37 |
38 | ..\..\Solutions\
39 | true
40 |
41 |
42 | true
43 | full
44 | false
45 | bin\Debug\
46 | DEBUG;TRACE
47 | prompt
48 | 4
49 |
50 |
51 | AllRules.ruleset
52 |
53 |
54 | pdbonly
55 | true
56 | bin\Release\
57 | TRACE
58 | prompt
59 | 4
60 |
61 |
62 | AllRules.ruleset
63 |
64 |
65 |
66 | ..\..\Packages\log4net.1.2.10\lib\2.0\log4net.dll
67 |
68 |
69 | ..\..\Packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll
70 |
71 |
72 | False
73 | ..\..\Packages\Newtonsoft.Json.4.5.4\lib\net40\Newtonsoft.Json.dll
74 |
75 |
76 | ..\..\Packages\SharpArch.Domain.2.0.4\lib\NET40\SharpArch.Domain.dll
77 |
78 |
79 |
80 |
81 | 3.5
82 |
83 |
84 | 3.5
85 |
86 |
87 | 3.5
88 |
89 |
90 |
91 |
92 |
93 |
94 | Properties\AssemblyVersion.cs
95 |
96 |
97 | Properties\CommonAssemblyInfo.cs
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 | False
118 | .NET Framework 3.5 SP1 Client Profile
119 | false
120 |
121 |
122 | False
123 | .NET Framework 3.5 SP1
124 | true
125 |
126 |
127 | False
128 | Windows Installer 3.1
129 | true
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
144 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/SharpArchContrib.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/Solutions/SharpArchContrib.Core/SharpArchContrib.snk
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Core/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/AbortTransactionException.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 | using System.Runtime.Serialization;
5 |
6 | [Serializable]
7 | public class AbortTransactionException : Exception
8 | {
9 | public AbortTransactionException()
10 | {
11 | }
12 |
13 | public AbortTransactionException(string message)
14 | : base(message)
15 | {
16 | }
17 |
18 | public AbortTransactionException(string message, Exception inner)
19 | : base(message, inner)
20 | {
21 | }
22 |
23 | protected AbortTransactionException(SerializationInfo info, StreamingContext context)
24 | : base(info, context)
25 | {
26 | }
27 | }
28 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/IThreadSafeDictionary.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System.Collections.Generic;
4 |
5 | ///
6 | /// Taken from http://devplanet.com/blogs/brianr/archive/2008/09/29/thread-safe-dictionary-update.aspx
7 | ///
8 | ///
9 | ///
10 | public interface IThreadSafeDictionary : IDictionary
11 | {
12 | ///
13 | /// Merge is similar to the SQL merge or upsert statement.
14 | ///
15 | /// Key to lookup
16 | /// New Value
17 | void MergeSafe(TKey key, TValue newValue);
18 |
19 | ///
20 | /// This is a blind remove. Prevents the need to check for existence first.
21 | ///
22 | /// Key to Remove
23 | void RemoveSafe(TKey key);
24 | }
25 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/ITransactionAttributeSettings.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | public interface ITransactionAttributeSettings
4 | {
5 | TransactionAttributeSettings Settings { get; set; }
6 | }
7 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/ITransactionManager.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | public interface ITransactionManager
4 | {
5 | string Name { get; }
6 |
7 | int TransactionDepth { get; }
8 |
9 | object CommitTransaction(string factoryKey, object transactionState);
10 |
11 | object PopTransaction(string factoryKey, object transactionState);
12 |
13 | object PushTransaction(string factoryKey, object transactionState);
14 |
15 | object RollbackTransaction(string factoryKey, object transactionState);
16 |
17 | bool TransactionIsActive(string factoryKey);
18 | }
19 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/IUnitOfWorkSessionStorage.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 |
5 | using SharpArch.NHibernate;
6 |
7 | [CLSCompliant(false)]
8 | public interface IUnitOfWorkSessionStorage : ISessionStorage
9 | {
10 | void EndUnitOfWork(bool closeSessions);
11 | }
12 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/MultiTenantSessionFactoryKeyProvider.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 | using System.Linq;
5 |
6 | using SharpArch.NHibernate;
7 |
8 | using SharpArchContrib.Core.Extensions;
9 | using SharpArchContrib.Core.MultiTenant;
10 |
11 | public class MultiTenantSessionFactoryKeyProvider : ISessionFactoryKeyProvider
12 | {
13 | private readonly ITenantContext tenantContext;
14 |
15 | public MultiTenantSessionFactoryKeyProvider(ITenantContext tenantContext)
16 | {
17 | this.tenantContext = tenantContext;
18 | }
19 |
20 | public string GetKey()
21 | {
22 | var key = this.tenantContext.Key;
23 | return string.IsNullOrEmpty(key) ? NHibernateSession.DefaultFactoryKey : key;
24 | }
25 |
26 | public string GetKeyFrom(object anObject)
27 | {
28 | var type = anObject.GetType();
29 | var isMultiTenant = type.IsImplementationOf() ||
30 | type.IsImplementationOf() ||
31 | IsRepositoryForMultiTenantEntity(type);
32 | return isMultiTenant ? GetKey() : NHibernateSession.DefaultFactoryKey;
33 | }
34 |
35 | public bool IsRepositoryForMultiTenantEntity(Type type)
36 | {
37 | if (!type.IsGenericType)
38 | {
39 | return false;
40 | }
41 |
42 | var genericTypes = type.GetGenericArguments();
43 | if (!genericTypes.Any())
44 | {
45 | return false;
46 | }
47 |
48 | var firstGenericType = genericTypes[0];
49 | return firstGenericType.IsImplementationOf();
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/NHibernateTransactionManager.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 |
5 | using SharpArch.NHibernate;
6 |
7 | ///
8 | /// Provides support for System.Transaction transactions
9 | ///
10 | [Serializable]
11 | public class NHibernateTransactionManager : TransactionManagerBase
12 | {
13 | public override string Name
14 | {
15 | get
16 | {
17 | return "NHibernate TransactionManager";
18 | }
19 | }
20 |
21 | public override object CommitTransaction(string factoryKey, object transactionState)
22 | {
23 | var transaction = NHibernateSession.CurrentFor(factoryKey).Transaction;
24 | if (this.TransactionDepth == 1 && transaction.IsActive)
25 | {
26 | transaction.Commit();
27 | }
28 |
29 | return transactionState;
30 | }
31 |
32 | public override object PushTransaction(string factoryKey, object transactionState)
33 | {
34 | transactionState = base.PushTransaction(factoryKey, transactionState);
35 |
36 | var transaction = NHibernateSession.CurrentFor(factoryKey).Transaction;
37 | if (!transaction.IsActive)
38 | {
39 | transaction.Begin();
40 | }
41 |
42 | return transactionState;
43 | }
44 |
45 | public override object RollbackTransaction(string factoryKey, object transactionState)
46 | {
47 | var transaction = NHibernateSession.CurrentFor(factoryKey).Transaction;
48 | if (this.TransactionDepth == 1 && transaction.IsActive)
49 | {
50 | transaction.Rollback();
51 | }
52 |
53 | return transactionState;
54 | }
55 |
56 | public override bool TransactionIsActive(string factoryKey)
57 | {
58 | var transaction = NHibernateSession.CurrentFor(factoryKey).Transaction;
59 | return transaction != null && transaction.IsActive;
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/SystemTransactionManager.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 | using System.Transactions;
5 |
6 | using SharpArch.NHibernate;
7 |
8 | ///
9 | /// Provides support for System.Transaction transactions
10 | ///
11 | [Serializable]
12 | public class SystemTransactionManager : TransactionManagerBase
13 | {
14 | public override string Name
15 | {
16 | get
17 | {
18 | return "System TransactionManager";
19 | }
20 | }
21 |
22 | public override object CommitTransaction(string factoryKey, object transactionState)
23 | {
24 | var transactionScope = transactionState as TransactionScope;
25 | if (transactionScope != null)
26 | {
27 | transactionScope.Complete();
28 | }
29 |
30 | return transactionState;
31 | }
32 |
33 | public override object PopTransaction(string factoryKey, object transactionState)
34 | {
35 | var transactionScope = transactionState as TransactionScope;
36 | if (transactionScope != null)
37 | {
38 | transactionScope.Dispose();
39 | transactionState = null;
40 | }
41 |
42 | return base.PopTransaction(factoryKey, transactionState);
43 | }
44 |
45 | public override object PushTransaction(string factoryKey, object transactionState)
46 | {
47 | transactionState = base.PushTransaction(factoryKey, transactionState);
48 |
49 | // If this is a new transaction, we have to close the session,
50 | // start the transaction and then open the new session to
51 | // associated the NHibernate session with the transaction.
52 | // This is usually not a high cost activity since the connection
53 | // will be pulled out of the connection pool
54 | var session = NHibernateSession.CurrentFor(factoryKey);
55 | var newTransaction = !this.TransactionIsActive(factoryKey);
56 | if (newTransaction)
57 | {
58 | session.Disconnect();
59 | }
60 |
61 | transactionState = new TransactionScope();
62 |
63 | if (newTransaction)
64 | {
65 | session.Reconnect();
66 | }
67 |
68 | return transactionState;
69 | }
70 |
71 | public override object RollbackTransaction(string factoryKey, object transactionState)
72 | {
73 | return transactionState;
74 | }
75 |
76 | public override bool TransactionIsActive(string factoryKey)
77 | {
78 | return Transaction.Current != null;
79 | }
80 | }
81 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/ThreadSafeDictionary.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 | using System.Collections;
5 | using System.Collections.Generic;
6 | using System.Threading;
7 |
8 | ///
9 | /// Taken from http://devplanet.com/blogs/brianr/archive/2008/09/29/thread-safe-dictionary-update.aspx
10 | ///
11 | ///
12 | ///
13 | [Serializable]
14 | public class ThreadSafeDictionary : IThreadSafeDictionary
15 | {
16 | // This is the internal dictionary that we are wrapping
17 | private readonly IDictionary dict = new Dictionary();
18 |
19 | [NonSerialized]
20 | private readonly ReaderWriterLockSlim dictionaryLock = Locks.GetLockInstance(LockRecursionPolicy.NoRecursion);
21 | // setup the lock;
22 | public virtual int Count
23 | {
24 | get
25 | {
26 | using (new ReadOnlyLock(this.dictionaryLock))
27 | {
28 | return this.dict.Count;
29 | }
30 | }
31 | }
32 |
33 | public virtual bool IsReadOnly
34 | {
35 | get
36 | {
37 | using (new ReadOnlyLock(this.dictionaryLock))
38 | {
39 | return this.dict.IsReadOnly;
40 | }
41 | }
42 | }
43 |
44 | public virtual ICollection Keys
45 | {
46 | get
47 | {
48 | using (new ReadOnlyLock(this.dictionaryLock))
49 | {
50 | return new List(this.dict.Keys);
51 | }
52 | }
53 | }
54 |
55 | public virtual ICollection Values
56 | {
57 | get
58 | {
59 | using (new ReadOnlyLock(this.dictionaryLock))
60 | {
61 | return new List(this.dict.Values);
62 | }
63 | }
64 | }
65 |
66 | public virtual TValue this[TKey key]
67 | {
68 | get
69 | {
70 | using (new ReadOnlyLock(this.dictionaryLock))
71 | {
72 | return this.dict[key];
73 | }
74 | }
75 |
76 | set
77 | {
78 | using (new WriteLock(this.dictionaryLock))
79 | {
80 | this.dict[key] = value;
81 | }
82 | }
83 | }
84 |
85 | public virtual void Add(KeyValuePair item)
86 | {
87 | using (new WriteLock(this.dictionaryLock))
88 | {
89 | this.dict.Add(item);
90 | }
91 | }
92 |
93 | public virtual void Clear()
94 | {
95 | using (new WriteLock(this.dictionaryLock))
96 | {
97 | this.dict.Clear();
98 | }
99 | }
100 |
101 | public virtual bool Contains(KeyValuePair item)
102 | {
103 | using (new ReadOnlyLock(this.dictionaryLock))
104 | {
105 | return this.dict.Contains(item);
106 | }
107 | }
108 |
109 | public virtual void CopyTo(KeyValuePair[] array, int arrayIndex)
110 | {
111 | using (new ReadOnlyLock(this.dictionaryLock))
112 | {
113 | this.dict.CopyTo(array, arrayIndex);
114 | }
115 | }
116 |
117 | public virtual bool Remove(KeyValuePair item)
118 | {
119 | using (new WriteLock(this.dictionaryLock))
120 | {
121 | return this.dict.Remove(item);
122 | }
123 | }
124 |
125 | public virtual void Add(TKey key, TValue value)
126 | {
127 | using (new WriteLock(this.dictionaryLock))
128 | {
129 | this.dict.Add(key, value);
130 | }
131 | }
132 |
133 | public virtual bool ContainsKey(TKey key)
134 | {
135 | using (new ReadOnlyLock(this.dictionaryLock))
136 | {
137 | return this.dict.ContainsKey(key);
138 | }
139 | }
140 |
141 | public virtual bool Remove(TKey key)
142 | {
143 | using (new WriteLock(this.dictionaryLock))
144 | {
145 | return this.dict.Remove(key);
146 | }
147 | }
148 |
149 | public virtual bool TryGetValue(TKey key, out TValue value)
150 | {
151 | using (new ReadOnlyLock(this.dictionaryLock))
152 | {
153 | return this.dict.TryGetValue(key, out value);
154 | }
155 | }
156 |
157 | IEnumerator IEnumerable.GetEnumerator()
158 | {
159 | throw new NotSupportedException(
160 | "Cannot enumerate a threadsafe dictionary. Instead, enumerate the keys or values collection");
161 | }
162 |
163 | public virtual IEnumerator> GetEnumerator()
164 | {
165 | throw new NotSupportedException(
166 | "Cannot enumerate a threadsafe dictionary. Instead, enumerate the keys or values collection");
167 | }
168 |
169 | ///
170 | /// Merge does a blind remove, and then add. Basically a blind Upsert.
171 | ///
172 | /// Key to lookup
173 | /// New Value
174 | public void MergeSafe(TKey key, TValue newValue)
175 | {
176 | using (new WriteLock(this.dictionaryLock))
177 | {
178 | // take a writelock immediately since we will always be writing
179 | if (this.dict.ContainsKey(key))
180 | {
181 | this.dict.Remove(key);
182 | }
183 |
184 | this.dict.Add(key, newValue);
185 | }
186 | }
187 |
188 | ///
189 | /// This is a blind remove. Prevents the need to check for existence first.
190 | ///
191 | /// Key to remove
192 | public void RemoveSafe(TKey key)
193 | {
194 | using (new ReadLock(this.dictionaryLock))
195 | {
196 | if (this.dict.ContainsKey(key))
197 | {
198 | using (new WriteLock(this.dictionaryLock))
199 | {
200 | this.dict.Remove(key);
201 | }
202 | }
203 | }
204 | }
205 | }
206 |
207 | public static class Locks
208 | {
209 | public static ReaderWriterLockSlim GetLockInstance()
210 | {
211 | return GetLockInstance(LockRecursionPolicy.SupportsRecursion);
212 | }
213 |
214 | public static ReaderWriterLockSlim GetLockInstance(LockRecursionPolicy recursionPolicy)
215 | {
216 | return new ReaderWriterLockSlim(recursionPolicy);
217 | }
218 |
219 | public static void GetReadLock(ReaderWriterLockSlim locks)
220 | {
221 | var lockAcquired = false;
222 | while (!lockAcquired)
223 | {
224 | lockAcquired = locks.TryEnterUpgradeableReadLock(1);
225 | }
226 | }
227 |
228 | public static void GetReadOnlyLock(ReaderWriterLockSlim locks)
229 | {
230 | var lockAcquired = false;
231 | while (!lockAcquired)
232 | {
233 | lockAcquired = locks.TryEnterReadLock(1);
234 | }
235 | }
236 |
237 | public static void GetWriteLock(ReaderWriterLockSlim locks)
238 | {
239 | var lockAcquired = false;
240 | while (!lockAcquired)
241 | {
242 | lockAcquired = locks.TryEnterWriteLock(1);
243 | }
244 | }
245 |
246 | public static void ReleaseLock(ReaderWriterLockSlim locks)
247 | {
248 | ReleaseWriteLock(locks);
249 | ReleaseReadLock(locks);
250 | ReleaseReadOnlyLock(locks);
251 | }
252 |
253 | public static void ReleaseReadLock(ReaderWriterLockSlim locks)
254 | {
255 | if (locks.IsUpgradeableReadLockHeld)
256 | {
257 | locks.ExitUpgradeableReadLock();
258 | }
259 | }
260 |
261 | public static void ReleaseReadOnlyLock(ReaderWriterLockSlim locks)
262 | {
263 | if (locks.IsReadLockHeld)
264 | {
265 | locks.ExitReadLock();
266 | }
267 | }
268 |
269 | public static void ReleaseWriteLock(ReaderWriterLockSlim locks)
270 | {
271 | if (locks.IsWriteLockHeld)
272 | {
273 | locks.ExitWriteLock();
274 | }
275 | }
276 | }
277 |
278 | public abstract class BaseLock : IDisposable
279 | {
280 | [CLSCompliant(false)]
281 | protected ReaderWriterLockSlim _Locks;
282 |
283 | public BaseLock(ReaderWriterLockSlim locks)
284 | {
285 | this._Locks = locks;
286 | }
287 |
288 | public abstract void Dispose();
289 | }
290 |
291 | public class ReadLock : BaseLock
292 | {
293 | public ReadLock(ReaderWriterLockSlim locks)
294 | : base(locks)
295 | {
296 | Locks.GetReadLock(this._Locks);
297 | }
298 |
299 | public override void Dispose()
300 | {
301 | Locks.ReleaseReadLock(this._Locks);
302 | }
303 | }
304 |
305 | public class ReadOnlyLock : BaseLock
306 | {
307 | public ReadOnlyLock(ReaderWriterLockSlim locks)
308 | : base(locks)
309 | {
310 | Locks.GetReadOnlyLock(this._Locks);
311 | }
312 |
313 | public override void Dispose()
314 | {
315 | Locks.ReleaseReadOnlyLock(this._Locks);
316 | }
317 | }
318 |
319 | public class WriteLock : BaseLock
320 | {
321 | public WriteLock(ReaderWriterLockSlim locks)
322 | : base(locks)
323 | {
324 | Locks.GetWriteLock(this._Locks);
325 | }
326 |
327 | public override void Dispose()
328 | {
329 | Locks.ReleaseWriteLock(this._Locks);
330 | }
331 | }
332 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/ThreadSessionStorage.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Threading;
6 |
7 | using global::NHibernate;
8 |
9 | using SharpArch.NHibernate;
10 |
11 | public class ThreadSessionStorage : IUnitOfWorkSessionStorage
12 | {
13 | private readonly ThreadSafeDictionary perThreadSessionStorage =
14 | new ThreadSafeDictionary();
15 |
16 | public IEnumerable GetAllSessions()
17 | {
18 | return this.GetSimpleSessionStorageForThread().GetAllSessions();
19 | }
20 |
21 | public ISession GetSessionForKey(string factoryKey)
22 | {
23 | return this.GetSimpleSessionStorageForThread().GetSessionForKey(factoryKey);
24 | }
25 |
26 | public void SetSessionForKey(string factoryKey, ISession session)
27 | {
28 | this.GetSimpleSessionStorageForThread().SetSessionForKey(factoryKey, session);
29 | }
30 |
31 | public void EndUnitOfWork(bool closeSessions)
32 | {
33 | if (closeSessions)
34 | {
35 | NHibernateSession.CloseAllSessions();
36 | this.perThreadSessionStorage.Remove(this.GetCurrentThreadName());
37 | }
38 | else
39 | {
40 | foreach (var session in this.GetAllSessions())
41 | {
42 | session.Clear();
43 | }
44 | }
45 | }
46 |
47 | private string GetCurrentThreadName()
48 | {
49 | if (Thread.CurrentThread.Name == null)
50 | {
51 | Thread.CurrentThread.Name = Guid.NewGuid().ToString();
52 | }
53 |
54 | return Thread.CurrentThread.Name;
55 | }
56 |
57 | private SimpleSessionStorage GetSimpleSessionStorageForThread()
58 | {
59 | var currentThreadName = this.GetCurrentThreadName();
60 | SimpleSessionStorage sessionStorage;
61 | if (!this.perThreadSessionStorage.TryGetValue(currentThreadName, out sessionStorage))
62 | {
63 | sessionStorage = new SimpleSessionStorage();
64 | this.perThreadSessionStorage.Add(currentThreadName, sessionStorage);
65 | }
66 |
67 | return sessionStorage;
68 | }
69 | }
70 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/TransactionAttributeSettings.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 |
5 | using SharpArch.NHibernate;
6 |
7 | [Serializable]
8 | public class TransactionAttributeSettings
9 | {
10 | public TransactionAttributeSettings()
11 | {
12 | this.FactoryKey = NHibernateSession.DefaultFactoryKey;
13 | this.IsExceptionSilent = false;
14 | this.ReturnValue = null;
15 | }
16 |
17 | public string FactoryKey { get; set; }
18 |
19 | public bool IsExceptionSilent { get; set; }
20 |
21 | public object ReturnValue { get; set; }
22 | }
23 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/TransactionManagerBase.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 | using System.Threading;
5 |
6 | using log4net;
7 |
8 | [Serializable]
9 | public abstract class TransactionManagerBase : ITransactionManager
10 | {
11 | private static readonly ILog logger = LogManager.GetLogger(typeof(TransactionManagerBase));
12 |
13 | [ThreadStatic]
14 | private static int transactionDepth;
15 |
16 | public abstract string Name { get; }
17 |
18 | public int TransactionDepth
19 | {
20 | get
21 | {
22 | return transactionDepth;
23 | }
24 | }
25 |
26 | public abstract object CommitTransaction(string factoryKey, object transactionState);
27 |
28 | public virtual object PopTransaction(string factoryKey, object transactionState)
29 | {
30 | Interlocked.Decrement(ref transactionDepth);
31 | this.Log(string.Format("Pop Transaction to Depth {0}", transactionDepth));
32 | return transactionState;
33 | }
34 |
35 | public virtual object PushTransaction(string factoryKey, object transactionState)
36 | {
37 | Interlocked.Increment(ref transactionDepth);
38 | this.Log(string.Format("Push Transaction to Depth {0}", transactionDepth));
39 | return transactionState;
40 | }
41 |
42 | public abstract object RollbackTransaction(string factoryKey, object transactionState);
43 |
44 | public abstract bool TransactionIsActive(string factoryKey);
45 |
46 | protected void Log(string message)
47 | {
48 | logger.Debug(string.Format("{0}: {1}", this.Name, message));
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/NHibernate/UnitOfWorkAttributeSettings.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Data.NHibernate
2 | {
3 | using System;
4 |
5 | [Serializable]
6 | public class UnitOfWorkAttributeSettings : TransactionAttributeSettings
7 | {
8 | public UnitOfWorkAttributeSettings()
9 | {
10 | this.CloseSessions = true;
11 | }
12 |
13 | public bool CloseSessions { get; set; }
14 | }
15 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | [assembly: AssemblyTitle("SharpArchContrib.Data")]
5 | [assembly: AssemblyDescription("")]
6 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/SharpArchContrib.Data.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {E33E2468-B055-4F3D-83DB-8F991F600A47}
9 | Library
10 | Properties
11 | SharpArchContrib.Data
12 | SharpArchContrib.Data
13 | v4.0
14 | 512
15 | true
16 |
17 |
18 |
19 |
20 | 3.5
21 |
22 | publish\
23 | true
24 | Disk
25 | false
26 | Foreground
27 | 7
28 | Days
29 | false
30 | false
31 | true
32 | 0
33 | 1.0.0.%2a
34 | false
35 | false
36 | true
37 |
38 | ..\..\Solutions\
39 | true
40 |
41 |
42 | true
43 | full
44 | false
45 | bin\Debug\
46 | DEBUG;TRACE
47 | prompt
48 | 4
49 | AllRules.ruleset
50 |
51 |
52 | pdbonly
53 | true
54 | bin\Release\
55 | TRACE
56 | prompt
57 | 4
58 | AllRules.ruleset
59 |
60 |
61 |
62 | False
63 | ..\..\Packages\FluentNHibernate.1.3.0.727\lib\FluentNHibernate.dll
64 |
65 |
66 | ..\..\Packages\Iesi.Collections.3.2.0.4000\lib\Net35\Iesi.Collections.dll
67 |
68 |
69 | ..\..\Packages\log4net.1.2.10\lib\2.0\log4net.dll
70 |
71 |
72 | ..\..\Packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll
73 |
74 |
75 | False
76 | ..\..\Packages\Newtonsoft.Json.4.5.4\lib\net40\Newtonsoft.Json.dll
77 |
78 |
79 | False
80 | ..\..\Packages\NHibernate.3.3.0.4000\lib\Net35\NHibernate.dll
81 |
82 |
83 | ..\..\Packages\SharpArch.Domain.2.0.4\lib\NET40\SharpArch.Domain.dll
84 |
85 |
86 | ..\..\Packages\SharpArch.NHibernate.2.0.4\lib\NET40\SharpArch.NHibernate.dll
87 |
88 |
89 |
90 |
91 | 3.5
92 |
93 |
94 |
95 | 3.5
96 |
97 |
98 | 3.5
99 |
100 |
101 |
102 |
103 |
104 |
105 | Properties\AssemblyVersion.cs
106 |
107 |
108 | Properties\CommonAssemblyInfo.cs
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}
128 | SharpArchContrib.Core
129 |
130 |
131 |
132 |
133 | False
134 | .NET Framework 3.5 SP1 Client Profile
135 | false
136 |
137 |
138 | False
139 | .NET Framework 3.5 SP1
140 | true
141 |
142 |
143 | False
144 | Windows Installer 3.1
145 | true
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
161 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/SharpArchContrib.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/Solutions/SharpArchContrib.Data/SharpArchContrib.snk
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Data/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/Logging/ExceptionHandlerAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.PostSharp.Logging
2 | {
3 | using System;
4 |
5 | using Microsoft.Practices.ServiceLocation;
6 |
7 | using global::PostSharp.Aspects;
8 | using global::PostSharp.Extensibility;
9 |
10 | using SharpArchContrib.Core.Logging;
11 |
12 | [Serializable]
13 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false,
14 | Inherited = false)]
15 | [MulticastAttributeUsage(
16 | MulticastTargets.Method | MulticastTargets.InstanceConstructor | MulticastTargets.StaticConstructor,
17 | AllowMultiple = true)]
18 | public sealed class ExceptionHandlerAttribute : OnExceptionAspect
19 | {
20 | #region Constants and Fields
21 |
22 | private IExceptionLogger exceptionLogger;
23 |
24 | #endregion
25 |
26 | #region Constructors and Destructors
27 |
28 | ///
29 | /// Constructor
30 | ///
31 | public ExceptionHandlerAttribute()
32 | {
33 | this.Settings = new ExceptionHandlerAttributeSettings();
34 | }
35 |
36 | #endregion
37 |
38 | #region Properties
39 |
40 | public bool IsSilent
41 | {
42 | get
43 | {
44 | return this.Settings.IsSilent;
45 | }
46 |
47 | set
48 | {
49 | this.Settings.IsSilent = value;
50 | }
51 | }
52 |
53 | public object ReturnValue
54 | {
55 | get
56 | {
57 | return this.Settings.ReturnValue;
58 | }
59 |
60 | set
61 | {
62 | this.Settings.ReturnValue = value;
63 | }
64 | }
65 |
66 | public ExceptionHandlerAttributeSettings Settings { get; set; }
67 |
68 | private IExceptionLogger ExceptionLogger
69 | {
70 | get
71 | {
72 | if (this.exceptionLogger == null)
73 | {
74 | this.exceptionLogger = ServiceLocator.Current.GetInstance();
75 | }
76 |
77 | return this.exceptionLogger;
78 | }
79 | }
80 |
81 | #endregion
82 |
83 | #region Public Methods
84 |
85 | public override void OnException(MethodExecutionArgs eventArgs)
86 | {
87 | this.ExceptionLogger.LogException(eventArgs.Exception, this.IsSilent, eventArgs.Method.DeclaringType);
88 | if (this.IsSilent)
89 | {
90 | eventArgs.FlowBehavior = FlowBehavior.Return;
91 | eventArgs.ReturnValue = this.ReturnValue;
92 | }
93 | }
94 |
95 | #endregion
96 | }
97 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/Logging/LogAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.PostSharp.Logging
2 | {
3 | using System;
4 |
5 | using log4net;
6 |
7 | using Microsoft.Practices.ServiceLocation;
8 |
9 | using global::PostSharp.Aspects;
10 | using global::PostSharp.Extensibility;
11 |
12 | using SharpArchContrib.Core.Logging;
13 |
14 | [Serializable]
15 | [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false,
16 | Inherited = false)]
17 | [MulticastAttributeUsage(
18 | MulticastTargets.Method | MulticastTargets.InstanceConstructor | MulticastTargets.StaticConstructor,
19 | AllowMultiple = true)]
20 | public class LogAttribute : OnMethodBoundaryAspect
21 | {
22 | #region Constants and Fields
23 |
24 | private IMethodLogger methodLogger;
25 |
26 | #endregion
27 |
28 | #region Constructors and Destructors
29 |
30 | public LogAttribute()
31 | {
32 | this.Settings = new LogAttributeSettings(LoggingLevel.Debug, LoggingLevel.Debug, LoggingLevel.Error);
33 | }
34 |
35 | #endregion
36 |
37 | #region Properties
38 |
39 | public LoggingLevel EntryLevel
40 | {
41 | get
42 | {
43 | return this.Settings.EntryLevel;
44 | }
45 |
46 | set
47 | {
48 | this.Settings.EntryLevel = value;
49 | }
50 | }
51 |
52 | public LoggingLevel ExceptionLevel
53 | {
54 | get
55 | {
56 | return this.Settings.ExceptionLevel;
57 | }
58 |
59 | set
60 | {
61 | this.Settings.ExceptionLevel = value;
62 | }
63 | }
64 |
65 | public LogAttributeSettings Settings { get; set; }
66 |
67 | public LoggingLevel SuccessLevel
68 | {
69 | get
70 | {
71 | return this.Settings.SuccessLevel;
72 | }
73 |
74 | set
75 | {
76 | this.Settings.SuccessLevel = value;
77 | }
78 | }
79 |
80 | private IMethodLogger MethodLogger
81 | {
82 | get
83 | {
84 | if (this.methodLogger == null)
85 | {
86 | this.methodLogger = ServiceLocator.Current.GetInstance();
87 | }
88 |
89 | return this.methodLogger;
90 | }
91 | }
92 |
93 | #endregion
94 |
95 | #region Public Methods
96 |
97 | public sealed override void OnEntry(MethodExecutionArgs eventArgs)
98 | {
99 | this.MethodLogger.LogEntry(eventArgs.Method, eventArgs.Arguments.ToArray(), this.EntryLevel);
100 | }
101 |
102 | public sealed override void OnException(MethodExecutionArgs eventArgs)
103 | {
104 | this.methodLogger.LogException(eventArgs.Method, eventArgs.Exception, this.ExceptionLevel);
105 | }
106 |
107 | public sealed override void OnSuccess(MethodExecutionArgs eventArgs)
108 | {
109 | this.methodLogger.LogSuccess(eventArgs.Method, eventArgs.ReturnValue, this.SuccessLevel);
110 | }
111 |
112 | #endregion
113 |
114 | #region Methods
115 |
116 | private bool ShouldLog(ILog logger, LoggingLevel loggingLevel, MethodExecutionArgs args)
117 | {
118 | if (args != null && args.Method != null && args.Method.Name != null)
119 | {
120 | return logger.IsEnabledFor(loggingLevel);
121 | }
122 |
123 | return false;
124 | }
125 |
126 | #endregion
127 | }
128 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/NHibernate/TransactionAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.PostSharp.NHibernate
2 | {
3 | using System;
4 |
5 | using Microsoft.Practices.ServiceLocation;
6 |
7 | using global::PostSharp.Aspects;
8 | using global::PostSharp.Extensibility;
9 |
10 | using SharpArch.Domain;
11 | using SharpArch.NHibernate;
12 |
13 | using SharpArchContrib.Core.Logging;
14 | using SharpArchContrib.Data.NHibernate;
15 |
16 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
17 | [MulticastAttributeUsage(MulticastTargets.Method, AllowMultiple = true)]
18 | [Serializable]
19 | public class TransactionAttribute : OnMethodBoundaryAspect, ITransactionAttributeSettings
20 | {
21 | #region Constants and Fields
22 |
23 | protected TransactionAttributeSettings attributeSettings;
24 |
25 | private IExceptionLogger exceptionLogger;
26 |
27 | private ITransactionManager transactionManager;
28 |
29 | #endregion
30 |
31 | #region Constructors and Destructors
32 |
33 | public TransactionAttribute()
34 | {
35 | this.attributeSettings = new TransactionAttributeSettings();
36 | }
37 |
38 | #endregion
39 |
40 | #region Properties
41 |
42 | public string FactoryKey
43 | {
44 | get
45 | {
46 | return this.Settings.FactoryKey;
47 | }
48 |
49 | set
50 | {
51 | if (value == null)
52 | {
53 | throw new PreconditionException("FactoryKey cannot be null");
54 | }
55 |
56 | this.Settings.FactoryKey = value;
57 | }
58 | }
59 |
60 | public bool IsExceptionSilent
61 | {
62 | get
63 | {
64 | return this.Settings.IsExceptionSilent;
65 | }
66 |
67 | set
68 | {
69 | this.Settings.IsExceptionSilent = value;
70 | }
71 | }
72 |
73 | public object ReturnValue
74 | {
75 | get
76 | {
77 | return this.Settings.ReturnValue;
78 | }
79 |
80 | set
81 | {
82 | this.Settings.ReturnValue = value;
83 | }
84 | }
85 |
86 | public TransactionAttributeSettings Settings
87 | {
88 | get
89 | {
90 | return this.attributeSettings;
91 | }
92 |
93 | set
94 | {
95 | if (value == null)
96 | {
97 | throw new PreconditionException("Settings must not be null");
98 | }
99 |
100 | this.attributeSettings = value;
101 | }
102 | }
103 |
104 | protected ITransactionManager TransactionManager
105 | {
106 | get
107 | {
108 | if (this.transactionManager == null)
109 | {
110 | this.transactionManager = ServiceLocator.Current.GetInstance();
111 | }
112 |
113 | return this.transactionManager;
114 | }
115 | }
116 |
117 | private IExceptionLogger ExceptionLogger
118 | {
119 | get
120 | {
121 | if (this.exceptionLogger == null)
122 | {
123 | this.exceptionLogger = ServiceLocator.Current.GetInstance();
124 | }
125 |
126 | return this.exceptionLogger;
127 | }
128 | }
129 |
130 | #endregion
131 |
132 | #region Public Methods
133 |
134 | public sealed override void OnEntry(MethodExecutionArgs eventArgs)
135 | {
136 | eventArgs.MethodExecutionTag = this.TransactionManager.PushTransaction(
137 | this.FactoryKey, eventArgs.MethodExecutionTag);
138 | }
139 |
140 | public override sealed void OnException(MethodExecutionArgs eventArgs)
141 | {
142 | eventArgs.MethodExecutionTag = this.CloseUnitOfWork(eventArgs.MethodExecutionTag, eventArgs.Exception == null);
143 |
144 | if (!(eventArgs.Exception is AbortTransactionException))
145 | {
146 | this.ExceptionLogger.LogException(
147 | eventArgs.Exception, this.IsExceptionSilent, eventArgs.Method.DeclaringType);
148 | }
149 |
150 | if (this.TransactionManager.TransactionDepth == 0 &&
151 | (this.IsExceptionSilent || eventArgs.Exception is AbortTransactionException))
152 | {
153 | eventArgs.FlowBehavior = FlowBehavior.Return;
154 | eventArgs.ReturnValue = this.ReturnValue;
155 | }
156 | }
157 |
158 | public sealed override void OnSuccess(MethodExecutionArgs eventArgs)
159 | {
160 | eventArgs.MethodExecutionTag = this.CloseUnitOfWork(eventArgs.MethodExecutionTag, eventArgs.Exception == null);
161 | }
162 |
163 | #endregion
164 |
165 | #region Methods
166 |
167 | protected virtual object CloseUnitOfWork(object transactionState, bool commit)
168 | {
169 | if (commit)
170 | {
171 | NHibernateSession.CurrentFor(this.FactoryKey).Flush();
172 | transactionState = this.TransactionManager.CommitTransaction(this.FactoryKey, transactionState);
173 | }
174 | else
175 | {
176 | transactionState = this.TransactionManager.RollbackTransaction(this.FactoryKey, transactionState);
177 | }
178 |
179 | transactionState = this.TransactionManager.PopTransaction(this.FactoryKey, transactionState);
180 |
181 | return transactionState;
182 | }
183 |
184 | #endregion
185 | }
186 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/NHibernate/UnitOfWorkAttribute.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.PostSharp.NHibernate
2 | {
3 | using System;
4 |
5 | using global::PostSharp.Aspects;
6 | using global::PostSharp.Extensibility;
7 |
8 | using SharpArch.NHibernate;
9 |
10 | using SharpArchContrib.Data.NHibernate;
11 |
12 | [Serializable]
13 | [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
14 | [MulticastAttributeUsage(MulticastTargets.Method, AllowMultiple = true)]
15 | public sealed class UnitOfWorkAttribute : TransactionAttribute
16 | {
17 | #region Constructors and Destructors
18 |
19 | public UnitOfWorkAttribute()
20 | {
21 | this.attributeSettings = new UnitOfWorkAttributeSettings();
22 | }
23 |
24 | #endregion
25 |
26 | #region Properties
27 |
28 | public bool CloseSessions
29 | {
30 | get
31 | {
32 | return this.UnitOfWorkSettings.CloseSessions;
33 | }
34 |
35 | set
36 | {
37 | this.UnitOfWorkSettings.CloseSessions = value;
38 | }
39 | }
40 |
41 | public UnitOfWorkAttributeSettings UnitOfWorkSettings
42 | {
43 | get
44 | {
45 | return (UnitOfWorkAttributeSettings)this.attributeSettings;
46 | }
47 |
48 | set
49 | {
50 | this.Settings = value;
51 | }
52 | }
53 |
54 | #endregion
55 |
56 | #region Methods
57 |
58 | protected override object CloseUnitOfWork(object transactionState, bool commit)
59 | {
60 | base.CloseUnitOfWork(transactionState, commit);
61 | if (this.TransactionManager.TransactionDepth == 0)
62 | {
63 | var sessionStorage = NHibernateSession.Storage as IUnitOfWorkSessionStorage;
64 | if (sessionStorage != null)
65 | {
66 | sessionStorage.EndUnitOfWork(this.CloseSessions);
67 | }
68 | }
69 |
70 | return transactionState;
71 | }
72 |
73 | #endregion
74 | }
75 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/PostSharp.license:
--------------------------------------------------------------------------------
1 | 21026-ATEWSQQQXEQZTPZQQQQQQQQQQQATAEDV56MCNGGVQJYTNTDVT4TW7GAF2M8KXMDVD6UCQERCE4UW3USEB8UTNA9FV29W7YDRCQCM3F6XDJFLHG5MVCJ2HAGUKDSGN4UQQ4UCQMYAAC653WXZQR5NLN7SS5BA2VDBFKYNQQKP
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | [assembly: AssemblyTitle("SharpArchContrib.PostSharp")]
5 | [assembly: AssemblyDescription("")]
6 | [assembly: CLSCompliant(true)]
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/SharpArchContrib.PostSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.30729
7 | 2.0
8 | {C3928AAD-61C3-4C2E-8FB3-A177B0DC3DB1}
9 | Library
10 | Properties
11 | SharpArchContrib.PostSharp
12 | SharpArchContrib.PostSharp
13 | v4.0
14 | 512
15 | false
16 |
17 |
18 |
19 |
20 | 3.5
21 |
22 | publish\
23 | true
24 | Disk
25 | false
26 | Foreground
27 | 7
28 | Days
29 | false
30 | false
31 | true
32 | 0
33 | 1.0.0.%2a
34 | false
35 | false
36 | true
37 |
38 | True
39 | ..\..\Solutions\
40 | true
41 |
42 |
43 | true
44 | full
45 | false
46 | bin\Debug\
47 | DEBUG;TRACE
48 | prompt
49 | 4
50 | AllRules.ruleset
51 |
52 |
53 | pdbonly
54 | true
55 | bin\Release\
56 | TRACE
57 | prompt
58 | 4
59 | AllRules.ruleset
60 |
61 |
62 |
63 | ..\..\Packages\FluentNHibernate.1.3.0.717\lib\FluentNHibernate.dll
64 |
65 |
66 | ..\..\Packages\Iesi.Collections.3.2.0.4000\lib\Net35\Iesi.Collections.dll
67 |
68 |
69 | ..\..\Packages\log4net.1.2.10\lib\2.0\log4net.dll
70 |
71 |
72 | ..\..\Packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll
73 |
74 |
75 | ..\..\Packages\Newtonsoft.Json.4.0.7\lib\net40\Newtonsoft.Json.dll
76 |
77 |
78 | ..\..\Packages\NHibernate.3.2.0.4000\lib\Net35\NHibernate.dll
79 |
80 |
81 | ..\..\Packages\PostSharp.2.1.5.1\lib\net20\PostSharp.dll
82 |
83 |
84 | ..\..\Packages\SharpArch.Domain.2.0.2\lib\NET40\SharpArch.Domain.dll
85 |
86 |
87 | ..\..\Packages\SharpArch.NHibernate.2.0.2\lib\NET40\SharpArch.NHibernate.dll
88 |
89 |
90 |
91 |
92 | 3.5
93 |
94 |
95 | 3.5
96 |
97 |
98 | 3.5
99 |
100 |
101 |
102 |
103 |
104 |
105 | Properties\AssemblyVersion.cs
106 |
107 |
108 | Properties\CommonAssemblyInfo.cs
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | False
119 | .NET Framework 3.5 SP1 Client Profile
120 | false
121 |
122 |
123 | False
124 | .NET Framework 3.5 SP1
125 | true
126 |
127 |
128 | False
129 | Windows Installer 3.1
130 | true
131 |
132 |
133 |
134 |
135 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}
136 | SharpArchContrib.Core
137 |
138 |
139 | {E33E2468-B055-4F3D-83DB-8F991F600A47}
140 | SharpArchContrib.Data
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
160 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/SharpArchContrib.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharparchitecture/Sharp-Architecture-Contrib/21b366d8bdb0da679189dc88c20145d64a157889/Solutions/SharpArchContrib.PostSharp/SharpArchContrib.snk
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.PostSharp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Specifications/ServiceLocatorHelper.cs:
--------------------------------------------------------------------------------
1 | namespace SharpArchContrib.Specifications
2 | {
3 | #region Using Directives
4 |
5 | using Microsoft.Practices.ServiceLocation;
6 |
7 | using Rhino.Mocks;
8 |
9 | #endregion
10 |
11 | public static class ServiceLocatorHelper
12 | {
13 | private static IServiceLocator provider;
14 |
15 | public static void InitialiseServiceLocator()
16 | {
17 | provider = MockRepository.GenerateStub();
18 |
19 | ServiceLocator.SetLocatorProvider(() => provider);
20 | }
21 |
22 | public static T AddToServiceLocator(this T o)
23 | {
24 | if (provider == null)
25 | {
26 | InitialiseServiceLocator();
27 | }
28 |
29 | provider.Stub(p => p.GetInstance()).Return(o);
30 | provider.Stub(p => p.GetService(typeof(T))).Return(o);
31 | return o;
32 | }
33 |
34 | public static void Reset()
35 | {
36 | provider = null;
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
75 |
76 |
77 |
78 |
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/AssemblySetup.cs:
--------------------------------------------------------------------------------
1 | namespace Tests
2 | {
3 | using System.IO;
4 |
5 | using log4net.Config;
6 |
7 | using NUnit.Framework;
8 |
9 | using Tests.Configuration;
10 |
11 | [SetUpFixture]
12 | public class AssemblySetup
13 | {
14 | [SetUp]
15 | public void SetUp()
16 | {
17 | this.InitializeDirectories();
18 | this.InitializeLog4Net();
19 | this.InitalizeServiceLocator();
20 | }
21 |
22 | private void InitalizeServiceLocator()
23 | {
24 | ServiceLocatorInitializer.Init();
25 | }
26 |
27 | private void InitializeDirectories()
28 | {
29 | if (Directory.Exists(Config.TestDataDir))
30 | {
31 | Directory.Delete(Config.TestDataDir, true);
32 | }
33 |
34 | Directory.CreateDirectory(Config.TestDataDir);
35 | }
36 |
37 | private void InitializeLog4Net()
38 | {
39 | XmlConfigurator.Configure();
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/Configuration/Config.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.Configuration
2 | {
3 | using System.IO;
4 |
5 | public static class Config
6 | {
7 | public static string TestDataDir
8 | {
9 | get
10 | {
11 | return Path.GetFullPath("TestData");
12 | }
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/DomainModel/AutoPersistenceModelGenerator.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.DomainModel
2 | {
3 | using System;
4 | using System.Linq;
5 |
6 | using FluentNHibernate.Automapping;
7 | using FluentNHibernate.Conventions;
8 |
9 | using SharpArch.Domain.DomainModel;
10 | using SharpArch.NHibernate.FluentNHibernate;
11 |
12 | using Tests.DomainModel.Conventions;
13 | using Tests.DomainModel.Entities;
14 |
15 | public class AutoPersistenceModelGenerator : IAutoPersistenceModelGenerator
16 | {
17 | [CLSCompliant(false)]
18 | public AutoPersistenceModel Generate()
19 | {
20 | var mappings = new AutoPersistenceModel();
21 | mappings.AddEntityAssembly(typeof(TestEntity).Assembly).Where(this.GetAutoMappingFilter);
22 | mappings.Conventions.Setup(this.GetConventions());
23 | mappings.Setup(this.GetSetup());
24 | mappings.IgnoreBase();
25 | mappings.IgnoreBase(typeof(EntityWithTypedId<>));
26 | mappings.UseOverridesFromAssemblyOf();
27 | return mappings;
28 | }
29 |
30 | ///
31 | /// Provides a filter for only including types which inherit from the IEntityWithTypedId interface.
32 | ///
33 | private bool GetAutoMappingFilter(Type t)
34 | {
35 | return
36 | t.GetInterfaces().Any(
37 | x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>));
38 | }
39 |
40 | private Action GetConventions()
41 | {
42 | return c =>
43 | {
44 | c.Add();
45 | c.Add();
46 | c.Add();
47 | c.Add();
48 | };
49 | }
50 |
51 | private Action GetSetup()
52 | {
53 | return c => { c.FindIdentity = type => type.Name == "Id"; };
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/DomainModel/Conventions/HasManyConvention.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.DomainModel.Conventions
2 | {
3 | using System;
4 |
5 | using FluentNHibernate.Conventions;
6 | using FluentNHibernate.Conventions.Instances;
7 |
8 | public class HasManyConvention : IHasManyConvention
9 | {
10 | [CLSCompliant(false)]
11 | public void Apply(IOneToManyCollectionInstance instance)
12 | {
13 | instance.Key.Column(instance.EntityType.Name + "Id");
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/DomainModel/Conventions/PrimaryKeyConvention.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.DomainModel.Conventions
2 | {
3 | using System;
4 |
5 | using FluentNHibernate.Conventions;
6 | using FluentNHibernate.Conventions.Instances;
7 |
8 | public class PrimaryKeyConvention : IIdConvention
9 | {
10 | [CLSCompliant(false)]
11 | public void Apply(IIdentityInstance instance)
12 | {
13 | instance.Column(instance.EntityType.Name + "Id");
14 | instance.UnsavedValue("0");
15 | instance.GeneratedBy.Identity();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/DomainModel/Conventions/ReferenceConvention.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.DomainModel.Conventions
2 | {
3 | using System;
4 |
5 | using FluentNHibernate.Conventions;
6 | using FluentNHibernate.Conventions.Instances;
7 |
8 | public class ReferenceConvention : IReferenceConvention
9 | {
10 | [CLSCompliant(false)]
11 | public void Apply(IManyToOneInstance instance)
12 | {
13 | instance.Column(instance.Property.Name + "Id");
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/DomainModel/Conventions/TableNameConvention.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.DomainModel.Conventions
2 | {
3 | using System;
4 |
5 | using FluentNHibernate.Conventions;
6 | using FluentNHibernate.Conventions.Instances;
7 |
8 | public class TableNameConvention : IClassConvention
9 | {
10 | [CLSCompliant(false)]
11 | public void Apply(IClassInstance instance)
12 | {
13 | instance.Table(instance.EntityType.Name);
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/DomainModel/Entities/TestEntity.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.DomainModel.Entities
2 | {
3 | using SharpArch.Domain.DomainModel;
4 |
5 | public class TestEntity : Entity
6 | {
7 | [DomainSignature]
8 | public virtual string Name { get; set; }
9 | }
10 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/DomainModel/NHibernateMaps/TestEntityMap.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.DomainModel.NHibernateMaps
2 | {
3 | using System;
4 |
5 | using FluentNHibernate.Automapping;
6 | using FluentNHibernate.Automapping.Alterations;
7 |
8 | using Tests.DomainModel.Entities;
9 |
10 | public class TestEntityMap : IAutoMappingOverride
11 | {
12 | [CLSCompliant(false)]
13 | public void Override(AutoMapping mapping)
14 | {
15 | mapping.Map(c => c.Name).Unique();
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/HibernateFile.cfg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | NHibernate.Connection.DriverConnectionProvider
7 |
8 |
9 | NHibernate.Dialect.SQLiteDialect
10 |
11 |
12 | NHibernate.Driver.SQLite20Driver
13 |
14 |
15 | Data Source=db.dat;Version=3;New=True;
16 |
17 | on_close
18 |
19 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/NHibernateTests/ITransactionTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.NHibernateTests
2 | {
3 | using SharpArch.Domain.PersistenceSupport;
4 | using Tests.DomainModel.Entities;
5 |
6 | public interface ITransactionTestProvider
7 | {
8 | string Name { get; }
9 |
10 | IRepository TestEntityRepository { get; set; }
11 |
12 | void CheckNumberOfEntities(int numberOfEntities);
13 |
14 | void DoCommit(string testEntityName);
15 |
16 | void DoCommitSilenceException(string testEntityName);
17 |
18 | void DoNestedCommit();
19 |
20 | void DoNestedForceRollback();
21 |
22 | void DoNestedInnerForceRollback();
23 |
24 | void DoRollback();
25 |
26 | void InitTransactionManager();
27 | }
28 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/NHibernateTests/TransactionTestProviderBase.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.NHibernateTests
2 | {
3 | using System;
4 |
5 | using global::SharpArchContrib.Data.NHibernate;
6 |
7 | using SharpArch.Domain.PersistenceSupport;
8 | using SharpArch.NHibernate;
9 | using SharpArch.Testing.NUnit;
10 |
11 | using Tests.DomainModel.Entities;
12 |
13 | public abstract class TransactionTestProviderBase
14 | {
15 | public IRepository TestEntityRepository { get; set; }
16 |
17 | protected abstract string TestEntityName { get; }
18 |
19 | public void CheckNumberOfEntities(int numberOfEntities)
20 | {
21 | var testEntityRepository = new NHibernateRepository();
22 | var testEntities = testEntityRepository.GetAll();
23 | testEntities.Count.ShouldEqual(numberOfEntities);
24 | }
25 |
26 | public virtual void Commit(string testEntityName)
27 | {
28 | this.DoCommit(testEntityName);
29 | this.CheckNumberOfEntities(1);
30 | }
31 |
32 | public virtual void DoCommit(string testEntityName)
33 | {
34 | this.InsertTestEntity(testEntityName);
35 | }
36 |
37 | public virtual void DoCommitSilenceException(string testEntityName)
38 | {
39 | this.InsertTestEntity(testEntityName);
40 | throw new Exception("Unknown Issue");
41 | }
42 |
43 | public virtual void DoNestedCommit()
44 | {
45 | this.InsertTestEntity(this.TestEntityName + "Outer");
46 | this.DoCommit(this.TestEntityName);
47 | }
48 |
49 | public virtual void DoNestedForceRollback()
50 | {
51 | this.InsertTestEntity(this.TestEntityName + "Outer");
52 | this.DoCommit(this.TestEntityName);
53 | throw new AbortTransactionException();
54 | }
55 |
56 | public virtual void DoNestedInnerForceRollback()
57 | {
58 | this.InsertTestEntity(this.TestEntityName + "Outer");
59 | this.DoRollback();
60 | }
61 |
62 | public virtual void DoRollback()
63 | {
64 | this.InsertTestEntity(this.TestEntityName);
65 | throw new AbortTransactionException();
66 | }
67 |
68 | protected void InsertTestEntity(string name)
69 | {
70 | var testEntityRepository = new NHibernateRepository();
71 | var testEntity = new TestEntity { Name = name };
72 | testEntityRepository.SaveOrUpdate(testEntity);
73 | NHibernateSession.Current.Evict(testEntity);
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/NHibernateTests/TransactionTestsBase.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.NHibernateTests
2 | {
3 | using System;
4 | using System.IO;
5 | using System.Reflection;
6 |
7 | using FluentNHibernate.Automapping;
8 |
9 | using NHibernate.Cfg;
10 | using NHibernate.Tool.hbm2ddl;
11 |
12 | using SharpArch.NHibernate;
13 | using SharpArch.NHibernate.Contracts.Repositories;
14 | using SharpArch.NHibernate.FluentNHibernate;
15 |
16 | using global::SharpArchContrib.Data.NHibernate;
17 |
18 | using Tests.DomainModel.Entities;
19 |
20 | public class TransactionTestsBase
21 | {
22 | protected INHibernateRepository testEntityRepository;
23 |
24 | public void SetUp()
25 | {
26 | this.InitializeDatabase();
27 | this.InitializeData();
28 | }
29 |
30 | public void TearDown()
31 | {
32 | this.Shutdown();
33 | }
34 |
35 | protected virtual void InitializeData()
36 | {
37 | this.testEntityRepository = new NHibernateRepository();
38 | }
39 |
40 | private AutoPersistenceModel GetAutoPersistenceModel(string[] assemblies)
41 | {
42 | foreach (var asmName in assemblies)
43 | {
44 | var asm = Assembly.Load(asmName);
45 | var asmTypes = asm.GetTypes();
46 |
47 | foreach (var asmType in asmTypes)
48 | {
49 | if (typeof(IAutoPersistenceModelGenerator).IsAssignableFrom(asmType))
50 | {
51 | var generator = Activator.CreateInstance(asmType) as IAutoPersistenceModelGenerator;
52 | return generator.Generate();
53 | }
54 | }
55 | }
56 |
57 | return null;
58 | }
59 |
60 | private string[] GetMappingAssemblies()
61 | {
62 | return new[] { "SharpArchContrib.Tests" };
63 | }
64 |
65 | private void InitializeDatabase()
66 | {
67 | if (File.Exists("db.dat"))
68 | {
69 | File.Delete("db.dat");
70 | }
71 |
72 | var cfg = this.InitializeNHibernateSession();
73 | var connection = NHibernateSession.Current.Connection;
74 | new SchemaExport(cfg).Execute(false, true, false, connection, null);
75 | }
76 |
77 | private Configuration InitializeNHibernateSession()
78 | {
79 | var mappingAssemblies = this.GetMappingAssemblies();
80 | var autoPersistenceModel = this.GetAutoPersistenceModel(mappingAssemblies);
81 | return NHibernateSession.Init(
82 | new ThreadSessionStorage(), mappingAssemblies, autoPersistenceModel, "HibernateFile.cfg.xml");
83 | }
84 |
85 | private void Shutdown()
86 | {
87 | NHibernateSession.CloseAllSessions();
88 | NHibernateSession.Reset();
89 | }
90 | }
91 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | [assembly: AssemblyTitle("SharpArchContrib.Tests")]
5 | [assembly: AssemblyDescription("")]
6 | [assembly: CLSCompliant(false)]
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/ServiceLocatorInitializer.cs:
--------------------------------------------------------------------------------
1 | namespace Tests
2 | {
3 | using System;
4 |
5 | using Castle.MicroKernel.Registration;
6 | using Castle.Windsor;
7 |
8 | using CommonServiceLocator.WindsorAdapter;
9 |
10 | using Microsoft.Practices.ServiceLocation;
11 |
12 | using SharpArch.Domain.PersistenceSupport;
13 | using SharpArch.NHibernate;
14 |
15 | using global::SharpArchContrib.Castle.CastleWindsor;
16 |
17 | using global::SharpArchContrib.Data.NHibernate;
18 |
19 | using Tests.NHibernateTests;
20 | using Tests.SharpArchContrib.Castle.Logging;
21 | using Tests.SharpArchContrib.Castle.NHibernate;
22 |
23 | public static class ServiceLocatorInitializer
24 | {
25 | public static void Init()
26 | {
27 | Init(typeof(NHibernateTransactionManager));
28 | }
29 |
30 | public static void Init(Type transactionManagerType)
31 | {
32 | IWindsorContainer container = new WindsorContainer();
33 | ComponentRegistrar.AddComponentsTo(container, transactionManagerType);
34 | RegisterTestServices(container);
35 | ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
36 | }
37 |
38 | private static void RegisterTestServices(IWindsorContainer container)
39 | {
40 | container.Register(Component.For()
41 | .ImplementedBy()
42 | .Forward()
43 | .Named("logTestClass"));
44 | container.Register(Component.For()
45 | .ImplementedBy()
46 | .Named("SystemTransactionTestProvider"));
47 | container.Register(Component.For()
48 | .ImplementedBy()
49 | .Named("NHibernateTransactionTestProvider"));
50 | container.Register(Component.For()
51 | .ImplementedBy()
52 | .Named("SystemUnitOfWorkTestProvider"));
53 | container.Register(Component.For()
54 | .ImplementedBy()
55 | .Named("NHibernateUnitOfWorkTestProvider"));
56 | container.Register(Component.For()
57 | .ImplementedBy()
58 | .Named("ExceptionHandlerTestClass"));
59 | container.Register(Component.For()
60 | .ImplementedBy()
61 | .Named("SessionFactoryKeyProvider"));
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/Logging/ExceptionHandlerAttributeTests.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 |
5 | using Microsoft.Practices.ServiceLocation;
6 |
7 | using NUnit.Framework;
8 |
9 | using SharpArch.Testing.NUnit;
10 |
11 | [TestFixture]
12 | public class ExceptionHandlerAttributeTests
13 | {
14 | private IExceptionHandlerTestClass exceptionHandlerTestClass;
15 |
16 | [Test]
17 | public void LoggedExceptionDoesNotRethrow()
18 | {
19 | Assert.DoesNotThrow(() => this.exceptionHandlerTestClass.ThrowExceptionSilent());
20 | }
21 |
22 | [Test]
23 | public void LoggedExceptionDoesNotRethrowWithReturn()
24 | {
25 | this.exceptionHandlerTestClass.ThrowExceptionSilentWithReturn().ShouldEqual(6f);
26 | }
27 |
28 | [Test]
29 | public void LoggedExceptionDoesNotRethrowWithReturnWithLogAttribute()
30 | {
31 | this.exceptionHandlerTestClass.ThrowExceptionSilentWithReturnWithLogAttribute().ShouldEqual(6f);
32 | }
33 |
34 | [Test]
35 | public void LoggedExceptionRethrows()
36 | {
37 | Assert.Throws(() => this.exceptionHandlerTestClass.ThrowException());
38 | }
39 |
40 | [SetUp]
41 | public void SetUp()
42 | {
43 | this.exceptionHandlerTestClass = ServiceLocator.Current.GetInstance();
44 | }
45 |
46 | [Test]
47 | public void ThrowBaseExceptionNoCatch()
48 | {
49 | Assert.Throws(() => this.exceptionHandlerTestClass.ThrowBaseExceptionNoCatch());
50 | }
51 |
52 | [Test]
53 | public void ThrowNotImplementedExceptionCatch()
54 | {
55 | this.exceptionHandlerTestClass.ThrowNotImplementedExceptionCatch().ShouldEqual(6f);
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/Logging/ExceptionHandlerTestClass.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 |
5 | using global::SharpArchContrib.Castle.Logging;
6 | using global::SharpArchContrib.Core.Logging;
7 |
8 | public class ExceptionHandlerTestClass : IExceptionHandlerTestClass
9 | {
10 | [ExceptionHandler(ExceptionType = typeof(NotImplementedException))]
11 | public float ThrowBaseExceptionNoCatch()
12 | {
13 | throw new Exception();
14 | }
15 |
16 | [ExceptionHandler]
17 | public void ThrowException()
18 | {
19 | throw new NotImplementedException();
20 | }
21 |
22 | [ExceptionHandler(IsSilent = true, ReturnValue = 6f)]
23 | public void ThrowExceptionSilent()
24 | {
25 | throw new NotImplementedException();
26 | }
27 |
28 | [ExceptionHandler(IsSilent = true, ReturnValue = 6f)]
29 | public float ThrowExceptionSilentWithReturn()
30 | {
31 | throw new NotImplementedException();
32 | }
33 |
34 | [ExceptionHandler(IsSilent = true, ReturnValue = 6f)]
35 | [Log(ExceptionLevel = LoggingLevel.Error)]
36 | public float ThrowExceptionSilentWithReturnWithLogAttribute()
37 | {
38 | throw new NotImplementedException();
39 | }
40 |
41 | [ExceptionHandler(IsSilent = true, ExceptionType = typeof(NotImplementedException), ReturnValue = 6f)]
42 | public float ThrowNotImplementedExceptionCatch()
43 | {
44 | throw new NotImplementedException();
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/Logging/IExceptionHandlerTestClass.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.Logging
2 | {
3 | public interface IExceptionHandlerTestClass
4 | {
5 | float ThrowBaseExceptionNoCatch();
6 |
7 | void ThrowException();
8 |
9 | void ThrowExceptionSilent();
10 |
11 | float ThrowExceptionSilentWithReturn();
12 |
13 | float ThrowExceptionSilentWithReturnWithLogAttribute();
14 |
15 | float ThrowNotImplementedExceptionCatch();
16 | }
17 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/Logging/ILogTestClass.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.Logging
2 | {
3 | public interface IAmForwarded
4 | {
5 | void MethodFromForwarded();
6 | }
7 |
8 |
9 | public interface ILogTestClass
10 | {
11 | int Method(string name, int val);
12 |
13 | int NotLogged(string name, int val);
14 |
15 | void ThrowException();
16 |
17 | int VirtualMethod(string name, int val);
18 | }
19 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/Logging/LogTestClass.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 |
5 | using global::SharpArchContrib.Castle.Logging;
6 |
7 | public class LogTestClass : ILogTestClass, IAmForwarded
8 | {
9 | [Log]
10 | public int Method(string name, int val)
11 | {
12 | return val;
13 | }
14 |
15 | [Log]
16 | public void MethodFromForwarded()
17 | {
18 | return;
19 | }
20 |
21 | public virtual int NotLogged(string name, int val)
22 | {
23 | return val;
24 | }
25 |
26 | [Log]
27 | public virtual void ThrowException()
28 | {
29 | throw new Exception("Boom");
30 | }
31 |
32 | [Log]
33 | public virtual int VirtualMethod(string name, int val)
34 | {
35 | return val;
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/Logging/LoggingTests.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.Logging
2 | {
3 | using System;
4 | using System.IO;
5 |
6 | using global::Castle.DynamicProxy;
7 |
8 | using Microsoft.Practices.ServiceLocation;
9 |
10 | using NUnit.Framework;
11 |
12 | using SharpArch.Testing.NUnit;
13 |
14 | using global::SharpArchContrib.Castle.Logging;
15 | using global::SharpArchContrib.Core.Logging;
16 |
17 | [TestFixture]
18 | public class LoggingTests
19 | {
20 | [Test]
21 | public void LoggingDebugEntryWorks()
22 | {
23 | this.TryLogging();
24 | this.TryLoggingViaProxy();
25 | var logPath =
26 | Path.GetFullPath(@"TestData/Tests.SharpArchContrib.Castle.Logging.DebugLevelTests.DebugLevel.log");
27 | File.Exists(logPath).ShouldBeTrue();
28 | var debugLogInfo = new FileInfo(logPath);
29 | debugLogInfo.Length.ShouldBeGreaterThan(0);
30 | }
31 |
32 | private void TryLogging()
33 | {
34 | var testClass = ServiceLocator.Current.GetInstance();
35 | testClass.Method("Tom", 1);
36 | testClass.VirtualMethod("Bill", 2);
37 | testClass.NotLogged("Philly", 3);
38 | Assert.Throws(() => testClass.ThrowException());
39 | }
40 |
41 | private void TryLoggingViaProxy()
42 | {
43 | var generator = new ProxyGenerator();
44 | var testLogger2 =
45 | generator.CreateClassProxy(
46 | ServiceLocator.Current.GetInstance("LogInterceptor"));
47 | testLogger2.GetMessage("message1");
48 | testLogger2.GetMessageVirtual("message2");
49 | testLogger2.GetMessageNotLogged("message3");
50 | }
51 |
52 | private void TryLoggingViaForwardedType()
53 | {
54 | var testClass = ServiceLocator.Current.GetInstance();
55 | testClass.MethodFromForwarded();
56 | }
57 |
58 | private string ReadLogFile(string logPath)
59 | {
60 | using (var fs = new FileStream(logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
61 | {
62 | using (var sr = new StreamReader(fs))
63 | {
64 | return sr.ReadToEnd();
65 | }
66 | }
67 | }
68 | public class TestLogger2
69 | {
70 | [Log]
71 | public string GetMessage(string message)
72 | {
73 | return message;
74 | }
75 |
76 | public virtual string GetMessageNotLogged(string message)
77 | {
78 | return message;
79 | }
80 |
81 | [Log(EntryLevel = LoggingLevel.Info)]
82 | public virtual string GetMessageVirtual(string message)
83 | {
84 | return message;
85 | }
86 | }
87 |
88 | // issue#1 https://github.com/sharparchitecture/Sharp-Architecture-Contrib/issues#issue/1
89 | [Test]
90 | public void LoggingViaForwardedTypeWorks()
91 | {
92 | var logPath =
93 | Path.GetFullPath(@"TestData/Tests.SharpArchContrib.Castle.Logging.DebugLevelTests.DebugLevel.log");
94 | TryLoggingViaForwardedType();
95 | File.Exists(logPath).ShouldBeTrue();
96 | var debugLogInfo = new FileInfo(logPath);
97 | debugLogInfo.Length.ShouldBeGreaterThan(0);
98 | var logFileContents = ReadLogFile(logPath);
99 | string messageThatShouldBeLoggedOnce = "MethodFromForwarded()";
100 | int firstOccurenceLocation = logFileContents.IndexOf(messageThatShouldBeLoggedOnce);
101 | int lastOccurenceLocation = logFileContents.LastIndexOf(messageThatShouldBeLoggedOnce);
102 | firstOccurenceLocation.ShouldBeGreaterThan(0);
103 | firstOccurenceLocation.ShouldEqual(lastOccurenceLocation);
104 | }
105 | }
106 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/NHibernate/NHibernateTransactionTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.NHibernate
2 | {
3 | using global::SharpArchContrib.Castle.NHibernate;
4 | using global::SharpArchContrib.Data.NHibernate;
5 |
6 | using Tests.NHibernateTests;
7 |
8 | public class NHibernateTransactionTestProvider : TransactionTestProviderBase, ITransactionTestProvider
9 | {
10 | public string Name
11 | {
12 | get
13 | {
14 | return "Castle NHibernateTransactionTestProvider";
15 | }
16 | }
17 |
18 | protected override string TestEntityName
19 | {
20 | get
21 | {
22 | return "NHibernateTransactionTest";
23 | }
24 | }
25 |
26 | [Transaction]
27 | public override void DoCommit(string testEntityName)
28 | {
29 | base.DoCommit(testEntityName);
30 | }
31 |
32 | [Transaction(IsExceptionSilent = true)]
33 | public override void DoCommitSilenceException(string testEntityName)
34 | {
35 | base.DoCommitSilenceException(testEntityName);
36 | }
37 |
38 | [Transaction]
39 | public override void DoNestedCommit()
40 | {
41 | base.DoNestedCommit();
42 | }
43 |
44 | [Transaction]
45 | public override void DoNestedForceRollback()
46 | {
47 | base.DoNestedInnerForceRollback();
48 | }
49 |
50 | [Transaction]
51 | public override void DoNestedInnerForceRollback()
52 | {
53 | base.DoNestedInnerForceRollback();
54 | }
55 |
56 | [Transaction]
57 | public override void DoRollback()
58 | {
59 | base.DoRollback();
60 | }
61 |
62 | public void InitTransactionManager()
63 | {
64 | ServiceLocatorInitializer.Init(typeof(NHibernateTransactionManager));
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/NHibernate/NHibernateUnitOfWorkTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.NHibernate
2 | {
3 | using global::SharpArchContrib.Castle.NHibernate;
4 | using global::SharpArchContrib.Data.NHibernate;
5 |
6 | using Tests.NHibernateTests;
7 |
8 | public class NHibernateUnitOfWorkTestProvider : TransactionTestProviderBase, ITransactionTestProvider
9 | {
10 | public string Name
11 | {
12 | get
13 | {
14 | return "Castle NHibernateUnitOfWorkTestProvider";
15 | }
16 | }
17 |
18 | protected override string TestEntityName
19 | {
20 | get
21 | {
22 | return "NHibernateUnitOfWorkTest";
23 | }
24 | }
25 |
26 | [UnitOfWork]
27 | public override void DoCommit(string testEntityName)
28 | {
29 | base.DoCommit(testEntityName);
30 | }
31 |
32 | [Transaction(IsExceptionSilent = true)]
33 | public override void DoCommitSilenceException(string testEntityName)
34 | {
35 | base.DoCommitSilenceException(testEntityName);
36 | }
37 |
38 | [UnitOfWork]
39 | public override void DoNestedCommit()
40 | {
41 | base.DoNestedCommit();
42 | }
43 |
44 | [UnitOfWork]
45 | public override void DoNestedForceRollback()
46 | {
47 | base.DoNestedInnerForceRollback();
48 | }
49 |
50 | [UnitOfWork]
51 | public override void DoNestedInnerForceRollback()
52 | {
53 | base.DoNestedInnerForceRollback();
54 | }
55 |
56 | [UnitOfWork]
57 | public override void DoRollback()
58 | {
59 | base.DoRollback();
60 | }
61 |
62 | public void InitTransactionManager()
63 | {
64 | ServiceLocatorInitializer.Init(typeof(NHibernateTransactionManager));
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/NHibernate/SystemTransactionTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.NHibernate
2 | {
3 | using global::SharpArchContrib.Castle.Logging;
4 | using global::SharpArchContrib.Castle.NHibernate;
5 | using global::SharpArchContrib.Data.NHibernate;
6 |
7 | using Tests.NHibernateTests;
8 |
9 | public class SystemTransactionTestProvider : TransactionTestProviderBase, ITransactionTestProvider
10 | {
11 | public string Name
12 | {
13 | get
14 | {
15 | return "Castle SystemTransactionTestProvider";
16 | }
17 | }
18 |
19 | protected override string TestEntityName
20 | {
21 | get
22 | {
23 | return "TransactionTest";
24 | }
25 | }
26 |
27 | [Transaction]
28 | public override void DoCommit(string testEntityName)
29 | {
30 | base.DoCommit(testEntityName);
31 | }
32 |
33 | [Transaction(IsExceptionSilent = true)]
34 | public override void DoCommitSilenceException(string testEntityName)
35 | {
36 | base.DoCommitSilenceException(testEntityName);
37 | }
38 |
39 | [Transaction]
40 | public override void DoNestedCommit()
41 | {
42 | base.DoNestedCommit();
43 | }
44 |
45 | [Transaction]
46 | public override void DoNestedForceRollback()
47 | {
48 | base.DoNestedInnerForceRollback();
49 | }
50 |
51 | [Log]
52 | [Transaction]
53 | public override void DoNestedInnerForceRollback()
54 | {
55 | base.DoNestedInnerForceRollback();
56 | }
57 |
58 | [Transaction]
59 | public override void DoRollback()
60 | {
61 | base.DoRollback();
62 | }
63 |
64 | public void InitTransactionManager()
65 | {
66 | ServiceLocatorInitializer.Init(typeof(SystemTransactionManager));
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/NHibernate/SystemUnitOfWorkTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.NHibernate
2 | {
3 | using global::SharpArchContrib.Castle.NHibernate;
4 | using global::SharpArchContrib.Data.NHibernate;
5 |
6 | using Tests.NHibernateTests;
7 |
8 | public class SystemUnitOfWorkTestProvider : TransactionTestProviderBase, ITransactionTestProvider
9 | {
10 | public string Name
11 | {
12 | get
13 | {
14 | return "Castle SystemUnitOfWorkTestProvider";
15 | }
16 | }
17 |
18 | protected override string TestEntityName
19 | {
20 | get
21 | {
22 | return "UnitOfWorkTest";
23 | }
24 | }
25 |
26 | [UnitOfWork]
27 | public override void Commit(string testEntityName)
28 | {
29 | base.Commit(testEntityName);
30 | }
31 |
32 | [UnitOfWork]
33 | public override void DoCommit(string testEntityName)
34 | {
35 | base.DoCommit(testEntityName);
36 | }
37 |
38 | [Transaction(IsExceptionSilent = true)]
39 | public override void DoCommitSilenceException(string testEntityName)
40 | {
41 | base.DoCommitSilenceException(testEntityName);
42 | }
43 |
44 | [UnitOfWork]
45 | public override void DoNestedCommit()
46 | {
47 | base.DoNestedCommit();
48 | }
49 |
50 | [UnitOfWork]
51 | public override void DoNestedForceRollback()
52 | {
53 | base.DoNestedInnerForceRollback();
54 | }
55 |
56 | [UnitOfWork]
57 | public override void DoNestedInnerForceRollback()
58 | {
59 | base.DoNestedInnerForceRollback();
60 | }
61 |
62 | [UnitOfWork]
63 | public override void DoRollback()
64 | {
65 | base.DoRollback();
66 | }
67 |
68 | public void InitTransactionManager()
69 | {
70 | ServiceLocatorInitializer.Init(typeof(SystemTransactionManager));
71 | }
72 | }
73 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Castle/NHibernate/TransactionAttributeTests.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Castle.NHibernate
2 | {
3 | using System;
4 |
5 | using NUnit.Framework;
6 |
7 | using SharpArch.Testing.NUnit;
8 |
9 | using global::SharpArchContrib.Castle.NHibernate;
10 |
11 | [TestFixture]
12 | public class TransactionAttributeTests
13 | {
14 | [Test]
15 | public void Gathering_Transaction_Attributes_Does_Not_Gather_UnitOfWork()
16 | {
17 | foreach (var methodInfo in typeof(TestClass).GetMethods())
18 | {
19 | if (methodInfo.Name == "Transaction" || methodInfo.Name == "UnitOfWork")
20 | {
21 | var attributes = (Attribute[])methodInfo.GetCustomAttributes(typeof(TransactionAttribute), false);
22 | attributes.Length.ShouldEqual(1);
23 | foreach (var attribute in attributes)
24 | {
25 | attribute.ShouldBeOfType(typeof(TransactionAttribute));
26 | attribute.ShouldNotBeOfType(typeof(UnitOfWorkAttribute));
27 | }
28 | }
29 | }
30 | }
31 |
32 | public class TestClass
33 | {
34 | [Transaction]
35 | [UnitOfWork]
36 | public void Transaction()
37 | {
38 | }
39 |
40 | [UnitOfWork]
41 | [Transaction]
42 | public void UnitOfWork()
43 | {
44 | }
45 | }
46 | }
47 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Core/ParameterCheckTests.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Core
2 | {
3 | using System.Collections.Generic;
4 |
5 | using NUnit.Framework;
6 |
7 | using SharpArch.Domain;
8 |
9 | using global::SharpArchContrib.Core;
10 |
11 | [TestFixture]
12 | public class ParameterCheckTests
13 | {
14 | [Test]
15 | public void DictionaryContainKey_Supports_Dictionary_With_String_Key_And_Value()
16 | {
17 | var dict = new Dictionary();
18 | Assert.Throws(() => ParameterCheck.DictionaryContainsKey(dict, "dict", "key"));
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.Data/NHibernate/MultiTenantSessionFactoryKeyProviderTests.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.Data.NHibernate
2 | {
3 | using NUnit.Framework;
4 |
5 | using Rhino.Mocks;
6 |
7 | using SharpArch.Domain.DomainModel;
8 | using SharpArch.Domain.PersistenceSupport;
9 | using SharpArch.NHibernate;
10 | using SharpArch.Testing.NUnit;
11 |
12 | using global::SharpArchContrib.Core.MultiTenant;
13 | using global::SharpArchContrib.Data.NHibernate;
14 |
15 | using Tests.DomainModel.Entities;
16 |
17 | public class TestMultiTenantEntity : Entity, IMultiTenantEntity
18 | {
19 | }
20 |
21 | public interface ITestRepository : IRepository
22 | {
23 | }
24 |
25 | public interface ITestMultiTenantRepository : IRepository, IMultiTenantRepository
26 | {
27 | }
28 |
29 | public class TestRepository : NHibernateRepository, ITestRepository
30 | {
31 | }
32 |
33 | public class TestMultiTenantRepository : NHibernateRepository, ITestMultiTenantRepository
34 | {
35 | }
36 |
37 | [TestFixture]
38 | public class MultiTenantSessionFactoryKeyProviderTests
39 | {
40 | private MultiTenantSessionFactoryKeyProvider provider;
41 |
42 |
43 | [SetUp]
44 | public void Setup()
45 | {
46 | var tenantContext = MockRepository.GenerateStub();
47 | this.provider = new MultiTenantSessionFactoryKeyProvider(tenantContext);
48 | }
49 |
50 | [Test]
51 | public void IsRepositoryForMultiTenantEntityReturnsFlaseForRepositoryForEntity()
52 | {
53 | var isRepositoryForMultiTenantEntity =
54 | this.provider.IsRepositoryForMultiTenantEntity(typeof(IRepository));
55 | isRepositoryForMultiTenantEntity.ShouldEqual(false);
56 | }
57 |
58 | [Test]
59 | public void IsRepositoryForMultiTenantEntityReturnsTrueForRepositoryForMultiTenantEntity()
60 | {
61 | var isRepositoryForMultiTenantEntity =
62 | this.provider.IsRepositoryForMultiTenantEntity(typeof(IRepository));
63 | isRepositoryForMultiTenantEntity.ShouldEqual(true);
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.PostSharp/Logging/DebugLevelTests.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.PostSharp.Logging
2 | {
3 | using System.IO;
4 |
5 | using NUnit.Framework;
6 |
7 | using SharpArch.Testing.NUnit;
8 |
9 | using global::SharpArchContrib.Core.Logging;
10 | using global::SharpArchContrib.PostSharp.Logging;
11 |
12 | [TestFixture]
13 | public class DebugLevelTests
14 | {
15 | [Test]
16 | public void LoggingDebugEntryWorks()
17 | {
18 | this.DebugLevelTestsCallThatLogs();
19 | this.DebugLevelTestsCallThatDoesNotLog();
20 | string logPath =
21 | Path.GetFullPath(@"TestData/Tests.SharpArchContrib.PostSharp.Logging.DebugLevelTests.DebugLevel.log");
22 | File.Exists(logPath).ShouldBeTrue();
23 | var debugLogInfo = new FileInfo(logPath);
24 | debugLogInfo.Length.ShouldBeGreaterThan(0);
25 | }
26 |
27 | [Log(EntryLevel = LoggingLevel.Info)]
28 | private void DebugLevelTestsCallThatDoesNotLog()
29 | {
30 | }
31 |
32 | [Log]
33 | private void DebugLevelTestsCallThatLogs()
34 | {
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.PostSharp/Logging/ExceptionHandlerAttributeTests.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.PostSharp.Logging
2 | {
3 | using System;
4 |
5 | using NUnit.Framework;
6 |
7 | using SharpArch.Testing.NUnit;
8 |
9 | using global::SharpArchContrib.Core.Logging;
10 | using global::SharpArchContrib.PostSharp.Logging;
11 |
12 | [TestFixture]
13 | public class ExceptionHandlerAttributeTests
14 | {
15 | [Test]
16 | public void LoggedExceptionDoesNotRethrow()
17 | {
18 | Assert.DoesNotThrow(() => this.ThrowExceptionSilent());
19 | }
20 |
21 | [Test]
22 | public void LoggedExceptionDoesNotRethrowWithReturn()
23 | {
24 | this.ThrowExceptionSilentWithReturn().ShouldEqual(6f);
25 | }
26 |
27 | [Test]
28 | public void LoggedExceptionDoesNotRethrowWithReturnWithLogAttribute()
29 | {
30 | this.ThrowExceptionSilentWithReturnWithLogAttribute().ShouldEqual(6f);
31 | }
32 |
33 | [Test]
34 | public void LoggedExceptionRethrows()
35 | {
36 | Assert.Throws(() => this.ThrowException());
37 | }
38 |
39 | [ExceptionHandler]
40 | private void ThrowException()
41 | {
42 | throw new NotImplementedException();
43 | }
44 |
45 | [ExceptionHandler(IsSilent = true, ReturnValue = 6f)]
46 | private void ThrowExceptionSilent()
47 | {
48 | throw new NotImplementedException();
49 | }
50 |
51 | [ExceptionHandler(IsSilent = true, ReturnValue = 6f)]
52 | private float ThrowExceptionSilentWithReturn()
53 | {
54 | throw new NotImplementedException();
55 | }
56 |
57 | [ExceptionHandler(IsSilent = true, ReturnValue = 6f, AspectPriority = 1)]
58 | [Log(ExceptionLevel = LoggingLevel.Error, AspectPriority = 2)]
59 | private float ThrowExceptionSilentWithReturnWithLogAttribute()
60 | {
61 | throw new NotImplementedException();
62 | }
63 | }
64 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.PostSharp/NHibernate/NHibernateTransactionTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.PostSharp.NHibernate
2 | {
3 | using global::SharpArchContrib.Data.NHibernate;
4 | using global::SharpArchContrib.PostSharp.NHibernate;
5 |
6 | using Tests.NHibernateTests;
7 |
8 | public class NHibernateTransactionTestProvider : TransactionTestProviderBase, ITransactionTestProvider
9 | {
10 | public string Name
11 | {
12 | get
13 | {
14 | return "PostSharp NHibernateTransactionTestProvider";
15 | }
16 | }
17 |
18 | protected override string TestEntityName
19 | {
20 | get
21 | {
22 | return "NHibernateTransactionTest";
23 | }
24 | }
25 |
26 | [Transaction]
27 | public override void DoCommit(string testEntityName)
28 | {
29 | base.DoCommit(testEntityName);
30 | }
31 |
32 | [Transaction(IsExceptionSilent = true)]
33 | public override void DoCommitSilenceException(string testEntityName)
34 | {
35 | base.DoCommitSilenceException(testEntityName);
36 | }
37 |
38 | [Transaction]
39 | public override void DoNestedCommit()
40 | {
41 | base.DoNestedCommit();
42 | }
43 |
44 | [Transaction]
45 | public override void DoNestedForceRollback()
46 | {
47 | base.DoNestedInnerForceRollback();
48 | }
49 |
50 | [Transaction]
51 | public override void DoNestedInnerForceRollback()
52 | {
53 | base.DoNestedInnerForceRollback();
54 | }
55 |
56 | [Transaction]
57 | public override void DoRollback()
58 | {
59 | base.DoRollback();
60 | }
61 |
62 | public void InitTransactionManager()
63 | {
64 | ServiceLocatorInitializer.Init(typeof(NHibernateTransactionManager));
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.PostSharp/NHibernate/NHibernateUnitOfWorkTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.PostSharp.NHibernate
2 | {
3 | using global::SharpArchContrib.Data.NHibernate;
4 | using global::SharpArchContrib.PostSharp.NHibernate;
5 |
6 | using Tests.NHibernateTests;
7 |
8 | public class NHibernateUnitOfWorkTestProvider : TransactionTestProviderBase, ITransactionTestProvider
9 | {
10 | public string Name
11 | {
12 | get
13 | {
14 | return "PostSharp NHibernateUnitOfWorkTestProvider";
15 | }
16 | }
17 |
18 | protected override string TestEntityName
19 | {
20 | get
21 | {
22 | return "NHibernateUnitOfWorkTest";
23 | }
24 | }
25 |
26 | [UnitOfWork]
27 | public override void DoCommit(string testEntityName)
28 | {
29 | base.DoCommit(testEntityName);
30 | }
31 |
32 | [Transaction(IsExceptionSilent = true)]
33 | public override void DoCommitSilenceException(string testEntityName)
34 | {
35 | base.DoCommitSilenceException(testEntityName);
36 | }
37 |
38 | [UnitOfWork]
39 | public override void DoNestedCommit()
40 | {
41 | base.DoNestedCommit();
42 | }
43 |
44 | [UnitOfWork]
45 | public override void DoNestedForceRollback()
46 | {
47 | base.DoNestedInnerForceRollback();
48 | }
49 |
50 | [UnitOfWork]
51 | public override void DoNestedInnerForceRollback()
52 | {
53 | base.DoNestedInnerForceRollback();
54 | }
55 |
56 | [UnitOfWork]
57 | public override void DoRollback()
58 | {
59 | base.DoRollback();
60 | }
61 |
62 | public void InitTransactionManager()
63 | {
64 | ServiceLocatorInitializer.Init(typeof(NHibernateTransactionManager));
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.PostSharp/NHibernate/SystemTransactionTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.PostSharp.NHibernate
2 | {
3 | using global::SharpArchContrib.Data.NHibernate;
4 | using global::SharpArchContrib.PostSharp.NHibernate;
5 |
6 | using Tests.NHibernateTests;
7 |
8 | public class SystemTransactionTestProvider : TransactionTestProviderBase, ITransactionTestProvider
9 | {
10 | public string Name
11 | {
12 | get
13 | {
14 | return "PostSharp SystemTransactionTestProvider";
15 | }
16 | }
17 |
18 | protected override string TestEntityName
19 | {
20 | get
21 | {
22 | return "TransactionTest";
23 | }
24 | }
25 |
26 | [Transaction]
27 | public override void DoCommit(string testEntityName)
28 | {
29 | base.DoCommit(testEntityName);
30 | }
31 |
32 | [Transaction(IsExceptionSilent = true)]
33 | public override void DoCommitSilenceException(string testEntityName)
34 | {
35 | base.DoCommitSilenceException(testEntityName);
36 | }
37 |
38 | [Transaction]
39 | public override void DoNestedCommit()
40 | {
41 | base.DoNestedCommit();
42 | }
43 |
44 | [Transaction]
45 | public override void DoNestedForceRollback()
46 | {
47 | base.DoNestedInnerForceRollback();
48 | }
49 |
50 | [Transaction]
51 | public override void DoNestedInnerForceRollback()
52 | {
53 | base.DoNestedInnerForceRollback();
54 | }
55 |
56 | [Transaction]
57 | public override void DoRollback()
58 | {
59 | base.DoRollback();
60 | }
61 |
62 | public void InitTransactionManager()
63 | {
64 | ServiceLocatorInitializer.Init(typeof(SystemTransactionManager));
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SharpArchContrib.PostSharp/NHibernate/SystemUnitOfWorkTestProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Tests.SharpArchContrib.PostSharp.NHibernate
2 | {
3 | using global::SharpArchContrib.Data.NHibernate;
4 | using global::SharpArchContrib.PostSharp.NHibernate;
5 |
6 | using Tests.NHibernateTests;
7 |
8 | public class SystemUnitOfWorkTestProvider : TransactionTestProviderBase, ITransactionTestProvider
9 | {
10 | public string Name
11 | {
12 | get
13 | {
14 | return "PostSharp SystemUnitOfWorkTestProvider";
15 | }
16 | }
17 |
18 | protected override string TestEntityName
19 | {
20 | get
21 | {
22 | return "UnitOfWorkTest";
23 | }
24 | }
25 |
26 | [UnitOfWork]
27 | public override void DoCommit(string testEntityName)
28 | {
29 | base.DoCommit(testEntityName);
30 | }
31 |
32 | [Transaction(IsExceptionSilent = true)]
33 | public override void DoCommitSilenceException(string testEntityName)
34 | {
35 | base.DoCommitSilenceException(testEntityName);
36 | }
37 |
38 | [UnitOfWork]
39 | public override void DoNestedCommit()
40 | {
41 | base.DoNestedCommit();
42 | }
43 |
44 | [UnitOfWork]
45 | public override void DoNestedForceRollback()
46 | {
47 | base.DoNestedInnerForceRollback();
48 | }
49 |
50 | [UnitOfWork]
51 | public override void DoNestedInnerForceRollback()
52 | {
53 | base.DoNestedInnerForceRollback();
54 | }
55 |
56 | [UnitOfWork]
57 | public override void DoRollback()
58 | {
59 | base.DoRollback();
60 | }
61 |
62 | public void InitTransactionManager()
63 | {
64 | ServiceLocatorInitializer.Init(typeof(SystemTransactionManager));
65 | }
66 | }
67 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/SyntaxHelper.cs:
--------------------------------------------------------------------------------
1 | namespace Tests
2 | {
3 | using System;
4 |
5 | using NUnit.Framework;
6 |
7 | public static class SyntaxHelper
8 | {
9 | public static void ShouldEqualInMemorySqlDateTime(this DateTime actual, DateTime expected)
10 | {
11 | var expectedWithoutMilliseconds = actual.AddMilliseconds(-1 * actual.Millisecond);
12 | Assert.AreEqual(actual, expectedWithoutMilliseconds);
13 | }
14 |
15 | public static void ShouldNotContain(this string actual, string expected)
16 | {
17 | StringAssert.DoesNotContain(expected, actual);
18 | }
19 | }
20 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/TestCategories.cs:
--------------------------------------------------------------------------------
1 | namespace Tests
2 | {
3 | public static class TestCategories
4 | {
5 | public const string FileDbTests = "File DB Tests";
6 | }
7 | }
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.Tests/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Solutions/SharpArchContrib.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{34D42016-342F-40AE-BAC8-54D6AA8A1020}"
5 | ProjectSection(SolutionItems) = preProject
6 | ..\license.txt = ..\license.txt
7 | ..\readme.txt = ..\readme.txt
8 | ..\VersionHistory.txt = ..\VersionHistory.txt
9 | EndProjectSection
10 | EndProject
11 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpArchContrib.Core", "SharpArchContrib.Core\SharpArchContrib.Core.csproj", "{EB8DABCF-B11F-49D4-B858-67C37AA204DB}"
12 | EndProject
13 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpArchContrib.Data", "SharpArchContrib.Data\SharpArchContrib.Data.csproj", "{E33E2468-B055-4F3D-83DB-8F991F600A47}"
14 | EndProject
15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpArchContrib.Tests", "SharpArchContrib.Tests\SharpArchContrib.Tests.csproj", "{CBFD99A2-2C17-431B-B507-599351F9F713}"
16 | EndProject
17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpArchContrib.Castle", "SharpArchContrib.Castle\SharpArchContrib.Castle.csproj", "{557E1790-FBDD-4FDE-86B2-93E2AD0E9E24}"
18 | EndProject
19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{8A2474ED-405C-4CFC-83C9-E6BF014D466A}"
20 | ProjectSection(SolutionItems) = preProject
21 | ..\Build\Build.cmd = ..\Build\Build.cmd
22 | ..\Build\Build.proj = ..\Build\Build.proj
23 | ..\Build\BuildAndPackage.cmd = ..\Build\BuildAndPackage.cmd
24 | ..\Build\BuildAndTest.cmd = ..\Build\BuildAndTest.cmd
25 | EndProjectSection
26 | EndProject
27 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{9BDAAA74-98A1-4AEE-BA02-1ACCB625BBE0}"
28 | ProjectSection(SolutionItems) = preProject
29 | .nuget\NuGet.exe = .nuget\NuGet.exe
30 | .nuget\NuGet.targets = .nuget\NuGet.targets
31 | EndProjectSection
32 | EndProject
33 | Global
34 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
35 | Debug|Any CPU = Debug|Any CPU
36 | Release|Any CPU = Release|Any CPU
37 | EndGlobalSection
38 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
39 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
41 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
42 | {EB8DABCF-B11F-49D4-B858-67C37AA204DB}.Release|Any CPU.Build.0 = Release|Any CPU
43 | {E33E2468-B055-4F3D-83DB-8F991F600A47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
44 | {E33E2468-B055-4F3D-83DB-8F991F600A47}.Debug|Any CPU.Build.0 = Debug|Any CPU
45 | {E33E2468-B055-4F3D-83DB-8F991F600A47}.Release|Any CPU.ActiveCfg = Release|Any CPU
46 | {E33E2468-B055-4F3D-83DB-8F991F600A47}.Release|Any CPU.Build.0 = Release|Any CPU
47 | {CBFD99A2-2C17-431B-B507-599351F9F713}.Debug|Any CPU.ActiveCfg = Debug|x86
48 | {CBFD99A2-2C17-431B-B507-599351F9F713}.Debug|Any CPU.Build.0 = Debug|x86
49 | {CBFD99A2-2C17-431B-B507-599351F9F713}.Release|Any CPU.ActiveCfg = Release|Any CPU
50 | {CBFD99A2-2C17-431B-B507-599351F9F713}.Release|Any CPU.Build.0 = Release|Any CPU
51 | {557E1790-FBDD-4FDE-86B2-93E2AD0E9E24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52 | {557E1790-FBDD-4FDE-86B2-93E2AD0E9E24}.Debug|Any CPU.Build.0 = Debug|Any CPU
53 | {557E1790-FBDD-4FDE-86B2-93E2AD0E9E24}.Release|Any CPU.ActiveCfg = Release|Any CPU
54 | {557E1790-FBDD-4FDE-86B2-93E2AD0E9E24}.Release|Any CPU.Build.0 = Release|Any CPU
55 | EndGlobalSection
56 | GlobalSection(SolutionProperties) = preSolution
57 | HideSolutionNode = FALSE
58 | EndGlobalSection
59 | EndGlobal
60 |
--------------------------------------------------------------------------------
/Solutions/nuget.config:
--------------------------------------------------------------------------------
1 |
2 | ..\Packages
3 |
--------------------------------------------------------------------------------
/VersionHistory.txt:
--------------------------------------------------------------------------------
1 | Version 1.0
2 | ==============================================================================
3 | Update to SharpArchitecture 1.0, NHibernate 3.3
4 | Breaking Change: Move ComponentRegistrar from SharpArchContrib.Core.CastleWindsor to SharpArchContrib.Castle.CastleWindsor and rename to CoreComponentRegistrar
5 | Breaking Change: Move registration of Data components to ComponentRegistrar in SharpArchContrib.Castle.CastleWindsor and rename to NHibernateTransactionsComponentRegistrar
6 |
7 | Version 0.6.1
8 | ==============================================================================
9 | * Assembly version left at 0.6.0 for easier upgrade
10 | Fixed issue #1 https://github.com/sharparchitecture/Sharp-Architecture-Contrib/issues#issue/1
11 | Fixed issue #2 https://github.com/sharparchitecture/Sharp-Architecture-Contrib/issues#issue/2
12 |
13 | Version 0.6.0
14 | ==============================================================================
15 | Introduced SharpArchContrib.Web.Mvc and RazorViewEngine
16 | Changed MethodLogger to use the logging level specified instead of always using Debug level
17 |
18 | Version 0.5.0
19 | ==============================================================================
20 | Update to .Net4 VS2010
21 | Works with SharpArch 1.9.5
22 |
23 | Version 0.4.0
24 | ==============================================================================
25 | Works with SharpArch 1.9
26 |
27 | Version 0.3.0
28 | ==============================================================================
29 | Removed PostSharp support. If you were using PostSharp, you can use
30 | the equivalent support found in SharpArchContrib.Castle instead.
31 |
32 | Works with the Q3 release of SharpArch.
33 |
34 | Version 0.2.0
35 | ===============================================================================
36 | Castle Interceptor versions of Log, Transaction and UnitOfWork attributes added.
37 |
38 | I am looking for suggestions on how to make the Castle versions of these
39 | attributes work better. Please post comments to the SharpArch list.
40 |
41 | Notes on this release can be found on my blog at
42 | http://tomcabanski.spaces.live.com/blog/cns!E0D3617496209F45!220.entry
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | New BSD License for S#arp Architecture Contrib from Codai, Inc.
2 |
3 | Copyright (c) 2009, Codai, Inc.
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without modification,
7 | are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice,
10 | this list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of Codai, Inc., nor the names of its
17 | contributors may be used to endorse or promote products derived from this
18 | software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------
/readme.txt:
--------------------------------------------------------------------------------
1 | =============================================
2 | LINE ENDINGS AND GIT
3 | =============================================
4 | Make sure to set AutoCRLF=true in your Git tool before cloning this repository.
5 | See http://help.github.com/dealing-with-lineendings/ for more information.
6 |
7 | =============================================
8 | Additional Contributions to Sharp Architcture
9 | =============================================
10 | This is an early beta containing additional contributions to Sharp Architecture.
11 | This project is currently sharing a home with its parent, Sharp Architecture, at
12 | http://www.sharparchitecture.net/.
13 |
14 | URLs of Interest:
15 |
16 | - Downloads: http://github.com/sharparchitecture/Sharp-Architecture-Contrib/downloads
17 | - GitHub Repository: http://github.com/sharparchitecture/Sharp-Architecture-Contrib
18 |
19 |
20 | =============================================
21 | Documentation
22 | =============================================
23 | The documentation wiki is http://wiki.sharparchitecture.net/SharpArchContrib.ashx.
24 | SharpArchContrib is currently a work in process so the documentation may not always be
25 | up to date. See VersionHistory.txt for information about changes made in each
26 | release and migration issues for existing projects.
27 |
28 | =============================================
29 | Getting Help
30 | =============================================
31 | You can post questions, suggestions and comments about SharpArchContrib
32 | to the Sharp Architecture group at http://groups.google.com/group/sharp-architecture.
33 |
34 | ============================================
35 | License
36 | ============================================
37 | Licensed under the New BSD license. See license.txt for details.
38 |
39 | =============================================
40 | Building
41 | =============================================
42 | Use build.bat from the command-line or click on ClickToBuild.bat in
43 | Windows Explorer. Project outputs will be placed in a the BuildOutput
44 | folder.
45 |
46 | =============================================
47 | Additional Dependencies
48 | =============================================
49 | SharpArchContrib currently depends on the master branch of SharpArch. The correct SharpArch
50 | binaries and source will be maintained on the SharpArchContrib page for convinience during the beta.
51 |
--------------------------------------------------------------------------------