Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / LocalService / CorrelationTokenTypeConvertor.cs / 1305376 / CorrelationTokenTypeConvertor.cs
using System; using System.Xml; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Runtime.Serialization; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Design; using System.Workflow.ComponentModel.Serialization; using System.Workflow.Runtime; using System.Globalization; namespace System.Workflow.Activities { internal sealed class CorrelationTokenTypeConverter : ExpandableObjectConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return (sourceType == typeof(string)); } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return (destinationType == typeof(string)); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { object convertedValue = null; string correlatorName = value as String; if (!String.IsNullOrEmpty(correlatorName)) { foreach (object obj in GetStandardValues(context)) { CorrelationToken correlator = obj as CorrelationToken; if (correlator != null && correlator.Name == correlatorName) { convertedValue = correlator; break; } } if (convertedValue == null) convertedValue = new CorrelationToken(correlatorName); } return convertedValue; } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { object convertedValue = null; CorrelationToken correlator = value as CorrelationToken; if (destinationType == typeof(string) && correlator != null) convertedValue = correlator.Name; return convertedValue; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { ArrayList values = new ArrayList(); Activity activity = context.Instance as Activity; if (activity != null) { foreach (Activity preceedingActivity in GetPreceedingActivities(activity)) { PropertyDescriptor correlatorProperty = TypeDescriptor.GetProperties(preceedingActivity)["CorrelationToken"] as PropertyDescriptor; if (correlatorProperty != null) { CorrelationToken correlator = correlatorProperty.GetValue(preceedingActivity) as CorrelationToken; if (correlator != null && !values.Contains(correlator)) values.Add(correlator); } } } return new StandardValuesCollection(values); } public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return false; } public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection properties = base.GetProperties(context, value, attributes); ArrayList props = new ArrayList(properties); return new PropertyDescriptorCollection((PropertyDescriptor[])props.ToArray(typeof(PropertyDescriptor))); } // private IEnumerable GetPreceedingActivities(Activity startActivity) { Activity currentActivity = null; StackactivityStack = new Stack (); activityStack.Push(startActivity); while ((currentActivity = activityStack.Pop()) != null) { if (currentActivity.Parent != null) { foreach (Activity siblingActivity in currentActivity.Parent.Activities) { if (siblingActivity == currentActivity) break; if (siblingActivity.Enabled) { if (siblingActivity is CompositeActivity) { foreach (Activity containedActivity in GetContainedActivities((CompositeActivity)siblingActivity)) yield return containedActivity; } else { yield return siblingActivity; } } } } activityStack.Push(currentActivity.Parent); } yield break; } private IEnumerable GetContainedActivities(CompositeActivity activity) { if (!activity.Enabled) yield break; foreach (Activity containedActivity in activity.Activities) { if (containedActivity is CompositeActivity) { foreach (Activity nestedActivity in GetContainedActivities((CompositeActivity)containedActivity)) { if (nestedActivity.Enabled) yield return nestedActivity; } } else { if (containedActivity.Enabled) yield return containedActivity; } } yield break; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Xml; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Runtime.Serialization; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Design; using System.Workflow.ComponentModel.Serialization; using System.Workflow.Runtime; using System.Globalization; namespace System.Workflow.Activities { internal sealed class CorrelationTokenTypeConverter : ExpandableObjectConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return (sourceType == typeof(string)); } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { return (destinationType == typeof(string)); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { object convertedValue = null; string correlatorName = value as String; if (!String.IsNullOrEmpty(correlatorName)) { foreach (object obj in GetStandardValues(context)) { CorrelationToken correlator = obj as CorrelationToken; if (correlator != null && correlator.Name == correlatorName) { convertedValue = correlator; break; } } if (convertedValue == null) convertedValue = new CorrelationToken(correlatorName); } return convertedValue; } public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) { object convertedValue = null; CorrelationToken correlator = value as CorrelationToken; if (destinationType == typeof(string) && correlator != null) convertedValue = correlator.Name; return convertedValue; } public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { ArrayList values = new ArrayList(); Activity activity = context.Instance as Activity; if (activity != null) { foreach (Activity preceedingActivity in GetPreceedingActivities(activity)) { PropertyDescriptor correlatorProperty = TypeDescriptor.GetProperties(preceedingActivity)["CorrelationToken"] as PropertyDescriptor; if (correlatorProperty != null) { CorrelationToken correlator = correlatorProperty.GetValue(preceedingActivity) as CorrelationToken; if (correlator != null && !values.Contains(correlator)) values.Add(correlator); } } } return new StandardValuesCollection(values); } public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return false; } public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { PropertyDescriptorCollection properties = base.GetProperties(context, value, attributes); ArrayList props = new ArrayList(properties); return new PropertyDescriptorCollection((PropertyDescriptor[])props.ToArray(typeof(PropertyDescriptor))); } // private IEnumerable GetPreceedingActivities(Activity startActivity) { Activity currentActivity = null; Stack activityStack = new Stack (); activityStack.Push(startActivity); while ((currentActivity = activityStack.Pop()) != null) { if (currentActivity.Parent != null) { foreach (Activity siblingActivity in currentActivity.Parent.Activities) { if (siblingActivity == currentActivity) break; if (siblingActivity.Enabled) { if (siblingActivity is CompositeActivity) { foreach (Activity containedActivity in GetContainedActivities((CompositeActivity)siblingActivity)) yield return containedActivity; } else { yield return siblingActivity; } } } } activityStack.Push(currentActivity.Parent); } yield break; } private IEnumerable GetContainedActivities(CompositeActivity activity) { if (!activity.Enabled) yield break; foreach (Activity containedActivity in activity.Activities) { if (containedActivity is CompositeActivity) { foreach (Activity nestedActivity in GetContainedActivities((CompositeActivity)containedActivity)) { if (nestedActivity.Enabled) yield return nestedActivity; } } else { if (containedActivity.Enabled) yield return containedActivity; } } yield break; } } } // 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
- WebPartVerbsEventArgs.cs
- ListMarkerLine.cs
- OleAutBinder.cs
- PeerNodeAddress.cs
- ToolStripContentPanelDesigner.cs
- FacetValueContainer.cs
- PtsCache.cs
- PermissionSet.cs
- RightsManagementInformation.cs
- WaitHandle.cs
- InfoCardRSAPKCS1SignatureDeformatter.cs
- Intellisense.cs
- ServiceElementCollection.cs
- SqlVersion.cs
- ExpandSegment.cs
- XmlMemberMapping.cs
- ServerIdentity.cs
- Point3DCollectionValueSerializer.cs
- RoleManagerSection.cs
- SqlCacheDependencyDatabaseCollection.cs
- WindowsRichEditRange.cs
- CachedFontFamily.cs
- Types.cs
- StringAttributeCollection.cs
- ByteAnimationBase.cs
- DockPatternIdentifiers.cs
- CodeTypeMemberCollection.cs
- RowCache.cs
- SynchronizedDispatch.cs
- PeerToPeerException.cs
- ToolStripItemCollection.cs
- LayoutEditorPart.cs
- StickyNote.cs
- RayHitTestParameters.cs
- SudsParser.cs
- SiblingIterators.cs
- TextRangeEditTables.cs
- Endpoint.cs
- InheritanceContextHelper.cs
- InlineCollection.cs
- DesignerLabelAdapter.cs
- HyperLink.cs
- AttachedPropertiesService.cs
- GetChildSubtree.cs
- ContextStack.cs
- TaskExceptionHolder.cs
- ColorConverter.cs
- Divide.cs
- PrimitiveXmlSerializers.cs
- KeyGesture.cs
- DataGridRelationshipRow.cs
- CodeEventReferenceExpression.cs
- Operators.cs
- AsyncPostBackErrorEventArgs.cs
- XmlSchemaCompilationSettings.cs
- TextTreeInsertElementUndoUnit.cs
- SrgsRulesCollection.cs
- DataGridViewCellStyle.cs
- Line.cs
- WeakHashtable.cs
- ChildChangedEventArgs.cs
- DataGridViewComboBoxCell.cs
- UnmanagedHandle.cs
- CacheSection.cs
- cookiecontainer.cs
- ToolboxComponentsCreatingEventArgs.cs
- RenderingBiasValidation.cs
- PointAnimationUsingPath.cs
- TextInfo.cs
- RegexBoyerMoore.cs
- Camera.cs
- JoinElimination.cs
- DropShadowEffect.cs
- VarRemapper.cs
- BasicCellRelation.cs
- XmlHierarchicalEnumerable.cs
- dataprotectionpermissionattribute.cs
- SafeRightsManagementPubHandle.cs
- ScrollEvent.cs
- DictionaryContent.cs
- CodeSubDirectoriesCollection.cs
- HttpPostedFile.cs
- FacetValueContainer.cs
- TextSegment.cs
- WebBrowser.cs
- ResetableIterator.cs
- PageFunction.cs
- SynchronizedKeyedCollection.cs
- ValidatingPropertiesEventArgs.cs
- TitleStyle.cs
- StoreItemCollection.cs
- PrincipalPermission.cs
- WebPermission.cs
- ResourceExpressionEditor.cs
- BCryptSafeHandles.cs
- GridEntryCollection.cs
- SourceElementsCollection.cs
- FileNotFoundException.cs
- TcpStreams.cs
- BindingValueChangedEventArgs.cs