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