/// <summary> /// Creates a new folder under the specified parent id. /// </summary> /// <param name="parentId">The parent id.</param> /// <returns>The ID of the created folder.</returns> public Guid CreateFolder(Guid?parentId) { // Create a default folder, which is valid if the parent is null var folder = new ConfigurationTreeFolder(SequentialGuid.NewGuid(), "New Folder", "ScenarioFolder", parentId); // Determine the real folder type and parent if (parentId != null) { EnterpriseTestMapNode node = _databaseMap[(Guid)parentId]; switch (node.NodeType) { case ConfigurationObjectType.EnterpriseScenario: case ConfigurationObjectType.ResourceFolder: folder.FolderType = "ResourceFolder"; break; case ConfigurationObjectType.VirtualResource: case ConfigurationObjectType.MetadataFolder: folder.FolderType = "MetadataFolder"; break; } } using (EnterpriseTestContext context = new EnterpriseTestContext()) { context.ConfigurationTreeFolders.AddObject(folder); HandleObjectChange(context, folder); context.SaveChanges(); } return(folder.ConfigurationTreeFolderId); }
/// <summary> /// Creates a node that is representative of the specified object (if applicable). /// </summary> /// <param name="entity">The entity.</param> /// <returns></returns> public static EnterpriseTestMapNode Create(object entity) { EnterpriseScenario scenario = entity as EnterpriseScenario; if (scenario != null) { return(new EnterpriseTestMapNode(scenario)); } VirtualResource resource = entity as VirtualResource; if (resource != null) { return(new EnterpriseTestMapNode(resource)); } VirtualResourceMetadata metadata = entity as VirtualResourceMetadata; if (metadata != null) { return(new EnterpriseTestMapNode(metadata)); } ConfigurationTreeFolder folder = entity as ConfigurationTreeFolder; if (folder != null) { return(new EnterpriseTestMapNode(folder)); } return(null); }
/// <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); } }
private void ScenarioSelectionForm_Load(object sender, EventArgs e) { bool noOrphans = true; using (EnterpriseTestContext context = new EnterpriseTestContext()) { var folders = ConfigurationTreeFolder.Select(context, "ScenarioFolder"); foreach (ConfigurationTreeFolder folder in ConfigurationTreeFolder.SortHierarchical(folders)) { RadTreeNode node = new RadTreeNode(folder.Name); node.Tag = folder.ConfigurationTreeFolderId; node.ImageKey = "Folder"; noOrphans &= AddNode(node, folder.ParentId); } foreach (EnterpriseScenario scenario in context.EnterpriseScenarios) { RadTreeNode node = new RadTreeNode(scenario.Name); node.Tag = scenario.EnterpriseScenarioId; node.ImageKey = "Scenario"; noOrphans &= AddNode(node, scenario.FolderId); } } if (!noOrphans) { MessageBox.Show("One or more scenarios or folders did not load into the tree successfully.\n" + "Please contact an administrator to determine which database items have incorrect configuration.", "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
/// <summary> /// Initializes a new instance of the <see cref="EnterpriseTestMapNode"/> class. /// </summary> /// <param name="folder">The folder.</param> public EnterpriseTestMapNode(ConfigurationTreeFolder folder) : this(folder.ConfigurationTreeFolderId) { ParentId = folder.ParentId; Name = folder.Name; NodeType = (ConfigurationObjectType)Enum.Parse(typeof(ConfigurationObjectType), folder.FolderType); }
public void LoadFolders() { saveToRadTreeView.Nodes.Clear(); using (EnterpriseTestContext context = new EnterpriseTestContext()) { var folders = ConfigurationTreeFolder.Select(context, "ScenarioFolder"); foreach (ConfigurationTreeFolder folder in ConfigurationTreeFolder.SortHierarchical(folders)) { RadTreeNode node = new RadTreeNode(folder.Name); node.Tag = folder.ConfigurationTreeFolderId; node.ImageKey = "Folder"; if (folder.ParentId == null) { saveToRadTreeView.Nodes.Add(node); } else { var temp = FindNode(folder.ParentId); if (temp != null) { temp.Nodes.Add(node); } else { saveToRadTreeView.Nodes.Add(node); } //FindNode(folder.ParentId).Nodes.Add(node); } } } FindSelectedNode(); }
private void ScenarioSelection_Loaded(object sender, RoutedEventArgs e) { EnterpriseTestContext context = new EnterpriseTestContext(); { var folders = ConfigurationTreeFolder.Select(context, "ScenarioFolder").Where(x => x.ParentId == null); ScenarioModel model = new ScenarioModel(folders.ToArray()); ScenarioTree.DataContext = model; } }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationObjectTag" /> class /// representing a <see cref="ConfigurationTreeFolder" /> object. /// </summary> /// <param name="folder">The <see cref="ConfigurationTreeFolder" />.</param> /// <exception cref="ArgumentNullException"><paramref name="folder" /> is null.</exception> public ConfigurationObjectTag(ConfigurationTreeFolder folder) { if (folder == null) { throw new ArgumentNullException(nameof(folder)); } Id = folder.ConfigurationTreeFolderId; ObjectType = EnumUtil.Parse <ConfigurationObjectType>(folder.FolderType); Name = folder.Name; ParentId = folder.ParentId; }
private void LoadSortedConfigFolders(EnterpriseTestContext context, ConfigurationObjectType folderType, IEnumerable <ConfigurationObjectTag> parentTags) { List <ConfigurationTreeFolder> folders = context.ConfigurationTreeFolders.Where(n => n.FolderType == folderType.ToString()).ToList(); Dictionary <Guid, VirtualResourceType> parentResourceTypes = parentTags.ToDictionary(n => n.Id, n => n.ResourceType); // Loop over folders collection until we reach a point where no folders are added. // The remainder of the folders don't have parents in the tree and will be ignored. bool foundFoldersToAdd; do { foundFoldersToAdd = false; // While loop used here so that we can modify the collection as we iterate int i = 0; while (i < folders.Count) { ConfigurationTreeFolder folder = folders[i]; // Determine whether or not we can create a tag for this folder right now ConfigurationObjectTag folderTag = null; if (folder.ParentId == null) { // Folder has no parent - add it now folderTag = new ConfigurationObjectTag(folder); } else { // Check to see if parent has already been added if (parentResourceTypes.TryGetValue(folder.ParentId.Value, out VirtualResourceType resourceType)) { // Parent has been added, so this folder can be added now folderTag = new ConfigurationObjectTag(folder, resourceType); } } // If we were able to create a tag, add it to the new list and remove it from the old if (folderTag != null) { foundFoldersToAdd = true; _configMap.Add(folderTag); parentResourceTypes.Add(folderTag.Id, folderTag.ResourceType); folders.RemoveAt(i); } else { // Cannot add this folder - move to the next one i++; } } } while (foundFoldersToAdd); }
private void ScenarioConfigurationTreeView_OnStartBatch(object sender, RadTreeViewEventArgs e) { ConfigurationObjectTag selected = scenarioConfigurationTreeView.SelectedConfigurationObject; if (selected != null && selected.ObjectType == ConfigurationObjectType.ScenarioFolder) { mainTabControl.SelectTab(execution_TabPage); List <Guid> scenarioIds = null; using (EnterpriseTestContext context = new EnterpriseTestContext()) { scenarioIds = (List <Guid>)ConfigurationTreeFolder.ContainedScenarioIds(context, selected.Id); } StartSession(scenarioIds); } }
/// <summary> /// Creates the folders within a scenario during import /// </summary> /// <param name="contract">The contract.</param> /// <param name="scenario">The scenario.</param> /// <param name="context">The context.</param> /// <param name="importMaps">The import maps.</param> private void CreateFolders(EnterpriseScenarioContract contract, EnterpriseScenario scenario, EnterpriseTestContext context, List <ContractFactory.ImportMap> importMaps) { try { foreach (var folder in contract.Folders) { // create the folder with parent defaulted to scenario var newFolderEntity = ConfigurationTreeFolder.CreateConfigurationTreeFolder(SequentialGuid.NewGuid(), folder.Name, folder.FolderType); newFolderEntity.ParentId = scenario.EnterpriseScenarioId; context.AddToConfigurationTreeFolders(newFolderEntity); // set children for folder based on import mapping var childMaps = (from c in folder.ChildIds join i in importMaps on c equals i.OldId select i); if (childMaps.Any()) { newFolderEntity.ParentId = childMaps.First().NewParentId; switch (folder.FolderType) { case "ResourceFolder": var vr = (from e in scenario.VirtualResources join c in childMaps on e.VirtualResourceId equals c.NewId select e).ToList(); vr.ForEach(x => x.FolderId = newFolderEntity.ConfigurationTreeFolderId); break; case "MetadataFolder": var md = (from e in scenario.VirtualResources.SelectMany(x => x.VirtualResourceMetadataSet) join c in childMaps on e.VirtualResourceMetadataId equals c.NewId select e).ToList(); md.ForEach(x => x.FolderId = newFolderEntity.ConfigurationTreeFolderId); break; default: break; } } } } catch (Exception ex) { TraceFactory.Logger.Error("Error creating folders within scenario", ex); } }
/// <summary> /// Creates a Copy of a Folder node. Can make an exact copy or one with a date/time stamp appended. /// </summary> /// <param name="source">Fodler to copy</param> /// <param name="parent">Parent node for the copy</param> /// <returns>Guid of the folder node that was created</returns> public Guid CopyFolder(Guid source, Guid?parent) { using (EnterpriseTestContext ctx = new EnterpriseTestContext()) { ConfigurationTreeFolder srcFolder = ConfigurationTreeFolder.Select(ctx, source); Guid dst = CreateFolder(parent); ConfigurationTreeFolder dstFolder = ConfigurationTreeFolder.Select(ctx, dst); Rename(dst, srcFolder.Name); HandleObjectChange(ctx, dstFolder); if (parent != null) { HandleObjectChange(ctx, GetEntityObject((Guid)parent)); } ctx.SaveChanges(); return(dst); } }
/// <summary> /// Adds the folder data to the specified scenario contract. /// </summary> /// <param name="contract">The scenario contract.</param> /// <param name="scenario">The scenario object.</param> private static void AddFolderDataToContract(EnterpriseScenarioContract contract, EnterpriseScenario scenario) { try { using (EnterpriseTestContext context = new EnterpriseTestContext()) { // get resource and metadata objects IEnumerable <VirtualResource> resources = scenario.VirtualResources.Where(v => v.FolderId.HasValue && v.FolderId.Value != Guid.Empty); IEnumerable <VirtualResourceMetadata> metadatas = resources.SelectMany(v => v.VirtualResourceMetadataSet).Where(m => m.FolderId.HasValue && m.FolderId.Value != Guid.Empty); // group each by the folder id var groupResources = (from r in resources group r by r.FolderId into g select new { FolderId = g.Key.Value, ChildIds = g.Select(x => x.VirtualResourceId) }); var groupMetadata = (from m in metadatas group m by m.FolderId into g select new { FolderId = g.Key.Value, ChildIds = g.Select(z => z.VirtualResourceMetadataId) }); // get referenced folders var allGroups = groupResources.Concat(groupMetadata); var folderIds = allGroups.Select(x => x.FolderId); IQueryable <ConfigurationTreeFolder> folders = ConfigurationTreeFolder.Select(context, folderIds); // add contract data for each referenced folder foreach (var group in allGroups) { ConfigurationTreeFolder folder = folders.FirstOrDefault(x => x.ConfigurationTreeFolderId.Equals(group.FolderId)); if (folder != null) { FolderContract folderContract = new FolderContract() { Name = folder.Name, FolderType = folder.FolderType, ChildIds = new Collection <Guid>(group.ChildIds.ToList()) }; contract.Folders.Add(folderContract); } } } } catch (Exception ex) { TraceFactory.Logger.Error("Error adding folder data.", ex); } }
private void ScenarioSelectionForm_Load(object sender, EventArgs e) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { var folders = ConfigurationTreeFolder.Select(context, "ScenarioFolder"); foreach (ConfigurationTreeFolder folder in ConfigurationTreeFolder.SortHierarchical(folders)) { RadTreeNode node = new RadTreeNode(folder.Name); node.Tag = folder.ConfigurationTreeFolderId; node.ImageKey = "Folder"; if (folder.ParentId == null) { scenarioTreeView.Nodes.Add(node); } else { FindNode(folder.ParentId).Nodes.Add(node); } } foreach (EnterpriseScenario scenario in context.EnterpriseScenarios) { RadTreeNode node = new RadTreeNode(scenario.Name); node.Tag = scenario.EnterpriseScenarioId; node.ImageKey = "Scenario"; if (scenario.FolderId == null) { scenarioTreeView.Nodes.Add(node); } else { FindNode(scenario.FolderId).Nodes.Add(node); } } } }
private static void LoadFolders(EnterpriseTestContext context, List <EnterpriseTestMapNode> nodes) { List <ConfigurationTreeFolder> remainingFolders = ConfigurationTreeFolder.Select(context).ToList(); List <ConfigurationTreeFolder> foldersToAdd = new List <ConfigurationTreeFolder>(); int lastCount = -1; // This process must be iterative, since folders can contain other folders. // Keep looping over the folders until none of them got processed - then we're done while (remainingFolders.Count != lastCount) { lastCount = remainingFolders.Count; // For all of the remaining folders, add any that we know we can add now foreach (ConfigurationTreeFolder folder in remainingFolders) { // If something needs to go in this folder, add it if (nodes.Any(n => n.ParentId == folder.ConfigurationTreeFolderId || n.FolderId == folder.ConfigurationTreeFolderId)) { foldersToAdd.Add(folder); } // If this is not a scenario folder, but its parent exists, add it else if (folder.FolderType != "ScenarioFolder" && nodes.Any(n => n.Id == folder.ParentId)) { foldersToAdd.Add(folder); } } // Add nodes for all of the folders to add, then remove them from the remaining folder list foreach (ConfigurationTreeFolder folder in foldersToAdd) { nodes.Add(new EnterpriseTestMapNode(folder)); remainingFolders.Remove(folder); } foldersToAdd.Clear(); } }
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(); } }
public ScenarioFolderViewModel(ConfigurationTreeFolder folder, ScenarioFolderViewModel parentFolder) : base(parentFolder, true) { _folder = folder; }
public ScenarioFolderViewModel(ConfigurationTreeFolder folder) : base(null, true) { _folder = folder; }
private static List <EnterpriseTestMapNode> LoadNodesFromDatabase(UserCredential user) { List <EnterpriseTestMapNode> nodes = new List <EnterpriseTestMapNode>(); bool needFilter = (user != null && !user.HasPrivilege(UserRole.Manager)); string sqlText = needFilter ? Resource.SelectTreeViewData.FormatWith(user.UserName) : Resource.SelectTreeViewDataNoFilter; using (EnterpriseTestContext context = new EnterpriseTestContext()) { Collection <ScenarioData> scenarioData = new Collection <ScenarioData>(); using (SqlAdapter adapter = new SqlAdapter(EnterpriseTestSqlConnection.ConnectionString)) { DbDataReader reader = adapter.ExecuteReader(sqlText); if (reader != null) { while (reader.Read()) { scenarioData.Add(new ScenarioData() { MetadataEnabled = !string.IsNullOrEmpty(reader["MDE"].ToString()) && (bool)reader["MDE"], MetadataFolderId = !string.IsNullOrEmpty(reader["MDFID"].ToString()) ? (Guid?)reader["MDFID"] : (Guid?)null, MetadataId = !string.IsNullOrEmpty(reader["MDID"].ToString()) ? (Guid)reader["MDID"] : Guid.Empty, MetadataName = !string.IsNullOrEmpty(reader["MDN"].ToString()) ? (string)reader["MDN"]: string.Empty, MetadataType = !string.IsNullOrEmpty(reader["MDT"].ToString()) ? (string)reader["MDT"] : string.Empty, ResourceEnabled = !string.IsNullOrEmpty(reader["VRE"].ToString()) && (bool)reader["VRE"], ResourceFolderId = !string.IsNullOrEmpty(reader["VRFID"].ToString()) ? (Guid?)reader["VRFID"] : (Guid?)null, ResourceId = !string.IsNullOrEmpty(reader["VRID"].ToString()) ? (Guid)reader["VRID"] : Guid.Empty, ResourceName = !string.IsNullOrEmpty(reader["VRN"].ToString()) ? (string)reader["VRN"] : string.Empty, ResourceType = !string.IsNullOrEmpty(reader["VRT"].ToString()) ? (string)reader["VRT"] : string.Empty, ScenarioFolderId = !string.IsNullOrEmpty(reader["ESFID"].ToString()) ? (Guid?)reader["ESFID"] : (Guid?)null, ScenarioId = (Guid)reader["ESID"], ScenarioName = (string)reader["ESN"], }); } } } nodes.AddRange (scenarioData .Where(x => x.ScenarioId != (Guid?)null && x.ScenarioId != Guid.Empty) .GroupBy(x => x.ScenarioId) .Select(x => new EnterpriseTestMapNode(x.First().ScenarioId) { NodeType = ConfigurationObjectType.EnterpriseScenario, Name = x.First().ScenarioName, FolderId = x.First().ScenarioFolderId }) ); nodes.AddRange (scenarioData .Where(x => x.ResourceId != (Guid?)null && x.ResourceId != Guid.Empty) .GroupBy(x => x.ResourceId) .Select(x => new EnterpriseTestMapNode(x.First().ResourceId) { NodeType = ConfigurationObjectType.VirtualResource, Name = x.First().ResourceName, FolderId = x.First().ResourceFolderId, ParentId = x.First().ScenarioId, Enabled = x.First().ResourceEnabled, ResourceType = x.First().ResourceType }) ); nodes.AddRange (scenarioData .Where(x => x.MetadataId != (Guid?)null && x.MetadataId != Guid.Empty) .GroupBy(x => x.MetadataId) .Select(x => new EnterpriseTestMapNode(x.First().MetadataId) { NodeType = ConfigurationObjectType.ResourceMetadata, Name = x.First().MetadataName, FolderId = x.First().MetadataFolderId, ParentId = x.First().ResourceId, Enabled = x.First().MetadataEnabled, ResourceType = x.First().ResourceType, MetadataType = x.First().MetadataType }) ); // Load the folders based on the test objects that have already been loaded if (needFilter) { LoadFolders(context, nodes); } else { foreach (ConfigurationTreeFolder folder in ConfigurationTreeFolder.Select(context)) { nodes.Add(new EnterpriseTestMapNode(folder)); } } } return(nodes); }
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(); } } } }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationObjectTag" /> class /// representing a <see cref="ConfigurationTreeFolder" /> object. /// </summary> /// <param name="folder">The <see cref="ConfigurationTreeFolder" />.</param> /// <param name="resourceType">The <see cref="VirtualResourceType" />.</param> /// <exception cref="ArgumentNullException"><paramref name="folder" /> is null.</exception> public ConfigurationObjectTag(ConfigurationTreeFolder folder, VirtualResourceType resourceType) : this(folder) { ResourceType = resourceType; }
private bool ImportConfigurationFiles() { try { SystemTrace.Instance.Debug("Checking for import files"); string[] importFiles = Directory.GetFiles("Import", "*.stbs"); if (importFiles.Count() > 0) { // Import any exported scenario files that were included in the installation using (EnterpriseTestContext context = new EnterpriseTestContext()) { UpdateStatus("Importing Scenarios"); ContractFactory.OnStatusChanged += ContractFactory_OnStatusChanged; string folderName = $"V{_ticket.CurrentVersion} Imports"; ConfigurationTreeFolder folder = context.ConfigurationTreeFolders.FirstOrDefault(x => x.Name.Equals(folderName)); if (folder == null) { folder = new ConfigurationTreeFolder(SequentialGuid.NewGuid(), folderName, ConfigurationObjectType.ScenarioFolder.ToString(), null); context.AddToConfigurationTreeFolders(folder); context.SaveChanges(); } //Ensure the path exists for import files in the shared folder location StringBuilder importDestination = new StringBuilder(_fileSharePath); importDestination.Append("\\Import\\V"); importDestination.Append(_ticket.CurrentVersion); Directory.CreateDirectory(importDestination.ToString()); importDestination.Append("\\"); int destinationPathIndex = importDestination.Length; foreach (string fileName in importFiles) { SystemTrace.Instance.Debug($"Importing {fileName}"); EnterpriseScenario enterpriseScenario = null; try { XElement fileData = XElement.Parse(File.ReadAllText(fileName)); // If this is a composite contract file it may contain printer and document // information in addition to the base scenario data. if (fileData.Name.LocalName == "Composite") { var compositeContract = Serializer.Deserialize <EnterpriseScenarioCompositeContract>(fileData); if (!ImportExportUtil.ProcessCompositeContractFile(compositeContract)) { SystemTrace.Instance.Error($"Failed to process composite contract: {fileName}."); } enterpriseScenario = ContractFactory.Create(compositeContract.Scenario); } else { var scenarioContract = Serializer.Deserialize <EnterpriseScenarioContract>(fileData); enterpriseScenario = ContractFactory.Create(scenarioContract); } enterpriseScenario.FolderId = folder.ConfigurationTreeFolderId; SystemTrace.Instance.Debug($"Adding Scenario '{enterpriseScenario.Name}'"); context.AddToEnterpriseScenarios(enterpriseScenario); // Copy the import file to the shared folder location importDestination.Append(Path.GetFileName(fileName)); try { File.Copy(fileName, importDestination.ToString(), true); } catch (Exception ex) { SystemTrace.Instance.Error($"Failed to copy '{fileName}' to '{importDestination.ToString()}'.", ex); } importDestination.Remove(destinationPathIndex, importDestination.Length - destinationPathIndex); } catch (Exception ex) { // Log an error for the current file, but keep going SystemTrace.Instance.Error($"Failed to import: {fileName}", ex); } } context.SaveChanges(); ContractFactory.OnStatusChanged -= ContractFactory_OnStatusChanged; UpdateStatus("Scenario Import Complete"); } } } catch (Exception ex) { SendError(ex); return(false); } return(true); }