예제 #1
0
        protected override bool ApplyTo(Activity rootActivity)
        {
            if (rootActivity == null)
            {
                return(false);
            }

            RuleDefinitions rules = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if (rules == null || rules.RuleSets == null)
            {
                return(false);
            }

            //
            bool setRuntimeMode = false;

            if (rules.RuleSets.RuntimeMode)
            {
                rules.RuleSets.RuntimeMode = false;
                setRuntimeMode             = true;
            }
            try
            {
                return(rules.RuleSets.Remove(ruleset.Name));
            }
            finally
            {
                if (setRuntimeMode)
                {
                    rules.RuleSets.RuntimeMode = true;
                }
            }
        }
예제 #2
0
        protected override bool ApplyTo(Activity rootActivity)
        {
            if (rootActivity == null)
            {
                return(false);
            }
            RuleDefinitions definitions = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if (definitions == null)
            {
                definitions = new RuleDefinitions();
                rootActivity.SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions);
            }
            bool flag = false;

            if (definitions.Conditions.RuntimeMode)
            {
                definitions.Conditions.RuntimeMode = false;
                flag = true;
            }
            try
            {
                definitions.Conditions.Add(this.ConditionDefinition);
            }
            finally
            {
                if (flag)
                {
                    definitions.Conditions.RuntimeMode = true;
                }
            }
            return(true);
        }
예제 #3
0
        internal static void Flush_Rules_DT(IServiceProvider serviceProvider, Activity activity)
        {
            RuleDefinitions rules = (RuleDefinitions)activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);

            if (rules != null)
            {
                WorkflowDesignerLoader loader = (WorkflowDesignerLoader)serviceProvider.GetService(typeof(WorkflowDesignerLoader));
                if (loader != null)
                {
                    string rulesFileName = string.Empty;
                    if (!string.IsNullOrEmpty(loader.FileName))
                    {
                        rulesFileName = Path.Combine(Path.GetDirectoryName(loader.FileName), Path.GetFileNameWithoutExtension(loader.FileName));
                    }
                    rulesFileName += ".rules";

                    using (TextWriter ruleFileWriter = loader.GetFileWriter(rulesFileName))
                    {
                        if (ruleFileWriter != null)
                        {
                            using (XmlWriter xmlWriter = Helpers.CreateXmlWriter(ruleFileWriter))
                            {
                                DesignerSerializationManager designerSerializationManager = new DesignerSerializationManager(serviceProvider);
                                using (designerSerializationManager.CreateSession())
                                {
                                    new WorkflowMarkupSerializer().Serialize(designerSerializationManager, xmlWriter, rules);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        internal static object OnGetRuleConditions(DependencyObject dependencyObject)
        {
            if (dependencyObject == null)
            {
                throw new ArgumentNullException("dependencyObject");
            }

            RuleDefinitions rules = dependencyObject.GetValueBase(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if (rules != null)
            {
                return(rules);
            }

            Activity rootActivity = dependencyObject as Activity;

            if (rootActivity.Parent == null)
            {
                rules = ConditionHelper.GetRuleDefinitionsFromManifest(rootActivity.GetType());
                if (rules != null)
                {
                    dependencyObject.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);
                }
            }
            return(rules);
        }
        internal static void Flush_Rules_DT(IServiceProvider serviceProvider, Activity activity)
        {
            RuleDefinitions definitions = (RuleDefinitions)activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);

            if (definitions != null)
            {
                WorkflowDesignerLoader service = (WorkflowDesignerLoader)serviceProvider.GetService(typeof(WorkflowDesignerLoader));
                if (service != null)
                {
                    string filePath = string.Empty;
                    if (!string.IsNullOrEmpty(service.FileName))
                    {
                        filePath = Path.Combine(Path.GetDirectoryName(service.FileName), Path.GetFileNameWithoutExtension(service.FileName));
                    }
                    filePath = filePath + ".rules";
                    using (TextWriter writer = service.GetFileWriter(filePath))
                    {
                        if (writer != null)
                        {
                            using (XmlWriter writer2 = System.Workflow.Activities.Common.Helpers.CreateXmlWriter(writer))
                            {
                                DesignerSerializationManager serializationManager = new DesignerSerializationManager(serviceProvider);
                                using (serializationManager.CreateSession())
                                {
                                    new WorkflowMarkupSerializer().Serialize(serializationManager, writer2, definitions);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #6
0
        public IList <WorkflowChangeAction> Diff(object originalDefinition, object changedDefinition)
        {
            RuleDefinitions originalRules = originalDefinition as RuleDefinitions;
            RuleDefinitions changedRules  = changedDefinition as RuleDefinitions;

            if ((originalRules == null) || (changedRules == null))
            {
                return(new List <WorkflowChangeAction>());
            }

            IList <WorkflowChangeAction> cdiff = Conditions.Diff(originalRules.Conditions, changedRules.Conditions);
            IList <WorkflowChangeAction> rdiff = RuleSets.Diff(originalRules.RuleSets, changedRules.RuleSets);

            // quick optimization -- if no condition changes, simply return the ruleset changes
            if (cdiff.Count == 0)
            {
                return(rdiff);
            }

            // merge ruleset changes into condition changes
            for (int i = 0; i < rdiff.Count; ++i)
            {
                cdiff.Add(rdiff[i]);
            }
            return(cdiff);
        }
예제 #7
0
        // Methods
        public override bool Evaluate(Activity activity, IServiceProvider provider)
        {
            Activity        parent      = activity;
            RuleDefinitions definitions = null;

            while (parent != null)
            {
                definitions = (RuleDefinitions)parent.GetValue(RuleDefinitions.RuleDefinitionsProperty);

                if (definitions != null)
                {
                    break;
                }

                parent = parent.Parent;
            }

            if (definitions == null)
            {
                Console.WriteLine("No definition");
                return(false);
            }

            //Console.WriteLine ("Definition {0} at {1}", definitions, parent);
            RuleValidation validation = new RuleValidation(activity.GetType(), null);
            RuleExecution  execution  = new RuleExecution(validation, parent);
            RuleCondition  condition  = definitions.Conditions [ConditionName];

            //Console.WriteLine ("Condition {0}", condition);
            return(condition.Evaluate(execution));
        }
 protected override bool ApplyTo(Activity rootActivity)
 {
     if (rootActivity == null)
     {
         return false;
     }
     RuleDefinitions definitions = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
     if (definitions == null)
     {
         definitions = new RuleDefinitions();
         rootActivity.SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions);
     }
     bool flag = false;
     if (definitions.Conditions.RuntimeMode)
     {
         definitions.Conditions.RuntimeMode = false;
         flag = true;
     }
     try
     {
         definitions.Conditions.Add(this.ConditionDefinition);
     }
     finally
     {
         if (flag)
         {
             definitions.Conditions.RuntimeMode = true;
         }
     }
     return true;
 }
        protected override bool ApplyTo(Activity rootActivity)
        {
            bool flag2;

            if (rootActivity == null)
            {
                return(false);
            }
            RuleDefinitions definitions = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if ((definitions == null) || (definitions.RuleSets == null))
            {
                return(false);
            }
            bool flag = false;

            if (definitions.RuleSets.RuntimeMode)
            {
                definitions.RuleSets.RuntimeMode = false;
                flag = true;
            }
            try
            {
                flag2 = definitions.RuleSets.Remove(this.ruleset.Name);
            }
            finally
            {
                if (flag)
                {
                    definitions.RuleSets.RuntimeMode = true;
                }
            }
            return(flag2);
        }
        protected override void InitializeProperties()
        {
            lock (syncLock)
            {
                if (this._runtimeInitialized)
                {
                    return;
                }

                Activity ownerActivity = base.ParentDependencyObject as Activity;

                CompositeActivity declaringActivity = Helpers.GetDeclaringActivity(ownerActivity);
                if (declaringActivity == null)
                {
                    declaringActivity = Helpers.GetRootActivity(ownerActivity) as CompositeActivity;
                }

                RuleDefinitions rules = ConditionHelper.Load_Rules_RT(declaringActivity);
                if (rules != null)
                {
                    rules.OnRuntimeInitialized();
                }
                base.InitializeProperties();
                _runtimeInitialized = true;
            }
        }
        internal static RuleDefinitions GetRuleDefinitionsFromManifest(Type workflowType)
        {
            if (workflowType == null)
            {
                throw new ArgumentNullException("workflowType");
            }
            RuleDefinitions definitions = null;

            if (cloneableOrNullRulesResources.ContainsKey(workflowType))
            {
                definitions = (RuleDefinitions)cloneableOrNullRulesResources[workflowType];
                if (definitions != null)
                {
                    definitions = definitions.Clone();
                }
                return(definitions);
            }
            string name = workflowType.Name + ".rules";
            Stream manifestResourceStream = workflowType.Module.Assembly.GetManifestResourceStream(workflowType, name);

            if (manifestResourceStream == null)
            {
                manifestResourceStream = workflowType.Module.Assembly.GetManifestResourceStream(name);
            }
            if (manifestResourceStream != null)
            {
                using (StreamReader reader = new StreamReader(manifestResourceStream))
                {
                    using (XmlReader reader2 = XmlReader.Create(reader))
                    {
                        definitions = new WorkflowMarkupSerializer().Deserialize(reader2) as RuleDefinitions;
                    }
                }
            }
            if (!uncloneableRulesResources.ContainsKey(workflowType))
            {
                try
                {
                    RuleDefinitions definitions2 = definitions;
                    if (definitions != null)
                    {
                        definitions = definitions.Clone();
                    }
                    lock (cloneableOrNullRulesResources)
                    {
                        cloneableOrNullRulesResources[workflowType] = definitions2;
                    }
                }
                catch (Exception)
                {
                    lock (uncloneableRulesResources)
                    {
                        uncloneableRulesResources[workflowType] = null;
                    }
                }
            }
            return(definitions);
        }
예제 #12
0
        public override bool Evaluate(Activity activity, IServiceProvider provider)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (string.IsNullOrEmpty(this._condition))
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_MissingConditionName, activity.Name));
            }

            RuleDefinitions defs = null;

            if (string.IsNullOrEmpty(this.declaringActivityId))
            {
                // No Runtime Initialization.
                CompositeActivity declaringActivity = null;
                defs = RuleConditionReference.GetRuleDefinitions(activity, out declaringActivity);
            }
            else
            {
                // Runtime Initialized.
                defs = (RuleDefinitions)activity.GetActivityByName(declaringActivityId).GetValue(RuleDefinitions.RuleDefinitionsProperty);
            }

            if ((defs == null) || (defs.Conditions == null))
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_MissingRuleConditions));
            }

            RuleCondition conditionDefinitionToEvaluate = defs.Conditions[this._condition];

            if (conditionDefinitionToEvaluate != null)
            {
                Activity       contextActivity = System.Workflow.Activities.Common.Helpers.GetEnclosingActivity(activity);
                RuleValidation validation      = new RuleValidation(contextActivity);
                if (!conditionDefinitionToEvaluate.Validate(validation))
                {
                    string message = string.Format(CultureInfo.CurrentCulture, Messages.ConditionValidationFailed, this._condition);
                    throw new InvalidOperationException(message);
                }

                RuleExecution context = new RuleExecution(validation, contextActivity, provider as ActivityExecutionContext);
                return(conditionDefinitionToEvaluate.Evaluate(context));
            }
            else
            {
                // no condition, so defaults to true
                return(true);
            }
        }
예제 #13
0
        internal static RuleDefinitions Load_Rules_RT(Activity declaringActivity)
        {
            RuleDefinitions rules = declaringActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if (rules == null)
            {
                rules = ConditionHelper.GetRuleDefinitionsFromManifest(declaringActivity.GetType());
                if (rules != null)
                {
                    declaringActivity.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);
                }
            }
            return(rules);
        }
예제 #14
0
        public override bool Evaluate(Activity activity, IServiceProvider provider)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (string.IsNullOrEmpty(this._condition))
            {
                throw new InvalidOperationException(SR.GetString("Error_MissingConditionName", new object[] { activity.Name }));
            }
            RuleDefinitions ruleDefinitions = null;

            if (string.IsNullOrEmpty(this.declaringActivityId))
            {
                CompositeActivity declaringActivity = null;
                ruleDefinitions = GetRuleDefinitions(activity, out declaringActivity);
            }
            else
            {
                ruleDefinitions = (RuleDefinitions)activity.GetActivityByName(this.declaringActivityId).GetValue(RuleDefinitions.RuleDefinitionsProperty);
            }
            if ((ruleDefinitions == null) || (ruleDefinitions.Conditions == null))
            {
                throw new InvalidOperationException(SR.GetString("Error_MissingRuleConditions"));
            }
            RuleCondition condition = ruleDefinitions.Conditions[this._condition];

            if (condition == null)
            {
                return(true);
            }
            Activity       enclosingActivity = Helpers.GetEnclosingActivity(activity);
            RuleValidation validation        = new RuleValidation(enclosingActivity);

            if (!condition.Validate(validation))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ConditionValidationFailed, new object[] { this._condition }));
            }
            RuleExecution execution = new RuleExecution(validation, enclosingActivity, provider as ActivityExecutionContext);

            return(condition.Evaluate(execution));
        }
예제 #15
0
        protected override void InitializeProperties()
        {
            lock (syncLock)
            {
                if (this._runtimeInitialized)
                {
                    return;
                }

                CompositeActivity declaringActivity = null;
                Activity          ownerActivity     = base.ParentDependencyObject as Activity;

                RuleDefinitions definitions = GetRuleDefinitions(ownerActivity, out declaringActivity);
                definitions.OnRuntimeInitialized();

                this.declaringActivityId = declaringActivity.QualifiedName;
                base.InitializeProperties();
                _runtimeInitialized = true;
            }
        }
예제 #16
0
        protected override bool ApplyTo(Activity rootActivity)
        {
            if (rootActivity == null)
            {
                return(false);
            }

            RuleDefinitions rules = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if (rules == null || rules.Conditions == null)
            {
                return(false);
            }

            if (rules.Conditions[this.ConditionDefinition.Name] == null)
            {
                return(false);
            }

            //
            bool setRuntimeMode = false;

            if (rules.Conditions.RuntimeMode)
            {
                rules.Conditions.RuntimeMode = false;
                setRuntimeMode = true;
            }
            try
            {
                rules.Conditions.Remove(this.ConditionDefinition.Name);
                rules.Conditions.Add(this.NewConditionDefinition);
            }
            finally
            {
                if (setRuntimeMode)
                {
                    rules.Conditions.RuntimeMode = true;
                }
            }
            return(true);
        }
예제 #17
0
        internal static RuleDefinitions Load_Rules_DT(IServiceProvider serviceProvider, DependencyObject activity)
        {
            RuleDefinitions rules = (RuleDefinitions)activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);

            if (rules == null)
            {
                WorkflowDesignerLoader loader = (WorkflowDesignerLoader)serviceProvider.GetService(typeof(WorkflowDesignerLoader));
                if (loader != null)
                {
                    string rulesFileName = string.Empty;
                    if (!string.IsNullOrEmpty(loader.FileName))
                    {
                        rulesFileName = Path.Combine(Path.GetDirectoryName(loader.FileName), Path.GetFileNameWithoutExtension(loader.FileName));
                    }
                    rulesFileName += ".rules";

                    try
                    {
                        using (TextReader ruleFileReader = loader.GetFileReader(rulesFileName))
                        {
                            if (ruleFileReader == null)
                            {
                                rules = new RuleDefinitions();
                            }
                            else
                            {
                                using (XmlReader xmlReader = XmlReader.Create(ruleFileReader))
                                    rules = new WorkflowMarkupSerializer().Deserialize(xmlReader) as RuleDefinitions;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        rules = new RuleDefinitions();
                        //
                    }
                }
                activity.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);
            }
            return(rules);
        }
        internal static RuleDefinitions Load_Rules_DT(IServiceProvider serviceProvider, DependencyObject activity)
        {
            RuleDefinitions definitions = (RuleDefinitions)activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);

            if (definitions == null)
            {
                WorkflowDesignerLoader service = (WorkflowDesignerLoader)serviceProvider.GetService(typeof(WorkflowDesignerLoader));
                if (service != null)
                {
                    string filePath = string.Empty;
                    if (!string.IsNullOrEmpty(service.FileName))
                    {
                        filePath = Path.Combine(Path.GetDirectoryName(service.FileName), Path.GetFileNameWithoutExtension(service.FileName));
                    }
                    filePath = filePath + ".rules";
                    try
                    {
                        using (TextReader reader = service.GetFileReader(filePath))
                        {
                            if (reader == null)
                            {
                                definitions = new RuleDefinitions();
                            }
                            else
                            {
                                using (XmlReader reader2 = XmlReader.Create(reader))
                                {
                                    definitions = new WorkflowMarkupSerializer().Deserialize(reader2) as RuleDefinitions;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        definitions = new RuleDefinitions();
                    }
                }
                activity.SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions);
            }
            return(definitions);
        }
 internal RuleDefinitions Clone()
 {
     RuleDefinitions definitions = new RuleDefinitions();
     if (this.ruleSets != null)
     {
         definitions.ruleSets = new RuleSetCollection();
         foreach (RuleSet set in this.ruleSets)
         {
             definitions.ruleSets.Add(set.Clone());
         }
     }
     if (this.conditions != null)
     {
         definitions.conditions = new RuleConditionCollection();
         foreach (RuleCondition condition in this.conditions)
         {
             definitions.conditions.Add(condition.Clone());
         }
     }
     return definitions;
 }
예제 #20
0
        internal RuleDefinitions Clone()
        {
            RuleDefinitions definitions = new RuleDefinitions();

            if (this.ruleSets != null)
            {
                definitions.ruleSets = new RuleSetCollection();
                foreach (RuleSet set in this.ruleSets)
                {
                    definitions.ruleSets.Add(set.Clone());
                }
            }
            if (this.conditions != null)
            {
                definitions.conditions = new RuleConditionCollection();
                foreach (RuleCondition condition in this.conditions)
                {
                    definitions.conditions.Add(condition.Clone());
                }
            }
            return(definitions);
        }
예제 #21
0
        public IList <WorkflowChangeAction> Diff(object originalDefinition, object changedDefinition)
        {
            RuleDefinitions definitions  = originalDefinition as RuleDefinitions;
            RuleDefinitions definitions2 = changedDefinition as RuleDefinitions;

            if ((definitions == null) || (definitions2 == null))
            {
                return(new List <WorkflowChangeAction>());
            }
            IList <WorkflowChangeAction> list  = this.Conditions.Diff(definitions.Conditions, definitions2.Conditions);
            IList <WorkflowChangeAction> list2 = this.RuleSets.Diff(definitions.RuleSets, definitions2.RuleSets);

            if (list.Count == 0)
            {
                return(list2);
            }
            for (int i = 0; i < list2.Count; i++)
            {
                list.Add(list2[i]);
            }
            return(list);
        }
예제 #22
0
        internal static object OnGetRuleConditions(DependencyObject dependencyObject)
        {
            if (dependencyObject == null)
            {
                throw new ArgumentNullException("dependencyObject");
            }
            RuleDefinitions valueBase = dependencyObject.GetValueBase(RuleDefinitionsProperty) as RuleDefinitions;

            if (valueBase == null)
            {
                Activity activity = dependencyObject as Activity;
                if (activity.Parent == null)
                {
                    valueBase = ConditionHelper.GetRuleDefinitionsFromManifest(activity.GetType());
                    if (valueBase != null)
                    {
                        dependencyObject.SetValue(RuleDefinitionsProperty, valueBase);
                    }
                }
            }
            return(valueBase);
        }
 protected override void InitializeProperties()
 {
     lock (this.syncLock)
     {
         if (!this._runtimeInitialized)
         {
             Activity          parentDependencyObject = base.ParentDependencyObject as Activity;
             CompositeActivity declaringActivity      = Helpers.GetDeclaringActivity(parentDependencyObject);
             if (declaringActivity == null)
             {
                 declaringActivity = Helpers.GetRootActivity(parentDependencyObject) as CompositeActivity;
             }
             RuleDefinitions definitions = ConditionHelper.Load_Rules_RT(declaringActivity);
             if (definitions != null)
             {
                 definitions.OnRuntimeInitialized();
             }
             base.InitializeProperties();
             this._runtimeInitialized = true;
         }
     }
 }
        protected override bool ApplyTo(Activity rootActivity)
        {
            if (rootActivity == null)
            {
                return(false);
            }
            RuleDefinitions definitions = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if ((definitions == null) || (definitions.RuleSets == null))
            {
                return(false);
            }
            if (definitions.RuleSets[this.RuleSetName] == null)
            {
                return(false);
            }
            bool flag = false;

            if (definitions.Conditions.RuntimeMode)
            {
                definitions.Conditions.RuntimeMode = false;
                flag = true;
            }
            try
            {
                definitions.RuleSets.Remove(this.RuleSetName);
                definitions.RuleSets.Add(this.updated);
            }
            finally
            {
                if (flag)
                {
                    definitions.RuleSets.RuntimeMode = true;
                }
            }
            return(true);
        }
예제 #25
0
        internal RuleDefinitions Clone()
        {
            RuleDefinitions newRuleDefinitions = new RuleDefinitions();

            if (this.ruleSets != null)
            {
                newRuleDefinitions.ruleSets = new RuleSetCollection();
                foreach (RuleSet r in this.ruleSets)
                {
                    newRuleDefinitions.ruleSets.Add(r.Clone());
                }
            }

            if (this.conditions != null)
            {
                newRuleDefinitions.conditions = new RuleConditionCollection();
                foreach (RuleCondition r in this.conditions)
                {
                    newRuleDefinitions.conditions.Add(r.Clone());
                }
            }

            return(newRuleDefinitions);
        }
예제 #26
0
        protected override bool ApplyTo(Activity rootActivity)
        {
            if (rootActivity == null)
            {
                return(false);
            }

            RuleDefinitions rules = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;

            if (rules == null)
            {
                rules = new RuleDefinitions();
                ((Activity)rootActivity).SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);
            }

            //
            bool setRuntimeMode = false;

            if (rules.Conditions.RuntimeMode)
            {
                rules.Conditions.RuntimeMode = false;
                setRuntimeMode = true;
            }
            try
            {
                rules.Conditions.Add(this.ConditionDefinition);
            }
            finally
            {
                if (setRuntimeMode)
                {
                    rules.Conditions.RuntimeMode = true;
                }
            }
            return(true);
        }
예제 #27
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RuleSetSelector selectorForm = new RuleSetSelector();
            selectorForm.RuleSetDataCollection.AddRange(ruleSetDataDictionary.Values);
            selectorForm.Instructions = "Select the RuleSets you would like to export.  Note that version numbers are not included in the output file, and only a single RuleSet with a given Name can be exported to the same file.";
            DialogResult selectorResult = selectorForm.ShowDialog();

            if (selectorResult == DialogResult.OK && selectorForm.SelectedRuleSetDataCollection.Count > 0)
            {
                RuleDefinitions ruleDefinitions = new RuleDefinitions();
                foreach (RuleSetData data in selectorForm.SelectedRuleSetDataCollection)
                {
                    ruleDefinitions.RuleSets.Add(data.RuleSet);
                }

                SaveFileDialog dialog = new SaveFileDialog();
                dialog.Filter = "Rules files (*.rules)|*.rules";
                dialog.AddExtension = true;
                dialog.DefaultExt = "rules";
                DialogResult result = dialog.ShowDialog();

                if (result == DialogResult.OK && !String.IsNullOrEmpty(dialog.FileName))
                {
                    XmlTextWriter writer = new XmlTextWriter(dialog.FileName, null);
                    serializer.Serialize(writer, ruleDefinitions);
                    writer.Flush();
                    writer.Close();
                }
            }
            else
            {
                MessageBox.Show("No RuleSets selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 public static string GetActivitySpecificDetails(this ActivityWrapper activityWrapper, RuleDefinitions ruleDefinitions)
 {
     var builder = new StringBuilder();
     builder.Append(ConvertActivity(activityWrapper.Current, ruleDefinitions));
     return builder.ToString();
 }
        private static string ConvertActivity(Activity current, RuleDefinitions ruleDefinitions)
        {
            var builder = new StringBuilder();
            if (current is IfElseActivity)
            {
                //var activity = current as IfElseActivity;
                //if (activity.Activities.Count > 0) // there are branches if..else..activity
                //{
                //    string[] dependents = activity.Activities.Select(x => x.Name).ToArray();

                //    builder.AppendFormat("There are {0} conditions executed in this scenario namely -", activity.Activities.Count)
                //        .AppendLine(dependents.ToCSV())
                //        .AppendLine();
                //}
            }
            else if (current is IfElseBranchActivity)
            {
                var activity = current as IfElseBranchActivity;
                builder.AppendLine(ConvertActivityCondition(activity.Condition, ruleDefinitions));
            }
            else if (current is WhileActivity)
            {
                var activity = current as WhileActivity;
                builder.AppendLine(ConvertActivityCondition(activity.Condition, ruleDefinitions));
            }
            //else if (current is SequenceActivity)
            //{

            //}
            //else if (current is ListenActivity)
            //{

            //}
            //else if (current is StateActivity)
            //{

            //}
            //else if (current is StateInitializationActivity)
            //{

            //}
            else if (current is SetStateActivity)
            {
                var activity = current as SetStateActivity;
                builder.AppendFormat("This activity sets the next state of the workflow to {0}", activity.TargetStateName).AppendLine();
            }
            //else if (current is EventDrivenActivity)
            //{

            //}
            else if (current is PolicyActivity)
            {
                var activity = current as PolicyActivity;
                builder.AppendLine(RuleTranslator.ConvertRuleSetReference(activity.RuleSetReference, ruleDefinitions));
            }
            else
            {
                Log.Debug("Not supported: " + current.GetType());
            }

            return builder.ToString().TrimEnd(Environment.NewLine.ToCharArray());
        }
예제 #30
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection errors    = base.Validate(manager, obj);
            RuleSetReference          reference = obj as RuleSetReference;

            if (reference == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.UnexpectedArgumentType, new object[] { typeof(RuleSetReference).FullName, "obj" }), "obj");
            }
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(Activity).Name }));
            }
            if (!(manager.Context[typeof(PropertyValidationContext)] is PropertyValidationContext))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(PropertyValidationContext).Name }));
            }
            if (!string.IsNullOrEmpty(reference.RuleSetName))
            {
                RuleDefinitions   definitions       = null;
                RuleSetCollection ruleSets          = null;
                CompositeActivity declaringActivity = Helpers.GetDeclaringActivity(activity);
                if (declaringActivity == null)
                {
                    declaringActivity = Helpers.GetRootActivity(activity) as CompositeActivity;
                }
                if (activity.Site != null)
                {
                    definitions = ConditionHelper.Load_Rules_DT(activity.Site, declaringActivity);
                }
                else
                {
                    definitions = ConditionHelper.Load_Rules_RT(declaringActivity);
                }
                if (definitions != null)
                {
                    ruleSets = definitions.RuleSets;
                }
                if ((ruleSets == null) || !ruleSets.Contains(reference.RuleSetName))
                {
                    ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, new object[] { reference.RuleSetName }), 0x576)
                    {
                        PropertyName = base.GetFullPropertyName(manager) + ".RuleSetName"
                    };
                    errors.Add(error);
                    return(errors);
                }
                RuleSet       set     = ruleSets[reference.RuleSetName];
                ITypeProvider service = (ITypeProvider)manager.GetService(typeof(ITypeProvider));
                using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                {
                    RuleValidation validation = new RuleValidation(activity, service, WorkflowCompilationContext.Current.CheckTypes);
                    set.Validate(validation);
                    ValidationErrorCollection errors2 = validation.Errors;
                    if (errors2.Count > 0)
                    {
                        string fullPropertyName = base.GetFullPropertyName(manager);
                        string str6             = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetExpression, new object[] { fullPropertyName });
                        int    errorNumber      = 0x577;
                        if (activity.Site != null)
                        {
                            foreach (ValidationError error2 in errors2)
                            {
                                ValidationError error3 = new ValidationError(error2.ErrorText, errorNumber)
                                {
                                    PropertyName = fullPropertyName + ".RuleSet Definition"
                                };
                                errors.Add(error3);
                            }
                            return(errors);
                        }
                        foreach (ValidationError error4 in errors2)
                        {
                            ValidationError error5 = new ValidationError(str6 + " " + error4.ErrorText, errorNumber)
                            {
                                PropertyName = fullPropertyName
                            };
                            errors.Add(error5);
                        }
                    }
                    return(errors);
                }
            }
            ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetName, new object[] { "RuleSetReference" }), 0x578)
            {
                PropertyName = base.GetFullPropertyName(manager) + ".RuleSetName"
            };

            errors.Add(item);
            return(errors);
        }
 private static string ConvertActivityCondition(ActivityCondition condition, RuleDefinitions ruleDefinitions)
 {
     var builder = new StringBuilder();
     if (condition != null)
     {
         if (condition is RuleConditionReference)
         {
             var ruleRef = (RuleConditionReference)condition;
             builder.AppendLine(RuleTranslator.ConvertRuleConditionReference(ruleDefinitions, ruleRef));
         }
         else
         {
             throw new NotSupportedException("Type not found:" + condition.GetType());
         }
     }
     else
     {
         builder.AppendLine("This activity gets executed if the other conditions fail in the evaluation process");
     }
     return builder.ToString();
 }
예제 #32
0
 private void saveRuleDef(string filename, RuleDefinitions ruleDef)
 {
     using (XmlTextWriter writer = new XmlTextWriter(filename, null))
     {
         WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
         serializer.Serialize(writer, ruleDef);
     }
 }
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            ValidationErrorCollection validationErrors = base.Validate(manager, obj);

            RuleSetReference ruleSetReference = obj as RuleSetReference;

            if (ruleSetReference == null)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Messages.UnexpectedArgumentType, typeof(RuleSetReference).FullName, "obj");
                throw new ArgumentException(message, "obj");
            }
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, typeof(Activity).Name);
                throw new InvalidOperationException(message);
            }
            PropertyValidationContext validationContext = manager.Context[typeof(PropertyValidationContext)] as PropertyValidationContext;

            if (validationContext == null)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, typeof(PropertyValidationContext).Name);
                throw new InvalidOperationException(message);
            }
            if (!string.IsNullOrEmpty(ruleSetReference.RuleSetName))
            {
                RuleDefinitions   rules             = null;
                RuleSetCollection ruleSetCollection = null;

                CompositeActivity declaringActivity = Helpers.GetDeclaringActivity(activity);
                if (declaringActivity == null)
                {
                    declaringActivity = Helpers.GetRootActivity(activity) as CompositeActivity;
                }
                if (activity.Site != null)
                {
                    rules = ConditionHelper.Load_Rules_DT(activity.Site, declaringActivity);
                }
                else
                {
                    rules = ConditionHelper.Load_Rules_RT(declaringActivity);
                }

                if (rules != null)
                {
                    ruleSetCollection = rules.RuleSets;
                }

                if (ruleSetCollection == null || !ruleSetCollection.Contains(ruleSetReference.RuleSetName))
                {
                    string          message         = string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, ruleSetReference.RuleSetName);
                    ValidationError validationError = new ValidationError(message, ErrorNumbers.Error_RuleSetNotFound);
                    validationError.PropertyName = GetFullPropertyName(manager) + "." + "RuleSetName";
                    validationErrors.Add(validationError);
                }
                else
                {
                    RuleSet actualRuleSet = ruleSetCollection[ruleSetReference.RuleSetName];

                    ITypeProvider typeProvider = (ITypeProvider)manager.GetService(typeof(ITypeProvider));

                    IDisposable localContextScope = (WorkflowCompilationContext.Current == null ? WorkflowCompilationContext.CreateScope(manager) : null);
                    try
                    {
                        RuleValidation validation = new RuleValidation(activity, typeProvider, WorkflowCompilationContext.Current.CheckTypes);
                        actualRuleSet.Validate(validation);
                        ValidationErrorCollection actualRuleSetErrors = validation.Errors;

                        if (actualRuleSetErrors.Count > 0)
                        {
                            string expressionPropertyName = GetFullPropertyName(manager);
                            string genericErrorMsg        = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetExpression, expressionPropertyName);
                            int    errorNumber            = ErrorNumbers.Error_InvalidRuleSetExpression;

                            if (activity.Site != null)
                            {
                                foreach (ValidationError actualError in actualRuleSetErrors)
                                {
                                    ValidationError validationError = new ValidationError(actualError.ErrorText, errorNumber);
                                    validationError.PropertyName = expressionPropertyName + "." + "RuleSet Definition";
                                    validationErrors.Add(validationError);
                                }
                            }
                            else
                            {
                                foreach (ValidationError actualError in actualRuleSetErrors)
                                {
                                    ValidationError validationError = new ValidationError(genericErrorMsg + " " + actualError.ErrorText, errorNumber);
                                    validationError.PropertyName = expressionPropertyName;
                                    validationErrors.Add(validationError);
                                }
                            }
                        }
                        //
                    }
                    finally
                    {
                        if (localContextScope != null)
                        {
                            localContextScope.Dispose();
                        }
                    }
                }
            }
            else
            {
                string          message         = string.Format(CultureInfo.CurrentCulture, Messages.InvalidRuleSetName, "RuleSetReference");
                ValidationError validationError = new ValidationError(message, ErrorNumbers.Error_InvalidRuleSetName);
                validationError.PropertyName = GetFullPropertyName(manager) + "." + "RuleSetName";
                validationErrors.Add(validationError);
            }
            return(validationErrors);
        }
        internal RuleDefinitions Clone()
        {
            RuleDefinitions newRuleDefinitions = new RuleDefinitions();

            if (this.ruleSets != null)
            {
                newRuleDefinitions.ruleSets = new RuleSetCollection();
                foreach (RuleSet r in this.ruleSets)
                    newRuleDefinitions.ruleSets.Add(r.Clone());
            }

            if (this.conditions != null)
            {
                newRuleDefinitions.conditions = new RuleConditionCollection();
                foreach (RuleCondition r in this.conditions)
                    newRuleDefinitions.conditions.Add(r.Clone());
            }

            return newRuleDefinitions;
        }
예제 #35
0
        private void AddOneFileCache(string fileName, RuleDefinitions ruleDefs)
        {
            if (ruleDefs == null || fileName == null || fileName.Trim().Equals(String.Empty))
                return;

            if (_cache.Contains(fileName))
                _cache.Remove(fileName);
            _cache.Add(fileName, ruleDefs);
        }
예제 #36
0
        internal static RuleDefinitions GetRuleDefinitionsFromManifest(Type workflowType)
        {
            if (workflowType == null)
            {
                throw new ArgumentNullException("workflowType");
            }

            RuleDefinitions rules = null;

            if (cloneableOrNullRulesResources.ContainsKey(workflowType))
            {
                rules = (RuleDefinitions)cloneableOrNullRulesResources[workflowType];
                if (rules != null)
                {
                    // This should always succeed, since it is coming out of the cloneable cache
                    rules = rules.Clone();
                }
            }
            else
            {
                string resourceName = workflowType.Name + ".rules";
                Stream stream       = workflowType.Module.Assembly.GetManifestResourceStream(workflowType, resourceName);

                // Try just the .rules file name. This is needed for wfc.exe compilation scenarios.
                if (stream == null)
                {
                    stream = workflowType.Module.Assembly.GetManifestResourceStream(resourceName);
                }

                if (stream != null)
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        using (XmlReader xmlReader = XmlReader.Create(reader))
                            rules = new WorkflowMarkupSerializer().Deserialize(xmlReader) as RuleDefinitions;
                    }
                }
                // Don't know yet whether 'rules' is cloneable, give it a try
                if (!uncloneableRulesResources.ContainsKey(workflowType))
                {
                    try
                    {
                        RuleDefinitions originalRules = rules;
                        if (rules != null)
                        {
                            rules = rules.Clone();
                        }
                        lock (cloneableOrNullRulesResources)
                        {
                            cloneableOrNullRulesResources[workflowType] = originalRules;
                        }
                    }
                    catch (Exception)
                    {
                        lock (uncloneableRulesResources)
                        {
                            uncloneableRulesResources[workflowType] = null;
                        }
                    }
                }
            }
            return(rules);
        }
        protected override bool ApplyTo(Activity rootActivity)
        {
            if (rootActivity == null)
                return false;

            RuleDefinitions rules = rootActivity.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions;
            if (rules == null)
            {
                rules = new RuleDefinitions();
                ((Activity)rootActivity).SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);
            }

            // 
            bool setRuntimeMode = false;
            if (rules.Conditions.RuntimeMode)
            {
                rules.Conditions.RuntimeMode = false;
                setRuntimeMode = true;
            }
            try
            {
                rules.Conditions.Add(this.ConditionDefinition);
            }
            finally
            {
                if (setRuntimeMode)
                    rules.Conditions.RuntimeMode = true;
            }
            return true;
        }
예제 #38
0
        internal static RuleDefinitions Load_Rules_DT(IServiceProvider serviceProvider, DependencyObject activity)
        {
            RuleDefinitions rules = (RuleDefinitions)activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);
            if (rules == null)
            {
                WorkflowDesignerLoader loader = (WorkflowDesignerLoader)serviceProvider.GetService(typeof(WorkflowDesignerLoader));
                if (loader != null)
                {
                    string rulesFileName = string.Empty;
                    if (!string.IsNullOrEmpty(loader.FileName))
                        rulesFileName = Path.Combine(Path.GetDirectoryName(loader.FileName), Path.GetFileNameWithoutExtension(loader.FileName));
                    rulesFileName += ".rules";

                    try
                    {
                        using (TextReader ruleFileReader = loader.GetFileReader(rulesFileName))
                        {
                            if (ruleFileReader == null)
                            {
                                rules = new RuleDefinitions();
                            }
                            else
                            {
                                using (XmlReader xmlReader = XmlReader.Create(ruleFileReader))
                                    rules = new WorkflowMarkupSerializer().Deserialize(xmlReader) as RuleDefinitions;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        rules = new RuleDefinitions();
                        // 
                    }
                }
                activity.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);
            }
            return rules;
        }
예제 #39
0
        public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
        {
            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }
            if (manager.Context == null)
            {
                throw new InvalidOperationException(Messages.ContextStackMissing);
            }
            ValidationErrorCollection errors    = base.Validate(manager, obj);
            RuleConditionReference    reference = obj as RuleConditionReference;

            if (reference == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.UnexpectedArgumentType, new object[] { typeof(RuleConditionReference).FullName, "obj" }), "obj");
            }
            Activity activity = manager.Context[typeof(Activity)] as Activity;

            if (activity == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(Activity).Name }));
            }
            if (!(manager.Context[typeof(PropertyValidationContext)] is PropertyValidationContext))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.ContextStackItemMissing, new object[] { typeof(PropertyValidationContext).Name }));
            }
            if (!string.IsNullOrEmpty(reference.ConditionName))
            {
                RuleDefinitions         definitions       = null;
                RuleConditionCollection conditions        = null;
                CompositeActivity       declaringActivity = Helpers.GetDeclaringActivity(activity);
                if (declaringActivity == null)
                {
                    declaringActivity = Helpers.GetRootActivity(activity) as CompositeActivity;
                }
                if (activity.Site != null)
                {
                    definitions = ConditionHelper.Load_Rules_DT(activity.Site, declaringActivity);
                }
                else
                {
                    definitions = ConditionHelper.Load_Rules_RT(declaringActivity);
                }
                if (definitions != null)
                {
                    conditions = definitions.Conditions;
                }
                if ((conditions == null) || !conditions.Contains(reference.ConditionName))
                {
                    ValidationError error = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, new object[] { reference.ConditionName }), 0x53e)
                    {
                        PropertyName = base.GetFullPropertyName(manager) + ".ConditionName"
                    };
                    errors.Add(error);
                    return(errors);
                }
                RuleCondition condition = conditions[reference.ConditionName];
                ITypeProvider service   = (ITypeProvider)manager.GetService(typeof(ITypeProvider));
                using ((WorkflowCompilationContext.Current == null) ? WorkflowCompilationContext.CreateScope(manager) : null)
                {
                    RuleValidation validation = new RuleValidation(activity, service, WorkflowCompilationContext.Current.CheckTypes);
                    condition.Validate(validation);
                    ValidationErrorCollection errors2 = validation.Errors;
                    if (errors2.Count > 0)
                    {
                        string fullPropertyName = base.GetFullPropertyName(manager);
                        string errorText        = string.Format(CultureInfo.CurrentCulture, Messages.InvalidConditionExpression, new object[] { fullPropertyName });
                        int    errorNumber      = 0x558;
                        if (activity.Site != null)
                        {
                            ValidationError error2 = new ValidationError(errorText, errorNumber)
                            {
                                PropertyName = fullPropertyName + ".Expression"
                            };
                            errors.Add(error2);
                        }
                        else
                        {
                            foreach (ValidationError error3 in errors2)
                            {
                                ValidationError error4 = new ValidationError(errorText + " " + error3.ErrorText, errorNumber)
                                {
                                    PropertyName = fullPropertyName + ".Expression"
                                };
                                errors.Add(error4);
                            }
                        }
                    }
                    foreach (RuleCondition condition2 in conditions)
                    {
                        if ((condition2.Name == reference.ConditionName) && (condition2 != condition))
                        {
                            ValidationError error5 = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.DuplicateConditions, new object[] { reference.ConditionName }), 0x53f)
                            {
                                PropertyName = base.GetFullPropertyName(manager) + ".ConditionName"
                            };
                            errors.Add(error5);
                        }
                    }
                    return(errors);
                }
            }
            ValidationError item = new ValidationError(string.Format(CultureInfo.CurrentCulture, Messages.InvalidConditionName, new object[] { "ConditionName" }), 0x540)
            {
                PropertyName = base.GetFullPropertyName(manager) + ".ConditionName"
            };

            errors.Add(item);
            return(errors);
        }
예제 #40
0
 private void saveRuleSet(string filename, RuleSet ruleSet)
 {
     using (XmlTextWriter writer = new XmlTextWriter(filename, null))
     {
         RuleDefinitions ruleDef = new RuleDefinitions();
         ruleDef.RuleSets.Add(ruleSet);
         WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
         serializer.Serialize(writer, ruleDef);
     }
 }
 internal static RuleDefinitions Load_Rules_DT(IServiceProvider serviceProvider, DependencyObject activity)
 {
     RuleDefinitions definitions = (RuleDefinitions) activity.GetValue(RuleDefinitions.RuleDefinitionsProperty);
     if (definitions == null)
     {
         WorkflowDesignerLoader service = (WorkflowDesignerLoader) serviceProvider.GetService(typeof(WorkflowDesignerLoader));
         if (service != null)
         {
             string filePath = string.Empty;
             if (!string.IsNullOrEmpty(service.FileName))
             {
                 filePath = Path.Combine(Path.GetDirectoryName(service.FileName), Path.GetFileNameWithoutExtension(service.FileName));
             }
             filePath = filePath + ".rules";
             try
             {
                 using (TextReader reader = service.GetFileReader(filePath))
                 {
                     if (reader == null)
                     {
                         definitions = new RuleDefinitions();
                     }
                     else
                     {
                         using (XmlReader reader2 = XmlReader.Create(reader))
                         {
                             definitions = new WorkflowMarkupSerializer().Deserialize(reader2) as RuleDefinitions;
                         }
                     }
                 }
             }
             catch (Exception)
             {
                 definitions = new RuleDefinitions();
             }
         }
         activity.SetValue(RuleDefinitions.RuleDefinitionsProperty, definitions);
     }
     return definitions;
 }
 public void Dispose()
 {
     _ruleDefinitions = null;
     _rulesStream = null;
 }
예제 #43
0
 public void saveRuleDef(string site, string station, string name, RuleDefinitions ruleDef)
 {
     StringWriter sw = new StringWriter();
     using (XmlTextWriter writer = new XmlTextWriter(sw))
     {
         WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
         serializer.Serialize(writer, ruleDef);
     }
     string content = sw.ToString();
     RouteManager.WriteRuleSet(site, station, name, content);
 }
        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]);
                            }
                        }
                    }
                });
        }
예제 #45
0
        public void saveRuleDef(string site, string station, string name, RuleDefinitions ruleDef)
        {
            string filepath = ConfigurationManager.AppSettings.Get("RulePath").ToString();

            string fileName = String.Format(filepath + "\\{0}.rules", name);
            this.saveRuleDef(site, station, name, ruleDef);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Excel.Range cell;

            RuleSet myRuleset = new RuleSet("RuleSet1");

            // Define property and activity reference expressions through CodeDom functionality
            CodeThisReferenceExpression refexp = new CodeThisReferenceExpression();
            CodePropertyReferenceExpression refTotalCost = new CodePropertyReferenceExpression(refexp, "totalCost");
            CodePropertyReferenceExpression refParamCategory = new CodePropertyReferenceExpression(refexp, "paramCategory");
            CodePropertyReferenceExpression refParamPrivilege = new CodePropertyReferenceExpression(refexp, "paramPrivilege");

            // Example :
            // IF paramCategory == 3
            // THEN totalCost = totalCost + 300

            for (int row = 4; row <= 8; row++)
            {
                cell = (Excel.Range)this.Cells[row, 2];
                if (String.IsNullOrEmpty((string)cell.Value2))
                    break;
                Rule myRule = new Rule("Rule" + row);
                myRuleset.Rules.Add(myRule);

                // Example :
                // paramCategory == 3
                CodeBinaryOperatorExpression ruleCondition = new CodeBinaryOperatorExpression();
                if ((string)cell.Value2 == "種別 (category)")
                    ruleCondition.Left = refParamCategory;
                else if ((string)cell.Value2 == "特典 (privilige)")
                    ruleCondition.Left = refParamPrivilege;
                ruleCondition.Operator = CodeBinaryOperatorType.ValueEquality;
                cell = (Excel.Range)this.Cells[row, 3];
                ruleCondition.Right = new CodePrimitiveExpression((int)(double)cell.Value2);
                myRule.Condition = new RuleExpressionCondition(ruleCondition);

                // Example :
                // totalCost = totalCost + 300
                CodeAssignStatement ruleAction = new CodeAssignStatement();
                ruleAction.Left = refTotalCost;
                CodeBinaryOperatorExpression actionRight = new CodeBinaryOperatorExpression();
                actionRight.Left = refTotalCost;
                cell = (Excel.Range)this.Cells[row, 4];
                if((string)cell.Value2 == "+")
                    actionRight.Operator = CodeBinaryOperatorType.Add;
                else if ((string)cell.Value2 == "-")
                    actionRight.Operator = CodeBinaryOperatorType.Subtract;
                else if ((string)cell.Value2 == "*")
                    actionRight.Operator = CodeBinaryOperatorType.Multiply;
                else if ((string)cell.Value2 == "/")
                    actionRight.Operator = CodeBinaryOperatorType.Divide;
                cell = (Excel.Range)this.Cells[row, 5];
                actionRight.Right = new CodePrimitiveExpression((int)(double)cell.Value2);
                ruleAction.Right = actionRight;
                myRule.ThenActions.Add(new RuleStatementAction(ruleAction));
            }

            // 必要に応じ、RuleValidation オブジェクトを使ってチェック!
            // (今回は省略 . . . . . . .)

            // RuleDefinitions を設定して保存
            RuleDefinitions ruleDef = new RuleDefinitions();
            ruleDef.RuleSets.Add(myRuleset);
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            cell = (Excel.Range) this.Cells[11, 2];
            XmlTextWriter writer = new XmlTextWriter((string) cell.Value2, System.Text.Encoding.Unicode);
            serializer.Serialize(writer, ruleDef);
            writer.Close();

            // ここでは、すぐにコンパイルして実行
            // (Custom WorkflowRuntime Service と Custom Policy Activity を作成して、データベースなど独自の Rule Cache を作成することも可能 . . .)

            MessageBox.Show("ルールを反映しました");
        }