Click here to Skip to main content
15,891,902 members
Articles / Hosted Services / Azure

Azure Service Bus Tester

Rate me:
Please Sign up or sign in to vote.
4.96/5 (16 votes)
27 Dec 2014CPOL28 min read 90K   2.9K   24  
This article describes the design and implementation of the small tool, tester for Windows Azure Service Bus Messaging.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Microsoft.ServiceBus.Messaging;
using Microsoft.ServiceBus;

namespace RKiss.Tools.ServiceBusTester.Dialogs
{
    public partial class SubscriptionDialog : Form
    {
        SubscriptionDescription subscriptionDescription;
        NamespaceManager namespaceManager;

        public SubscriptionDialog(NamespaceManager manager, SubscriptionDescription subscription, IEnumerable<RuleDescription> rules)
        {
            InitializeComponent();

            this.namespaceManager = manager;
            this.subscriptionDescription = subscription;
            this.textBoxName.Text = subscription.Name;
            this.textBoxTopicPath.Text = subscription.TopicPath;
            this.textBoxMessageCount.Text = subscription.MessageCount.ToString();
            this.textBoxMessageDeliveryCount.Text = subscription.MaxDeliveryCount.ToString();
            this.textBoxLockDuration.Text = subscription.LockDuration.ToString();
            this.textBoxStatus.Text = subscription.Status.ToString();
            this.textBoxForwardTo.Text = subscription.ForwardTo;
            this.textBoxUpdatedAt.Text = subscription.UpdatedAt.ToString();

            this.checkedListBoxOptions.Items.Add("EnableBatchedOperations", subscription.EnableBatchedOperations);
            this.checkedListBoxOptions.Items.Add("EnableDeadLetteringOnFilterEvaluationExceptions", subscription.EnableDeadLetteringOnFilterEvaluationExceptions);
            this.checkedListBoxOptions.Items.Add("EnableDeadLetteringOnMessageExpiration", subscription.EnableDeadLetteringOnMessageExpiration);
            this.checkedListBoxOptions.Items.Add("RequiresSession", subscription.RequiresSession);
            this.checkedListBoxOptions.Enabled = false;

            foreach (RuleDescription rule in rules)
            {
                this.dataGridViewRules.Rows.Add(rule.Name, (rule.Filter as SqlFilter).SqlExpression, (rule.Action is SqlRuleAction) ? (rule.Action as SqlRuleAction).SqlExpression : string.Empty);
            }

            this.Text += " - " + subscription.Name;

            if (rules.Count() > 0)
            {
                this.Height = this.Size.Height + Math.Min(rules.Count(), 5) * this.dataGridViewRules.Rows[0].Height;
                this.MinimumSize = new Size(this.Size.Width, this.Size.Height);
            }
            this.dataGridViewRules.DefaultCellStyle.SelectionBackColor = Color.DarkSlateBlue;
        }

        private void textBoxForwardTo_TextChanged(object sender, EventArgs e)
        {
            this.buttonPut.Visible = this.textBoxForwardTo.Text != subscriptionDescription.ForwardTo;
        }

        private void buttonPut_Click(object sender, EventArgs e)
        {
            try
            {
                this.subscriptionDescription.ForwardTo = this.textBoxForwardTo.Text;
                namespaceManager.UpdateSubscription(this.subscriptionDescription);
                this.buttonPut.Visible = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Update Subscription", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions