Added DictionaryAdapter.build.
[castle.git] / Services / Transaction / Castle.Services.Transaction / CallContextActivityManager.cs
blobebc98f5da43692b4cac69ed1db6df9ec52768bc7
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Services.Transaction
17 using System;
18 using System.Runtime.Remoting.Messaging;
20 public class CallContextActivityManager : MarshalByRefObject, IActivityManager
22 private const string Key = "Castle.Services.Transaction.Activity";
24 private object lockObj = new object();
26 /// <summary>
27 /// Initializes a new instance of the <see cref="CallContextActivityManager"/> class.
28 /// </summary>
29 public CallContextActivityManager()
31 CallContext.SetData(Key, null);
34 #region MarshalByRefObject
36 ///<summary>
37 ///Obtains a lifetime service object to control the lifetime policy for this instance.
38 ///</summary>
39 ///
40 ///<returns>
41 ///An object of type <see cref="T:System.Runtime.Remoting.Lifetime.ILease"></see> used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the <see cref="P:System.Runtime.Remoting.Lifetime.LifetimeServices.LeaseManagerPollTime"></see> property.
42 ///</returns>
43 ///
44 ///<exception cref="T:System.Security.SecurityException">The immediate caller does not have infrastructure permission. </exception><filterpriority>2</filterpriority><PermissionSet><IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="RemotingConfiguration, Infrastructure" /></PermissionSet>
45 public override object InitializeLifetimeService()
47 return null;
50 #endregion
52 /// <summary>
53 /// Gets the current activity.
54 /// </summary>
55 /// <value>The current activity.</value>
56 public Activity CurrentActivity
58 get
60 lock(lockObj)
62 Activity activity = (Activity) CallContext.GetData(Key);
64 if (activity == null)
66 activity = new Activity();
67 CallContext.SetData(Key, activity);
70 return activity;