public static Result <SisLine, Error> DeserializeSisLine(string line) { var cells = line.Split('\t'); if (cells.Length < 5) { return(new Error($"Invalid tab count, cannot parse as SisLine: {line}")); } var pos = DiagramPosition.TryFrom(cells[0]); if (!int.TryParse(cells[1], out int qty)) { return(new Error($"Could not parse line quantity: {line}")); } bool purch = cells[2].Contains("P"); bool gp = cells[2].Contains("G"); bool ccr = cells[2].Contains("C"); var pn = PartNumber.Parse(cells[3]); var desc = PartDescription.Parse(cells[4]); return(pn .CombineWith(desc) .CombineWith(pos) .Match( ok => new SisLine(ok.Item1, ok.Item2, ok.Item3, qty, purch, gp, ccr), err => Result.Error <SisLine, Error>(err))); }
public SisLine( PartNumber number, PartDescription description, DiagramPosition position, int quantity, bool purchasable = true, bool isChildGroup = false, bool isCcrPart = false) { Number = number ?? throw new ArgumentNullException(nameof(number)); Description = description ?? throw new ArgumentNullException(nameof(description)); Position = position; Quantity = Math.Max(1, quantity); Purchasable = purchasable; IsChildGroup = isChildGroup; IsCcrPart = isCcrPart; }
public static Result <SisGroup, Error> DeserializeSisGroup(string text) { var lines = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length < 1) { return(new Error()); } var firstLine = lines[0].Split('\t'); if (firstLine.Length < 3) { return(new Error("Could not separate group description from group number.")); } var groupNumber = PartNumber.Parse(firstLine[1]); var groupDesc = PartDescription.Parse(firstLine[2]); var lineResults = lines .Skip(1) // skip header line with group information .Select(txt => DeserializeSisLine(txt)) .ToList(); // fail if any lines could not be deserialized if (lineResults.Any(ln => ln.IsError)) { return(lineResults.First(ln => ln.IsError).ErrorOrThrow()); } var sisLines = lineResults .Select(ln => ln.ValueOrThrow()) // all results verified .ToList(); return(groupNumber .CombineWith(groupDesc) .Map(t => new SisGroup(t.Item1, t.Item2, sisLines))); }
public SisGroup(PartNumber groupNumber, PartDescription groupDescription, IReadOnlyList <SisLine> lines) { Number = groupNumber ?? throw new ArgumentNullException(nameof(groupNumber)); Description = groupDescription ?? throw new ArgumentNullException(nameof(groupDescription)); Lines = CompressMatchingLines(lines ?? throw new ArgumentNullException(nameof(lines))); }
public Part(PartNumber number, PartDescription description) { Number = number ?? throw new ArgumentNullException(nameof(number)); Description = description ?? throw new ArgumentNullException(nameof(description)); }