Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / SetState.cs / 1305376 / SetState.cs
namespace System.Workflow.Activities { using System; using System.Text; using System.Reflection; using System.Collections; using System.CodeDom; using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; using System.Drawing; using System.Drawing.Design; using System.Security; using System.Security.Permissions; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Design; using System.Collections.Generic; using System.Workflow.ComponentModel.Compiler; using System.Workflow.Activities.Common; [SRDescription(SR.SetStateActivityDescription)] [ToolboxItem(typeof(ActivityToolboxItem))] [Designer(typeof(SetStateDesigner), typeof(IDesigner))] [ToolboxBitmap(typeof(SetStateActivity), "Resources.SetStateActivity.png")] [ActivityValidator(typeof(SetStateValidator))] [SRCategory(SR.Standard)] [System.Runtime.InteropServices.ComVisible(false)] public sealed class SetStateActivity : Activity { internal const string TargetStateNamePropertyName = "TargetStateName"; //metadata property public static readonly DependencyProperty TargetStateNameProperty = DependencyProperty.Register(TargetStateNamePropertyName, typeof(string), typeof(SetStateActivity), new PropertyMetadata("", DependencyPropertyOptions.Metadata, new ValidationOptionAttribute(ValidationOption.Optional))); #region Constructors public SetStateActivity() { } public SetStateActivity(string name) : base(name) { } #endregion [SRDescription(SR.TargetStateDescription)] [Editor(typeof(StateDropDownEditor), typeof(UITypeEditor))] [DefaultValue((string)null)] public string TargetStateName { get { return base.GetValue(TargetStateNameProperty) as string; } set { base.SetValue(TargetStateNameProperty, value); } } protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) throw new ArgumentNullException("executionContext"); StateActivity parentState = StateMachineHelpers.FindEnclosingState(executionContext.Activity); StateActivity rootState = StateMachineHelpers.GetRootState(parentState); StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState); executionState.NextStateName = this.TargetStateName; return ActivityExecutionStatus.Closed; } } [System.Runtime.InteropServices.ComVisible(false)] internal sealed class SetStateValidator : ActivityValidator { public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj)); SetStateActivity setState = obj as SetStateActivity; if (setState == null) throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj"); if (!SetStateContainment.Validate(setState, validationErrors)) return validationErrors; // could not find a valid parent if (String.IsNullOrEmpty(setState.TargetStateName)) { validationErrors.Add(new ValidationError( SR.GetString(SR.Error_PropertyNotSet, SetStateActivity.TargetStateNamePropertyName), ErrorNumbers.Error_PropertyNotSet, false, SetStateActivity.TargetStateNamePropertyName)); } else { StateActivity enclosingState = StateMachineHelpers.FindEnclosingState(setState); Debug.Assert(enclosingState != null); // this should be caught by the SetStateContainment.Validate call above StateActivity rootState = StateMachineHelpers.GetRootState(enclosingState); StateActivity targetActivity = StateMachineHelpers.FindStateByName( rootState, setState.TargetStateName); StateActivity targetState = targetActivity as StateActivity; if (targetState == null) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToAState(), ErrorNumbers.Error_SetStateMustPointToAState, false, SetStateActivity.TargetStateNamePropertyName)); } else { if (!StateMachineHelpers.IsLeafState(targetState)) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToALeafNodeState(), ErrorNumbers.Error_SetStateMustPointToALeafNodeState, false, SetStateActivity.TargetStateNamePropertyName)); } } } return validationErrors; } #region SetStateContainement private class SetStateContainment { private bool validParentFound = true; private bool validParentStateFound; private SetStateContainment() { } public static bool Validate(SetStateActivity setState, ValidationErrorCollection validationErrors) { SetStateContainment containment = new SetStateContainment(); ValidateContainment(containment, setState); if (!containment.validParentFound || !containment.validParentStateFound) { validationErrors.Add(new ValidationError(SR.GetError_SetStateOnlyWorksOnStateMachineWorkflow(), ErrorNumbers.Error_SetStateOnlyWorksOnStateMachineWorkflow)); return false; } return true; } private static void ValidateContainment(SetStateContainment containment, Activity activity) { Debug.Assert(activity != null); if (activity.Parent == null || activity.Parent == activity) { containment.validParentFound = false; return; } if (SetStateValidator.IsValidContainer(activity.Parent)) { ValidateParentState(containment, activity.Parent); return; } ValidateContainment(containment, activity.Parent); } private static void ValidateParentState(SetStateContainment containment, CompositeActivity activity) { Debug.Assert(activity != null); if (activity.Parent == null) return; StateActivity state = activity.Parent as StateActivity; if (state != null) { containment.validParentStateFound = true; return; } ValidateParentState(containment, activity.Parent); } } #endregion #region Helper methods static internal bool IsValidContainer(CompositeActivity activity) { return (activity is EventDrivenActivity || activity is StateInitializationActivity); } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Workflow.Activities { using System; using System.Text; using System.Reflection; using System.Collections; using System.CodeDom; using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; using System.Drawing; using System.Drawing.Design; using System.Security; using System.Security.Permissions; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Design; using System.Collections.Generic; using System.Workflow.ComponentModel.Compiler; using System.Workflow.Activities.Common; [SRDescription(SR.SetStateActivityDescription)] [ToolboxItem(typeof(ActivityToolboxItem))] [Designer(typeof(SetStateDesigner), typeof(IDesigner))] [ToolboxBitmap(typeof(SetStateActivity), "Resources.SetStateActivity.png")] [ActivityValidator(typeof(SetStateValidator))] [SRCategory(SR.Standard)] [System.Runtime.InteropServices.ComVisible(false)] public sealed class SetStateActivity : Activity { internal const string TargetStateNamePropertyName = "TargetStateName"; //metadata property public static readonly DependencyProperty TargetStateNameProperty = DependencyProperty.Register(TargetStateNamePropertyName, typeof(string), typeof(SetStateActivity), new PropertyMetadata("", DependencyPropertyOptions.Metadata, new ValidationOptionAttribute(ValidationOption.Optional))); #region Constructors public SetStateActivity() { } public SetStateActivity(string name) : base(name) { } #endregion [SRDescription(SR.TargetStateDescription)] [Editor(typeof(StateDropDownEditor), typeof(UITypeEditor))] [DefaultValue((string)null)] public string TargetStateName { get { return base.GetValue(TargetStateNameProperty) as string; } set { base.SetValue(TargetStateNameProperty, value); } } protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) throw new ArgumentNullException("executionContext"); StateActivity parentState = StateMachineHelpers.FindEnclosingState(executionContext.Activity); StateActivity rootState = StateMachineHelpers.GetRootState(parentState); StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState); executionState.NextStateName = this.TargetStateName; return ActivityExecutionStatus.Closed; } } [System.Runtime.InteropServices.ComVisible(false)] internal sealed class SetStateValidator : ActivityValidator { public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = new ValidationErrorCollection(base.Validate(manager, obj)); SetStateActivity setState = obj as SetStateActivity; if (setState == null) throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(StateActivity).FullName), "obj"); if (!SetStateContainment.Validate(setState, validationErrors)) return validationErrors; // could not find a valid parent if (String.IsNullOrEmpty(setState.TargetStateName)) { validationErrors.Add(new ValidationError( SR.GetString(SR.Error_PropertyNotSet, SetStateActivity.TargetStateNamePropertyName), ErrorNumbers.Error_PropertyNotSet, false, SetStateActivity.TargetStateNamePropertyName)); } else { StateActivity enclosingState = StateMachineHelpers.FindEnclosingState(setState); Debug.Assert(enclosingState != null); // this should be caught by the SetStateContainment.Validate call above StateActivity rootState = StateMachineHelpers.GetRootState(enclosingState); StateActivity targetActivity = StateMachineHelpers.FindStateByName( rootState, setState.TargetStateName); StateActivity targetState = targetActivity as StateActivity; if (targetState == null) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToAState(), ErrorNumbers.Error_SetStateMustPointToAState, false, SetStateActivity.TargetStateNamePropertyName)); } else { if (!StateMachineHelpers.IsLeafState(targetState)) { validationErrors.Add(new ValidationError(SR.GetError_SetStateMustPointToALeafNodeState(), ErrorNumbers.Error_SetStateMustPointToALeafNodeState, false, SetStateActivity.TargetStateNamePropertyName)); } } } return validationErrors; } #region SetStateContainement private class SetStateContainment { private bool validParentFound = true; private bool validParentStateFound; private SetStateContainment() { } public static bool Validate(SetStateActivity setState, ValidationErrorCollection validationErrors) { SetStateContainment containment = new SetStateContainment(); ValidateContainment(containment, setState); if (!containment.validParentFound || !containment.validParentStateFound) { validationErrors.Add(new ValidationError(SR.GetError_SetStateOnlyWorksOnStateMachineWorkflow(), ErrorNumbers.Error_SetStateOnlyWorksOnStateMachineWorkflow)); return false; } return true; } private static void ValidateContainment(SetStateContainment containment, Activity activity) { Debug.Assert(activity != null); if (activity.Parent == null || activity.Parent == activity) { containment.validParentFound = false; return; } if (SetStateValidator.IsValidContainer(activity.Parent)) { ValidateParentState(containment, activity.Parent); return; } ValidateContainment(containment, activity.Parent); } private static void ValidateParentState(SetStateContainment containment, CompositeActivity activity) { Debug.Assert(activity != null); if (activity.Parent == null) return; StateActivity state = activity.Parent as StateActivity; if (state != null) { containment.validParentStateFound = true; return; } ValidateParentState(containment, activity.Parent); } } #endregion #region Helper methods static internal bool IsValidContainer(CompositeActivity activity) { return (activity is EventDrivenActivity || activity is StateInitializationActivity); } #endregion } } // 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
- InProcStateClientManager.cs
- StartUpEventArgs.cs
- XPathNavigatorKeyComparer.cs
- WebPartDeleteVerb.cs
- CreateUserWizard.cs
- NameObjectCollectionBase.cs
- PersonalizationProvider.cs
- RunInstallerAttribute.cs
- SerializationEventsCache.cs
- SAPICategories.cs
- DelegatingConfigHost.cs
- MessageAction.cs
- GeneratedView.cs
- MsmqSecureHashAlgorithm.cs
- ObjectView.cs
- SessionState.cs
- NotifyInputEventArgs.cs
- HtmlControl.cs
- TableCell.cs
- Rotation3DKeyFrameCollection.cs
- SqlGenerator.cs
- ObfuscationAttribute.cs
- TrackingMemoryStreamFactory.cs
- PropertyExpression.cs
- CustomLineCap.cs
- Int32Rect.cs
- CultureSpecificStringDictionary.cs
- CfgParser.cs
- StaticContext.cs
- UserMapPath.cs
- CompModSwitches.cs
- DiagnosticsElement.cs
- DefaultConfirmation.cs
- TextRangeEditTables.cs
- FtpWebResponse.cs
- ResourceProviderFactory.cs
- OleDbSchemaGuid.cs
- SqlFlattener.cs
- DatasetMethodGenerator.cs
- WebServiceData.cs
- PageBorderless.cs
- BindingCompleteEventArgs.cs
- FixedDocumentPaginator.cs
- StylusEventArgs.cs
- PathSegmentCollection.cs
- FilterException.cs
- Matrix3DValueSerializer.cs
- XmlSerializerSection.cs
- TimeSpanMinutesConverter.cs
- ByteFacetDescriptionElement.cs
- DispatcherFrame.cs
- SuppressMergeCheckAttribute.cs
- XmlSortKey.cs
- DateTimeOffsetAdapter.cs
- x509utils.cs
- RelationshipConstraintValidator.cs
- DataPager.cs
- MatchAttribute.cs
- TextEffectResolver.cs
- MonthChangedEventArgs.cs
- SafeNativeMethods.cs
- CalendarDay.cs
- Msec.cs
- CodeDomSerializer.cs
- HashStream.cs
- TdsValueSetter.cs
- ProxyManager.cs
- XmlTextReaderImpl.cs
- UICuesEvent.cs
- SortFieldComparer.cs
- SafeTokenHandle.cs
- DynamicField.cs
- SqlTrackingQuery.cs
- Serializer.cs
- WebSysDefaultValueAttribute.cs
- FirstMatchCodeGroup.cs
- CommandExpr.cs
- XPathAncestorIterator.cs
- KeyedPriorityQueue.cs
- DispatcherHooks.cs
- TemplateBamlTreeBuilder.cs
- FrameSecurityDescriptor.cs
- ApplicationSettingsBase.cs
- TextWriterEngine.cs
- PartitionResolver.cs
- ArcSegment.cs
- Object.cs
- Codec.cs
- CustomWebEventKey.cs
- CompiledXpathExpr.cs
- FunctionMappingTranslator.cs
- DataPointer.cs
- ScriptingScriptResourceHandlerSection.cs
- WebPartVerb.cs
- TreeNodeConverter.cs
- ZipIOZip64EndOfCentralDirectoryLocatorBlock.cs
- TextPointer.cs
- InvalidEnumArgumentException.cs
- SecureStringHasher.cs
- QueryOutputWriterV1.cs