// 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 <ITypeProvider>();

            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);
        }
Пример #2
0
        protected internal override Activity CreateInstance(XmlReader workflowDefinitionReader, XmlReader rulesReader)
        {
            if (workflowDefinitionReader == null)
            {
                throw new ArgumentNullException("workflowDefinitionReader");
            }
            Activity activity = null;
            ValidationErrorCollection errors    = new ValidationErrorCollection();
            ServiceContainer          container = new ServiceContainer();
            ITypeProvider             service   = base.Runtime.GetService <ITypeProvider>();

            if (service != null)
            {
                container.AddService(typeof(ITypeProvider), service);
            }
            DesignerSerializationManager manager = new DesignerSerializationManager(container);

            try
            {
                using (manager.CreateSession())
                {
                    WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager);
                    activity = new WorkflowMarkupSerializer().Deserialize(serializationManager, workflowDefinitionReader) as Activity;
                    if ((activity != null) && (rulesReader != null))
                    {
                        object obj2 = new WorkflowMarkupSerializer().Deserialize(serializationManager, rulesReader);
                        activity.SetValue(ConditionTypeConverter.DeclarativeConditionDynamicProp, obj2);
                    }
                    foreach (object obj3 in manager.Errors)
                    {
                        if (obj3 is WorkflowMarkupSerializationException)
                        {
                            errors.Add(new ValidationError(((WorkflowMarkupSerializationException)obj3).Message, 0x15b));
                        }
                        else
                        {
                            errors.Add(new ValidationError(obj3.ToString(), 0x15b));
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                errors.Add(new ValidationError(exception.Message, 0x15b));
            }
            if (errors.HasErrors)
            {
                throw new WorkflowValidationFailedException(ExecutionStringManager.WorkflowValidationFailure, errors);
            }
            return(activity);
        }
        System.Workflow.ComponentModel.Activity DeSerizalizeDefinition(byte[] workflowDefinition, byte[] ruleDefinition)
        {
            System.IO.Stream definitionStream = null;
            System.IO.Stream ruleStream       = null;

            System.Xml.XmlReader definitionReader = null;
            System.Xml.XmlReader ruleReader       = null;

            try
            {
                definitionStream          = new System.IO.MemoryStream(workflowDefinition);
                definitionStream.Position = 0;
                definitionReader          = System.Xml.XmlReader.Create(definitionStream);

                if (ruleDefinition != null)
                {
                    ruleStream          = new System.IO.MemoryStream(ruleDefinition);
                    ruleStream.Position = 0;
                    ruleReader          = System.Xml.XmlReader.Create(ruleStream);
                }

                System.Workflow.ComponentModel.Activity root = null;
                ValidationErrorCollection errors             = new ValidationErrorCollection();
                ServiceContainer          serviceContainer   = new ServiceContainer();

                if (this.typeProvider != null)
                {
                    serviceContainer.AddService(typeof(ITypeProvider), this.typeProvider);
                }

                DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer);
                try
                {
                    using (manager.CreateSession())
                    {
                        WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                        root = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, definitionReader) as System.Workflow.ComponentModel.Activity;

                        if (root != null && ruleReader != null)
                        {
                            object rules = new WorkflowMarkupSerializer().Deserialize(xomlSerializationManager, ruleReader);
                            root.SetValue(System.Workflow.Activities.Rules.RuleDefinitions.RuleDefinitionsProperty, rules);
                        }

                        foreach (object error in manager.Errors)
                        {
                            if (error is WorkflowMarkupSerializationException)
                            {
                                errors.Add(new ValidationError(((WorkflowMarkupSerializationException)error).Message, 1));
                            }
                            else
                            {
                                errors.Add(new ValidationError(error.ToString(), 1));
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    errors.Add(new ValidationError(e.Message, 1));
                }

                if (errors.HasErrors)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new WorkflowValidationFailedException(SR2.GetString(SR2.WorkflowValidationFailed), errors));
                }

                return(root);
            }
            finally
            {
                if (definitionStream != null)
                {
                    definitionStream.Dispose();
                }
                if (ruleStream != null)
                {
                    ruleStream.Dispose();
                }
            }
        }