/// <summary> /// Gets the AssociatedProducts for the given scenario. /// </summary> /// <param name="context">The EnterpriseTest data context.</param> /// <param name="scenario">The scenario.</param> /// <returns>The AssociatedProducts for the given scenario.</returns> public static IEnumerable <ScenarioProduct> GetAssociatedProducts(EnterpriseTestContext context, EnterpriseScenario scenario) { List <string> metadataTypes = new List <string>(); foreach (VirtualResource vr in scenario.VirtualResources) { foreach (var vrms in vr.VirtualResourceMetadataSet) { metadataTypes.Add(vrms.MetadataType); } } List <AssociatedProduct> associatedProducts = context.AssociatedProducts.Where(n => n.MetadataTypes.Any(m => metadataTypes.Contains(m.Name))).ToList(); IEnumerable <Guid> productIds = associatedProducts.Select(x => x.AssociatedProductId); List <AssociatedProductVersion> productVersions = AssociatedProductVersion.SelectVersions(context, productIds, scenario.EnterpriseScenarioId).ToList(); return(from productInfo in associatedProducts join versionInfo in productVersions on productInfo.AssociatedProductId equals versionInfo.AssociatedProductId select new ScenarioProduct { ProductId = productInfo.AssociatedProductId, Version = versionInfo.Version, ScenarioId = versionInfo.EnterpriseScenarioId, Name = productInfo.Name, Vendor = productInfo.Vendor, Active = versionInfo.Active }); }
/// <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) { _scenario = entity as EnterpriseScenario; if (_scenario == null) { throw new ControlTypeMismatchException(entity, typeof(EnterpriseScenario)); } _owner = _scenario.Owner; // Set data source for the grid view and resize the columns resource_GridView.DataSource = _scenario.VirtualResources; resource_GridView.BestFitColumns(); // Set data sources for combo boxes using (EnterpriseTestContext context = new EnterpriseTestContext()) { string scenarioTags = GlobalSettings.Items[Setting.ScenarioTags]; vertical_ComboBox.Items.AddRange(scenarioTags.Split(',')); category_ComboBox.DataSource = EnterpriseScenario.SelectDistinctCompany(context).ToList(); if (UserManager.CurrentUser.HasPrivilege(UserRole.Manager) || (!string.IsNullOrEmpty(_scenario.Owner) && _scenario.Owner.Equals(UserManager.CurrentUserName))) { owner_ComboBox.Items.Add("Unknown"); foreach (var name in context.Users.Select(x => x.UserName)) { owner_ComboBox.Items.Add(name); } owner_ComboBox.SelectedItem = _scenario.Owner; editorGroups_CheckedListBox.BackColor = Color.FromKnownColor(KnownColor.Window); } else { owner_ComboBox.Items.Add(_scenario.Owner); editorGroups_CheckedListBox.SelectionMode = SelectionMode.None; editorGroups_CheckedListBox.BackColor = Color.FromKnownColor(KnownColor.Control); } LoadGroups(context); foreach (var group in context.UserGroups) { _availableGroups.Add(group); } sessionCycle_ComboBox.DataSource = ResourceWindowsCategory.Select(context, ResourceWindowsCategoryType.SessionCycle.ToString()); sessionCycle_ComboBox.SelectedIndex = -1; if (!string.IsNullOrEmpty(_scenario.ScenarioSettings)) { _settings = LegacySerializer.DeserializeDataContract <ScenarioSettings>(_scenario.ScenarioSettings); sessionCycle_ComboBox.SelectedIndex = ResourceWindowsCategory.Select(context, ResourceWindowsCategoryType.SessionCycle.ToString()).Select(x => x.Name).ToList().IndexOf(_settings.TargetCycle); } List <string> metadatas = new List <string>(); foreach (VirtualResource vr in _scenario.VirtualResources.Where(n => n.Enabled)) { foreach (var vrms in vr.VirtualResourceMetadataSet.Where(n => n.Enabled)) { metadatas.Add(vrms.MetadataType); } } _associatedProducts = context.AssociatedProducts.Where(n => n.MetadataTypes.Any(m => metadatas.Contains(m.Name))).ToList(); var productIds = _associatedProducts.Select(x => x.AssociatedProductId); _productVersions = AssociatedProductVersion.SelectVersions(context, productIds, _scenario.EnterpriseScenarioId).ToList(); _scenarioProducts = from productInfo in _associatedProducts join versionInfo in _productVersions on productInfo.AssociatedProductId equals versionInfo.AssociatedProductId select new ScenarioProduct { ProductId = productInfo.AssociatedProductId, Version = versionInfo.Version, ScenarioId = _scenario.EnterpriseScenarioId, Name = productInfo.Name, Vendor = productInfo.Vendor, Active = versionInfo.Active }; var scenarioProducts = _scenarioProducts.ToList(); if (scenarioProducts.Count != 0) { scenarioProductBindingSource.Clear(); scenarioProductBindingSource.DataSource = scenarioProducts.Distinct(new ScenarioProductEqualityComparer()); scenarioProductBindingSource.ResetBindings(true); } } // Set up data bindings name_TextBox.DataBindings.Add("Text", _scenario, "Name"); description_TextBox.DataBindings.Add("Text", _scenario, "Description"); category_ComboBox.DataBindings.Add("Text", _scenario, "Company"); vertical_ComboBox.DataBindings.Add("Text", _scenario, "Vertical"); //owner_ComboBox.DataBindings.Add("Text", _scenario, "Owner"); CreateResourceDropDownMenu(); //_associateProductHandler.CopyToUI(_associateProductHandler.CopyFromScenario(_scenario), this.associatedProducts_DataGrid); List <TimeSpan> failTimes = new List <TimeSpan>(); Dictionary <string, int> failureItems = new Dictionary <string, int>(); failureItems.Add("1 Failure", 1); failureItems.Add("2 Failures", 2); failureItems.Add("5 Failures", 5); failureItems.Add("10 Failures", 10); failureItems.Add("15 Failures", 15); failureItems.Add("20 Failures", 20); failTimes.Add(TimeSpan.FromMinutes(15)); failTimes.Add(TimeSpan.FromMinutes(30)); failTimes.Add(TimeSpan.FromHours(1)); failTimes.Add(TimeSpan.FromHours(2)); failTimes.Add(TimeSpan.FromHours(6)); failTimes.Add(TimeSpan.FromHours(12)); failureTime_comboBox.DataSource = new BindingSource(failTimes, null); threshold_comboBox.DataSource = new BindingSource(failureItems, null); threshold_comboBox.DisplayMember = "Key"; threshold_comboBox.ValueMember = "Value"; //if a new scenario, get empty, otherwise gather saved info from enterprise test. if (!string.IsNullOrEmpty(_scenario.ScenarioSettings)) { _settings = LegacySerializer.DeserializeDataContract <ScenarioSettings>(_scenario.ScenarioSettings); //Populate boxes from selected settings dartLog_CheckBox.Checked = _settings.NotificationSettings.CollectDartLogs; email_textBox.Text = _settings.NotificationSettings.Emails; failureTime_comboBox.SelectedIndex = failTimes.FindIndex(x => x == _settings.NotificationSettings.FailureTime); threshold_comboBox.SelectedIndex = failureItems.ToList().FindIndex(x => x.Value == _settings.NotificationSettings.FailureCount); triggerList_TextBox.Lines = _settings.NotificationSettings.TriggerList; //runtime_NumericUpDown.Value = _settings.EstimatedRunTime; runtime_NumericUpDown.Value = Math.Min(_settings.EstimatedRunTime, runtime_NumericUpDown.Maximum); logLocation_TextBox.Text = _settings.LogLocation; eventLog_CheckBox.Checked = _settings.CollectEventLogs; _scenarioCustomDictionary = _settings.ScenarioCustomDictionary; if (_scenarioCustomDictionary != null && _scenarioCustomDictionary.Count != 0) { customDictionary_listBox.DataSource = new BindingSource(_scenarioCustomDictionary, null); customDictionary_listBox.DisplayMember = "Key"; customDictionary_listBox.ValueMember = "Value"; } } else { //Populate combo boxes try { dartLog_CheckBox.Checked = _settings.NotificationSettings.CollectDartLogs; } catch { dartLog_CheckBox.Checked = false; } email_textBox.Text = ""; //Log settings logLocation_TextBox.Text = ""; eventLog_CheckBox.Checked = false; runtime_NumericUpDown.Value = Math.Min(_scenario.EstimatedRuntime, runtime_NumericUpDown.Maximum); } if (string.IsNullOrEmpty(logLocation_TextBox.Text)) { logLocation_TextBox.Text = GlobalSettings.WcfHosts[WcfService.DataLog]; } AddEventHandlers(); }