private void InsertPartInPartsCollection(AssetPartCollection <TAssetPartDesign, TAssetPart> newPartCollection, TAssetPartDesign rootPart) { var node = HierarchyNode[nameof(AssetCompositeHierarchyData <TAssetPartDesign, TAssetPart> .Parts)]; node.Add(rootPart); foreach (var childPart in AssetHierarchy.EnumerateChildParts(rootPart.Part, false)) { var partDesign = newPartCollection[childPart.Id]; InsertPartInPartsCollection(newPartCollection, partDesign); } }
private void RemovePartFromPartsCollection(TAssetPartDesign rootPart) { foreach (var childPart in AssetHierarchy.EnumerateChildParts(rootPart.Part, false)) { var partDesign = AssetHierarchy.Hierarchy.Parts[childPart.Id]; RemovePartFromPartsCollection(partDesign); } var node = HierarchyNode[nameof(AssetCompositeHierarchyData <TAssetPartDesign, TAssetPart> .Parts)]; var index = new Index(AssetHierarchy.Hierarchy.Parts.IndexOf(rootPart)); node.Remove(rootPart, index); }
/// <summary> /// Removes a part from this asset. This method updates the <see cref="AssetCompositeHierarchyData{TAssetPartDesign, TAssetPart}.Parts"/> collection. /// If the part to remove is a root part, it also updates the <see cref="AssetCompositeHierarchyData{TAssetPartDesign, TAssetPart}.RootPartIds"/> collection. /// Otherwise, it updates the collection containing the list of children from the parent of this part. /// </summary> /// <param name="partDesign">The part to remove from this asset.</param> public void RemovePartFromAsset(TAssetPartDesign partDesign) { if (!AssetHierarchy.Hierarchy.RootPartIds.Contains(partDesign.Part.Id)) { var parent = AssetHierarchy.GetParent(partDesign.Part); RemoveChildPartFromParentPart(parent, partDesign.Part); } else { var index = new Index(AssetHierarchy.Hierarchy.RootPartIds.IndexOf(partDesign.Part.Id)); var rootPartsNode = HierarchyNode[nameof(AssetCompositeHierarchyData <TAssetPartDesign, TAssetPart> .RootPartIds)]; rootPartsNode.Remove(partDesign.Part.Id, index); } RemovePartFromPartsCollection(partDesign); }
public bool InsertOrUpdateAssetHierarchy(Asset childAsset, Asset parentAsset) { /* The input includes a parent and child. The child exists; the parent might not. * Any and all records in the hierarchy with the child asset (in the child position) will be updated * to point to the new parent, if specified, or to no parent, if a parent isn't specified. * If nothing is found with the child asset, a new record will be inserted. * * Limitation: This routine looks for the first parent. It won't work properly if the parent appears twice. */ bool success = false; AssetHierarchy parentAssetHierarchy = null; // If the parent is specified in the argument list, get the first time the parent appears in the hierarchy. // If the parent asset is specified but does not appear in the hierarchy, add the parent to the hierarchy. if( parentAsset != null ) { // Look for a record in the hierarchy for the parent. // If there isn't one, create a new top level record in the hierarchy for the parent. parentAssetHierarchy = _assetHierarchyRepository.FirstOrDefault(p => p.AssetId == parentAsset.Id); if ( parentAssetHierarchy == null ) { parentAssetHierarchy = new AssetHierarchy { TenantId = childAsset.TenantId, AssetId = parentAsset.Id // ParentAssetHierarchyId -- not set, as this is a new top level }; long id = _assetHierarchyRepository.InsertAndGetId(parentAssetHierarchy); parentAssetHierarchy.Id = id; } } // Get all records in the AssetHierarchy table with the child asset List<AssetHierarchy> assetHierarchies = _assetHierarchyRepository.GetAllList(p => p.AssetId == childAsset.Id); if (assetHierarchies != null && assetHierarchies.Count > 0) { // The child already appears in the hierarchy. // Loop through all records in the hierarchy and update them to the new parent (if it exists) or null (if not). foreach( AssetHierarchy hierarchy in assetHierarchies ) { if (parentAssetHierarchy != null) { // A record exists in the hierarchy for the parent: we have a parent hierarchy.ParentAssetHierarchyId = parentAssetHierarchy.Id; } else { // A record does not exist in the hierarchy for the parent: we do not have a parent long? parentAssetHierarchyId = null; hierarchy.ParentAssetHierarchyId = parentAssetHierarchyId; } } } else { // Nothing exists in the AssetHierarchy table, so insert a new record for the child. if (parentAssetHierarchy != null) { // A record exists in the hierarchy for the parent: we have a parent AssetHierarchy hierarchy = new AssetHierarchy { TenantId = childAsset.TenantId, AssetId = childAsset.Id, ParentAssetHierarchyId = parentAssetHierarchy.Id }; long id = _assetHierarchyRepository.InsertAndGetId(hierarchy); } else { // A record does not exist in the hierarchy for the parent: we do not have a parent AssetHierarchy hierarchy = new AssetHierarchy { TenantId = childAsset.TenantId, AssetId = childAsset.Id // ParentAssetHierarchyId -- not set, as this is a new top level }; long id = _assetHierarchyRepository.InsertAndGetId(hierarchy); } } return success; }
/// <summary> /// Adds a script to be emitted by the RenderScripts method. /// </summary> /// <param name="html">The HTMLHelper.</param> /// <param name="scriptUrl">The script URL.</param> /// <param name="scriptUrl">The display priority.</param> public static void AddScript(this HtmlHelper html, string scriptUrl, AssetHierarchy hierarchy = AssetHierarchy.Page) { Scripts.Add(new Asset { Url = scriptUrl, AssetHierarchy = hierarchy }); }
/// <summary> /// Adds a stylesheet to be emitted by the RenderStyleSheets method. /// </summary> /// <param name="html">The HTMLHelper</param> /// <param name="styleUrl">The stylesheet URL.</param> /// <param name="scriptUrl">The display priority.</param> /// public static void AddStyleSheet(this HtmlHelper html, string styleUrl, AssetHierarchy hierarchy = AssetHierarchy.Page) { Styles.Add(new Asset { Url = styleUrl, AssetHierarchy = hierarchy }); }