private void button1_Click(object sender, RoutedEventArgs e) { // verifiy that TargetObject property has been configured object input = ModelItem.Properties["Input"].ComputedValue; if (input == null) { System.Windows.MessageBox.Show("Input argument needs to be configured before adding the rules"); return; } // verify that target object is correctly configured InArgument arg = input as InArgument; if (arg == null) { System.Windows.MessageBox.Show("Invalid value for Input argument"); return; } // open the ruleset editor Type inputType = arg.ArgumentType; RuleSet ruleSet = ModelItem.Properties["RuleSet"].ComputedValue as RuleSet; if (ruleSet == null) ruleSet = new RuleSet(); // popup the dialog for editing the rules RuleSetDialog ruleSetDialog = new RuleSetDialog(inputType, null, ruleSet); DialogResult result = ruleSetDialog.ShowDialog(); // update the model item if (result == DialogResult.OK) //check if they cancelled { ModelItem.Properties["RuleSet"].SetValue(ruleSetDialog.RuleSet); } }
private void EditarReglasAutorizaciones(Type type, string fileName) { // Rules file name to serialize to and deserialize from RuleSet ruleSet = null; WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); if (Existe(fileName)) { ruleSet = GetRuleSetFromFile(fileName); } // Create a RuleSet that works with Orders (just another .net Object) RuleSetDialog ruleSetDialog = new RuleSetDialog(type, null, ruleSet); // Show the RuleSet Editor DialogResult result = ruleSetDialog.ShowDialog(); if (result == DialogResult.OK) { ruleSet = ruleSetDialog.RuleSet; // Serialize to a .rules file XmlWriter rulesWriter = XmlWriter.Create(fileName); serializer.Serialize(rulesWriter, ruleSet); rulesWriter.Close(); } }
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 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); }
public static void DesignRule(System.Workflow.ComponentModel.Activity activity, bool UseProvider) { RuleSet ruleSet = null; //MessageBox.Show(activity.UserData[0].ToString()); //MessageBox.Show(activity.GetType().ToString()); string ruleName = activity.UserData[0].ToString(); //load ruleset try { ruleSet = RuleSetManagerFactory.CreateRuleSetManager(RuleDesigner.RemotingUrl).getRuleSetDesign("", "", ruleName); } catch (Exception e) { MessageBox.Show("Error deserializing file: " + ruleName + e.Message); } if (ruleSet == null) { MessageBox.Show("RuleSet is null"); ruleSet = new RuleSet(ruleName); } RuleSetDialog ruleSetDialog = null; if (UseProvider) { TypeProvider provider = new TypeProvider(null); AssemblyName[] ass = activity.GetType().Assembly.GetReferencedAssemblies(); provider.AddAssembly(activity.GetType().Assembly); FillWithAssemblies(provider, ass); ruleSetDialog = new RuleSetDialog(activity.GetType(), provider, ruleSet); } else { ruleSetDialog = new RuleSetDialog(activity, ruleSet); } var result = ruleSetDialog.ShowDialog(); // Only update the .rules file if the OK is pressed if (result == DialogResult.OK) { ruleSet = ruleSetDialog.RuleSet; try { Console.WriteLine(ruleName); RuleSetManagerFactory.CreateRuleSetManager(RuleDesigner.RemotingUrl).saveRuleSetDesign("", "", ruleName, ruleSet); } catch (Exception e) { MessageBox.Show(e.ToString()); } } }
static void Main() { FileRepository rep = new FileRepository(); RuleSet ruleset = rep.Load(Filename); RuleSetDialog dialog = new RuleSetDialog(typeof(Person), null, ruleset); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { rep.Save(dialog.RuleSet, Filename); } }
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); } }
protected override object OnNewInternal() { using (RuleSetDialog dialog = new RuleSetDialog(base.Activity, null)) { if (DialogResult.OK == dialog.ShowDialog(this)) { RuleSet ruleSet = dialog.RuleSet; ruleSet.Name = this.ruleSetCollection.GenerateRuleSetName(); this.ruleSetCollection.Add(ruleSet); return(ruleSet); } } return(null); }
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; }
protected override bool OnEditInternal(object currentRuleObject, out object updatedRuleObject) { RuleSet ruleSet = currentRuleObject as RuleSet; updatedRuleObject = null; using (RuleSetDialog dialog = new RuleSetDialog(base.Activity, ruleSet)) { if (DialogResult.OK == dialog.ShowDialog()) { this.ruleSetCollection.Remove(ruleSet.Name); this.ruleSetCollection.Add(dialog.RuleSet); updatedRuleObject = dialog.RuleSet; return true; } } return false; }
protected override bool OnEditInternal(object currentRuleObject, out object updatedRuleObject) { RuleSet ruleSet = currentRuleObject as RuleSet; updatedRuleObject = null; using (RuleSetDialog dialog = new RuleSetDialog(base.Activity, ruleSet)) { if (DialogResult.OK == dialog.ShowDialog()) { this.ruleSetCollection.Remove(ruleSet.Name); this.ruleSetCollection.Add(dialog.RuleSet); updatedRuleObject = dialog.RuleSet; return(true); } } return(false); }
private void editButton_Click(object sender, EventArgs e) { if (selectedRuleSetData != null) { if (selectedRuleSetData.Activity != null) { RuleSetDialog ruleSetDialog = new RuleSetDialog(selectedRuleSetData.Activity, null, selectedRuleSetData.RuleSet); DialogResult result = ruleSetDialog.ShowDialog(); if (result == DialogResult.OK) //check if they cancelled { selectedRuleSetData.RuleSet = ruleSetDialog.RuleSet; this.MarkDirty(selectedRuleSetData); } } else { MessageBox.Show("You must first specify a target Activity for the RuleSet.", "RuleSet Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("You must first select a RuleSet.", "RuleSet Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
void viewRuleSetButton_Click(object sender, RoutedEventArgs e) { // get the rulesFilePath property object rulesFilePath = ModelItem.Properties["RulesFilePath"].Value; rulesFilePath = ((ModelItem)rulesFilePath).GetCurrentValue(); // correct the rules file path (in case is a relative path) string correctedRulesFilePath = GetRulesFilePath((string)rulesFilePath); // verify that RulesFilePath property has been configured if (rulesFilePath == null || !(rulesFilePath is string)) { System.Windows.MessageBox.Show("Rules File Path needs to be configured before viewing or editing the rules"); return; } else if (!File.Exists(correctedRulesFilePath)) { System.Windows.MessageBox.Show(string.Format("Rules File Path provided not found ({0})", correctedRulesFilePath)); return; } // verify that RuleSetName property has been configured object ruleSetName = ModelItem.Properties["RuleSetName"].Value; ruleSetName = ((ModelItem)ruleSetName).GetCurrentValue(); if (ruleSetName == null) { System.Windows.MessageBox.Show("RuleSet Name needs to be configured before viewing or editing the rules"); return; } // verify that TargetObject property has been configured object targetObject = ModelItem.Properties["TargetObject"].Value; targetObject = ((ModelItem)targetObject).GetCurrentValue(); if (targetObject == null) { System.Windows.MessageBox.Show("TargetObject needs to be configured before viewing or editing the rules"); return; } // verify that target object is correctly configured InArgument targetObjArg = targetObject as InArgument; if (targetObjArg == null) { System.Windows.MessageBox.Show("Invalid target object"); return; } // open the ruleset editor Type targetObjectType = targetObjArg.ArgumentType; WorkflowMarkupSerializer ser = new WorkflowMarkupSerializer(); RuleDefinitions ruleDefs = ser.Deserialize(new System.Xml.XmlTextReader((string)correctedRulesFilePath)) as RuleDefinitions; RuleSet ruleSet = ruleDefs.RuleSets[(string)ruleSetName]; // popup the dialog for viewing the rules RuleSetDialog ruleSetDialog = new RuleSetDialog(targetObjectType, null, ruleSet); DialogResult result = ruleSetDialog.ShowDialog(); // update if they changed the Rules if (result == DialogResult.OK) //If OK was pressed { for (int index = 0; index < ruleDefs.RuleSets.Count; index++) { if (ruleDefs.RuleSets[index].Name == (string)ruleSetName) { ruleDefs.RuleSets[index] = ruleSetDialog.RuleSet; break; } } try { ser.Serialize(new System.Xml.XmlTextWriter(correctedRulesFilePath, null), ruleDefs); } catch (UnauthorizedAccessException) { // File does not have write access. Make a local copy so user changes are not lost FileInfo fileInfo = new FileInfo(correctedRulesFilePath); // create local file by adding a random suffix to original filename string localFileCopy = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.')) + new Random().Next() + fileInfo.Extension; ser.Serialize(new System.Xml.XmlTextWriter((string)localFileCopy, null), ruleDefs); System.Windows.MessageBox.Show("Rules file is not writeable. Created copy of your changes in " + localFileCopy); } } }
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; }
private void LstRulesSelectedIndexChanged(object sender, EventArgs e) { if (lstRules.SelectedIndex != -1) { var item = (BindItem)lstRules.SelectedItem; if (item == null) return; var model = (RulesDomModel)item.Value; var set = (RuleSet)model.ParentRuleSet; using (var dialog = new RuleSetDialog(typeof(Activity), null, set)) { dialog.ShowDialog(); } } }
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); }