protected override void DoDefaultAction()
        {
            base.DoDefaultAction();
            WorkflowDesignerLoader service = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

            if ((service != null) && service.InDebugMode)
            {
                throw new InvalidOperationException(Messages.DebugModeEditsDisallowed);
            }
            PolicyActivity activity = (PolicyActivity)base.Activity;

            if (!System.Workflow.Activities.Common.Helpers.IsActivityLocked(activity))
            {
                RuleDefinitions definitions = ConditionHelper.Load_Rules_DT(this, System.Workflow.Activities.Common.Helpers.GetRootActivity(activity));
                if (definitions != null)
                {
                    RuleSetCollection ruleSets         = definitions.RuleSets;
                    RuleSetReference  ruleSetReference = activity.RuleSetReference;
                    RuleSet           ruleSet          = null;
                    string            key = null;
                    if ((ruleSetReference != null) && !string.IsNullOrEmpty(ruleSetReference.RuleSetName))
                    {
                        key = ruleSetReference.RuleSetName;
                        if (ruleSets.Contains(key))
                        {
                            ruleSet = ruleSets[key];
                        }
                    }
                    else
                    {
                        key = ruleSets.GenerateRuleSetName();
                    }
                    using (RuleSetDialog dialog = new RuleSetDialog(activity, ruleSet))
                    {
                        if (DialogResult.OK == dialog.ShowDialog())
                        {
                            if (ruleSet != null)
                            {
                                ruleSets.Remove(key);
                            }
                            else
                            {
                                dialog.RuleSet.Name       = key;
                                activity.RuleSetReference = new RuleSetReference(key);
                            }
                            ruleSets.Add(dialog.RuleSet);
                            ConditionHelper.Flush_Rules_DT(this, System.Workflow.Activities.Common.Helpers.GetRootActivity(activity));
                        }
                    }
                }
                TypeDescriptor.GetProperties(activity)["RuleSetReference"].SetValue(activity, activity.RuleSetReference);
            }
        }
Ejemplo n.º 2
0
 protected override object OnNewInternal()
 {
     using (RuleSetDialog dlg = new RuleSetDialog(this.Activity, null))
     {
         if (DialogResult.OK == dlg.ShowDialog(this))
         {
             RuleSet ruleSet = dlg.RuleSet;
             ruleSet.Name = ruleSetCollection.GenerateRuleSetName();
             this.ruleSetCollection.Add(ruleSet);
             return(ruleSet);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        protected override void DoDefaultAction()
        {
            base.DoDefaultAction();

            // Do not allow editing if in debug mode.
            WorkflowDesignerLoader workflowDesignerLoader = this.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

            if (workflowDesignerLoader != null && workflowDesignerLoader.InDebugMode)
            {
                throw new InvalidOperationException(Messages.DebugModeEditsDisallowed);
            }

            // Do not allow editing if locked
            PolicyActivity activity = (PolicyActivity)this.Activity;

            if (Helpers.IsActivityLocked(activity))
            {
                return;
            }

            RuleDefinitions rules = ConditionHelper.Load_Rules_DT(this, Helpers.GetRootActivity(activity));

            if (rules != null)
            {
                RuleSetCollection ruleSetCollection = rules.RuleSets;
                RuleSetReference  ruleSetReference  = activity.RuleSetReference;
                RuleSet           ruleSet           = null;
                string            ruleSetName       = null;
                if (ruleSetReference != null &&
                    !string.IsNullOrEmpty(ruleSetReference.RuleSetName))
                {
                    ruleSetName = ruleSetReference.RuleSetName;
                    if (ruleSetCollection.Contains(ruleSetName))
                    {
                        ruleSet = ruleSetCollection[ruleSetName];
                    }
                }
                else
                {
                    ruleSetName = ruleSetCollection.GenerateRuleSetName();
                }
                using (RuleSetDialog dlg = new RuleSetDialog(activity, ruleSet))
                {
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        if (ruleSet != null) // modifying
                        {
                            ruleSetCollection.Remove(ruleSetName);
                        }
                        else // creating
                        {
                            dlg.RuleSet.Name          = ruleSetName;
                            activity.RuleSetReference = new RuleSetReference(ruleSetName);
                        }
                        ruleSetCollection.Add(dlg.RuleSet);
                        ConditionHelper.Flush_Rules_DT(this, Helpers.GetRootActivity(activity));
                    }
                }
            }

            // force revalidation by setting a property
            TypeDescriptor.GetProperties(activity)["RuleSetReference"].SetValue(activity, activity.RuleSetReference);
        }