Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / TrustUi / MS / Internal / documents / Application / ChainOfDependencies.cs / 1 / ChainOfDependencies.cs
//------------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
//
// A Generic that provides user with the ability to chain dependent objects
// of a shared base type and perform actions on them in order of dependency.
//
//
// History:
// 08/28/2005: [....]: Initial implementation.
//-----------------------------------------------------------------------------
namespace MS.Internal.Documents.Application
{
///
/// A Generic that provides user with the ability to chain dependent objects
/// of a shared base type and perform actions on them in order of dependency.
///
///
/// This is different from the chain of responsiblity in the following ways:
///
/// - Order of execution in the chain can be inversed by calling LastToFirst.
/// - The same operation is performed on each member once.
///
/// This class has many methods which are intentionaly recursive. There is
/// currently no validation to prevent cyclic dependencies. As the chain is
/// currently fixed at compile time there is no need; StackOverFlowException
/// durring testing is fine.
///
/// A type common to all in the chain.
internal static class ChainOfDependencies where T : IChainOfDependenciesNode
{
#region Internal Methods
//-------------------------------------------------------------------------
// Internal Methods
//-------------------------------------------------------------------------
///
/// Gets the last member in the chain. (The one with no dependencies.)
///
/// The current member.
/// The last member in the chain. (The one with no dependencies.)
///
internal static T GetLast(T member)
{
T last = member;
if (member.Dependency != null)
{
last = GetLast(member.Dependency);
}
return last;
}
///
/// Will perform the action from the member with no dependencies to the most
/// dependent member.
///
/// The member on which to perform the action.
/// The action to perform on the member.
/// Returns true if all the actions returned true.
internal static bool OrderByLeastDependent(
T member,
ChainOfDependencies.Action action)
{
bool satisfied = true;
T nextInChain = member.Dependency;
if (nextInChain != null)
{
satisfied = OrderByLeastDependent(nextInChain, action);
}
if (satisfied)
{
satisfied = action(member);
}
else
{
Trace.SafeWrite(
Trace.File,
"Dependency for {0}#{1} was not satisfied skipping action.",
member.GetType(),
member.GetHashCode());
}
return satisfied;
}
///
/// Will perform the action from most dependent to not dependent.
///
/// The member on which to perform the action.
/// The action to perform on the member.
/// Returns true if the all the actions returned true.
internal static bool OrderByMostDependent(
T member,
ChainOfDependencies.Action action)
{
bool satisfied = action(member);
T nextInChain = member.Dependency;
if (satisfied)
{
if (nextInChain != null)
{
satisfied = OrderByMostDependent(nextInChain, action);
}
}
else
{
Trace.SafeWrite(
Trace.File,
"Dependency for {0}#{1} was not satisfied skipping action.",
member.GetType(),
member.GetHashCode());
}
return satisfied;
}
#endregion Internal Methods
#region Internal Delegates
//--------------------------------------------------------------------------
// Internal Delegates
//-------------------------------------------------------------------------
///
/// An action to perform on a ChainOfDependencies member.
///
/// The member on which to perform the action.
/// True if the dependency was satisfied.
internal delegate bool Action(T member);
#endregion Internal Delegates
}
}
// 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
- FolderBrowserDialogDesigner.cs
- SchemaNames.cs
- Int32Animation.cs
- ExpressionBindings.cs
- DesignTimeVisibleAttribute.cs
- WindowsSysHeader.cs
- OptimisticConcurrencyException.cs
- MetafileHeader.cs
- LinearGradientBrush.cs
- DragDropHelper.cs
- JsonUriDataContract.cs
- DataGridPagingPage.cs
- QuadraticBezierSegment.cs
- EnvelopedSignatureTransform.cs
- SpeechRecognizer.cs
- OleDbReferenceCollection.cs
- BaseTemplateParser.cs
- ScrollItemPattern.cs
- DataObjectMethodAttribute.cs
- VideoDrawing.cs
- RefExpr.cs
- BuildProvider.cs
- BuiltInExpr.cs
- ValidatedControlConverter.cs
- ProcessThreadCollection.cs
- WaitingCursor.cs
- _BaseOverlappedAsyncResult.cs
- RolePrincipal.cs
- BamlResourceDeserializer.cs
- XamlRtfConverter.cs
- BindingCollection.cs
- ArrangedElement.cs
- CompilerTypeWithParams.cs
- InkCanvasFeedbackAdorner.cs
- CodeAttributeDeclaration.cs
- CleanUpVirtualizedItemEventArgs.cs
- ClickablePoint.cs
- MultiTouchSystemGestureLogic.cs
- cookiecollection.cs
- DbConnectionPoolOptions.cs
- LinqDataSourceDeleteEventArgs.cs
- SafeCryptoHandles.cs
- SourceFilter.cs
- CodeComment.cs
- IProducerConsumerCollection.cs
- SizeF.cs
- ValueUtilsSmi.cs
- FullTextState.cs
- IIS7WorkerRequest.cs
- Journaling.cs
- CompoundFileDeflateTransform.cs
- SourceElementsCollection.cs
- FlowDocumentPage.cs
- ThreadAbortException.cs
- TimeSpanOrInfiniteConverter.cs
- GridErrorDlg.cs
- EventManager.cs
- GeneralTransformGroup.cs
- SortExpressionBuilder.cs
- ActivityTypeResolver.xaml.cs
- TypedTableBaseExtensions.cs
- XmlElementCollection.cs
- SizeAnimationBase.cs
- BamlWriter.cs
- ToggleButtonAutomationPeer.cs
- NameValuePair.cs
- TextPattern.cs
- GridViewRowCollection.cs
- DataGridBoolColumn.cs
- odbcmetadatacolumnnames.cs
- OdbcParameterCollection.cs
- ComponentEditorForm.cs
- AssemblySettingAttributes.cs
- LifetimeServices.cs
- ZipFileInfo.cs
- MsmqIntegrationSecurityMode.cs
- AttributeTableBuilder.cs
- PeerTransportListenAddressValidator.cs
- HtmlControl.cs
- OrderedDictionaryStateHelper.cs
- EntityModelSchemaGenerator.cs
- ZoneIdentityPermission.cs
- DynamicRendererThreadManager.cs
- GroupItemAutomationPeer.cs
- Vector.cs
- SQLDouble.cs
- CodeTypeReferenceSerializer.cs
- Timeline.cs
- RelationalExpressions.cs
- DbMetaDataCollectionNames.cs
- CompiledAction.cs
- ExtensionCollection.cs
- XmlDataSourceView.cs
- SingleConverter.cs
- DesignerTransaction.cs
- BitmapSourceSafeMILHandle.cs
- PrinterSettings.cs
- ColorConverter.cs
- SectionXmlInfo.cs
- SecureEnvironment.cs