private ItemDetails GetPart(LddPart source) { var idsToCheck = new List <string>(); var checkedIds = new List <string>(); idsToCheck.Add(source.DesignId); while (idsToCheck.Count > 0) { var id = idsToCheck[0]; idsToCheck.RemoveAt(0); checkedIds.Add(id); var itemDetails = _itemService.GetItem(ItemTypeCodes.Part, id); if (itemDetails != null) { return(itemDetails); } var rebrickablePartInfo = _rebrickableApi.GetPartInfo(id); if (rebrickablePartInfo != null) { var candidates = new List <string>(); candidates.AddRange(rebrickablePartInfo.BricklinkItemIds); candidates.AddRange(rebrickablePartInfo.RebrickablePartIds); var toAdd = candidates.Where(c => !idsToCheck.Contains(c) && !checkedIds.Contains(c)); idsToCheck.AddRange(toAdd); } } return(null); }
public IReadOnlyCollection <LddPart> ExtractPartsList(string fileName) { var xml = GetXmlFromLddFile(fileName); var doc = new XmlDocument(); doc.LoadXml(xml); var partNodes = doc.SelectNodes("//Part"); List <LddPart> parts = new List <LddPart>(); if (partNodes == null) { return(parts); } foreach (XmlNode node in partNodes) { var part = new LddPart(); part.DesignId = node.Attributes["designID"]?.InnerText; part.Materials = node.Attributes["materials"]?.InnerText; part.Decoration = node.Attributes["decoration"]?.InnerText; parts.Add(part); } return(parts); }
private int?GetColorId(LddPart source) { var colorId = source.Materials; if (colorId.EndsWith(",0")) { colorId = colorId.Substring(0, colorId.Length - 2); } if (!_colorMap.ContainsKey(colorId)) { return(null); } return(_colorMap[colorId]); }
public MappingResult <MappedPart> MapItem(LddPart source) { var result = new MappingResult <MappedPart>(); var mapped = new MappedPart(); var itemDetails = GetPart(source); if (itemDetails == null) { result.WasSuccessful = false; result.Message = string.Format("Unable to locate part mapping."); return(result); } mapped.ItemId = itemDetails.ItemId; var colorId = GetColorId(source); if (!colorId.HasValue) { result.WasSuccessful = false; result.Message = string.Format("Unable to locate color mapping."); return(result); } mapped.ColorId = colorId.Value; if (!string.IsNullOrWhiteSpace(source.Decoration) && source.Decoration != "0") { result.WasSuccessful = false; result.Message = string.Format("Decorated elements are not currently supported."); return(result); } result.Mapped = mapped; result.WasSuccessful = true; return(result); }