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); }
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); }
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)); } } }
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); }
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 }); }
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); }
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); }