private void btnCreateDelete_Click(object sender, EventArgs e) { try { if (serviceBusHelper == null || ruleWrapper == null || ruleWrapper.SubscriptionDescription == null) { return; } if (btnCreateDelete.Text == RemoveText && ruleWrapper.SubscriptionDescription != null && !string.IsNullOrWhiteSpace(ruleWrapper.SubscriptionDescription.Name) && ruleWrapper.RuleDescription != null && !string.IsNullOrWhiteSpace(ruleWrapper.RuleDescription.Name)) { using (var deleteForm = new DeleteForm(ruleWrapper.RuleDescription.Name, RuleEntity.ToLower())) { if (deleteForm.ShowDialog() == DialogResult.OK) { serviceBusHelper.RemoveRule(ruleWrapper.SubscriptionDescription, ruleWrapper.RuleDescription); } } return; } if (btnCreateDelete.Text == AddText) { if (string.IsNullOrWhiteSpace(txtName.Text)) { writeToLog(NameCannotBeNull); return; } var ruleDescription = new RuleDescription(txtName.Text); if (!string.IsNullOrWhiteSpace(txtSqlFilterExpression.Text)) { ruleDescription.Filter = new SqlFilter(txtSqlFilterExpression.Text); } if (!string.IsNullOrWhiteSpace(txtSqlFilterAction.Text)) { ruleDescription.Action = new SqlRuleAction(txtSqlFilterAction.Text); } ruleWrapper.RuleDescription = serviceBusHelper.AddRule(ruleWrapper.SubscriptionDescription, ruleDescription); InitializeData(); } } catch (Exception ex) { HandleException(ex); } }
/// <summary> /// Creates the subscriptions which xml definition is contained in the collection passed as a parameter. /// </summary> /// <param name="serviceBusHelper">A ServiceBusHelper object.</param> /// <param name="topicDescription">A description of the topic to which to add the subscription.</param> /// <param name="subscriptions">The IEnumerable<XElement/> collection containing the xml definition of the subscriptions to create.</param> private static void CreateSubscriptions(ServiceBusHelper serviceBusHelper, TopicDescription topicDescription, IEnumerable <XElement> subscriptions) { try { if (serviceBusHelper == null || subscriptions == null) { return; } var fullName = typeof(SubscriptionDescription).FullName; if (string.IsNullOrEmpty(fullName) || !propertyCache.ContainsKey(fullName)) { return; } var propertyDictionary = propertyCache[fullName]; var ruleName = string.Format(NodeNameFormat, Namespace, RuleEntity); var rulesName = string.Format(NodeNameFormat, Namespace, RuleEntityList); foreach (var subscription in subscriptions) { var propertyValue = new Dictionary <string, object>(); var properties = subscription.Elements(); IEnumerable <XElement> rules = null; foreach (var property in properties) { if (property.Name == rulesName) { rules = property.Descendants(ruleName); } else { var xmlReader = property.CreateReader(); GetPropertyValue(propertyDictionary, propertyValue, xmlReader); } } if (propertyValue.ContainsKey(Name) && propertyValue.ContainsKey(TopicPath)) { RuleDescription defaultRuleDescription = null; IEnumerable <RuleDescription> nonDefaultRuleDescriptions = null; var ruleDescriptions = CreateRules(serviceBusHelper, rules); if (ruleDescriptions != null) { defaultRuleDescription = ruleDescriptions.FirstOrDefault(r => r.Name == RuleDescription.DefaultRuleName); nonDefaultRuleDescriptions = ruleDescriptions.Where(r => r.Name != RuleDescription.DefaultRuleName); } var subscriptionDescription = new SubscriptionDescription(propertyValue[TopicPath] as string, propertyValue[Name] as string); SetPropertyValue(propertyDictionary, propertyValue, subscriptionDescription); if (defaultRuleDescription != null) { serviceBusHelper.CreateSubscription(topicDescription, subscriptionDescription, defaultRuleDescription); } else { serviceBusHelper.CreateSubscription(topicDescription, subscriptionDescription); } if (nonDefaultRuleDescriptions != null) { foreach (var ruleDescription in nonDefaultRuleDescriptions) { serviceBusHelper.AddRule(subscriptionDescription, ruleDescription); } } } } } catch (Exception ex) { HandleException(ex); } }
void btnCreateDelete_Click(object sender, EventArgs e) { try { if (serviceBusHelper == null || ruleWrapper?.SubscriptionDescription == null) { return; } if (btnCreateDelete.Text == RemoveText && !string.IsNullOrWhiteSpace(ruleWrapper.SubscriptionDescription?.Name) && !string.IsNullOrWhiteSpace(ruleWrapper.RuleDescription?.Name)) { using (var deleteForm = new DeleteForm(ruleWrapper.RuleDescription.Name, RuleEntity.ToLower())) { if (deleteForm.ShowDialog() == DialogResult.OK) { serviceBusHelper.RemoveRule(ruleWrapper.SubscriptionDescription, ruleWrapper.RuleDescription); } } return; } if (btnCreateDelete.Text != AddText) { return; } if (string.IsNullOrWhiteSpace(txtName.Text)) { writeToLog(NameCannotBeNull); return; } var ruleDescription = new RuleDescription(txtName.Text); if (checkBoxIsCorrelationFilter.Checked) { var filter = new CorrelationFilter() { ContentType = (!string.IsNullOrWhiteSpace(txtCorrelationFilterContentType.Text) ? txtCorrelationFilterContentType.Text : null), CorrelationId = (!string.IsNullOrWhiteSpace(txtCorrelationFilterCorrelationId.Text) ? txtCorrelationFilterCorrelationId.Text : null), Label = (!string.IsNullOrWhiteSpace(txtCorrelationFilterLabel.Text) ? txtCorrelationFilterLabel.Text : null), MessageId = (!string.IsNullOrWhiteSpace(txtCorrelationFilterMessageId.Text) ? txtCorrelationFilterMessageId.Text : null), ReplyTo = (!string.IsNullOrWhiteSpace(txtCorrelationFilterReplyTo.Text) ? txtCorrelationFilterReplyTo.Text : null), ReplyToSessionId = (!string.IsNullOrWhiteSpace(txtCorrelationFilterReplyToSessionId.Text) ? txtCorrelationFilterReplyToSessionId.Text : null), SessionId = (!string.IsNullOrWhiteSpace(txtCorrelationFilterSessionId.Text) ? txtCorrelationFilterSessionId.Text : null), To = (!string.IsNullOrWhiteSpace(txtCorrelationFilterTo.Text) ? txtCorrelationFilterTo.Text : null) }; if (userPropertyBindingList != null) { foreach (var prop in userPropertyBindingList) { filter.Properties.Add(prop.Name, prop.Value); } } ruleDescription.Filter = filter; } else { if (!string.IsNullOrWhiteSpace(txtFilterExpression.Text)) { ruleDescription.Filter = new SqlFilter(txtFilterExpression.Text); } } if (!string.IsNullOrWhiteSpace(txtSqlFilterAction.Text)) { ruleDescription.Action = new SqlRuleAction(txtSqlFilterAction.Text); } ruleWrapper.RuleDescription = serviceBusHelper.AddRule(ruleWrapper.SubscriptionDescription, ruleDescription); InitializeData(); } catch (Exception ex) { HandleException(ex); } }