private static TextBlock FormatCondition([NotNull] RuleConditionDescriptor descriptor, bool isFirst) { Debug.ArgumentNotNull(descriptor, nameof(descriptor)); var textBlock = new TextBlock(); if (!isFirst) { var span = new Span(); FormatOperator(descriptor, span); span.Tag = descriptor; textBlock.Inlines.Add(span); textBlock.Inlines.Add(new Run(@" ")); } var notHyperlink = new Hyperlink(new Run(descriptor.IsNot ? @"except when" : @"when")); notHyperlink.Tag = descriptor; textBlock.Inlines.Add(notHyperlink); textBlock.Inlines.Add(new Run(@" ")); FormatText(textBlock, descriptor.DisplayText, descriptor.Parameters); return(textBlock); }
/// <summary>Adds the condition.</summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Input.MouseButtonEventArgs"/> instance containing the event data.</param> private void AddCondition([NotNull] object sender, [NotNull] MouseButtonEventArgs e) { Debug.ArgumentNotNull(sender, "sender"); Debug.ArgumentNotNull(e, "e"); var selectedItem = this.Conditions.SelectedItem as ListBoxItem; if (selectedItem == null) { return; } var condition = selectedItem.Tag as RuleManager.RuleConditionInfo; if (condition == null) { return; } var descriptor = new RuleConditionDescriptor { Condition = condition.GetInstance(), Operator = RuleConditionDescriptorOperator.And, IsNot = false }; /* * this.Rule.ConditionDescriptors.Add(descriptor); * * this.RenderRule(this.Rule); */ }
private static void FormatOperator([NotNull] RuleConditionDescriptor descriptor, [NotNull] Span span) { Debug.ArgumentNotNull(descriptor, nameof(descriptor)); Debug.ArgumentNotNull(span, nameof(span)); if (descriptor.Operator == RuleConditionDescriptorOperator.And) { span.Inlines.Add(new Run(@" ")); } var op = descriptor.Operator == RuleConditionDescriptorOperator.And ? @"and" : @"or"; var operatorHyperlink = new Hyperlink(new Run(op)); operatorHyperlink.Tag = descriptor; span.Inlines.Add(operatorHyperlink); }
private void FormatOperator([NotNull] RuleConditionDescriptor descriptor, [NotNull] Span span) { Debug.ArgumentNotNull(descriptor, "descriptor"); Debug.ArgumentNotNull(span, "span"); if (descriptor.Operator == RuleConditionDescriptorOperator.And) { span.Inlines.Add(new Run(@" ")); } var op = descriptor.Operator == RuleConditionDescriptorOperator.And ? @"and" : @"or"; var operatorHyperlink = new Hyperlink(new Run(op)); operatorHyperlink.Click += this.ToggleOperator; operatorHyperlink.Tag = descriptor; span.Inlines.Add(operatorHyperlink); }
private bool MoveCondition([NotNull] Rule rule, [NotNull] RuleConditionDescriptor condition, bool dryRun) { Debug.ArgumentNotNull(rule, nameof(rule)); Debug.ArgumentNotNull(condition, nameof(condition)); var index = rule.ConditionDescriptors.IndexOf(condition) + GetOffset(); if (index < 0 || index >= rule.ConditionDescriptors.Count) { return(false); } if (!dryRun) { rule.ConditionDescriptors.Remove(condition); rule.ConditionDescriptors.Insert(index, condition); } return(true); }
private static void LoadConditions([NotNull] XElement conditions, [NotNull] Rule rule) { Debug.ArgumentNotNull(conditions, nameof(conditions)); Debug.ArgumentNotNull(rule, nameof(rule)); foreach (var element in conditions.Elements()) { var condition = new RuleConditionDescriptor { IsNot = element.GetAttributeValue("not") == @"true", Operator = element.GetAttributeValue("operator") == @"and" ? RuleConditionDescriptorOperator.And : RuleConditionDescriptorOperator.Or, Condition = GetInstance <RuleCondition>(element.GetAttributeValue("type")) }; var parameters = element.Element(@"parameters"); if (parameters != null) { LoadParameters(parameters, condition.Parameters); } rule.ConditionDescriptors.Add(condition); } }