コード例 #1
0
        private RuleSet getRuleSet(string content)
        {
            object objectRuleSet = null;

            // Deserialize the .rules file that contains one RuleSet
            StringReader sr = new StringReader(content);
            using (XmlTextReader reader = new XmlTextReader(sr))
            {
                WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
                objectRuleSet = serializer.Deserialize(reader);
            }

            RuleSet ruleSet = null;
            if (objectRuleSet != null && objectRuleSet is RuleSet)
            {
                ruleSet = (RuleSet)objectRuleSet;
            }
            RuleDefinitions ruleDef = null;
            if (objectRuleSet != null && objectRuleSet is RuleDefinitions)
            {
                ruleDef = (RuleDefinitions)objectRuleSet;
            }
            if (ruleDef == null && ruleSet == null && objectRuleSet != null)
            {
                // Throw an exception if file does not contain any RuleSet
                throw new InvalidOperationException("RuleSet is null, objectRuleSet.Type: " + objectRuleSet.GetType().FullName);
            }
            if (ruleDef.RuleSets != null && ruleDef.RuleSets.Count > 0)
            {
                ruleSet = ruleDef.RuleSets[0];
            }
            return ruleSet;
        }
コード例 #2
0
ファイル: Repository.cs プロジェクト: hva/RuleSetDialog
 public RuleSet Load(string filename)
 {
     using (XmlTextReader reader = new XmlTextReader(filename))
     {
         WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
         return serializer.Deserialize(reader) as RuleSet;
     }
 }
コード例 #3
0
        // �����́A���[�h���ɌĂ΂�܂�
        protected override void PerformLoad(IDesignerSerializationManager serializationManager)
        {
            base.PerformLoad(serializationManager);

            XmlReader reader = new XmlTextReader(this.xomlfile);
            WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
            Activity rootActivity = (Activity)xomlSerializer.Deserialize(reader);
            reader.Close();

            NestedActivityLoad(rootActivity);
        }
コード例 #4
0
        public RuleSet GetRuleSetFromFile(string fileName)
        {
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

            XmlTextReader rulesReader = new XmlTextReader(fileName);

            var ruleSet = (RuleSet)serializer.Deserialize(rulesReader);
            rulesReader.Close();

            return ruleSet;
        }
コード例 #5
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            XmlReader reader = new XmlTextReader(RuleFilePath);
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            RuleDefinitions ruleDef = (RuleDefinitions)serializer.Deserialize(reader);
            reader.Close();

            // ルートアクティビティを取得
            Activity root = this;
            while (root.Parent != null)
                root = root.Parent;

            for (int i = 0; i < ruleDef.RuleSets.Count; i++)
            {
                RuleSet myRuleSet = ruleDef.RuleSets[i];
                RuleEngine ruleEng = new RuleEngine(myRuleSet, root.GetType());
                ruleEng.Execute(root, executionContext);
            }

            return base.Execute(executionContext);
        }
コード例 #6
0
ファイル: RoutingTable.cs プロジェクト: spzenk/sfdocsamples
 private RuleSet GetRuleSetFromFile(string ruleSetName, string ruleSetFileName)
 {
     XmlTextReader routingTableDataFileReader = new XmlTextReader(ruleSetFileName);
     RuleDefinitions ruleDefinitions = null;
     if (routingTableDataFileReader != null)
     {
         try
         {
             WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
             ruleDefinitions = serializer.Deserialize(routingTableDataFileReader) as RuleDefinitions;
         }
         catch (Exception e)
         {
             throw new ApplicationException("The specified file is not a valid rules file \"" + ruleSetFileName + "\"", e);
         }
         if (ruleDefinitions != null)
         {
             try
             {
                 RuleSet ruleSet = ruleDefinitions.RuleSets[ruleSetName];
                 return ruleSet;
             }
             catch (Exception e)
             {
                 throw new ApplicationException("The specified rules file does not have the ruleset with name : " + ruleSetName, e);
             }
         }
         else
         {
             throw new ApplicationException("There are no rulesets inside rules file");
         }
     }
     else
     {
         throw new ApplicationException("Can't find a valid file at the specified location. " + ruleSetFileName);
     }
 }
コード例 #7
0
ファイル: RuleService.cs プロジェクト: egreene/PracticeGDVP
 public RuleSet DeserializeRules(string rules)
 {
     WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
     RuleSet ruleset = (RuleSet)serializer.Deserialize(XmlReader.Create(new StringReader(rules)));
     return ruleset;
 }
コード例 #8
0
        private static ArrayList CloneWorkflowChangeActions(ArrayList workflowChanges, Activity rootActivity)
        {
            if (workflowChanges == null)
                throw new ArgumentNullException("workflowChanges");

            if (rootActivity == null)
                throw new ArgumentNullException("rootActivity");

            string dynamicUpdateHistory = null;
            TypeProvider typeProvider = CreateTypeProvider(rootActivity);
            ServiceContainer serviceContainer = new ServiceContainer();
            serviceContainer.AddService(typeof(ITypeProvider), typeProvider);
            DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer);
            WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();

            ArrayList clonedWorkflowChanges = null;
            // serialize dynamic updates
            using (manager.CreateSession())
            {
                using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
                {
                    using (XmlWriter xmlWriter = Helpers.CreateXmlWriter(sw))
                    {
                        WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                        xomlSerializer.Serialize(xomlSerializationManager, xmlWriter, workflowChanges);
                        dynamicUpdateHistory = sw.ToString();
                    }
                }

                // deserialize those
                using (StringReader sr = new StringReader(dynamicUpdateHistory))
                {
                    using (XmlReader xmlReader = XmlReader.Create(sr))
                    {
                        WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                        clonedWorkflowChanges = xomlSerializer.Deserialize(xomlSerializationManager, xmlReader) as ArrayList;
                    }
                }
            }
            return clonedWorkflowChanges;
        }
コード例 #9
0
        private void LoadDefFromReader(SqlDataReader reader, object parameter)
        {
            if (null == reader)
                throw new ArgumentNullException("reader");

            if (!reader.Read())
                throw new ArgumentException(ExecutionStringManager.InvalidDefinitionReader);

            StringReader sr = new StringReader(reader.GetString(0));

            //Deserialize the xoml and set the root activity
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            DesignerSerializationManager serializationManager = new DesignerSerializationManager();
            IList errors = null;
            try
            {
                using (serializationManager.CreateSession())
                {
                    using (XmlReader xmlReader = XmlReader.Create(sr))
                    {
                        _def = serializer.Deserialize(serializationManager, xmlReader) as Activity;
                        errors = serializationManager.Errors;
                    }
                }
            }
            finally
            {
                sr.Close();
            }

            if ((null == _def) || ((null != errors) && (errors.Count > 0)))
                throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);
        }
 protected internal override bool ApplyTo(Activity rootActivity)
 {
     if (rootActivity == null)
     {
         throw new ArgumentNullException("rootActivity");
     }
     if (!(rootActivity is CompositeActivity))
     {
         throw new ArgumentException(SR.GetString("Error_RootActivityTypeInvalid"), "rootActivity");
     }
     CompositeActivity compositeActivity = rootActivity.TraverseDottedPathFromRoot(base.OwnerActivityDottedPath) as CompositeActivity;
     if (compositeActivity == null)
     {
         return false;
     }
     compositeActivity.DynamicUpdateMode = true;
     CompositeActivity parent = this.addedActivity.Parent;
     try
     {
         this.addedActivity.SetParent(compositeActivity);
         Activity addedActivity = this.addedActivity;
         if (!this.addedActivity.DesignMode)
         {
             addedActivity = this.addedActivity.Clone();
         }
         else
         {
             TypeProvider serviceInstance = WorkflowChanges.CreateTypeProvider(rootActivity);
             ServiceContainer provider = new ServiceContainer();
             provider.AddService(typeof(ITypeProvider), serviceInstance);
             DesignerSerializationManager manager = new DesignerSerializationManager(provider);
             WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
             string s = string.Empty;
             using (manager.CreateSession())
             {
                 using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
                 {
                     using (XmlWriter writer2 = Helpers.CreateXmlWriter(writer))
                     {
                         WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager);
                         serializer.Serialize(serializationManager, writer2, this.addedActivity);
                         s = writer.ToString();
                     }
                 }
                 using (StringReader reader = new StringReader(s))
                 {
                     using (XmlReader reader2 = XmlReader.Create(reader))
                     {
                         WorkflowMarkupSerializationManager manager3 = new WorkflowMarkupSerializationManager(manager);
                         addedActivity = serializer.Deserialize(manager3, reader2) as Activity;
                     }
                 }
             }
             if (addedActivity == null)
             {
                 throw new InvalidOperationException(SR.GetString("Error_ApplyDynamicChangeFailed"));
             }
         }
         if (compositeActivity.WorkflowCoreRuntime != null)
         {
             ((IDependencyObjectAccessor) addedActivity).InitializeInstanceForRuntime(compositeActivity.WorkflowCoreRuntime);
         }
         addedActivity.SetParent(null);
         compositeActivity.Activities.Insert(this.index, addedActivity);
     }
     finally
     {
         this.addedActivity.SetParent(parent);
         compositeActivity.DynamicUpdateMode = false;
     }
     return true;
 }
コード例 #11
0
ファイル: Loader.cs プロジェクト: ssickles/archive
        protected override void PerformLoad(IDesignerSerializationManager serializationManager)
        {
            IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
            Activity rootActivity = null;
            //First see if we have a workflow type
            if (WorkflowType != null)
            {
                rootActivity = (Activity)Activator.CreateInstance(WorkflowType);
            }
            else
            {
                // Create a text reader out of the doc data, and ask
                TextReader reader = new StringReader(this.xamlValue);
                try
                {
                    using (XmlReader xmlReader = XmlReader.Create(reader))
                    {
                        WorkflowMarkupSerializer xamlSerializer = new WorkflowMarkupSerializer();
                        rootActivity = xamlSerializer.Deserialize(xmlReader) as Activity;
                    }
                }
                finally
                {
                    reader.Close();
                }
            }

            if (rootActivity != null && designerHost != null)
            {
                AddObjectGraphToDesignerHost(designerHost, rootActivity);
            }
        }
コード例 #12
0
ファイル: WorkflowLoader.cs プロジェクト: ssickles/archive
        private Activity DeserializeFromMarkup(String fileName)
        {
            Activity workflow = null;

            //construct a serialization manager.
            DesignerSerializationManager dsm
                = new DesignerSerializationManager();
            using (dsm.CreateSession())
            {
                using (XmlReader xmlReader
                    = XmlReader.Create(fileName))
                {
                    //deserialize the workflow from the XmlReader
                    WorkflowMarkupSerializer markupSerializer
                        = new WorkflowMarkupSerializer();
                    workflow = markupSerializer.Deserialize(
                        dsm, xmlReader) as Activity;

                    if (dsm.Errors.Count > 0)
                    {
                        WorkflowMarkupSerializationException error
                            = dsm.Errors[0]
                              as WorkflowMarkupSerializationException;
                        throw error;
                    }
                }

                //deserialize a .rules file is one exists
                String rulesFileName = GetRulesFileName(fileName);
                if (File.Exists(rulesFileName))
                {
                    //read the .rules file
                    using (XmlReader xmlReader
                        = XmlReader.Create(rulesFileName))
                    {
                        WorkflowMarkupSerializer markupSerializer
                            = new WorkflowMarkupSerializer();
                        //deserialize the rule definitions
                        RuleDefinitions ruleDefinitions
                            = markupSerializer.Deserialize(dsm, xmlReader)
                                as RuleDefinitions;
                        if (ruleDefinitions != null)
                        {
                            //add the rules definitions to the workflow
                            workflow.SetValue(
                                RuleDefinitions.RuleDefinitionsProperty,
                                ruleDefinitions);
                        }
                    }
                }
            }
            return workflow;
        }
コード例 #13
0
        void viewRuleSetButton_Click(object sender, RoutedEventArgs e)
        {
            // get the rulesFilePath property
            object rulesFilePath = ModelItem.Properties["RulesFilePath"].Value;
            rulesFilePath = ((ModelItem)rulesFilePath).GetCurrentValue();

            // correct the rules file path (in case is a relative path)
            string correctedRulesFilePath = GetRulesFilePath((string)rulesFilePath);

            // verify that RulesFilePath property has been configured
            if (rulesFilePath == null || !(rulesFilePath is string))
            {
                System.Windows.MessageBox.Show("Rules File Path needs to be configured before viewing or editing the rules");
                return;
            }
            else if (!File.Exists(correctedRulesFilePath))
            {
                System.Windows.MessageBox.Show(string.Format("Rules File Path provided not found ({0})", correctedRulesFilePath));
                return;
            }

            // verify that RuleSetName property has been configured
            object ruleSetName = ModelItem.Properties["RuleSetName"].Value;
            ruleSetName = ((ModelItem)ruleSetName).GetCurrentValue();
            if (ruleSetName == null)
            {
                System.Windows.MessageBox.Show("RuleSet Name needs to be configured before viewing or editing the rules");
                return;
            }

            // verify that TargetObject property has been configured
            object targetObject = ModelItem.Properties["TargetObject"].Value;
            targetObject = ((ModelItem)targetObject).GetCurrentValue();
            if (targetObject == null)
            {
                System.Windows.MessageBox.Show("TargetObject needs to be configured before viewing or editing the rules");
                return;
            }

            // verify that target object is correctly configured
            InArgument targetObjArg = targetObject as InArgument;
            if (targetObjArg == null)
            {
                System.Windows.MessageBox.Show("Invalid target object");
                return;
            }

            // open the ruleset editor
            Type targetObjectType = targetObjArg.ArgumentType;
            WorkflowMarkupSerializer ser = new WorkflowMarkupSerializer();
            RuleDefinitions ruleDefs = ser.Deserialize(new System.Xml.XmlTextReader((string)correctedRulesFilePath)) as RuleDefinitions;
            RuleSet ruleSet = ruleDefs.RuleSets[(string)ruleSetName];

            // popup the dialog for viewing the rules
            RuleSetDialog ruleSetDialog = new RuleSetDialog(targetObjectType, null, ruleSet);
            DialogResult result = ruleSetDialog.ShowDialog();

            // update if they changed the Rules
            if (result == DialogResult.OK) //If OK was pressed
            {
                for (int index = 0; index < ruleDefs.RuleSets.Count; index++)
                {
                    if (ruleDefs.RuleSets[index].Name == (string)ruleSetName)
                    {
                        ruleDefs.RuleSets[index] = ruleSetDialog.RuleSet;
                        break;
                    }
                }
                try
                {
                    ser.Serialize(new System.Xml.XmlTextWriter(correctedRulesFilePath, null), ruleDefs);
                }
                catch (UnauthorizedAccessException)
                {
                    // File does not have write access. Make a local copy so user changes are not lost
                    FileInfo fileInfo = new FileInfo(correctedRulesFilePath);
                    // create local file by adding a random suffix to original filename
                    string localFileCopy = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.')) + new Random().Next() + fileInfo.Extension;
                    ser.Serialize(new System.Xml.XmlTextWriter((string)localFileCopy, null), ruleDefs);
                    System.Windows.MessageBox.Show("Rules file is not writeable. Created copy of your changes in " + localFileCopy);
                }
            }
        }
コード例 #14
0
ファイル: Program.cs プロジェクト: tian1ll1/WPF_Examples
        static void Main(string[] args)
        {
            // load the ruleset from the ruleset file
            string rulesFilePath = ConfigurationManager.AppSettings["rulesFilePath"];
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            XmlTextReader reader = new XmlTextReader(rulesFilePath);
            RuleDefinitions rules = serializer.Deserialize(reader) as RuleDefinitions;
            RuleSet ruleSet = rules.RuleSets[0];

            // create orders
            Variable<Order> order1 = new Variable<Order>() { Name = "Order1", Default = new LambdaValue<Order>(c => new Order(650, CustomerType.Residential)) };
            Variable<Order> order2 = new Variable<Order>() { Name = "Order2", Default = new LambdaValue<Order>(c => new Order(15000, CustomerType.Business)) };
            Variable<Order> order3 = new Variable<Order>() { Name = "Order3", Default = new LambdaValue<Order>(c => new Order(650, CustomerType.Business)) };

            // create and run workflow instance
            WorkflowInvoker.Invoke(
                new Sequence
                {
                    Variables = { order1, order2, order3 },
                    Activities =
                    {
                        //---------------------------------------
                        // Rule: Order > 500 and CustomerType is Residential
                        //---------------------------------------
                        new WriteLine { Text = new InArgument<string>("OrderValue > 500 and is Residential customer => discount = 5%") },
                        new WriteLine
                        {
                            Text = new InArgument<string>(c => string.Format("   Before Evaluation: {0}", order1.Get(c).ToString()))
                        },
                        new Policy4<Order>
                        {
                            RuleSet = ruleSet,
                            Input = new InArgument<Order>(order1),
                            Result = new OutArgument<Order>(order1)
                        },
                        new WriteLine
                        {
                            Text = new InArgument<string>(c => string.Format("   After Evaluation: {0}", order1.Get(c).ToString()))
                        },

                        //---------------------------------------
                        // Rule: Order > 10000 and CustomerType is Businesss
                        //---------------------------------------
                        new WriteLine(),
                        new WriteLine { Text = new InArgument<string>("OrderValue > 10000 and is Business customer => discount = 10%") },
                        new WriteLine
                        {
                            Text = new InArgument<string>(c => string.Format("   Before Evaluation: {0}", order2.Get(c).ToString()))
                        },
                        new Policy4<Order>
                        {
                            RuleSet = ruleSet,
                            Input = new InArgument<Order>(order2),
                            Result = new OutArgument<Order>(order2)
                        },
                        new WriteLine
                        {
                            Text = new InArgument<string>(c => string.Format("   After Evaluation: {0}", order2.Get(c).ToString()))
                        },

                        //---------------------------------------
                        // No Rules Applied
                        //---------------------------------------
                        new WriteLine(),
                        new WriteLine { Text = new InArgument<string>("This order does not match any of the rules above") },
                        new WriteLine
                        {
                            Text = new InArgument<string>(c => string.Format("   Before Evaluation: {0}", order3.Get(c).ToString()))
                        },
                        new Policy4<Order>
                        {
                            RuleSet = ruleSet,
                            Input = new InArgument<Order>(order3),
                            Result = new OutArgument<Order>(order3)
                        },
                        new WriteLine
                        {
                            Text = new InArgument<string>(c => string.Format("   After Evaluation: {0}", order3.Get(c).ToString()))
                        }

                    }
                }
            );

            // wait until the user press a key
            Console.WriteLine("Press any key to exit...");
            Console.Read();
        }
コード例 #15
0
ファイル: RulesUtil.cs プロジェクト: huamouse/Taoqi
		public static RuleSet Deserialize(string sXOML)
		{
			RuleSet rules = null;
			using ( StringReader stm = new StringReader(sXOML) )
			{
				using ( XmlTextReader xrdr = new XmlTextReader(stm) )
				{
					WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
					rules = (RuleSet) serializer.Deserialize(xrdr);
				}
			}
			return rules;
		}
コード例 #16
0
        private void LoadWorkflowChangeEventArgsFromReader(SqlDataReader reader, object parameter)
        {
            if (null == reader)
                throw new ArgumentNullException("reader");

            if (null == parameter)
                throw new ArgumentNullException("parameter");

            WorkflowTrackingRecord record = parameter as WorkflowTrackingRecord;

            if (null == record)
                throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsParameter, "parameter");

            if (!reader.Read())
                throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader);

            StringReader sr = new StringReader(reader.GetString(0));

            //Deserialize the xoml and set the root activity
            Activity def = null;
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            DesignerSerializationManager serializationManager = new DesignerSerializationManager();
            IList errors = null;
            try
            {
                using (serializationManager.CreateSession())
                {
                    using (XmlReader xmlReader = XmlReader.Create(sr))
                    {
                        def = serializer.Deserialize(serializationManager, xmlReader) as Activity;
                        errors = serializationManager.Errors;
                    }
                }
            }
            finally
            {
                sr.Close();
            }

            if ((null == def) || ((null != errors) && (errors.Count > 0)))
                throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);

            if (!reader.NextResult())
                throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader);
            //
            // There is a result set that we don't care about for this scenario, skip it
            if (!reader.NextResult())
                throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader);

            List<WorkflowChangeAction> actions = new List<WorkflowChangeAction>();
            DateTime currDT = DateTime.MinValue;
            int currEventOrder = -1;
            int currOrder = -1;

            while (reader.Read())
            {
                DateTime dt = reader.GetDateTime(1);
                int eventOrder = reader.GetInt32(2);
                int order = reader.GetInt32(3);
                //
                // Build temp lists as we read the results but
                // only save the last set of change actions
                if (dt > currDT && eventOrder > currEventOrder)
                {
                    currEventOrder = eventOrder;
                    currOrder = order;
                    currDT = dt;
                    actions = new List<WorkflowChangeAction>();
                }

                using (sr = new StringReader(reader.GetString(0)))
                {
                    using (serializationManager.CreateSession())
                    {
                        using (XmlReader xmlReader = XmlReader.Create(sr))
                        {
                            ActivityChangeAction aAction = serializer.Deserialize(serializationManager, xmlReader) as ActivityChangeAction;

                            errors = serializationManager.Errors;
                            if (null == aAction)
                                throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);

                            actions.Add(aAction);
                            aAction.ApplyTo(def);
                        }
                    }
                }
            }

            record.EventArgs = new TrackingWorkflowChangedEventArgs(actions, def);
        }
コード例 #17
0
ファイル: FLDesignerLoader.cs プロジェクト: san90279/UK_OAS
        protected override void PerformLoad(IDesignerSerializationManager serializationManager)
        {
            base.PerformLoad(serializationManager);

            if ((string.IsNullOrEmpty(_fileName) || !File.Exists(_fileName)) && _stream == null)
            {
                return;
            }

            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            XmlReader reader = null;
            if (!string.IsNullOrEmpty(_fileName))
            {
                reader = XmlReader.Create(_fileName);
            }
            else
            {
                reader = XmlReader.Create(_stream);
            }

            object deserializedObject = serializer.Deserialize(serializationManager, reader);
            CompositeActivity rootActivity = deserializedObject as CompositeActivity;

            reader.Close();

            _workflow.Description = rootActivity.Description;
            ((IFLRootActivity)_workflow).TableName = ((IFLRootActivity)rootActivity).TableName;
            ((IFLRootActivity)_workflow).EEPAlias = ((IFLRootActivity)rootActivity).EEPAlias;
            ((IFLRootActivity)_workflow).OrgKind = ((IFLRootActivity)rootActivity).OrgKind;
            ((IFLRootActivity)_workflow).Keys = ((IFLRootActivity)rootActivity).Keys;
            ((IFLRootActivity)_workflow).PresentFields = ((IFLRootActivity)rootActivity).PresentFields;
            ((IFLRootActivity)_workflow).FormName = ((IFLRootActivity)rootActivity).FormName;
            ((IFLRootActivity)_workflow).WebFormName = ((IFLRootActivity)rootActivity).WebFormName;
            ((IFLRootActivity)_workflow).ExpTime = ((IFLRootActivity)rootActivity).ExpTime;
            ((IFLRootActivity)_workflow).UrgentTime = ((IFLRootActivity)rootActivity).UrgentTime;
            ((IFLRootActivity)_workflow).ExpTimeField = ((IFLRootActivity)rootActivity).ExpTimeField;
            ((IFLRootActivity)_workflow).TimeUnit = ((IFLRootActivity)rootActivity).TimeUnit;
            ((IFLRootActivity)_workflow).NotifySendMail = ((IFLRootActivity)rootActivity).NotifySendMail;
            ((IFLRootActivity)_workflow).SkipForSameUser = ((IFLRootActivity)rootActivity).SkipForSameUser;
            ((IFLRootActivity)_workflow).RejectProcedure = ((IFLRootActivity)rootActivity).RejectProcedure;
            ((IFLRootActivity)_workflow).BodyField = ((IFLRootActivity)rootActivity).BodyField;
            //((ISupportSetConnectionString)_workflow).EEPAlias = ((ISupportSetConnectionString)rootActivity).EEPAlias;
            //((ISupportSetConnectionString)_workflow).ConnectionType = ((ISupportSetConnectionString)rootActivity).ConnectionType;
            ((ISupportSetClientDll)_workflow).ClientDll = ((ISupportSetClientDll)rootActivity).ClientDll;

            //List<string> names = new List<string>();
            //foreach (Activity acitivity in rootActivity.Activities)
            //{
            //    names.Add(acitivity.QualifiedName);
            //}

            //foreach (string name in names)
            //{
            //    Activity activity = rootActivity.GetActivityByName(name);
            //    rootActivity.Activities.Remove(activity);
            //    _workflow.Activities.Add(activity);
            //    AddActivityToDesigner(activity);
            //}

            List<Activity> activities = new List<Activity>();
            foreach (Activity activity in rootActivity.Activities)
            {
                activities.Add(activity);
            }

            foreach (Activity activity in activities)
            {
                rootActivity.Activities.Remove(activity);
                _workflow.Activities.Add(activity);
                AddActivityToDesigner(activity);
            }
        }
コード例 #18
0
        private void LoadChangesFromReader(SqlDataReader reader, object parameter)
        {
            if (!reader.Read())
                return;
            //
            // Reset the min to the most recent change event
            DateTime tmpDT = _changesMinDT;
            if (!reader.IsDBNull(0))
                tmpDT = reader.GetDateTime(0);

            if (reader.NextResult())
            {
                WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
                DesignerSerializationManager serializationManager = new DesignerSerializationManager();
                while (reader.Read())
                {
                    IList errors = null;
                    using (StringReader sr = new StringReader(reader.GetString(0)))
                    {
                        using (serializationManager.CreateSession())
                        {
                            using (XmlReader xmlReader = XmlReader.Create(sr))
                            {
                                ActivityChangeAction aAction = serializer.Deserialize(serializationManager, xmlReader) as ActivityChangeAction;

                                errors = serializationManager.Errors;
                                if (null != aAction)
                                    aAction.ApplyTo(_def);
                                else
                                    throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);
                            }
                        }
                    }
                }
            }

            if (tmpDT > _changesMinDT)
            {
                _changed = true;
                _changesMinDT = tmpDT;
            }
        }
 private void LoadChangesFromReader(SqlDataReader reader, object parameter)
 {
     if (reader.Read())
     {
         DateTime dateTime = this._changesMinDT;
         if (!reader.IsDBNull(0))
         {
             dateTime = reader.GetDateTime(0);
         }
         if (reader.NextResult())
         {
             WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
             DesignerSerializationManager serializationManager = new DesignerSerializationManager();
             while (reader.Read())
             {
                 using (StringReader reader2 = new StringReader(reader.GetString(0)))
                 {
                     using (serializationManager.CreateSession())
                     {
                         using (XmlReader reader3 = XmlReader.Create(reader2))
                         {
                             ActivityChangeAction action = serializer.Deserialize(serializationManager, reader3) as ActivityChangeAction;
                             IList errors = serializationManager.Errors;
                             if (action == null)
                             {
                                 throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);
                             }
                             action.ApplyTo(this._def);
                             continue;
                         }
                     }
                 }
             }
         }
         if (dateTime > this._changesMinDT)
         {
             this._changed = true;
             this._changesMinDT = dateTime;
         }
     }
 }
コード例 #20
0
        protected internal override bool ApplyTo(Activity rootActivity)
        {
            if (rootActivity == null)
                throw new ArgumentNullException("rootActivity");
            if (!(rootActivity is CompositeActivity))
                throw new ArgumentException(SR.GetString(SR.Error_RootActivityTypeInvalid), "rootActivity");

            CompositeActivity ownerActivity = rootActivity.TraverseDottedPathFromRoot(this.OwnerActivityDottedPath) as CompositeActivity;
            if (ownerActivity == null)
                return false;

            // !!!work around: 
            ownerActivity.DynamicUpdateMode = true;
            CompositeActivity addedActivityOwner = this.addedActivity.Parent;
            try
            {
                this.addedActivity.SetParent(ownerActivity);
                Activity clonedAddedActivity = this.addedActivity;
                if (!this.addedActivity.DesignMode)
                    clonedAddedActivity = this.addedActivity.Clone();
                // We need to serialize and deserialize in order to clone during design mode
                else
                {
                    TypeProvider typeProvider = WorkflowChanges.CreateTypeProvider(rootActivity);
                    ServiceContainer serviceContainer = new ServiceContainer();
                    serviceContainer.AddService(typeof(ITypeProvider), typeProvider);
                    DesignerSerializationManager manager = new DesignerSerializationManager(serviceContainer);
                    WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
                    string addedActivityText = string.Empty;
                    // serialize dynamic updates
                    using (manager.CreateSession())
                    {
                        using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
                        {
                            using (XmlWriter xmlWriter = Helpers.CreateXmlWriter(sw))
                            {
                                WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                                xomlSerializer.Serialize(xomlSerializationManager, xmlWriter, this.addedActivity);
                                addedActivityText = sw.ToString();
                            }
                        }

                        // deserialize those
                        using (StringReader sr = new StringReader(addedActivityText))
                        {
                            using (XmlReader xmlReader = XmlReader.Create(sr))
                            {
                                WorkflowMarkupSerializationManager xomlSerializationManager = new WorkflowMarkupSerializationManager(manager);
                                clonedAddedActivity = xomlSerializer.Deserialize(xomlSerializationManager, xmlReader) as Activity;
                            }
                        }
                    }
                    if (clonedAddedActivity == null)
                        throw new InvalidOperationException(SR.GetString(SR.Error_ApplyDynamicChangeFailed));
                }
                if (ownerActivity.WorkflowCoreRuntime != null)
                    ((IDependencyObjectAccessor)clonedAddedActivity).InitializeInstanceForRuntime(ownerActivity.WorkflowCoreRuntime);

                clonedAddedActivity.SetParent(null);
                ownerActivity.Activities.Insert(this.index, clonedAddedActivity);
            }
            finally
            {
                this.addedActivity.SetParent(addedActivityOwner);
                ownerActivity.DynamicUpdateMode = false;
            }
            return true;
        }
 private void LoadDefFromReader(SqlDataReader reader, object parameter)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (!reader.Read())
     {
         throw new ArgumentException(ExecutionStringManager.InvalidDefinitionReader);
     }
     StringReader input = new StringReader(reader.GetString(0));
     WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
     DesignerSerializationManager serializationManager = new DesignerSerializationManager();
     IList errors = null;
     try
     {
         using (serializationManager.CreateSession())
         {
             using (XmlReader reader3 = XmlReader.Create(input))
             {
                 this._def = serializer.Deserialize(serializationManager, reader3) as Activity;
                 errors = serializationManager.Errors;
             }
         }
     }
     finally
     {
         input.Close();
     }
     if ((this._def == null) || ((errors != null) && (errors.Count > 0)))
     {
         throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);
     }
 }
コード例 #22
0
 private static ArrayList CloneWorkflowChangeActions(ArrayList workflowChanges, Activity rootActivity)
 {
     if (workflowChanges == null)
     {
         throw new ArgumentNullException("workflowChanges");
     }
     if (rootActivity == null)
     {
         throw new ArgumentNullException("rootActivity");
     }
     string s = null;
     TypeProvider serviceInstance = CreateTypeProvider(rootActivity);
     ServiceContainer provider = new ServiceContainer();
     provider.AddService(typeof(ITypeProvider), serviceInstance);
     DesignerSerializationManager manager = new DesignerSerializationManager(provider);
     WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
     using (manager.CreateSession())
     {
         using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
         {
             using (XmlWriter writer2 = Helpers.CreateXmlWriter(writer))
             {
                 WorkflowMarkupSerializationManager serializationManager = new WorkflowMarkupSerializationManager(manager);
                 serializer.Serialize(serializationManager, writer2, workflowChanges);
                 s = writer.ToString();
             }
         }
         using (StringReader reader = new StringReader(s))
         {
             using (XmlReader reader2 = XmlReader.Create(reader))
             {
                 WorkflowMarkupSerializationManager manager3 = new WorkflowMarkupSerializationManager(manager);
                 return (serializer.Deserialize(manager3, reader2) as ArrayList);
             }
         }
     }
 }
 private void LoadWorkflowChangeEventArgsFromReader(SqlDataReader reader, object parameter)
 {
     if (reader == null)
     {
         throw new ArgumentNullException("reader");
     }
     if (parameter == null)
     {
         throw new ArgumentNullException("parameter");
     }
     WorkflowTrackingRecord record = parameter as WorkflowTrackingRecord;
     if (record == null)
     {
         throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsParameter, "parameter");
     }
     if (!reader.Read())
     {
         throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader);
     }
     StringReader input = new StringReader(reader.GetString(0));
     Activity rootActivity = null;
     WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
     DesignerSerializationManager serializationManager = new DesignerSerializationManager();
     IList errors = null;
     try
     {
         using (serializationManager.CreateSession())
         {
             using (XmlReader reader3 = XmlReader.Create(input))
             {
                 rootActivity = serializer.Deserialize(serializationManager, reader3) as Activity;
                 errors = serializationManager.Errors;
             }
         }
     }
     finally
     {
         input.Close();
     }
     if ((rootActivity == null) || ((errors != null) && (errors.Count > 0)))
     {
         throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);
     }
     if (!reader.NextResult())
     {
         throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader);
     }
     if (!reader.NextResult())
     {
         throw new ArgumentException(ExecutionStringManager.InvalidWorkflowChangeEventArgsReader);
     }
     List<WorkflowChangeAction> changes = new List<WorkflowChangeAction>();
     DateTime minValue = DateTime.MinValue;
     int num = -1;
     while (reader.Read())
     {
         DateTime dateTime = reader.GetDateTime(1);
         int num2 = reader.GetInt32(2);
         int num3 = reader.GetInt32(3);
         if ((dateTime > minValue) && (num2 > num))
         {
             num = num2;
             minValue = dateTime;
             changes = new List<WorkflowChangeAction>();
         }
         using (input = new StringReader(reader.GetString(0)))
         {
             using (serializationManager.CreateSession())
             {
                 using (XmlReader reader4 = XmlReader.Create(input))
                 {
                     ActivityChangeAction item = serializer.Deserialize(serializationManager, reader4) as ActivityChangeAction;
                     errors = serializationManager.Errors;
                     if (item == null)
                     {
                         throw new WorkflowMarkupSerializationException(ExecutionStringManager.WorkflowMarkupDeserializationError);
                     }
                     changes.Add(item);
                     item.ApplyTo(rootActivity);
                 }
             }
             continue;
         }
     }
     record.EventArgs = new TrackingWorkflowChangedEventArgs(changes, rootActivity);
 }
コード例 #24
0
        public void GetRuleDefinitions()
        {
            var serializer = new WorkflowMarkupSerializer();
            _ruleDefinitions = new RuleDefinitions();

            Parallel.For(0, _rulesStream.Count, streamCounter =>
                {
                    using (XmlReader reader = new XmlTextReader(_rulesStream[streamCounter]))
                    {
                        var temp = serializer.Deserialize(reader) as RuleDefinitions;

                        if (temp == null) return;

                        if (temp.RuleSets != null)
                        {
                            for (int i=0; i < temp.RuleSets.Count; i++)
                            {
                                _ruleDefinitions.RuleSets.Add(temp.RuleSets[i]);
                            }
                        }
                        if (temp.Conditions != null)
                        {
                            for (int i = 0; i < temp.Conditions.Count; i++)
                            {
                                _ruleDefinitions.Conditions.Add(temp.Conditions[i]);
                            }
                        }
                    }
                });
        }
コード例 #25
0
ファイル: FileRuleSetManager.cs プロジェクト: wra222/testgit
        private RuleDefinitions getRuleDef(string filename)
        {
            object objectRuleSet = null;

            // Deserialize the .rules file that contains one RuleSet
            using (XmlTextReader reader = new XmlTextReader(filename))
            {
                WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
                objectRuleSet = serializer.Deserialize(reader);
            }

            RuleDefinitions ruleDef = null;
            if (objectRuleSet != null && objectRuleSet is RuleDefinitions)
            {
                ruleDef = (RuleDefinitions)objectRuleSet;
            }
            if (ruleDef == null && objectRuleSet != null)
            {
                // Throw an exception if file does not contain any RuleSet
                throw new InvalidOperationException("RuleSets is null, objectRuleSets.Type: " + objectRuleSet.GetType().FullName);
            }
            return ruleDef;
        }