Exemplo n.º 1
0
        public override void SetValue(object component, object value)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            RuleSetReference reference = component as RuleSetReference;

            if (reference == null)
            {
                throw new ArgumentNullException("component");
            }
            RuleSet item = value as RuleSet;

            if (!string.IsNullOrEmpty(reference.RuleSetName))
            {
                ISite serviceProvider = PropertyDescriptorUtils.GetSite(base.ServiceProvider, component);
                if (serviceProvider == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ISite).FullName }));
                }
                RuleSetCollection ruleSets    = null;
                RuleDefinitions   definitions = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity));
                if (definitions != null)
                {
                    ruleSets = definitions.RuleSets;
                }
                if ((ruleSets != null) && ruleSets.Contains(reference.RuleSetName))
                {
                    ruleSets.Remove(reference.RuleSetName);
                    ruleSets.Add(item);
                    ConditionHelper.Flush_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity));
                }
            }
        }
        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);
            }
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object valueToConvert)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string ruleSetName = valueToConvert as string;

            if ((ruleSetName == null) || (ruleSetName.TrimEnd().Length == 0))
            {
                ruleSetName = string.Empty;
            }

            ISite site = PropertyDescriptorUtils.GetSite(context, context.Instance);

            if (site == null)
            {
                string message = string.Format(CultureInfo.CurrentCulture, Messages.MissingService, typeof(ISite).FullName);
                throw new InvalidOperationException(message);
            }

            RuleSetCollection ruleSetCollection = null;
            RuleDefinitions   rules             = ConditionHelper.Load_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));

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

            if (ruleSetCollection != null && ruleSetName.Length != 0 && !ruleSetCollection.Contains(ruleSetName))
            {
                //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection
                RuleSet newRuleSet = new RuleSet();
                newRuleSet.Name = ruleSetName;
                ruleSetCollection.Add(newRuleSet);
                ConditionHelper.Flush_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));
            }

            RuleSetReference ruleSetReference = new RuleSetReference();

            ruleSetReference.RuleSetName = ruleSetName;

            return(ruleSetReference);
        }
        public override void SetValue(object component, object value)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            RuleSetReference ruleSetReference = component as RuleSetReference;

            if (ruleSetReference == null)
            {
                throw new ArgumentNullException("component");
            }

            RuleSet ruleSet = value as RuleSet;

            if (!string.IsNullOrEmpty(ruleSetReference.RuleSetName))
            {
                ISite site = PropertyDescriptorUtils.GetSite(this.ServiceProvider, component);
                if (site == null)
                {
                    string message = string.Format(CultureInfo.CurrentCulture, Messages.MissingService, typeof(ISite).FullName);
                    throw new InvalidOperationException(message);
                }

                RuleSetCollection ruleSetCollection = null;
                RuleDefinitions   rules             = ConditionHelper.Load_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));
                if (rules != null)
                {
                    ruleSetCollection = rules.RuleSets;
                }

                if (ruleSetCollection != null && ruleSetCollection.Contains(ruleSetReference.RuleSetName))
                {
                    ruleSetCollection.Remove(ruleSetReference.RuleSetName);
                    ruleSetCollection.Add(ruleSet);
                    ConditionHelper.Flush_Rules_DT(site, Helpers.GetRootActivity(site.Component as Activity));
                }
            }
        }
Exemplo n.º 5
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object valueToConvert)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            string key = valueToConvert as string;

            if ((key == null) || (key.TrimEnd(new char[0]).Length == 0))
            {
                key = string.Empty;
            }
            ISite serviceProvider = PropertyDescriptorUtils.GetSite(context, context.Instance);

            if (serviceProvider == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Messages.MissingService, new object[] { typeof(ISite).FullName }));
            }
            RuleSetCollection ruleSets    = null;
            RuleDefinitions   definitions = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity));

            if (definitions != null)
            {
                ruleSets = definitions.RuleSets;
            }
            if (((ruleSets != null) && (key.Length != 0)) && !ruleSets.Contains(key))
            {
                RuleSet item = new RuleSet {
                    Name = key
                };
                ruleSets.Add(item);
                ConditionHelper.Flush_Rules_DT(serviceProvider, Helpers.GetRootActivity(serviceProvider.Component as Activity));
            }
            return(new RuleSetReference {
                RuleSetName = key
            });
        }
Exemplo n.º 6
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);
        }