Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.WorkflowServices / System / Workflow / Runtime / WorkflowDefinitionContext.cs / 1305376 / WorkflowDefinitionContext.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.Workflow.Runtime { using System.ComponentModel.Design; using System.Reflection; using System.Runtime; using System.ServiceModel; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Compiler; abstract class WorkflowDefinitionContext { WorkflowRuntime workflowRuntime; public abstract string ConfigurationName { get; } public abstract string WorkflowName { get; } internal protected WorkflowRuntime WorkflowRuntime { get { Fx.Assert(this.workflowRuntime != null, "Attempt to call WorkflowRuntime before Register"); return this.workflowRuntime; } } public abstract WorkflowInstance CreateWorkflow(); public abstract WorkflowInstance CreateWorkflow(Guid instanceId); public abstract Activity GetWorkflowDefinition(); internal void Register(WorkflowRuntime workflowRuntime, bool validate) { if (workflowRuntime == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowRuntime"); } this.workflowRuntime = workflowRuntime; OnRegister(); if (!this.workflowRuntime.IsStarted) { this.workflowRuntime.StartRuntime(); } if (validate) { ValidateDefinition(); } } protected static TypeProvider CreateTypeProvider(Activity rootActivity) { TypeProvider typeProvider = new TypeProvider(null); Type companionType = rootActivity.GetType(); typeProvider.SetLocalAssembly(companionType.Assembly); typeProvider.AddAssembly(companionType.Assembly); foreach (AssemblyName assemblyName in companionType.Assembly.GetReferencedAssemblies()) { Assembly referencedAssembly = null; try { referencedAssembly = Assembly.Load(assemblyName); if (referencedAssembly != null) { typeProvider.AddAssembly(referencedAssembly); } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } } if (referencedAssembly == null && assemblyName.CodeBase != null) { typeProvider.AddAssemblyReference(assemblyName.CodeBase); } } return typeProvider; } protected abstract void OnRegister(); protected abstract void OnValidate(ValidationErrorCollection errors); void ValidateDefinition() { ValidationErrorCollection errors = new ValidationErrorCollection(); Activity rootActivity = GetWorkflowDefinition(); ITypeProvider typeProvider = CreateTypeProvider(rootActivity); ServiceContainer serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(ITypeProvider), typeProvider); ValidationManager validationManager = new ValidationManager(serviceContainer); foreach (Validator validator in validationManager.GetValidators(rootActivity.GetType())) { foreach (ValidationError error in validator.Validate(validationManager, rootActivity)) { if (!error.UserData.Contains(typeof(Activity))) { error.UserData[typeof(Activity)] = rootActivity; } errors.Add(error); } } OnValidate(errors); if (errors.HasErrors) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WorkflowValidationFailedException(SR2.WorkflowValidationFailed, errors)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RecordsAffectedEventArgs.cs
- TargetControlTypeAttribute.cs
- TabControlEvent.cs
- ExtractCollection.cs
- SharedUtils.cs
- Registry.cs
- FontWeightConverter.cs
- XmlNamespaceDeclarationsAttribute.cs
- ServiceModelTimeSpanValidator.cs
- WebService.cs
- CssStyleCollection.cs
- DecoderFallbackWithFailureFlag.cs
- Utils.cs
- FileSecurity.cs
- UpdateInfo.cs
- PackWebRequest.cs
- LingerOption.cs
- MailAddressCollection.cs
- DataObjectCopyingEventArgs.cs
- RegexFCD.cs
- GPRECTF.cs
- TextEditorDragDrop.cs
- SchemaImporter.cs
- DiscoveryUtility.cs
- ViewCellSlot.cs
- PrimitiveOperationFormatter.cs
- UnionCqlBlock.cs
- SelectionChangedEventArgs.cs
- RefExpr.cs
- SegmentInfo.cs
- UnsafeNativeMethods.cs
- ExclusiveTcpListener.cs
- CompoundFileIOPermission.cs
- ExtractedStateEntry.cs
- WaitHandleCannotBeOpenedException.cs
- BrowserDefinitionCollection.cs
- DeferredReference.cs
- ScopedKnownTypes.cs
- XPathNavigatorKeyComparer.cs
- CodeIdentifier.cs
- LineInfo.cs
- SqlDataReader.cs
- UnmanagedBitmapWrapper.cs
- QueryBranchOp.cs
- DynamicRendererThreadManager.cs
- ExpandCollapseProviderWrapper.cs
- Journaling.cs
- DesignerInterfaces.cs
- SystemEvents.cs
- SizeAnimationClockResource.cs
- PropertyOverridesDialog.cs
- QuaternionIndependentAnimationStorage.cs
- WebBaseEventKeyComparer.cs
- UnaryNode.cs
- HttpVersion.cs
- TypeDelegator.cs
- XmlSchemaDocumentation.cs
- PageCache.cs
- TableLayoutColumnStyleCollection.cs
- CaseStatementProjectedSlot.cs
- Convert.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- HttpCacheVaryByContentEncodings.cs
- Avt.cs
- KeyConstraint.cs
- FileDataSourceCache.cs
- DateTimePickerDesigner.cs
- Ref.cs
- RequestCachePolicy.cs
- SafeTimerHandle.cs
- DataGridViewCellCancelEventArgs.cs
- BaseParagraph.cs
- WebBrowser.cs
- __Error.cs
- WindowsScrollBarBits.cs
- BitmapEffectInputConnector.cs
- ComPlusAuthorization.cs
- ClientTarget.cs
- UrlMappingsSection.cs
- XPathQilFactory.cs
- ParagraphResult.cs
- SplashScreenNativeMethods.cs
- StatusStrip.cs
- AnnotationResource.cs
- RadialGradientBrush.cs
- ContractMapping.cs
- EdmFunction.cs
- PrimitiveXmlSerializers.cs
- RuntimeDelegateArgument.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- TextRange.cs
- dataprotectionpermission.cs
- AlignmentYValidation.cs
- DateTimeOffsetAdapter.cs
- SrgsDocumentParser.cs
- QueuedDeliveryRequirementsMode.cs
- GridViewRowPresenter.cs
- NumberFunctions.cs
- PeerName.cs
- XmlILOptimizerVisitor.cs