public ContainerForm(ServiceBusHelper serviceBusHelper, MainForm mainForm, FormTypeEnum formType, SubscriptionWrapper subscriptionWrapper)
        {
            try
            {
                InitializeComponent();
                Task.Factory.StartNew(AsyncWriteToLog).ContinueWith(t =>
                {
                    if (t.IsFaulted && t.Exception != null)
                    {
                        WriteToLog(t.Exception.Message);
                    }
                });
                this.mainForm        = mainForm;
                mainSplitterDistance = mainSplitContainer.SplitterDistance;
                SuspendLayout();
                panelMain.SuspendDrawing();
                panelMain.Controls.Clear();
                panelMain.BackColor = SystemColors.GradientInactiveCaption;

                if (formType == FormTypeEnum.Listener)
                {
                    var listenerControl = new ListenerControl(WriteToLog, StopLog, StartLog, new ServiceBusHelper(WriteToLog, serviceBusHelper), subscriptionWrapper.SubscriptionDescription)
                    {
                        Location = new Point(1, panelMain.HeaderHeight + 1),
                        Size     = new Size(panelMain.Size.Width - 3, subscriptionWrapper.SubscriptionDescription.RequiresSession ? 544 : 520),
                        Anchor   = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                    };
                    listenerControl.Focus();

                    Text = string.Format(SubscriptionListenerFormat, subscriptionWrapper.SubscriptionDescription.Name);
                    mainSplitContainer.SplitterDistance = subscriptionWrapper.SubscriptionDescription.RequiresSession ? 570 : listenerControl.Size.Height + 26;
                    panelMain.HeaderText = string.Format(HeaderTextSubscriptionListenerFormat, subscriptionWrapper.SubscriptionDescription.Name);
                    panelMain.Controls.Add(listenerControl);
                }
                else
                {
                    testSubscriptionControl = new TestSubscriptionControl(mainForm, WriteToLog, StopLog, StartLog, new ServiceBusHelper(WriteToLog, serviceBusHelper), subscriptionWrapper)
                    {
                        Location = new Point(1, panelMain.HeaderHeight + 1),
                        Size     = new Size(panelMain.Size.Width - 3, panelMain.Size.Height - 26),
                        Anchor   = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                    };

                    testSubscriptionControl.btnCancel.Click -= testSubscriptionControl.btnCancel_Click;
                    testSubscriptionControl.btnCancel.Click += BtnCancelOnClick;
                    testSubscriptionControl.Focus();

                    Text = string.Format(TestSubscriptionFormat, subscriptionWrapper.SubscriptionDescription.Name);

                    panelMain.HeaderText = string.Format(HeaderTextTestSubscriptionFormat, subscriptionWrapper.SubscriptionDescription.Name);
                    panelMain.Controls.Add(testSubscriptionControl);
                }
                SetStyle(ControlStyles.ResizeRedraw, true);
            }
            finally
            {
                panelMain.ResumeDrawing();
                ResumeLayout();
            }
        }
        public ContainerForm(ServiceBusHelper serviceBusHelper, MainForm mainForm, FormTypeEnum formType, QueueDescription queueDescription)
        {
            try
            {
                InitializeComponent();
                Task.Factory.StartNew(AsyncWriteToLog).ContinueWith(t =>
                {
                    if (t.IsFaulted && t.Exception != null)
                    {
                        WriteToLog(t.Exception.Message);
                    }
                });
                this.mainForm        = mainForm;
                mainSplitterDistance = mainSplitContainer.SplitterDistance;
                SuspendLayout();
                panelMain.SuspendDrawing();
                panelMain.Controls.Clear();
                panelMain.BackColor = SystemColors.GradientInactiveCaption;

                if (formType == FormTypeEnum.Listener)
                {
                    var listenerControl = new ListenerControl(WriteToLog, StopLog, StartLog, new ServiceBusHelper(WriteToLog, serviceBusHelper), queueDescription)
                    {
                        Location = new Point(1, panelMain.HeaderHeight + 1),
                        Size     = new Size(panelMain.Size.Width - 3, queueDescription.RequiresSession ? 544 : 520),
                        Anchor   = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                    };
                    listenerControl.Focus();

                    Text = string.Format(QueueListenerFormat, queueDescription.Path);
                    mainSplitContainer.SplitterDistance = queueDescription.RequiresSession ? 570 : listenerControl.Size.Height + 26;
                    panelMain.HeaderText = string.Format(HeaderTextQueueListenerFormat, queueDescription.Path);
                    panelMain.Controls.Add(listenerControl);
                }
                else
                {
                    testQueueControl = new TestQueueControl(mainForm, WriteToLog, StopLog, StartLog, new ServiceBusHelper(WriteToLog, serviceBusHelper), queueDescription)
                    {
                        Location = new Point(1, panelMain.HeaderHeight + 1),
                        Size     = new Size(panelMain.Size.Width - 3, panelMain.Size.Height - 26),
                        Anchor   = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                    };


                    if (formType == FormTypeEnum.Send)
                    {
                        testQueueControl.mainTabControl.TabPages.RemoveAt(2);
                        testQueueControl.receiverEnabledCheckBox.Checked = false;
                        testQueueControl.senderEnabledCheckBox.Checked   = true;
                        testQueueControl.senderEnabledCheckBox.Visible   = false;
                        testQueueControl.grouperMessage.Location         = new Point(testQueueControl.grouperMessage.Location.X, 8);
                        testQueueControl.grouperMessage.Size             = new Size(testQueueControl.grouperMessage.Size.Width,
                                                                                    testQueueControl.grouperMessage.Size.Height + 16);
                        testQueueControl.grouperSender.Location = new Point(testQueueControl.grouperSender.Location.X, 8);
                        testQueueControl.grouperSender.Size     = new Size(testQueueControl.grouperSender.Size.Width,
                                                                           testQueueControl.grouperSender.Size.Height + 16);
                        Text = string.Format(SendMessagesFormat, queueDescription.Path);
                    }
                    else
                    {
                        Text             = string.Format(TestQueueFormat, queueDescription.Path);
                        logTraceListener = new LogTraceListener(WriteToLog);
                        Trace.Listeners.Add(logTraceListener);
                    }

                    testQueueControl.btnCancel.Text   = CloseLabel;
                    testQueueControl.btnCancel.Click -= testQueueControl.btnCancel_Click;
                    testQueueControl.btnCancel.Click += BtnCancelOnClick;
                    testQueueControl.Focus();

                    panelMain.HeaderText = string.Format(HeaderTextTestQueueFormat, queueDescription.Path);
                    panelMain.Controls.Add(testQueueControl);
                }
                SetStyle(ControlStyles.ResizeRedraw, true);
            }
            finally
            {
                panelMain.ResumeDrawing();
                ResumeLayout();
            }
        }