private void btnCreateDelete_Click(object sender, EventArgs e) { try { if (serviceBusHelper == null) { return; } if (btnCreateDelete.Text == DeleteText) { using (var deleteForm = new DeleteForm(eventHubDescription.Path, EventHubEntity.ToLower())) { if (deleteForm.ShowDialog() == DialogResult.OK) { serviceBusHelper.DeleteEventHub(eventHubDescription); } } } else { if (string.IsNullOrWhiteSpace(txtPath.Text)) { writeToLog(PathCannotBeNull); return; } var description = new EventHubDescription(txtPath.Text) { UserMetadata = txtUserMetadata.Text }; description.MessageRetentionInDays = trackBarMessageRetentionInDays.Value; description.PartitionCount = trackBarPartitionCount.Value; var bindingList = authorizationRulesBindingSource.DataSource as BindingList <AuthorizationRuleWrapper>; if (bindingList != null) { for (var i = 0; i < bindingList.Count; i++) { var rule = bindingList[i]; if (serviceBusHelper.IsCloudNamespace) { if (string.IsNullOrWhiteSpace(rule.KeyName)) { writeToLog(string.Format(KeyNameCannotBeNull, i)); continue; } } var rightList = new List <AccessRights>(); if (rule.Manage) { rightList.AddRange(new[] { AccessRights.Manage, AccessRights.Send, AccessRights.Listen }); } else { if (rule.Send) { rightList.Add(AccessRights.Send); } if (rule.Listen) { rightList.Add(AccessRights.Listen); } } if (serviceBusHelper.IsCloudNamespace) { if (string.IsNullOrWhiteSpace(rule.SecondaryKey)) { description.Authorization.Add(new SharedAccessAuthorizationRule(rule.KeyName, rule.PrimaryKey ?? SharedAccessAuthorizationRule.GenerateRandomKey(), rightList)); } else { description.Authorization.Add(new SharedAccessAuthorizationRule(rule.KeyName, rule.PrimaryKey ?? SharedAccessAuthorizationRule.GenerateRandomKey(), rule.SecondaryKey ?? SharedAccessAuthorizationRule.GenerateRandomKey(), rightList)); } } else { description.Authorization.Add(new AllowRule(rule.IssuerName, rule.ClaimType, rule.ClaimValue, rightList)); } } } eventHubDescription = serviceBusHelper.CreateEventHub(description); InitializeControls(); } } catch (Exception ex) { HandleException(ex); } }