/// <summary> /// Removes the specified definition. /// </summary> /// <param name="definition">The definition.</param> public void Remove(IDefinition definition) { if (definition.IsFromGame) { gameDefinitionsCount--; } if (gameDefinitionsCount < 0) { gameDefinitionsCount = 0; } definitions.Remove(definition); var hierarchicalDefinition = mainHierarchalDefinitions.GetFirstByNameNoLock(nameof(IHierarchicalDefinitions.Name), ResolveHierarchalParentDirectory(definition)); if (hierarchicalDefinition != null) { if (childHierarchicalDefinitions.TryGetValue(hierarchicalDefinition.Name, out var children)) { var child = children.GetFirstByNameNoLock(nameof(IHierarchicalDefinitions.Name), definition.Id); if (child != null) { children.Remove(child); } if (!children.Select(p => p).Any()) { childHierarchicalDefinitions.TryRemove(hierarchicalDefinition.Name, out _); mainHierarchalDefinitions.Remove(hierarchicalDefinition); } } } }
/// <summary> /// Removes the specified definition. /// </summary> /// <param name="definition">The definition.</param> public void Remove(IDefinition definition) { definitions.Remove(definition); var hierarchicalDefinition = mainHierarchalDefinitions.GetFirstByNameNoLock(nameof(IHierarchicalDefinitions.Name), definition.ParentDirectoryCI); if (hierarchicalDefinition != null) { if (childHierarchicalDefinitions.TryGetValue(hierarchicalDefinition.Name, out var children)) { var child = children.GetFirstByNameNoLock(nameof(IHierarchicalDefinitions.Name), definition.Id); if (child != null) { children.Remove(child); } if (children.Select(p => p).Count() == 0) { childHierarchicalDefinitions.TryRemove(hierarchicalDefinition.Name, out _); mainHierarchalDefinitions.Remove(hierarchicalDefinition); } } } }
/// <summary> /// Changes the state of the hierarchical reset. /// </summary> /// <param name="definition">The definition.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool ChangeHierarchicalResetState(IDefinition definition) { if (definition != null) { var parentDirectoryCI = ResolveHierarchalParentDirectory(definition); var hierarchicalDefinition = mainHierarchalDefinitions.GetFirstByNameNoLock(nameof(IHierarchicalDefinitions.Name), parentDirectoryCI); if (hierarchicalDefinition != null) { if (childHierarchicalDefinitions.TryGetValue(hierarchicalDefinition.Name, out var children)) { var child = children.GetFirstByNameNoLock(nameof(IHierarchicalDefinitions.Name), definition.Id); if (child != null) { child.ResetType = definition.ResetType; AddOrRemoveFromResetDefinitions(definition, false); hierarchicalDefinition.ResetType = children.Any(p => p.ResetType != ResetType.None) ? ResetType.Any : ResetType.None; return(true); } } } } return(false); }