Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / TrustUi / MS / Internal / documents / Application / ChainOfResponsibility.cs / 1 / ChainOfResponsibility.cs
//------------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// An implementation of the 'Chain of Responsibility' from Design Patterns
//
//
// History:
// 08/28/2005: [....]: Initial implementation.
//-----------------------------------------------------------------------------
using System.Collections.Generic;
namespace MS.Internal.Documents.Application
{
///
/// An implementation of the 'Chain of Responsibility' from Design Patterns
///
///
/// Design Comments:
///
/// The pattern is implemented as:
///
/// - concrete coupling of Ts (successors) at construction
/// - request are represented by ChainOfResponsiblity[T, S].Action delegate
/// where S is the parameter data
/// - IChainOfResponsibiltyNode[S] is used to determin if the member is willing
/// to participate in the request.
///
/// A common type for all members of the chain.
/// A common type for data for all members of the chain.
///
internal class ChainOfResponsiblity where T : IChainOfResponsibiltyNode
{
#region Constructors
//-------------------------------------------------------------------------
// Constructors
//-------------------------------------------------------------------------
///
/// Provides for concrete coupling of T's at construction.
///
///
internal ChainOfResponsiblity(
params T[] members)
{
_members = new List(members);
}
#endregion Constructors
#region Internal Methods
//--------------------------------------------------------------------------
// Internal Methods
//-------------------------------------------------------------------------
///
/// Will dispatch the action first to last in the chain until a member
/// reports handling the action.
///
/// True if successfully handled by a member.
/// The action to perform.
/// The subject to perform it on.
internal bool Dispatch(ChainOfResponsiblity.Action action, S subject)
{
bool handled = false;
foreach (T member in _members)
{
if (member.IsResponsible(subject))
{
Trace.SafeWrite(
Trace.File,
"Dispatching {0} to {1} using {2}.",
action.Method.Name,
member.GetType().Name,
subject.GetType().Name);
handled = action(member, subject);
if (handled)
{
Trace.SafeWrite(
Trace.File,
"Finished {0} by {1} with {2}.",
action.Method.Name,
member.GetType().Name,
subject.GetType().Name);
break;
}
}
}
return handled;
}
#endregion Internal Methods
#region Internal Delegates
//--------------------------------------------------------------------------
// Internal Delegates
//--------------------------------------------------------------------------
///
/// Actions which members T can be perform on S.
///
/// The member to perform the action.
/// The subject to perform the action on.
/// True if handled by the member.
internal delegate bool Action(T member, S subject);
#endregion Internal Delegates
#region Private Fields
//-------------------------------------------------------------------------
// Private Fields
//--------------------------------------------------------------------------
///
/// The concrete list of members.
///
private List _members;
#endregion Private Fields
}
}
// 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
- ZipIOExtraFieldZip64Element.cs
- ExtendedPropertyInfo.cs
- ReadingWritingEntityEventArgs.cs
- FormViewUpdateEventArgs.cs
- Rotation3D.cs
- RichTextBox.cs
- COM2ExtendedBrowsingHandler.cs
- PagedDataSource.cs
- SafeFileMappingHandle.cs
- UrlMappingsSection.cs
- ToolboxItem.cs
- PersonalizationStateQuery.cs
- SqlCharStream.cs
- Expander.cs
- autovalidator.cs
- OAVariantLib.cs
- ContextMenuService.cs
- GestureRecognizer.cs
- PageThemeCodeDomTreeGenerator.cs
- SQLBinaryStorage.cs
- DbConnectionPoolGroup.cs
- BindingMAnagerBase.cs
- FlowDocument.cs
- FontFamily.cs
- unsafenativemethodsother.cs
- XmlBaseWriter.cs
- BindingNavigator.cs
- ScrollBarAutomationPeer.cs
- SystemException.cs
- MachineKeySection.cs
- CodeTypeParameterCollection.cs
- FixedSOMGroup.cs
- DriveNotFoundException.cs
- fixedPageContentExtractor.cs
- DbBuffer.cs
- SqlFunctions.cs
- ReadOnlyTernaryTree.cs
- BaseServiceProvider.cs
- SuppressMessageAttribute.cs
- XmlQueryRuntime.cs
- SkipStoryboardToFill.cs
- MarshalByValueComponent.cs
- ConstraintEnumerator.cs
- MonitorWrapper.cs
- Transform.cs
- _OSSOCK.cs
- SystemNetworkInterface.cs
- StorageSetMapping.cs
- ServicePerformanceCounters.cs
- StateMachineWorkflowInstance.cs
- UIElementIsland.cs
- XmlDataSourceView.cs
- ItemChangedEventArgs.cs
- GlyphsSerializer.cs
- HttpCapabilitiesEvaluator.cs
- HtmlElementCollection.cs
- Dictionary.cs
- IsolatedStoragePermission.cs
- DayRenderEvent.cs
- LayoutTableCell.cs
- PathGradientBrush.cs
- NativeWindow.cs
- UnsafeNativeMethods.cs
- TransformerTypeCollection.cs
- SerializerDescriptor.cs
- CodeGeneratorOptions.cs
- XmlArrayItemAttributes.cs
- RichTextBoxAutomationPeer.cs
- StrokeNodeOperations2.cs
- BinHexEncoder.cs
- HttpCacheVaryByContentEncodings.cs
- DefaultIfEmptyQueryOperator.cs
- HitTestParameters.cs
- SafeRightsManagementQueryHandle.cs
- WorkflowInstanceAbortedRecord.cs
- IntegrationExceptionEventArgs.cs
- DataSetMappper.cs
- FileAccessException.cs
- __TransparentProxy.cs
- _SslSessionsCache.cs
- DataControlFieldCollection.cs
- WebPartsPersonalizationAuthorization.cs
- TrimSurroundingWhitespaceAttribute.cs
- WebPartConnection.cs
- SystemFonts.cs
- DataGridViewCheckBoxColumn.cs
- DbFunctionCommandTree.cs
- InternalDispatchObject.cs
- SchemaEntity.cs
- TableParagraph.cs
- ChannelBinding.cs
- DragDeltaEventArgs.cs
- ToolStripSystemRenderer.cs
- ObjectSecurity.cs
- AsyncDataRequest.cs
- CodeAttributeArgumentCollection.cs
- X509ThumbprintKeyIdentifierClause.cs
- ReadOnlyDictionary.cs
- XmlSerializerNamespaces.cs
- SchemaDeclBase.cs