Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Transactions / TransactionCache.cs / 1 / TransactionCache.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Transactions { using System; using System.Collections.Generic; using System.Diagnostics; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Security; using System.Threading; using System.Transactions; using System.Xml; //----------------------------------------------------------------------------------------- // Transaction caches //----------------------------------------------------------------------------------------- class WsatExtendedInformationCache : TransactionCache{ public static void Cache(Transaction tx, WsatExtendedInformation info) { WsatExtendedInformationCache entry = new WsatExtendedInformationCache(); entry.AddEntry(tx, tx, info); } } class WsatIncomingTransactionCache : TransactionCache { public static void Cache(string identifier, Transaction tx) { WsatIncomingTransactionCache entry = new WsatIncomingTransactionCache(); entry.AddEntry(tx, identifier, tx); } } abstract class TransactionCache { static Dictionary cache = new Dictionary (); static ReaderWriterLock cacheLock = new ReaderWriterLock(); T key; protected void AddEntry(Transaction transaction, T key, S value) { this.key = key; if (Add(key, value)) { transaction.TransactionCompleted += new TransactionCompletedEventHandler(OnTransactionCompleted); } } void OnTransactionCompleted(object sender, TransactionEventArgs e) { Remove(this.key); } static bool Add(T key, S value) { bool lockHeld = false; try { try { } finally { cacheLock.AcquireWriterLock(Timeout.Infinite); lockHeld = true; } if (!cache.ContainsKey(key)) { cache.Add(key, value); return true; } } finally { if (lockHeld) { cacheLock.ReleaseWriterLock(); } } return false; } static void Remove(T key) { bool lockHeld = false; try { try { } finally { cacheLock.AcquireWriterLock(Timeout.Infinite); lockHeld = true; } bool remove = cache.Remove(key); if (!(remove)) { // tx processing requires failfast when state is inconsistent DiagnosticUtility.FailFast("TransactionCache: key must be present in transaction cache"); } } finally { if (lockHeld) { cacheLock.ReleaseWriterLock(); } } } public static bool Find(T key, out S value) { bool lockHeld = false; try { try { } finally { cacheLock.AcquireReaderLock(Timeout.Infinite); lockHeld = true; } if (cache.TryGetValue(key, out value)) { return true; } } finally { if (lockHeld) { cacheLock.ReleaseReaderLock(); } } return false; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- AsyncResult.cs
- SoapAttributeAttribute.cs
- ActivityDesigner.cs
- TransactionTable.cs
- DataServiceHostFactory.cs
- MeshGeometry3D.cs
- BorderGapMaskConverter.cs
- UpdatePanelControlTrigger.cs
- SmtpFailedRecipientsException.cs
- ObjectFullSpanRewriter.cs
- AutomationElement.cs
- ReferenceEqualityComparer.cs
- DBCommand.cs
- AvTrace.cs
- ErrorProvider.cs
- ListItemConverter.cs
- GenerateTemporaryAssemblyTask.cs
- Listbox.cs
- Assembly.cs
- HandlerBase.cs
- OutputCacheProviderCollection.cs
- Track.cs
- PeerInvitationResponse.cs
- BasicBrowserDialog.cs
- SoapEnumAttribute.cs
- SqlFileStream.cs
- SQLDoubleStorage.cs
- COM2ExtendedBrowsingHandler.cs
- TableRowCollection.cs
- LazyTextWriterCreator.cs
- IntSecurity.cs
- GeneralTransform3DGroup.cs
- DynamicArgumentDesigner.xaml.cs
- DiscoveryClientProtocol.cs
- HtmlEncodedRawTextWriter.cs
- IisTraceListener.cs
- HandlerBase.cs
- Int32AnimationUsingKeyFrames.cs
- ImageClickEventArgs.cs
- DataPagerField.cs
- ConfigurationLockCollection.cs
- WebPartConnectionsCancelVerb.cs
- HasCopySemanticsAttribute.cs
- QueryExpr.cs
- Classification.cs
- CacheChildrenQuery.cs
- FileRegion.cs
- SetStateEventArgs.cs
- TextLine.cs
- TypeSystem.cs
- XmlFormatExtensionPrefixAttribute.cs
- PersistNameAttribute.cs
- FontStyleConverter.cs
- ExtensionDataObject.cs
- FreezableCollection.cs
- TextServicesPropertyRanges.cs
- Section.cs
- FilteredDataSetHelper.cs
- DeadCharTextComposition.cs
- MessageHeader.cs
- oledbconnectionstring.cs
- NonSerializedAttribute.cs
- Grant.cs
- ProfilePropertySettings.cs
- TemplateDefinition.cs
- OperationGenerator.cs
- Matrix.cs
- SmtpReplyReaderFactory.cs
- ValidationSummaryDesigner.cs
- WebBrowserNavigatingEventHandler.cs
- Stroke.cs
- XmlSerializerNamespaces.cs
- MILUtilities.cs
- UserControlAutomationPeer.cs
- ExtentJoinTreeNode.cs
- JulianCalendar.cs
- XmlCharacterData.cs
- AsymmetricKeyExchangeFormatter.cs
- IsolatedStoragePermission.cs
- HtmlInputControl.cs
- ServiceDesigner.cs
- RenderData.cs
- SqlAliasesReferenced.cs
- AccessControlEntry.cs
- CacheMemory.cs
- SpeechRecognizer.cs
- SimpleType.cs
- DelegateArgumentValue.cs
- NetworkInterface.cs
- HttpWrapper.cs
- Point4DConverter.cs
- NonParentingControl.cs
- WhitespaceRule.cs
- DefaultAutoFieldGenerator.cs
- SerializationFieldInfo.cs
- AppDomainManager.cs
- NumberFormatInfo.cs
- ResourceReferenceKeyNotFoundException.cs
- SoapAttributes.cs
- CustomErrorCollection.cs