/// <summary> /// Creates a copy of a Resource. /// </summary> /// <param name="source">The Source Resource to copy from</param> /// <param name="srcParent"></param> /// <param name="newParent"></param> /// <param name="Mappings"></param> /// <returns>Guid of the Resource node that was created</returns> public Guid CopyResource(Guid source, Guid srcParent, Guid newParent, Dictionary <Guid?, Guid?> Mappings) { using (EnterpriseTestContext ctx = new EnterpriseTestContext()) { VirtualResource vrSource = VirtualResource.Select(ctx, source); VirtualResource vrCopy = vrSource.ShallowCopy(); HandleObjectChange(ctx, vrCopy); ctx.SaveChanges(); EnterpriseScenario dstScenario; if (vrSource.EnterpriseScenarioId == srcParent) { dstScenario = EnterpriseScenario.Select(ctx, newParent); } else { try { vrCopy.FolderId = (Guid)Mappings[srcParent]; dstScenario = EnterpriseScenario.Select(ctx, (Guid)Mappings[vrSource.EnterpriseScenarioId]); } catch (Exception) { throw new Exception("Cannot find New Target Scenario /Resource Folder for " + source.ToString()); } } dstScenario.VirtualResources.Add(vrCopy); HandleObjectChange(ctx, vrCopy); HandleObjectChange(ctx, dstScenario); ctx.SaveChanges(); return(vrCopy.VirtualResourceId); } }
/// <summary> /// Creates a <see cref="SessionTicket"/> using the specififed scenario name. /// </summary> /// <param name="scenarioNames">List of the scenarios to execute.</param> /// <param name="sessionName">Name of the session to execute scenarios</param> /// <param name="durationHours">The session duration in hours.</param> /// <returns></returns> /// <exception cref="System.InvalidOperationException">Scenario with specified name is not found in the database.</exception> public static SessionTicket Create(IEnumerable <string> scenarioNames, string sessionName, int durationHours = 2) { SessionTicket ticket = new SessionTicket() { ExpirationDate = DateTime.Now.AddHours(durationHours), DurationHours = durationHours, SessionName = sessionName }; using (EnterpriseTestContext context = new EnterpriseTestContext()) { foreach (string scenarioName in scenarioNames) { if (!string.IsNullOrEmpty(scenarioName)) { var scenario = EnterpriseScenario.Select(context, scenarioName); if (scenario == null) { throw new InvalidOperationException($"'{scenarioName}' is not found in the database."); } ((List <Guid>)ticket.ScenarioIds).Add(scenario.EnterpriseScenarioId); } } } return(ticket); }
/// <summary> /// Gets the entity object. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public EntityObject GetEntityObject(Guid id) { // Discard our old entity context and create a new one. This seems wasteful, // but if we maintain the same context it will cache all the data that is ever // loaded from it. This can cause huge memory growth over time, as well as // concurrency issues. Creating a new context is cheap and avoids these issues. if (_context != null) { _context.Dispose(); } _context = new EnterpriseTestContext(); EnterpriseTestMapNode node = _databaseMap[id]; switch (node.NodeType) { case ConfigurationObjectType.EnterpriseScenario: return(EnterpriseScenario.Select(_context, id)); case ConfigurationObjectType.VirtualResource: return(VirtualResource.Select(_context, id)); case ConfigurationObjectType.ResourceMetadata: return(VirtualResourceMetadata.Select(_context, id)); case ConfigurationObjectType.ScenarioFolder: case ConfigurationObjectType.ResourceFolder: case ConfigurationObjectType.MetadataFolder: return(ConfigurationTreeFolder.Select(_context, id)); default: return(null); } }
/// <summary> /// Loads all data from the database required to build the manifests for this Scenario so that /// properties like Resources and Quantities can be evaluated before the actual building of the manifests. /// </summary> private void Initialize() { using (EnterpriseTestContext context = new EnterpriseTestContext()) { TraceFactory.Logger.Debug($"Loading all resources for scenarioId: {ScenarioId}"); // Get the enabled VirtualResources but filter out any disabled items from the VirtualResourceMetadataSet var resources = EnterpriseScenario.SelectWithAllChildren(context, ScenarioId)?.VirtualResources.Where(e => e.Enabled); if (resources == null || !resources.Any()) { //No reason to continue if there are no resources return; } foreach (var resource in resources) { var temp = resource.VirtualResourceMetadataSet.Where(x => x.Enabled).ToList(); resource.VirtualResourceMetadataSet.Clear(); temp.ForEach(resource.VirtualResourceMetadataSet.Add); } Resources = resources; ManifestSet.ScenarioId = ScenarioId; ManifestSet.ScenarioName = EnterpriseScenario.Select(context, ScenarioId).Name; Quantities = new SessionResourceQuantity(Resources); } }
private void LoadScenario(Guid scenarioId, EnterpriseTestContext context) { EnterpriseScenario scenario = EnterpriseScenario.Select(context, scenarioId); if (scenario != null) { _scenario = scenario.Clone(); selectedScenario_TextBox.Text = _scenario.Name; } }
private void LoadVirtualResources() { _context = new EnterpriseTestContext(); ModifiedScenario = EnterpriseScenario.Select(_context, _scenarioId); _resources = ModifiedScenario.VirtualResources.ToList(); this.Text = ModifiedScenario.Name; }
/// <summary> /// Initializes the wizard page with the specified <see cref="WizardConfiguration"/>. /// </summary> /// <param name="configuration">The <see cref="WizardConfiguration"/>.</param> public bool Initialize(WizardConfiguration configuration) { Ticket = configuration.Ticket; _scenarios = new BindingList <ScenarioSelectionItem>(); scenarios_DataGridView.DataSource = null; if (STFDispatcherManager.Dispatcher == null && STFDispatcherManager.ConnectToDispatcher() == false) { //The user canceled the connect dialog return(false); } using (new BusyCursor()) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { foreach (EnterpriseScenario scenario in EnterpriseScenario.Select(context, Ticket.ScenarioIds)) { _scenarios.Add(new ScenarioSelectionItem(scenario)); } LoadComboBoxes(context); } _bindingSource = new BindingSource(_scenarios, string.Empty); scenarios_DataGridView.DataSource = _bindingSource; } //Set data from Ticket if (Ticket.SessionId != null) { SetEstimatedRunTime(); sessionName_ComboBox.Text = string.IsNullOrEmpty(Ticket.SessionName) ? "Multiple Scenarios" : Ticket.SessionName; } if (!_initial) { SessionClient.Instance.Close(Ticket.SessionId); sessionType_ComboBox.SelectedText = Ticket.SessionType; if (!string.IsNullOrEmpty(Ticket.EmailAddresses)) { runtime_NumericUpDown.Value = Math.Min(Ticket.DurationHours, runtime_NumericUpDown.Maximum); } } environment_Label.Text = "{0} {1} Environment".FormatWith(GlobalSettings.Items[Setting.Organization], GlobalSettings.Items[Setting.Environment]); dispatcher_Label.Text = STFDispatcherManager.Dispatcher.HostName; _initial = false; return(true); }
private bool PerformDataIntegrityCheck(EnterpriseTestContext context, Guid scenarioId) { EnterpriseScenario scenario = EnterpriseScenario.Select(context, scenarioId); if (platform_RadioButton.Checked) { return(WizardPageManager.PerformScenarioIntegrityCheck(scenario, (FrameworkClientPlatform)platform_ComboBox.SelectedItem)); } else if (holdId_RadioButton.Checked) { return(WizardPageManager.PerformScenarioIntegrityCheck(scenario, (string)holdId_ComboBox.SelectedItem)); } else { return(WizardPageManager.PerformScenarioIntegrityCheck(scenario)); } }
/// <summary> /// Performs final validation before allowing the user to navigate away from the page. /// </summary> /// <returns> /// True if this page was successfully validated. /// </returns> public bool Complete() { if (!ValidateInput()) { return(false); } // We're gonna need a data context several times in the following lines using (EnterpriseTestContext context = new EnterpriseTestContext()) { List <EnterpriseScenario> scenarios = EnterpriseScenario.Select(context, Ticket.ScenarioIds).ToList(); // Perform a data integrity check on the scenarios if (PerformDataIntegrityCheck(scenarios) == false) { return(false); } //PopulateNotificationSettings() TODO: What about the email list? The ticket has an email list. Can we repurpose it for batch operations? // Populate ticket data from the UI Ticket.ScenarioIds = GetSelectedScenarioIds(); Ticket.CollectEventLogs = false; Ticket.SessionName = sessionName_ComboBox.Text; Ticket.SessionType = sessionType_ComboBox.Text; Ticket.SessionCycle = sessionCycle_ComboBox.Text; Ticket.Reference = WizardPageManager.GetReferenceData(reference_TextBox); Ticket.SessionNotes = notes_TextBox.Text; Ticket.DurationHours = (int)runtime_NumericUpDown.Value; SessionLogRetention logRetention = EnumUtil.GetByDescription <SessionLogRetention>((string)retention_ComboBox.SelectedItem); Ticket.ExpirationDate = logRetention.GetExpirationDate(DateTime.Now); Ticket.LogLocation = GlobalSettings.WcfHosts[WcfService.DataLog]; SetAssociatedProducts(context, scenarios); // Doesn't make sense to save session name for batch operation. context.SaveChanges(); } // Initiate the session with the dispatcher TraceFactory.Logger.Debug($"Calling Initiate() on {Ticket.SessionId}"); SessionClient.Instance.InitiateSession(Ticket); return(true); }
private void LoadScenario(Guid scenarioId, EnterpriseTestContext context) { EnterpriseScenario scenario = EnterpriseScenario.Select(context, scenarioId); if (scenario != null) { Ticket.ScenarioIds = new List <Guid>() { scenarioId }; _scenario = scenario; selectedScenario_TextBox.Text = scenario.Name; runtime_NumericUpDown.Value = Math.Min(scenario.EstimatedRuntime, runtime_NumericUpDown.Maximum); //Ensure we don't exceed the NumericUpDown.Maximum. //Populate Associated Products _scenarioProducts = WizardPageManager.GetAssociatedProducts(context, scenario); scenarioProductBindingSource.DataSource = _scenarioProducts; scenarioProductBindingSource.ResetBindings(true); } }
private void add_Button_Click(object sender, EventArgs e) { using (ScenarioSelectionForm selectionForm = new ScenarioSelectionForm()) { if (selectionForm.ShowDialog() == DialogResult.OK) { EnterpriseScenario scenario = null; using (new BusyCursor()) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { scenario = EnterpriseScenario.Select(context, selectionForm.SelectedScenarioId); _bindingSource.Add(new ScenarioSelectionItem(scenario)); } } _bindingSource.MoveLast(); SetEstimatedRunTime(); } } }
/// <summary> /// Creates a copy of a scenario. Can make an exact copy, or one that has the name appendeed with a time/date stamp /// </summary> /// <param name="source">The Source scenario Id</param> /// <param name="parent">Parent if available</param> /// <returns>Guid of the Scenario node that was created</returns> public Guid CopyScenario(Guid source, Guid?parent) { using (EnterpriseTestContext ctx = new EnterpriseTestContext()) { var srcScenario = EnterpriseScenario.Select(ctx, source); Guid dst = CreateScenario(parent); EnterpriseScenario dstScenario = EnterpriseScenario.Select(ctx, dst); dstScenario.Name = srcScenario.Name; dstScenario.Description = srcScenario.Description; dstScenario.Vertical = srcScenario.Vertical; dstScenario.Company = srcScenario.Company; HandleObjectChange(ctx, dstScenario); if (parent != null) { HandleObjectChange(ctx, GetEntityObject((Guid)parent)); } ctx.SaveChanges(); return(dst); } }
private void LoadScenarios(XElement scenarios) { _scenarioList.Clear(); foreach (var scenario in scenarios.Elements("Scenario")) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { var enterpriseScenario = EnterpriseScenario.Select(context, Guid.Parse(scenario.Value)); if (enterpriseScenario != null) { _scenarioList.Add(new ScenarioQueueList() { ScenarioName = enterpriseScenario.Name, ScenarioId = enterpriseScenario.EnterpriseScenarioId, Status = "Yet to Start" }); } else { MessageBox.Show("Scenario:{0} not found".FormatWith(scenario.Value)); } } } }
private void MoveHandler(EnterpriseTestContext context, IEnumerable <Guid> affected) { foreach (Guid affectedId in affected) { EnterpriseTestMapNode moved = _databaseMap[affectedId]; switch (moved.NodeType) { case ConfigurationObjectType.EnterpriseScenario: var scenario = EnterpriseScenario.Select(context, affectedId); scenario.FolderId = moved.FolderId; HandleObjectChange(context, scenario); break; case ConfigurationObjectType.VirtualResource: var resource = VirtualResource.Select(context, affectedId); resource.EnterpriseScenarioId = (Guid)moved.ParentId; resource.FolderId = moved.FolderId; HandleObjectChange(context, resource); break; case ConfigurationObjectType.ResourceMetadata: var metadata = VirtualResourceMetadata.Select(context, affectedId); metadata.VirtualResourceId = (Guid)moved.ParentId; metadata.FolderId = moved.FolderId; HandleObjectChange(context, metadata); break; case ConfigurationObjectType.ScenarioFolder: case ConfigurationObjectType.ResourceFolder: case ConfigurationObjectType.MetadataFolder: var folder = ConfigurationTreeFolder.Select(context, affectedId); folder.ParentId = moved.ParentId; HandleObjectChange(context, folder); break; } } context.SaveChanges(); }
/// <summary> /// Renames the object with the specified id. /// </summary> /// <param name="id">The id.</param> /// <param name="name">The name.</param> public void Rename(Guid id, string name) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { EnterpriseTestMapNode node = _databaseMap[id]; switch (node.NodeType) { case ConfigurationObjectType.EnterpriseScenario: var scenario = EnterpriseScenario.Select(context, id); scenario.Name = name; HandleObjectChange(context, scenario); break; case ConfigurationObjectType.VirtualResource: var resource = VirtualResource.Select(context, id); resource.Name = name; HandleObjectChange(context, resource); break; case ConfigurationObjectType.ResourceMetadata: var metadata = VirtualResourceMetadata.Select(context, id); metadata.Name = name; HandleObjectChange(context, metadata); break; case ConfigurationObjectType.ScenarioFolder: case ConfigurationObjectType.ResourceFolder: case ConfigurationObjectType.MetadataFolder: var folder = ConfigurationTreeFolder.Select(context, id); folder.Name = name; HandleObjectChange(context, folder); break; } context.SaveChanges(); } }
private static void DatabaseDelete(IEnumerable <EnterpriseTestMapNode> nodes) { //-------------------------------------------------------------------------------------------------- // ADD: CR #1894. Cascading deletes were throwing an unhandled exception because of a DB Foreign // Key Constraint on the folderId field. What that means is that the ORDER in which things are // deleted, now becomes very important. If we attempt to remove a 'container' before we remove // the contents, the exception will be thrown when the contents are removed. So - in order to make // this work, we group the objects to be deleted - and then we have to order those groups (since the // order of the GroupBy could be non-deterministic) and make sure that we delete things in the // correct sequence. There is probably a more elegant way of doing this - but there was no time. using (EnterpriseTestContext context = new EnterpriseTestContext()) { int[] ordered = new int[6] { -1, -1, -1, -1, -1, -1 }; var colls = nodes.GroupBy(n => n.NodeType, n => n.Id); int ndx = 0; foreach (var grp in colls) { switch (grp.Key) { case ConfigurationObjectType.ResourceMetadata: ordered[0] = ndx++; break; case ConfigurationObjectType.MetadataFolder: ordered[1] = ndx++; break; case ConfigurationObjectType.VirtualResource: ordered[2] = ndx++; break; case ConfigurationObjectType.ResourceFolder: ordered[3] = ndx++; break; case ConfigurationObjectType.EnterpriseScenario: ordered[4] = ndx++; break; case ConfigurationObjectType.ScenarioFolder: ordered[5] = ndx++; break; } } for (ndx = 0; ndx < 6; ndx++) { if (ordered[ndx] >= 0) { switch (colls.ElementAt(ordered[ndx]).Key) { case ConfigurationObjectType.ResourceMetadata: foreach (var vrmd in VirtualResourceMetadata.Select(context, colls.ElementAt(ordered[ndx]))) { context.DeleteObject(vrmd); } break; case ConfigurationObjectType.MetadataFolder: foreach (var mdf in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx]))) { context.DeleteObject(mdf); } break; case ConfigurationObjectType.VirtualResource: foreach (var vr in VirtualResource.Select(context, colls.ElementAt(ordered[ndx]))) { context.DeleteObject(vr); } break; case ConfigurationObjectType.ResourceFolder: foreach (var rf in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx]))) { context.DeleteObject(rf); } break; case ConfigurationObjectType.EnterpriseScenario: foreach (var scenario in EnterpriseScenario.Select(context, colls.ElementAt(ordered[ndx]))) { context.DeleteObject(scenario); } break; case ConfigurationObjectType.ScenarioFolder: foreach (var sf in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx]))) { var deletingScenarioIds = nodes.Where(n => n.NodeType == ConfigurationObjectType.EnterpriseScenario).Select(n => n.Id); foreach (var folder in ConfigurationTreeFolder.Select(context, colls.ElementAt(ordered[ndx]))) { var containedScenarios = ConfigurationTreeFolder.ContainedScenarioIds(context, folder.ConfigurationTreeFolderId); if (containedScenarios.All(n => deletingScenarioIds.Contains(n))) { // All of the sceanrios under this folder are in the list of scenarios to delete, // so we can delete this folder as well. context.DeleteObject(folder); } } } break; } context.SaveChanges(); } } } }