private void nameTextBox_Validating(object sender, CancelEventArgs e) { if (this.rulesListView.SelectedItems.Count > 0) { Rule rule = this.rulesListView.SelectedItems[0].Tag as Rule; if (this.nameTextBox.Text != rule.Name) { string ruleName = this.nameTextBox.Text; if (string.IsNullOrEmpty(ruleName)) { e.Cancel = true; DesignerHelpers.DisplayError(Messages.Error_RuleNameIsEmpty, this.Text, this.serviceProvider); } else if (rule.Name == ruleName) { this.nameTextBox.Text = ruleName; } else if (!IsUniqueIdentifier(ruleName)) { e.Cancel = true; DesignerHelpers.DisplayError(Messages.Error_DuplicateRuleName, this.Text, this.serviceProvider); } else { rule.Name = ruleName; UpdateItem(this.rulesListView.SelectedItems[0], rule); } } } }
private void conditionTextBox_Validating(object sender, CancelEventArgs e) { if (this.rulesListView.SelectedItems.Count == 0) { return; } try { Rule rule = this.rulesListView.SelectedItems[0].Tag as Rule; RuleCondition ruleCondition = this.ruleParser.ParseCondition(this.conditionTextBox.Text); rule.Condition = ruleCondition; if (!string.IsNullOrEmpty(this.conditionTextBox.Text)) { this.conditionTextBox.Text = ruleCondition.ToString().Replace("\n", "\r\n"); } UpdateItem(this.rulesListView.SelectedItems[0], rule); conditionErrorProvider.SetError(this.conditionTextBox, string.Empty); } catch (Exception ex) { conditionErrorProvider.SetError(this.conditionTextBox, ex.Message); DesignerHelpers.DisplayError(Messages.Error_ConditionParser + "\n" + ex.Message, this.Text, this.serviceProvider); e.Cancel = true; } }
private void elseTextBox_Validating(object sender, CancelEventArgs e) { if (this.rulesListView.SelectedItems.Count == 0) { return; } try { Rule rule = (Rule)this.rulesListView.SelectedItems[0].Tag; List <RuleAction> ruleElseActions = this.ruleParser.ParseStatementList(this.elseTextBox.Text); this.elseTextBox.Text = GetActionsString(ruleElseActions); rule.ElseActions.Clear(); foreach (RuleAction ruleAction in ruleElseActions) { rule.ElseActions.Add(ruleAction); } UpdateItem(this.rulesListView.SelectedItems[0], rule); elseErrorProvider.SetError(this.elseTextBox, string.Empty); } catch (Exception ex) { elseErrorProvider.SetError(this.elseTextBox, ex.Message); DesignerHelpers.DisplayError(Messages.Error_ActionsParser + "\n" + ex.Message, this.Text, this.serviceProvider); e.Cancel = true; } }
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; RuleConditionReference instance = typeDescriptorContext.Instance as RuleConditionReference; if (((instance == null) || (instance.ConditionName == null)) || (instance.ConditionName.Length <= 0)) { throw new ArgumentException(Messages.ConditionNameNotSet); } Activity component = null; IReferenceService service = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService; if (service != null) { component = service.GetComponent(typeDescriptorContext.Instance) as Activity; } RuleConditionCollection conditions = null; RuleDefinitions definitions = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(component)); if (definitions != null) { conditions = definitions.Conditions; } if ((conditions != null) && !conditions.Contains(instance.ConditionName)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, new object[] { instance.ConditionName })); } this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService)); if (this.editorService != null) { CodeExpression expression = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression; try { using (RuleConditionDialog dialog = new RuleConditionDialog(component, expression)) { if (DialogResult.OK == this.editorService.ShowDialog(dialog)) { obj2 = dialog.Expression; } } } catch (NotSupportedException) { DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider); } } return(obj2); }
private void RuleConditionDialog_FormClosing(object sender, FormClosingEventArgs e) { if (wasOKed && syntaxException != null) { e.Cancel = true; DesignerHelpers.DisplayError(Messages.Error_ConditionParser + "\n" + syntaxException.Message, this.Text, this.serviceProvider); if (syntaxException is RuleSyntaxException) { this.conditionTextBox.SelectionStart = ((RuleSyntaxException)syntaxException).Position; } this.conditionTextBox.SelectionLength = 0; this.conditionTextBox.ScrollToCaret(); wasOKed = false; } }
private void priorityTextBox_Validating(object sender, CancelEventArgs e) { if (this.rulesListView.SelectedItems.Count > 0) { Rule rule = this.rulesListView.SelectedItems[0].Tag as Rule; try { rule.Priority = int.Parse(this.priorityTextBox.Text, CultureInfo.CurrentCulture); UpdateItem(this.rulesListView.SelectedItems[0], rule); } catch { e.Cancel = true; DesignerHelpers.DisplayError(Messages.Error_InvalidPriority, this.Text, this.serviceProvider); } } }
private void OnDelete(object sender, EventArgs e) { MessageBoxOptions mbo = (MessageBoxOptions)0; if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft) { mbo = MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading; } DialogResult dr = MessageBox.Show(this, this.ConfirmDeleteMessageText, this.ConfirmDeleteTitleText, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, mbo); if (dr == DialogResult.OK) { using (new WaitCursor()) { object ruleObject = this.rulesListView.SelectedItems[0].Tag; try { this.OnComponentChanging(); int selectionIndex = this.rulesListView.SelectedIndices[0]; object selectedRuleObject = null; OnDeleteInternal(ruleObject); this.rulesListView.Items.RemoveAt(selectionIndex); if (this.rulesListView.Items.Count > 0) { int newSelectionIndex = Math.Min(selectionIndex, this.rulesListView.Items.Count - 1); this.rulesListView.Items[newSelectionIndex].Selected = true; selectedRuleObject = this.rulesListView.Items[newSelectionIndex].Tag; } this.UpdatePreview(this.previewRichTextBox, selectedRuleObject); this.OnComponentChanged(); } catch (InvalidOperationException ex) { DesignerHelpers.DisplayError(ex.Message, this.Text, this.activity.Site); } } } }
private void OnRename(object sender, EventArgs e) { try { this.OnComponentChanging(); object tag = this.rulesListView.SelectedItems[0].Tag; string str = this.OnRenameInternal(tag); if (str != null) { using (new WaitCursor()) { ListViewItem item = this.rulesListView.SelectedItems[0]; item.Text = str; this.OnComponentChanged(); } } } catch (InvalidOperationException exception) { DesignerHelpers.DisplayError(exception.Message, this.Text, this.activity.Site); } }
private void OnNew(object sender, EventArgs e) { try { this.OnComponentChanging(); object ruleObject = this.OnNewInternal(); if (ruleObject != null) { using (new WaitCursor()) { ListViewItem listViewItem = this.rulesListView.Items.Add(new ListViewItem()); this.UpdateListViewItem(ruleObject, listViewItem); listViewItem.Selected = true; this.OnComponentChanged(); } } } catch (InvalidOperationException exception) { DesignerHelpers.DisplayError(exception.Message, this.Text, this.activity.Site); } }
private void OnEdit(object sender, EventArgs e) { try { this.OnComponentChanging(); object updatedRuleObject = null; object tag = this.rulesListView.SelectedItems[0].Tag; if (this.OnEditInternal(tag, out updatedRuleObject)) { using (new WaitCursor()) { this.UpdateListViewItem(updatedRuleObject, this.rulesListView.SelectedItems[0]); this.UpdatePreview(this.previewRichTextBox, updatedRuleObject); this.OnComponentChanged(); } } } catch (InvalidOperationException exception) { DesignerHelpers.DisplayError(exception.Message, this.Text, this.activity.Site); } }
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 expression if the name is not set. RuleConditionReference conditionDeclaration = typeDescriptorContext.Instance as RuleConditionReference; if (conditionDeclaration == null || conditionDeclaration.ConditionName == null || conditionDeclaration.ConditionName.Length <= 0) { throw new ArgumentException(Messages.ConditionNameNotSet); } Activity baseActivity = null; IReferenceService rs = serviceProvider.GetService(typeof(IReferenceService)) as IReferenceService; if (rs != null) { baseActivity = rs.GetComponent(typeDescriptorContext.Instance) as Activity; } RuleConditionCollection conditionDefinitions = null; RuleDefinitions rules = ConditionHelper.Load_Rules_DT(serviceProvider, Helpers.GetRootActivity(baseActivity)); if (rules != null) { conditionDefinitions = rules.Conditions; } if (conditionDefinitions != null && !conditionDefinitions.Contains(conditionDeclaration.ConditionName)) { string message = string.Format(CultureInfo.CurrentCulture, Messages.ConditionNotFound, conditionDeclaration.ConditionName); throw new ArgumentException(message); } this.editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { CodeExpression experssion = typeDescriptorContext.PropertyDescriptor.GetValue(typeDescriptorContext.Instance) as CodeExpression; try { using (RuleConditionDialog dlg = new RuleConditionDialog(baseActivity, experssion)) { if (DialogResult.OK == editorService.ShowDialog(dlg)) { returnVal = dlg.Expression; } } } catch (NotSupportedException) { DesignerHelpers.DisplayError(Messages.Error_ExpressionNotSupported, Messages.ConditionEditor, serviceProvider); } } return(returnVal); }