Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / RunTime / Hosting / DefaultWorkflowLoaderService.cs / 1305376 / DefaultWorkflowLoaderService.cs
#region Imports using System; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Text; using System.IO; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Compiler; using System.Workflow.ComponentModel.Serialization; using System.Workflow.ComponentModel.Design; using System.Workflow.Runtime; #endregion namespace System.Workflow.Runtime.Hosting { public class DefaultWorkflowLoaderService : WorkflowLoaderService { protected internal override Activity CreateInstance(Type workflowType) { if (workflowType == null) throw new ArgumentNullException("workflowType"); if (!typeof(Activity).IsAssignableFrom(workflowType)) throw new ArgumentException(ExecutionStringManager.TypeMustImplementRootActivity); if (workflowType.GetConstructor(System.Type.EmptyTypes) == null) throw new ArgumentException(ExecutionStringManager.TypeMustHavePublicDefaultConstructor); return Activator.CreateInstance(workflowType) as Activity; } // This function will create a new root activity definition tree by deserializing the xoml and the rules file. protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader) { if (workflowDefinitionReader == null) throw new ArgumentNullException("workflowDefinitionReader"); Activity root = null; ValidationErrorCollection errors = new ValidationErrorCollection(); ServiceContainer serviceContainer = new ServiceContainer(); ITypeProvider typeProvider = this.Runtime.GetService(); if (typeProvider != null) serviceContainer.AddService(typeof(ITypeProvider), typeProvider); DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer); try { using (manager.CreateSession()) { WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager); root = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, workflowDefinitionReader) as Activity; if (root != null && rulesReader != null) { object rules = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, rulesReader); root.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, rules); } foreach (object error in manager.Errors) { if (error is WorkflowMarkupSerializationException) errors.Add(new ValidationError(((WorkflowMarkupSerializationException)error).Message, ErrorNumbers.Error_SerializationError)); else errors.Add(new ValidationError(error.ToString(), ErrorNumbers.Error_SerializationError)); } } } catch (Exception e) { errors.Add(new ValidationError(e.Message, ErrorNumbers.Error_SerializationError)); } if (errors.HasErrors) throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); return root; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. #region Imports using System; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using System.Xml; using System.Text; using System.IO; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Compiler; using System.Workflow.ComponentModel.Serialization; using System.Workflow.ComponentModel.Design; using System.Workflow.Runtime; #endregion namespace System.Workflow.Runtime.Hosting { public class DefaultWorkflowLoaderService : WorkflowLoaderService { protected internal override Activity CreateInstance(Type workflowType) { if (workflowType == null) throw new ArgumentNullException("workflowType"); if (!typeof(Activity).IsAssignableFrom(workflowType)) throw new ArgumentException(ExecutionStringManager.TypeMustImplementRootActivity); if (workflowType.GetConstructor(System.Type.EmptyTypes) == null) throw new ArgumentException(ExecutionStringManager.TypeMustHavePublicDefaultConstructor); return Activator.CreateInstance(workflowType) as Activity; } // This function will create a new root activity definition tree by deserializing the xoml and the rules file. protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader) { if (workflowDefinitionReader == null) throw new ArgumentNullException("workflowDefinitionReader"); Activity root = null; ValidationErrorCollection errors = new ValidationErrorCollection(); ServiceContainer serviceContainer = new ServiceContainer(); ITypeProvider typeProvider = this.Runtime.GetService (); if (typeProvider != null) serviceContainer.AddService(typeof(ITypeProvider), typeProvider); DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer); try { using (manager.CreateSession()) { WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager); root = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, workflowDefinitionReader) as Activity; if (root != null && rulesReader != null) { object rules = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, rulesReader); root.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, rules); } foreach (object error in manager.Errors) { if (error is WorkflowMarkupSerializationException) errors.Add(new ValidationError(((WorkflowMarkupSerializationException)error).Message, ErrorNumbers.Error_SerializationError)); else errors.Add(new ValidationError(error.ToString(), ErrorNumbers.Error_SerializationError)); } } } catch (Exception e) { errors.Add(new ValidationError(e.Message, ErrorNumbers.Error_SerializationError)); } if (errors.HasErrors) throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors); return root; } } } // 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
- RelatedPropertyManager.cs
- SafeFileMappingHandle.cs
- GroupQuery.cs
- SessionStateContainer.cs
- FileCodeGroup.cs
- ReliableSession.cs
- CodeNamespaceImportCollection.cs
- PageClientProxyGenerator.cs
- IOThreadScheduler.cs
- DataGridViewSelectedCellCollection.cs
- XmlILCommand.cs
- Variant.cs
- CodeNamespace.cs
- WindowsSolidBrush.cs
- OptimalTextSource.cs
- Point.cs
- MarshalByRefObject.cs
- XamlDesignerSerializationManager.cs
- MetadataPropertyAttribute.cs
- ComboBox.cs
- SecurityTokenSerializer.cs
- OrCondition.cs
- WindowsListViewItem.cs
- CapabilitiesUse.cs
- IBuiltInEvidence.cs
- FaultContractInfo.cs
- namescope.cs
- RangeValueProviderWrapper.cs
- PackageFilter.cs
- Int64Storage.cs
- EncryptedPackageFilter.cs
- SaveFileDialog.cs
- CfgArc.cs
- TextEditorTables.cs
- OneOfScalarConst.cs
- GridViewRow.cs
- Oid.cs
- AlphabeticalEnumConverter.cs
- EntityContainerAssociationSet.cs
- XamlVector3DCollectionSerializer.cs
- safemediahandle.cs
- PlainXmlDeserializer.cs
- ReadOnlyMetadataCollection.cs
- OutputCacheProfileCollection.cs
- XPathQueryGenerator.cs
- PointAnimation.cs
- ColumnCollection.cs
- HtmlFormParameterWriter.cs
- ResourceDefaultValueAttribute.cs
- RemoteX509AsymmetricSecurityKey.cs
- CodeTypeDelegate.cs
- FixedSOMImage.cs
- ContainerUIElement3D.cs
- ReverseInheritProperty.cs
- UserValidatedEventArgs.cs
- WebBrowserHelper.cs
- RemotingService.cs
- PersonalizablePropertyEntry.cs
- WsdlParser.cs
- CustomErrorsSection.cs
- SizeAnimation.cs
- BlurBitmapEffect.cs
- RegistrySecurity.cs
- DbProviderFactories.cs
- AlignmentXValidation.cs
- XmlWriterDelegator.cs
- ListItemConverter.cs
- NotSupportedException.cs
- MenuStrip.cs
- AccessDataSourceView.cs
- TableItemPatternIdentifiers.cs
- EditingScope.cs
- SqlRemoveConstantOrderBy.cs
- DockingAttribute.cs
- Stylesheet.cs
- TimerElapsedEvenArgs.cs
- StickyNoteHelper.cs
- Stack.cs
- OutOfProcStateClientManager.cs
- FlowDecisionLabelFeature.cs
- BorderGapMaskConverter.cs
- StandardToolWindows.cs
- AppDomain.cs
- WriteableBitmap.cs
- NotifyParentPropertyAttribute.cs
- HostedElements.cs
- NativeMethods.cs
- RecordManager.cs
- BaseAutoFormat.cs
- ObjectAnimationUsingKeyFrames.cs
- Block.cs
- BindingSource.cs
- HwndStylusInputProvider.cs
- LowerCaseStringConverter.cs
- OrElse.cs
- Section.cs
- ModuleElement.cs
- AuditLevel.cs
- WindowsNonControl.cs
- Coordinator.cs