Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Behaviors / ExceptionHandler.cs / 1305376 / ExceptionHandler.cs
namespace System.Workflow.ComponentModel { #region Imports using System; using System.Drawing; using System.CodeDom; using System.Collections; using System.Reflection; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Workflow.ComponentModel.Design; using System.Workflow.ComponentModel.Compiler; #endregion [SRDescription(SR.FaultHandlerActivityDescription)] [ToolboxItem(typeof(ActivityToolboxItem))] [ToolboxBitmap(typeof(FaultHandlerActivity), "Resources.Exception.png")] [SRCategory(SR.Standard)] [Designer(typeof(FaultHandlerActivityDesigner), typeof(IDesigner))] [ActivityValidator(typeof(FaultHandlerActivityValidator))] public sealed class FaultHandlerActivity : CompositeActivity, IActivityEventListener, ITypeFilterProvider, IDynamicPropertyTypeProvider { public static readonly DependencyProperty FaultTypeProperty = DependencyProperty.Register("FaultType", typeof(Type), typeof(FaultHandlerActivity), new PropertyMetadata(DependencyPropertyOptions.Metadata)); internal static readonly DependencyProperty FaultProperty = DependencyProperty.Register("Fault", typeof(Exception), typeof(FaultHandlerActivity)); public FaultHandlerActivity() { } public FaultHandlerActivity(string name) : base(name) { } [Editor(typeof(TypeBrowserEditor), typeof(UITypeEditor))] [SRDescription(SR.ExceptionTypeDescr)] [MergableProperty(false)] public Type FaultType { get { return (Type)base.GetValue(FaultTypeProperty); } set { base.SetValue(FaultTypeProperty, value); } } [SRDescription(SR.FaultDescription)] [MergableProperty(false)] [ReadOnly(true)] public Exception Fault { get { return base.GetValue(FaultProperty) as Exception; } } internal void SetException(Exception e) { this.SetValue(FaultProperty, e); } protected internal override void Initialize(IServiceProvider provider) { if (this.Parent == null) throw new InvalidOperationException(SR.GetString(SR.Error_MustHaveParent)); base.Initialize(provider); } protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { return SequenceHelper.Execute(this, executionContext); } protected internal override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext) { return SequenceHelper.Cancel(this, executionContext); } void IActivityEventListener .OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e) { SequenceHelper.OnEvent(this, sender, e); } protected internal override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity) { SequenceHelper.OnActivityChangeRemove(this, executionContext, removedActivity); } protected internal override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext) { SequenceHelper.OnWorkflowChangesCompleted(this, executionContext); } #region ITypeFilterProvider Members bool ITypeFilterProvider.CanFilterType(Type type, bool throwOnError) { bool isAssignable = TypeProvider.IsAssignable(typeof(Exception), type); if (throwOnError && !isAssignable) throw new Exception(SR.GetString(SR.Error_ExceptionTypeNotException, type, "Type")); return isAssignable; } string ITypeFilterProvider.FilterDescription { get { return SR.GetString(SR.FilterDescription_FaultHandlerActivity); } } #endregion #region IDynamicPropertyTypeProvider Members Type IDynamicPropertyTypeProvider.GetPropertyType(IServiceProvider serviceProvider, string propertyName) { if (propertyName == null) throw new ArgumentNullException("propertyName"); Type returnType = null; if (string.Equals(propertyName, "Fault", StringComparison.Ordinal)) { returnType = this.FaultType; if (returnType == null) returnType = typeof(Exception); } return returnType; } AccessTypes IDynamicPropertyTypeProvider.GetAccessType(IServiceProvider serviceProvider, string propertyName) { if (propertyName == null) throw new ArgumentNullException("propertyName"); if (propertyName.Equals("Fault", StringComparison.Ordinal)) return AccessTypes.Write; else return AccessTypes.Read; } #endregion } internal sealed class FaultHandlerActivityValidator : CompositeActivityValidator { public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = base.Validate(manager, obj); FaultHandlerActivity exceptionHandler = obj as FaultHandlerActivity; if (exceptionHandler == null) throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(FaultHandlerActivity).FullName), "obj"); // check parent must be exception handler if (!(exceptionHandler.Parent is FaultHandlersActivity)) validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityParentNotFaultHandlersActivity), ErrorNumbers.Error_FaultHandlerActivityParentNotFaultHandlersActivity)); // validate exception property ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider == null) throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName)); // Validate the required Type property ValidationError error = null; if (exceptionHandler.FaultType == null) { error = new ValidationError(SR.GetString(SR.Error_TypePropertyInvalid, "FaultType"), ErrorNumbers.Error_PropertyNotSet); error.PropertyName = "FaultType"; validationErrors.Add(error); } else if (!TypeProvider.IsAssignable(typeof(Exception), exceptionHandler.FaultType)) { error = new ValidationError(SR.GetString(SR.Error_TypeTypeMismatch, new object[] { "FaultType", typeof(Exception).FullName }), ErrorNumbers.Error_TypeTypeMismatch); error.PropertyName = "FaultType"; validationErrors.Add(error); } // Generate a warning for unrechable code, if the catch type is all and this is not the last exception handler. /*if (exceptionHandler.FaultType == typeof(System.Exception) && exceptionHandler.Parent is FaultHandlersActivity && ((FaultHandlersActivity)exceptionHandler.Parent).Activities.IndexOf(exceptionHandler) != ((FaultHandlersActivity)exceptionHandler.Parent).Activities.Count - 1) { error = new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityAllMustBeLast), ErrorNumbers.Error_FaultHandlerActivityAllMustBeLast, true); error.PropertyName = "FaultType"; validationErrors.Add(error); }*/ if (exceptionHandler.EnabledActivities.Count == 0) validationErrors.Add(new ValidationError(SR.GetString(SR.Warning_EmptyBehaviourActivity, typeof(FaultHandlerActivity).FullName, exceptionHandler.QualifiedName), ErrorNumbers.Warning_EmptyBehaviourActivity, true)); // fault handler can not contain fault handlers, compensation handler and cancellation handler if (((ISupportAlternateFlow)exceptionHandler).AlternateFlowActivities.Count > 0) validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs)); return validationErrors; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Workflow.ComponentModel { #region Imports using System; using System.Drawing; using System.CodeDom; using System.Collections; using System.Reflection; using System.Collections.Generic; using System.ComponentModel; using System.Drawing.Design; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Workflow.ComponentModel.Design; using System.Workflow.ComponentModel.Compiler; #endregion [SRDescription(SR.FaultHandlerActivityDescription)] [ToolboxItem(typeof(ActivityToolboxItem))] [ToolboxBitmap(typeof(FaultHandlerActivity), "Resources.Exception.png")] [SRCategory(SR.Standard)] [Designer(typeof(FaultHandlerActivityDesigner), typeof(IDesigner))] [ActivityValidator(typeof(FaultHandlerActivityValidator))] public sealed class FaultHandlerActivity : CompositeActivity, IActivityEventListener , ITypeFilterProvider, IDynamicPropertyTypeProvider { public static readonly DependencyProperty FaultTypeProperty = DependencyProperty.Register("FaultType", typeof(Type), typeof(FaultHandlerActivity), new PropertyMetadata(DependencyPropertyOptions.Metadata)); internal static readonly DependencyProperty FaultProperty = DependencyProperty.Register("Fault", typeof(Exception), typeof(FaultHandlerActivity)); public FaultHandlerActivity() { } public FaultHandlerActivity(string name) : base(name) { } [Editor(typeof(TypeBrowserEditor), typeof(UITypeEditor))] [SRDescription(SR.ExceptionTypeDescr)] [MergableProperty(false)] public Type FaultType { get { return (Type)base.GetValue(FaultTypeProperty); } set { base.SetValue(FaultTypeProperty, value); } } [SRDescription(SR.FaultDescription)] [MergableProperty(false)] [ReadOnly(true)] public Exception Fault { get { return base.GetValue(FaultProperty) as Exception; } } internal void SetException(Exception e) { this.SetValue(FaultProperty, e); } protected internal override void Initialize(IServiceProvider provider) { if (this.Parent == null) throw new InvalidOperationException(SR.GetString(SR.Error_MustHaveParent)); base.Initialize(provider); } protected internal override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { return SequenceHelper.Execute(this, executionContext); } protected internal override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext) { return SequenceHelper.Cancel(this, executionContext); } void IActivityEventListener .OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs e) { SequenceHelper.OnEvent(this, sender, e); } protected internal override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity) { SequenceHelper.OnActivityChangeRemove(this, executionContext, removedActivity); } protected internal override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext) { SequenceHelper.OnWorkflowChangesCompleted(this, executionContext); } #region ITypeFilterProvider Members bool ITypeFilterProvider.CanFilterType(Type type, bool throwOnError) { bool isAssignable = TypeProvider.IsAssignable(typeof(Exception), type); if (throwOnError && !isAssignable) throw new Exception(SR.GetString(SR.Error_ExceptionTypeNotException, type, "Type")); return isAssignable; } string ITypeFilterProvider.FilterDescription { get { return SR.GetString(SR.FilterDescription_FaultHandlerActivity); } } #endregion #region IDynamicPropertyTypeProvider Members Type IDynamicPropertyTypeProvider.GetPropertyType(IServiceProvider serviceProvider, string propertyName) { if (propertyName == null) throw new ArgumentNullException("propertyName"); Type returnType = null; if (string.Equals(propertyName, "Fault", StringComparison.Ordinal)) { returnType = this.FaultType; if (returnType == null) returnType = typeof(Exception); } return returnType; } AccessTypes IDynamicPropertyTypeProvider.GetAccessType(IServiceProvider serviceProvider, string propertyName) { if (propertyName == null) throw new ArgumentNullException("propertyName"); if (propertyName.Equals("Fault", StringComparison.Ordinal)) return AccessTypes.Write; else return AccessTypes.Read; } #endregion } internal sealed class FaultHandlerActivityValidator : CompositeActivityValidator { public override ValidationErrorCollection Validate(ValidationManager manager, object obj) { ValidationErrorCollection validationErrors = base.Validate(manager, obj); FaultHandlerActivity exceptionHandler = obj as FaultHandlerActivity; if (exceptionHandler == null) throw new ArgumentException(SR.GetString(SR.Error_UnexpectedArgumentType, typeof(FaultHandlerActivity).FullName), "obj"); // check parent must be exception handler if (!(exceptionHandler.Parent is FaultHandlersActivity)) validationErrors.Add(new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityParentNotFaultHandlersActivity), ErrorNumbers.Error_FaultHandlerActivityParentNotFaultHandlersActivity)); // validate exception property ITypeProvider typeProvider = manager.GetService(typeof(ITypeProvider)) as ITypeProvider; if (typeProvider == null) throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(ITypeProvider).FullName)); // Validate the required Type property ValidationError error = null; if (exceptionHandler.FaultType == null) { error = new ValidationError(SR.GetString(SR.Error_TypePropertyInvalid, "FaultType"), ErrorNumbers.Error_PropertyNotSet); error.PropertyName = "FaultType"; validationErrors.Add(error); } else if (!TypeProvider.IsAssignable(typeof(Exception), exceptionHandler.FaultType)) { error = new ValidationError(SR.GetString(SR.Error_TypeTypeMismatch, new object[] { "FaultType", typeof(Exception).FullName }), ErrorNumbers.Error_TypeTypeMismatch); error.PropertyName = "FaultType"; validationErrors.Add(error); } // Generate a warning for unrechable code, if the catch type is all and this is not the last exception handler. /*if (exceptionHandler.FaultType == typeof(System.Exception) && exceptionHandler.Parent is FaultHandlersActivity && ((FaultHandlersActivity)exceptionHandler.Parent).Activities.IndexOf(exceptionHandler) != ((FaultHandlersActivity)exceptionHandler.Parent).Activities.Count - 1) { error = new ValidationError(SR.GetString(SR.Error_FaultHandlerActivityAllMustBeLast), ErrorNumbers.Error_FaultHandlerActivityAllMustBeLast, true); error.PropertyName = "FaultType"; validationErrors.Add(error); }*/ if (exceptionHandler.EnabledActivities.Count == 0) validationErrors.Add(new ValidationError(SR.GetString(SR.Warning_EmptyBehaviourActivity, typeof(FaultHandlerActivity).FullName, exceptionHandler.QualifiedName), ErrorNumbers.Warning_EmptyBehaviourActivity, true)); // fault handler can not contain fault handlers, compensation handler and cancellation handler if (((ISupportAlternateFlow)exceptionHandler).AlternateFlowActivities.Count > 0) validationErrors.Add(new ValidationError(SR.GetString(SR.Error_ModelingConstructsCanNotContainModelingConstructs), ErrorNumbers.Error_ModelingConstructsCanNotContainModelingConstructs)); return validationErrors; } } } // 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
- LeftCellWrapper.cs
- TextServicesLoader.cs
- FontFamilyIdentifier.cs
- TextBounds.cs
- X509SecurityTokenProvider.cs
- DataGridDetailsPresenter.cs
- CharacterBufferReference.cs
- RSAProtectedConfigurationProvider.cs
- FontDialog.cs
- M3DUtil.cs
- BrowserInteropHelper.cs
- HMACSHA384.cs
- ConfigUtil.cs
- XmlTextReaderImpl.cs
- DataServiceRequestException.cs
- ToolTipAutomationPeer.cs
- DrawingVisual.cs
- ObservableDictionary.cs
- RadioButtonBaseAdapter.cs
- AddInBase.cs
- MenuItem.cs
- DictionaryEntry.cs
- RegexCaptureCollection.cs
- CqlBlock.cs
- XmlArrayItemAttributes.cs
- StatusStrip.cs
- IsolatedStorageException.cs
- Partitioner.cs
- DataColumnPropertyDescriptor.cs
- FileVersion.cs
- COM2DataTypeToManagedDataTypeConverter.cs
- XamlDesignerSerializationManager.cs
- WorkflowOperationBehavior.cs
- Currency.cs
- cookie.cs
- FtpRequestCacheValidator.cs
- ValidationRule.cs
- PageClientProxyGenerator.cs
- EntityDesignerDataSourceView.cs
- XamlTreeBuilderBamlRecordWriter.cs
- IndicFontClient.cs
- SelectedDatesCollection.cs
- DynamicValueConverter.cs
- XmlTextReaderImplHelpers.cs
- RuleSettingsCollection.cs
- HttpCookie.cs
- SqlCommandSet.cs
- DoubleLinkList.cs
- IPHostEntry.cs
- AxHostDesigner.cs
- PageAdapter.cs
- RefType.cs
- MasterPage.cs
- SafeRegistryKey.cs
- BasicKeyConstraint.cs
- GridViewDeleteEventArgs.cs
- ExpressionVisitor.cs
- WmlLabelAdapter.cs
- AutomationIdentifier.cs
- Behavior.cs
- SystemDropShadowChrome.cs
- Attributes.cs
- MenuItemBinding.cs
- DateTimePickerDesigner.cs
- XmlUTF8TextReader.cs
- Geometry3D.cs
- NamespaceQuery.cs
- DebugControllerThread.cs
- FontConverter.cs
- ReadOnlyNameValueCollection.cs
- CachedRequestParams.cs
- WindowsPrincipal.cs
- PartialTrustHelpers.cs
- DrawingContextDrawingContextWalker.cs
- DataGridViewRowConverter.cs
- AspCompat.cs
- DataServiceKeyAttribute.cs
- _NestedSingleAsyncResult.cs
- UnsafeNativeMethods.cs
- PerformanceCounter.cs
- SchemaType.cs
- ParameterBuilder.cs
- streamingZipPartStream.cs
- RootBrowserWindow.cs
- AppearanceEditorPart.cs
- LayoutInformation.cs
- HttpAsyncResult.cs
- DocumentXmlWriter.cs
- EmptyReadOnlyDictionaryInternal.cs
- TargetPerspective.cs
- ListControlBoundActionList.cs
- NumericPagerField.cs
- OdbcConnectionStringbuilder.cs
- BaseEntityWrapper.cs
- BuildProvider.cs
- ObjectContextServiceProvider.cs
- TextEditorContextMenu.cs
- BaseCAMarshaler.cs
- DbMetaDataCollectionNames.cs
- securitycriticaldata.cs