private void SetupExecutionPlanBindings(LoadTesterConfiguration configuration)
        {
            _currentConfig = configuration;

            SuspendLayout();

            currentPlan_Label.Text        = "Execution Plan for: '{0}'".FormatWith(configuration.Name);
            currentActivity_Panel.Enabled = true;

            SelectTab(_currentConfig.ExecutionPlan.Mode);
            SelectTab(_currentConfig.ExecutionPlan.RampUpMode);

            // Set up execution thread count for the current plan
            threadCount_NumericUpDown.ValueChanged -= threadCount_NumericUpDown_ValueChanged;
            threadCount_NumericUpDown.Maximum       = 500;
            threadCount_NumericUpDown.Minimum       = 1;
            threadCount_NumericUpDown.Value         = _currentConfig.ThreadCount;
            threadCount_NumericUpDown.ValueChanged += threadCount_NumericUpDown_ValueChanged;

            // Set up the number of threads to start if the ramp up is in a rate based mode
            rampUpThreadCount_NumericUpDown.ValueChanged -= rampUpThreadCount_NumericUpDown_ValueChanged;
            rampUpThreadCount_NumericUpDown.Maximum       = _currentConfig.ThreadCount;
            rampUpThreadCount_NumericUpDown.Minimum       = 1;
            rampUpThreadCount_NumericUpDown.Value         = (_currentConfig.ExecutionPlan.RampUpPacingThreads < _currentConfig.ThreadCount)
                                                  ? _currentConfig.ExecutionPlan.RampUpPacingThreads
                                                  : _currentConfig.ThreadCount;
            rampUpThreadCount_NumericUpDown.ValueChanged += rampUpThreadCount_NumericUpDown_ValueChanged;

            // Set the initial value and update it through the ValueChanged event
            rampUpThreads_TimeSpanControl.Value = _currentConfig.ExecutionPlan.RampUpPacingDelay;

            // Set the initial value and update it through the ValueChanged event
            rampUp_TimeDelayControl.Randomize = _currentConfig.ExecutionPlan.RandomizeRampUpDelay;
            rampUp_TimeDelayControl.MinDelay  = TimeSpan.FromSeconds(_currentConfig.ExecutionPlan.MinRampUpDelay);
            rampUp_TimeDelayControl.MaxDelay  = TimeSpan.FromSeconds(_currentConfig.ExecutionPlan.MaxRampUpDelay);

            // Clear, then reset the data bindings for the activity duration value
            duration_TextBox.DataBindings.Clear();
            Binding binding = new Binding("Text", _currentConfig.ExecutionPlan, "DurationTime");

            binding.Format += new ConvertEventHandler(ConvertTotalMinutesToHourMinute);
            binding.Parse  += new ConvertEventHandler(ConvertHourMinuteToTotalMinutes);
            duration_TextBox.DataBindings.Add(binding);

            delayInterval_CheckBox.DataBindings.Clear();
            delayInterval_CheckBox.DataBindings.Add("Checked", _currentConfig.ExecutionPlan, "DelayOneInterval");

            // Set the initial value and update it through the ValueChanged event
            pacing_TimeDelayControl.Randomize = _currentConfig.ExecutionPlan.RandomizeActivityDelay;
            pacing_TimeDelayControl.MinDelay  = TimeSpan.FromSeconds(_currentConfig.ExecutionPlan.MinActivityDelay);
            pacing_TimeDelayControl.MaxDelay  = TimeSpan.FromSeconds(_currentConfig.ExecutionPlan.MaxActivityDelay);

            // Clear and rebind the repeat count for the activity.
            repeatCount_TextBox.DataBindings.Clear();
            repeatCount_TextBox.DataBindings.Add("Text", _currentConfig.ExecutionPlan, "RepeatCount");

            ResumeLayout();
        }
        private void AddActivity(VirtualResourceMetadata metadata)
        {
            metadata.VirtualResourceId = _loadTester.VirtualResourceId;
            metadata.Enabled           = true;
            //metadata.ExecutionOrder = _loadTester.VirtualResourceMetadataSet.Count + 1;
            _loadTester.VirtualResourceMetadataSet.Add(metadata);

            LoadTesterConfiguration config = new LoadTesterConfiguration();

            //config.Name = metadata.Name;
            //config.MetadataType = metadata.MetadataType;
            //config.ThreadCount = 1;
            config.Metadata      = metadata;
            config.ExecutionPlan = new LoadTesterExecutionPlan();
            _configurations.Add(config);

            // Set the current plan to this new entry
            _currentConfig = config;
            activity_GridView.Rows[_configurations.Count - 1].IsSelected = true;

            switch (config.ExecutionPlan.Mode)
            {
            case ExecutionMode.RateBased:
                execution_TabControl.SelectedTab = rateBased_TabPage;
                break;

            case ExecutionMode.Duration:
                execution_TabControl.SelectedTab = timeBased_TabPage;
                break;

            case ExecutionMode.Poisson:
                execution_TabControl.SelectedTab = poisson_TabPage;
                break;
            }

            switch (config.ExecutionPlan.RampUpMode)
            {
            case RampUpMode.RateBased:
                rampUp_TabControl.SelectedTab = timeBasedRampUp_TabPage;
                break;

            case RampUpMode.TimeBased:
                rampUp_TabControl.SelectedTab = rateBasedRampUp_TabPage;
                break;
            }

            SetupExecutionPlanBindings(config);
        }
        /// <summary>
        /// Initializes this instance with the specified object.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <exception cref="ControlTypeMismatchException">
        /// Thrown when an object of incorrect type is passed to this instance.
        ///   </exception>
        public override void Initialize(object entity)
        {
            _loadTester = entity as LoadTester;
            if (_loadTester == null)
            {
                throw new ControlTypeMismatchException(entity, typeof(LoadTester));
            }

            // Load the configurations into the helper class
            LoadTesterConfiguration config = null;

            foreach (var item in _loadTester.VirtualResourceMetadataSet)
            {
                config          = new LoadTesterConfiguration();
                config.Metadata = item;

                if (item.ExecutionPlan == null)
                {
                    config.ExecutionPlan = new LoadTesterExecutionPlan();
                }
                else
                {
                    config.ExecutionPlan = LegacySerializer.DeserializeDataContract <LoadTesterExecutionPlan>(item.ExecutionPlan);
                }

                _configurations.Add(config);
            }

            // Load the activities into the binding list
            activity_GridView.DataSource = _configurations;
            activity_GridView.BestFitColumns();

            if (!GlobalSettings.IsDistributedSystem)
            {
                virtualMachinePlatform_ComboBox.Visible = false;
                platform_Label.Visible = false;
                _loadTester.Platform   = "LOCAL";
            }
            else
            {
                virtualMachinePlatform_ComboBox.SetPlatform(_loadTester.Platform, WorkerType);
            }

            name_TextBox.DataBindings.Add("Text", _loadTester, "Name");
            description_TextBox.DataBindings.Add("Text", _loadTester, "Description");

            // Set up execution thread count for the current plan
            maxThreadsPerVM_NumericUpDown.ValueChanged -= maxThreadsPerVM_NumericUpDown_ValueChanged;
            maxThreadsPerVM_NumericUpDown.Maximum       = 500;
            maxThreadsPerVM_NumericUpDown.Minimum       = 1;
            maxThreadsPerVM_NumericUpDown.Value         = _loadTester.ThreadsPerVM;
            maxThreadsPerVM_NumericUpDown.ValueChanged += maxThreadsPerVM_NumericUpDown_ValueChanged;

            CreateActivityDropDownMenu();

            if (_configurations.Count > 0)
            {
                // Select the first item in the list and then setup the databindings for that list.
                activity_GridView.Rows[0].IsSelected = true;
                var configuration = activity_GridView.Rows[0].DataBoundItem as LoadTesterConfiguration;
                SetupExecutionPlanBindings(configuration);
            }
        }