예제 #1
0
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            object obj2 = o;

            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (this.editorService != null)
            {
                Activity          component = null;
                IReferenceService service   = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
                if (service != null)
                {
                    component = service.GetComponent(typeDescriptorContext.Instance) as Activity;
                }
                string           name      = null;
                RuleSetReference reference = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as RuleSetReference;
                if (reference != null)
                {
                    name = reference.RuleSetName;
                }
                RuleSetBrowserDialog dialog = new RuleSetBrowserDialog(component, name);
                if (DialogResult.OK == this.editorService.ShowDialog(dialog))
                {
                    obj2 = typeDescriptorContext.PropertyDescriptor.Converter.ConvertFrom(typeDescriptorContext, CultureInfo.CurrentUICulture, dialog.SelectedName);
                }
            }
            return(obj2);
        }
        public override object GetValue(object component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }

            RuleSetReference ruleSetReference = component as RuleSetReference;

            if (!string.IsNullOrEmpty(ruleSetReference.RuleSetName))
            {
                RuleDefinitions rules = GetRuleDefinitions(component);
                if (rules != null)
                {
                    RuleSetCollection ruleSetCollection = rules.RuleSets;
                    if (ruleSetCollection != null && ruleSetCollection.Contains(ruleSetReference.RuleSetName))
                    {
                        //in this case, RuleExpressionCondition is the only type allowed in the ruleConditionCollection
                        RuleSet ruleSet = ruleSetCollection[ruleSetReference.RuleSetName];
                        return(ruleSet);
                    }
                }
            }
            return(null);
        }
예제 #3
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));
                }
            }
        }
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            object obj2 = o;
            WorkflowDesignerLoader loader = serviceProvider.GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

            if ((loader != null) && loader.InDebugMode)
            {
                throw new InvalidOperationException(Messages.DebugModeEditsDisallowed);
            }
            RuleSetReference instance = typeDescriptorContext.Instance as RuleSetReference;

            if (((instance == null) || (instance.RuleSetName == null)) || (instance.RuleSetName.Length <= 0))
            {
                throw new ArgumentException(Messages.RuleSetNameNotSet);
            }
            Activity          component = null;
            IReferenceService service   = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;

            if (service != null)
            {
                component = service.GetComponent(typeDescriptorContext.Instance) as Activity;
            }
            RuleSetCollection ruleSets    = null;
            RuleDefinitions   definitions = ConditionHelper.Load_Rules_DT(serviceProvider, System.Workflow.Activities.Common.Helpers.GetRootActivity(component));

            if (definitions != null)
            {
                ruleSets = definitions.RuleSets;
            }
            if ((ruleSets != null) && !ruleSets.Contains(instance.RuleSetName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, new object[] { instance.RuleSetName }));
            }
            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (this.editorService != null)
            {
                RuleSet ruleSet = ruleSets[instance.RuleSetName];
                using (RuleSetDialog dialog = new RuleSetDialog(component, ruleSet))
                {
                    if (DialogResult.OK == this.editorService.ShowDialog(dialog))
                    {
                        obj2 = dialog.RuleSet;
                    }
                }
            }
            return(obj2);
        }
        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);
        }
예제 #7
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }
            if (destinationType != typeof(string))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }
            RuleSetReference reference = value as RuleSetReference;

            if (reference != null)
            {
                return(reference.RuleSetName);
            }
            return(null);
        }
예제 #8
0
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            object returnVal = o;

            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (editorService != null)
            {
                Activity baseActivity = null;

                IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;
                if (rs != null)
                {
                    baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
                }

                string           ruleSetName      = null;
                RuleSetReference ruleSetReference = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as RuleSetReference;
                if (ruleSetReference != null)
                {
                    ruleSetName = ruleSetReference.RuleSetName;
                }

                RuleSetBrowserDialog dlg = new RuleSetBrowserDialog(baseActivity, ruleSetName);

                if (DialogResult.OK == editorService.ShowDialog(dlg))
                {
                    returnVal = typeDescriptorContext.PropertyDescriptor.Converter.ConvertFrom(typeDescriptorContext, CultureInfo.CurrentUICulture, dlg.SelectedName);
                }
            }

            return(returnVal);
        }
        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));
                }
            }
        }
예제 #10
0
        public override object GetValue(object component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            RuleSetReference reference = component as RuleSetReference;

            if (!string.IsNullOrEmpty(reference.RuleSetName))
            {
                RuleDefinitions ruleDefinitions = base.GetRuleDefinitions(component);
                if (ruleDefinitions != null)
                {
                    RuleSetCollection ruleSets = ruleDefinitions.RuleSets;
                    if ((ruleSets != null) && ruleSets.Contains(reference.RuleSetName))
                    {
                        return(ruleSets[reference.RuleSetName]);
                    }
                }
            }
            return(null);
        }
예제 #11
0
        internal static string ConvertRuleSetReference(RuleSetReference ruleReference, RuleDefinitions ruleDefinitions, bool displayActivityDetails = true)
        {
            var    builder     = new StringBuilder();
            string ruleSetName = ruleReference.RuleSetName;

            try
            {
                RuleSet ruleSet = ruleDefinitions.RuleSets.First(x => x.Name == ruleSetName);
                if (ruleSet.Rules.Count > 0)
                {
                    builder.Append(ConvertRuleSet(ruleSet, displayActivityDetails));
                }
                else
                {
                    builder.Append("No rules existing for this ruleset: " + ruleSetName);
                }
            }
            catch
            {
                //builder.AppendFormat("This activity executes rules group by name '{0}' ", ruleSetName);
            }
            return(builder.ToString());
        }
        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;
        }
예제 #13
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);
        }
예제 #14
0
        public override object EditValue(ITypeDescriptorContext typeDescriptorContext, IServiceProvider serviceProvider, object o)
        {
            if (typeDescriptorContext == null)
            {
                throw new ArgumentNullException("typeDescriptorContext");
            }
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            object returnVal = o;

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

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

            // Do not allow editing expression if the name is not set.
            RuleSetReference ruleSetReference = typeDescriptorContext.Instance as RuleSetReference;

            if (ruleSetReference == null || ruleSetReference.RuleSetName == null || ruleSetReference.RuleSetName.Length <= 0)
            {
                throw new ArgumentException(Messages.RuleSetNameNotSet);
            }

            Activity baseActivity = null;

            IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService;

            if (rs != null)
            {
                baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity;
            }

            RuleSetCollection ruleSetCollection = null;
            RuleDefinitions   rules             = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity));

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

            if (ruleSetCollection != null && !ruleSetCollection.Contains(ruleSetReference.RuleSetName))
            {
                string message = string.Format(CultureInfo.CurrentCulture, Messages.RuleSetNotFound, ruleSetReference.RuleSetName);
                throw new ArgumentException(message);
            }

            this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
            if (editorService != null)
            {
                RuleSet ruleSet = ruleSetCollection[ruleSetReference.RuleSetName];
                using (RuleSetDialog dlg = new RuleSetDialog(baseActivity, ruleSet))
                {
                    if (DialogResult.OK == editorService.ShowDialog(dlg))
                    {
                        returnVal = dlg.RuleSet;
                    }
                }
            }
            return(returnVal);
        }