public static List <T> GetChildObjects <T>(this CobieObject obj) { if (obj.GetType() == typeof(AssetType)) { return(((AssetType)obj).Assets as List <T>); } if (obj.GetType() == typeof(Zone)) { return(((Zone)obj).SpaceObjects.ToList() as List <T>); } return(null); }
public static void SetChildObjects <TChild>(this CobieObject obj, List <TChild> newChildrenSet) { if (obj.GetType() == typeof(AssetType)) { ((AssetType)obj).Assets = newChildrenSet as List <Asset>; } else if (obj.GetType() == typeof(Zone)) { var destZone = obj as Zone; if (destZone == null) { return; } destZone.Spaces = new List <SpaceKey>(); // since this is a setter it's ok to create new. var destFaclity = destZone.Facility; if (destFaclity.Floors == null) // we dont' wipe floors away, only prepare if it's null { destFaclity.Floors = new List <Floor>(); } var tmpStorey = destFaclity.Get <Floor>(fl => fl.Name == @"DPoWTemporaryHoldingStorey").FirstOrDefault(); if (tmpStorey == null) { tmpStorey = destFaclity.Create <Floor>(); tmpStorey.Name = FacilityValidator.TemporaryFloorName; tmpStorey.Spaces = new List <Space>(); destFaclity.Floors.Add(tmpStorey); } foreach (var child in newChildrenSet.OfType <Space>()) { // add reference to the space in the zone destZone.Spaces.Add(new SpaceKey { Name = child.Name }); // the outer function will then ensure that floor and spaces are avalialale in the report facility tmpStorey.Spaces.Add(child); } } }
/// <summary> /// Write the text to the TextWriter /// </summary> /// <param name="logMe">string to write</param> public void WriteLine(CobieObject rootObj, CobieObject parentObj, Type mergeType, int duplicateNo, int mergedNo, int depthIndicator) { if (logger != null) { string mergeindicator = (mergedNo > 0) ? "*" : ""; StringBuilder sb = new StringBuilder(); if (mergedNo > 0) { sb.Append("*"); } else { sb.Append(" "); } if (depthIndicator > 0) { sb.Append('\t', depthIndicator); } if (rootObj != null && (depthIndicator == 0)) { sb.Append(rootObj.GetType().Name); sb.Append("("); sb.Append(rootObj.Name); sb.Append(":"); sb.Append(rootObj.ExternalId); sb.Append("): "); } if (parentObj != null) { sb.Append(parentObj.GetType().Name); sb.Append("("); sb.Append(parentObj.Name); sb.Append(":"); sb.Append(parentObj.ExternalId); sb.Append("): "); } sb.Append(mergeType.Name); sb.Append(" "); sb.Append(duplicateNo); sb.Append(" duplicate, "); sb.Append(mergedNo); sb.Append(" merged."); logger.WriteLine(sb.ToString()); } }