Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Base / Core / OrderToken.cs / 1305376 / OrderToken.cs
namespace System.Activities.Presentation {
using System;
using System.Collections.Generic;
using System.Text;
using System.Activities.Presentation;
///
/// OrderToken is a generic class used to identify the sort
/// order of hierarchical items. OrderTokens can be used
/// to define priority that is based on some predefined defaults or
/// based on other OrderTokens.
///
abstract class OrderToken : IComparable {
private readonly OrderToken _reference;
private readonly OrderTokenPrecedence _precedence;
private readonly OrderTokenConflictResolution _conflictResolution;
private readonly int _depth;
private readonly int _index;
private int _nextChildIndex;
///
/// Creates a new OrderToken instance based on the specified
/// referenced OrderToken, precedence, and conflict resolution
/// semantics.
///
/// Precedence of this token based on the
/// referenced token.
/// Referenced token. May be null for the
/// root token case (token that's not dependent on anything else).
/// Conflict resolution semantics.
/// Winning ConflictResultion semantic should only be used
/// on predefined, default OrderToken instances to ensure
/// their correct placement in more complex chain of order
/// dependencies.
protected OrderToken(
OrderTokenPrecedence precedence,
OrderToken reference,
OrderTokenConflictResolution conflictResolution) {
if (!EnumValidator.IsValid(precedence)) throw FxTrace.Exception.AsError(new ArgumentOutOfRangeException("precedence"));
if (!EnumValidator.IsValid(conflictResolution)) throw FxTrace.Exception.AsError(new ArgumentOutOfRangeException("conflictResolution"));
_reference = reference;
_precedence = precedence;
_conflictResolution = conflictResolution;
_depth = reference == null ? 0 : reference._depth + 1;
_index = reference == null ? -1 : reference._nextChildIndex++;
}
///
/// Compares this order token with the specified order token.
/// The comparsion for OrderTokens that don't belong to the same
/// chain of OrderTokens will be resolved non-deterministically.
///
/// The token to compare this token to.
/// 0 when the tokens have an equal order priority,
/// -1 if this order comes before the specified order,
/// 1 otherwise.
/// When other is null
public virtual int CompareTo(OrderToken other) {
if (other == null)
throw FxTrace.Exception.ArgumentNull("other");
if (other == this)
return 0;
OrderToken thisOrder = this;
// Find a common parent
while (thisOrder._reference != other._reference) {
if (thisOrder._depth == other._depth)
{
thisOrder = thisOrder._reference;
other = other._reference;
}
else{
if (thisOrder._depth > other._depth) {
if (thisOrder._reference == other) return thisOrder._precedence == OrderTokenPrecedence.After ? 1 : -1;
thisOrder = thisOrder._reference;
}
else {
if (other._reference == thisOrder) return other._precedence == OrderTokenPrecedence.After ? -1 : 1;
other = other._reference;
}
}
}
// One order "before", one order "after"? Easy, return the
// "before" order.
if (thisOrder._precedence != other._precedence)
return thisOrder._precedence == OrderTokenPrecedence.Before ? -1 : 1;
// Both orders "before" the parent? Roots win, otherwise call ResolveConflict().
if (thisOrder._precedence == OrderTokenPrecedence.Before) {
if (thisOrder._conflictResolution == OrderTokenConflictResolution.Win)
return -1;
else if (other._conflictResolution == OrderTokenConflictResolution.Win)
return 1;
return ResolveConflict(thisOrder, other);
}
// Both orders "after" the parent? Roots win, otherwise call ResolveConflict().
if (thisOrder._conflictResolution == OrderTokenConflictResolution.Win)
return 1;
else if (other._conflictResolution == OrderTokenConflictResolution.Win)
return -1;
return ResolveConflict(thisOrder, other);
}
///
/// This method is called by CompareTo()'s default implementation when two OrderTokens
/// appear to be equivalent. The base functionality of this method uses the instantiation
/// order of the two tokens as a tie-breaker. Override this method to
/// implement custom algorithms. Note that if this method ever returns 0
/// (indicating that the two tokens are equivalent) and if these tokens
/// belong to a list that gets sorted multiple times, the relative order in
/// which they appear in the list will not be guaranteed. This side-effect
/// may or may not be a problem depending on the application.
///
/// Left OrderToken
/// Right OrderToken
/// 0, if the two are equal, -1, if left comes before right,
/// 1 otherwise.
protected virtual int ResolveConflict(OrderToken left, OrderToken right) {
return left._index.CompareTo(right._index);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Activities.Presentation {
using System;
using System.Collections.Generic;
using System.Text;
using System.Activities.Presentation;
///
/// OrderToken is a generic class used to identify the sort
/// order of hierarchical items. OrderTokens can be used
/// to define priority that is based on some predefined defaults or
/// based on other OrderTokens.
///
abstract class OrderToken : IComparable {
private readonly OrderToken _reference;
private readonly OrderTokenPrecedence _precedence;
private readonly OrderTokenConflictResolution _conflictResolution;
private readonly int _depth;
private readonly int _index;
private int _nextChildIndex;
///
/// Creates a new OrderToken instance based on the specified
/// referenced OrderToken, precedence, and conflict resolution
/// semantics.
///
/// Precedence of this token based on the
/// referenced token.
/// Referenced token. May be null for the
/// root token case (token that's not dependent on anything else).
/// Conflict resolution semantics.
/// Winning ConflictResultion semantic should only be used
/// on predefined, default OrderToken instances to ensure
/// their correct placement in more complex chain of order
/// dependencies.
protected OrderToken(
OrderTokenPrecedence precedence,
OrderToken reference,
OrderTokenConflictResolution conflictResolution) {
if (!EnumValidator.IsValid(precedence)) throw FxTrace.Exception.AsError(new ArgumentOutOfRangeException("precedence"));
if (!EnumValidator.IsValid(conflictResolution)) throw FxTrace.Exception.AsError(new ArgumentOutOfRangeException("conflictResolution"));
_reference = reference;
_precedence = precedence;
_conflictResolution = conflictResolution;
_depth = reference == null ? 0 : reference._depth + 1;
_index = reference == null ? -1 : reference._nextChildIndex++;
}
///
/// Compares this order token with the specified order token.
/// The comparsion for OrderTokens that don't belong to the same
/// chain of OrderTokens will be resolved non-deterministically.
///
/// The token to compare this token to.
/// 0 when the tokens have an equal order priority,
/// -1 if this order comes before the specified order,
/// 1 otherwise.
/// When other is null
public virtual int CompareTo(OrderToken other) {
if (other == null)
throw FxTrace.Exception.ArgumentNull("other");
if (other == this)
return 0;
OrderToken thisOrder = this;
// Find a common parent
while (thisOrder._reference != other._reference) {
if (thisOrder._depth == other._depth)
{
thisOrder = thisOrder._reference;
other = other._reference;
}
else{
if (thisOrder._depth > other._depth) {
if (thisOrder._reference == other) return thisOrder._precedence == OrderTokenPrecedence.After ? 1 : -1;
thisOrder = thisOrder._reference;
}
else {
if (other._reference == thisOrder) return other._precedence == OrderTokenPrecedence.After ? -1 : 1;
other = other._reference;
}
}
}
// One order "before", one order "after"? Easy, return the
// "before" order.
if (thisOrder._precedence != other._precedence)
return thisOrder._precedence == OrderTokenPrecedence.Before ? -1 : 1;
// Both orders "before" the parent? Roots win, otherwise call ResolveConflict().
if (thisOrder._precedence == OrderTokenPrecedence.Before) {
if (thisOrder._conflictResolution == OrderTokenConflictResolution.Win)
return -1;
else if (other._conflictResolution == OrderTokenConflictResolution.Win)
return 1;
return ResolveConflict(thisOrder, other);
}
// Both orders "after" the parent? Roots win, otherwise call ResolveConflict().
if (thisOrder._conflictResolution == OrderTokenConflictResolution.Win)
return 1;
else if (other._conflictResolution == OrderTokenConflictResolution.Win)
return -1;
return ResolveConflict(thisOrder, other);
}
///
/// This method is called by CompareTo()'s default implementation when two OrderTokens
/// appear to be equivalent. The base functionality of this method uses the instantiation
/// order of the two tokens as a tie-breaker. Override this method to
/// implement custom algorithms. Note that if this method ever returns 0
/// (indicating that the two tokens are equivalent) and if these tokens
/// belong to a list that gets sorted multiple times, the relative order in
/// which they appear in the list will not be guaranteed. This side-effect
/// may or may not be a problem depending on the application.
///
/// Left OrderToken
/// Right OrderToken
/// 0, if the two are equal, -1, if left comes before right,
/// 1 otherwise.
protected virtual int ResolveConflict(OrderToken left, OrderToken right) {
return left._index.CompareTo(right._index);
}
}
}
// 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
- DiscoveryEndpoint.cs
- NominalTypeEliminator.cs
- AnnotationAdorner.cs
- ExpandedWrapper.cs
- TargetControlTypeAttribute.cs
- XPathBuilder.cs
- TabPanel.cs
- FormViewModeEventArgs.cs
- DataPagerField.cs
- WebBrowserSiteBase.cs
- SpStreamWrapper.cs
- BindingMAnagerBase.cs
- StrokeNode.cs
- FilterQueryOptionExpression.cs
- XmlSchemaElement.cs
- ServiceModelPerformanceCounters.cs
- WindowsEditBoxRange.cs
- PageRequestManager.cs
- ProcessManager.cs
- HostVisual.cs
- ContextInformation.cs
- DataGridViewLayoutData.cs
- WebBrowserContainer.cs
- TdsParameterSetter.cs
- DataControlButton.cs
- MethodBuilder.cs
- X509Certificate2Collection.cs
- SwitchElementsCollection.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- ValidatorCollection.cs
- WeakReferenceKey.cs
- XmlnsDictionary.cs
- EmulateRecognizeCompletedEventArgs.cs
- StringConverter.cs
- TdsParserStaticMethods.cs
- BoolExpressionVisitors.cs
- DataGridViewControlCollection.cs
- DataGridColumn.cs
- ScriptIgnoreAttribute.cs
- SqlNodeTypeOperators.cs
- CompilerTypeWithParams.cs
- ForeignKeyFactory.cs
- CollectionConverter.cs
- HttpFormatExtensions.cs
- XmlReflectionImporter.cs
- PeerName.cs
- HelloMessageApril2005.cs
- Journaling.cs
- MaterialCollection.cs
- EventProperty.cs
- RealizationDrawingContextWalker.cs
- BezierSegment.cs
- XamlFilter.cs
- Utils.cs
- InputProviderSite.cs
- DataBindingsDialog.cs
- MemberDomainMap.cs
- Int16Converter.cs
- DefaultSerializationProviderAttribute.cs
- ComplusEndpointConfigContainer.cs
- Int32AnimationBase.cs
- ClientTargetSection.cs
- TableRow.cs
- ProxyFragment.cs
- ToolStripItemDataObject.cs
- ItemMap.cs
- InstanceOwnerQueryResult.cs
- Point3DCollectionValueSerializer.cs
- SvcMapFileLoader.cs
- RequestResizeEvent.cs
- URI.cs
- DbParameterCollectionHelper.cs
- WebMessageEncodingBindingElement.cs
- ConnectionModeReader.cs
- SafeIUnknown.cs
- AvTraceFormat.cs
- ToolStripArrowRenderEventArgs.cs
- HttpRequestMessageProperty.cs
- DataGridViewCellParsingEventArgs.cs
- XmlAttributes.cs
- QueryRewriter.cs
- XmlSubtreeReader.cs
- DisplayMemberTemplateSelector.cs
- UniqueID.cs
- RectAnimationBase.cs
- WebEventTraceProvider.cs
- DataGridColumnCollection.cs
- CodeSnippetTypeMember.cs
- PropertyCollection.cs
- ListBoxAutomationPeer.cs
- SelectedCellsCollection.cs
- TreeViewImageKeyConverter.cs
- ReceiveSecurityHeaderElementManager.cs
- TypeHelpers.cs
- _NestedMultipleAsyncResult.cs
- Drawing.cs
- XmlSigningNodeWriter.cs
- DivideByZeroException.cs
- HandlerWithFactory.cs
- CommentAction.cs