コード例 #1
0
        static internal string GetRuleSetPreview(RuleSet ruleSet)
        {
            StringBuilder preview = new StringBuilder();
            bool          first   = true;

            if (ruleSet != null)
            {
                foreach (Rule rule in ruleSet.Rules)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        preview.Append("\n");
                    }

                    preview.Append(rule.Name);
                    preview.Append(": ");
                    preview.Append(DesignerHelpers.GetRulePreview(rule));
                }
            }

            return(preview.ToString());
        }
コード例 #2
0
 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;
     }
 }
コード例 #3
0
 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);
             }
         }
     }
 }
コード例 #4
0
 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;
     }
 }
コード例 #5
0
 private void UpdateItem(ListViewItem listViewItem, Rule rule)
 {
     listViewItem.SubItems[0].Text = rule.Name;
     listViewItem.SubItems[1].Text = rule.Priority.ToString(CultureInfo.CurrentCulture);
     listViewItem.SubItems[2].Text = (string)this.reevaluationComboBox.Items[(int)rule.ReevaluationBehavior];
     listViewItem.SubItems[3].Text = rule.Active.ToString(CultureInfo.CurrentCulture);
     listViewItem.SubItems[4].Text = DesignerHelpers.GetRulePreview(rule);
 }
コード例 #6
0
        protected override void UpdatePreview(TextBox previewBox, object ruleObject)
        {
            RuleSet ruleSet = ruleObject as RuleSet;

            NativeMethods.SendMessage(previewBox.Handle, NativeMethods.WM_SETREDRAW, IntPtr.Zero, IntPtr.Zero);
            previewBox.Lines = DesignerHelpers.GetRuleSetPreview(ruleSet).Split('\n');
            NativeMethods.SendMessage(previewBox.Handle, NativeMethods.WM_SETREDRAW, new IntPtr(1), IntPtr.Zero);
            previewBox.Invalidate();
        }
コード例 #7
0
        protected override void UpdatePreview(TextBox previewBox, object ruleObject)
        {
            RuleSet ruleSet = ruleObject as RuleSet;

            System.Workflow.Activities.Common.NativeMethods.SendMessage(previewBox.Handle, 11, IntPtr.Zero, IntPtr.Zero);
            previewBox.Lines = DesignerHelpers.GetRuleSetPreview(ruleSet).Split(new char[] { '\n' });
            System.Workflow.Activities.Common.NativeMethods.SendMessage(previewBox.Handle, 11, new IntPtr(1), IntPtr.Zero);
            previewBox.Invalidate();
        }
コード例 #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 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);
        }
コード例 #9
0
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            RuleSet ruleSet = value as RuleSet;

            if ((destinationType == typeof(string)) && (ruleSet != null))
            {
                return(DesignerHelpers.GetRuleSetPreview(ruleSet));
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
コード例 #10
0
 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;
     }
 }
コード例 #11
0
 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);
         }
     }
 }
コード例 #12
0
        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);
                    }
                }
            }
        }
コード例 #13
0
 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);
     }
 }
コード例 #14
0
 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);
     }
 }
コード例 #15
0
 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);
     }
 }
コード例 #16
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 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);
        }