private SoftwareComponent BuildComponent(Model model, ComponentSpecification spec) { List <AssemblyPointer> componentPointers = new List <AssemblyPointer>(); List <SoftwareComponent> subcomponents = new List <SoftwareComponent>(); foreach (ComponentSpecification subSpec in spec.Subcomponents) { SoftwareComponent subcomponent = BuildComponent(model, subSpec); if (subcomponent != null) { subcomponents.Add(subcomponent); } } foreach (string assemblyname in spec.Assemblies) { if (assemblyname.Contains("*")) { Regex regex = new Regex(assemblyname); foreach (AssemblyPointer pointer in model.AllAssemblies().Where(x => regex.Match(x.GetName().Name).Success)) { if (pointer.Component() == null) { componentPointers.Add(pointer); pointer.AddProperty("Component", spec.Name); } } } else { AssemblyPointer pointer = model.FindPointerByName(assemblyname); if (pointer != null && pointer.Component() == null) { componentPointers.Add(pointer); pointer.AddProperty("Component", spec.Name); } } } try { SoftwareComponent component = new SoftwareComponent(spec.Name, componentPointers, spec.Color, subcomponents); return(component); } catch (ArgumentException e) { return(null); } }
private ComponentSpecification BuildSpec(int currentColumn, int assembliesColumn) { WorkbookStylesPart styles = workbookPart.WorkbookStylesPart; Stylesheet stylesheet = styles.Stylesheet; List <Cell> row = rows.First().Elements <Cell>().ToList(); Cell currentCell = row.ElementAt(currentColumn); string cellContent = TextInCell(currentCell); ComponentSpecification component = new ComponentSpecification(cellContent); currentColumn++; if (currentColumn != assembliesColumn) { currentCell = row.ElementAt(currentColumn); if (!string.IsNullOrEmpty(TextInCell(currentCell))) { do { component.Subcomponents.Add(BuildSpec(currentColumn, assembliesColumn)); if (rows.Count == 0) { break; } row = rows.First().Elements <Cell>().ToList(); currentCell = row.ElementAt(currentColumn); } while (!string.IsNullOrEmpty(TextInCell(currentCell)) && string.IsNullOrEmpty(TextInCell(row.ElementAt(currentColumn - 1)))); } else { if (rows.Count > 1) { do { try { component.Assemblies.Add(TextInCell(row.ElementAt(assembliesColumn))); } catch { MessageBox.Show("Invalid specification file :\nPlease respect the spreadsheet pattern, you didn't specified an assembly"); } rows.RemoveAt(0); if (rows.Count == 0) { break; } row = rows.First().Elements <Cell>().ToList(); currentCell = row.ElementAt(currentColumn); } while (string.IsNullOrEmpty(TextInCell(currentCell)) && string.IsNullOrEmpty(TextInCell(row.ElementAt(currentColumn - 1)))); if (!string.IsNullOrEmpty(TextInCell(currentCell)) && string.IsNullOrEmpty(TextInCell(row.ElementAt(currentColumn - 1)))) { do { component.Subcomponents.Add(BuildSpec(currentColumn, assembliesColumn)); if (rows.Count == 0) { break; } row = rows.First().Elements <Cell>().ToList(); currentCell = row.ElementAt(currentColumn); } while (!string.IsNullOrEmpty(TextInCell(currentCell)) && string.IsNullOrEmpty(TextInCell(row.ElementAt(currentColumn - 1)))); } } } } else { currentColumn--; cellContent = null; while (string.IsNullOrEmpty(cellContent)) { try { cellContent = TextInCell(row.ElementAt(assembliesColumn)); if (!string.IsNullOrEmpty(cellContent)) { component.Assemblies.Add(cellContent); } else { break; } } catch { MessageBox.Show("Invalid specification file :\nPlease respect the spreadsheet pattern, you didn't specified an assembly"); } rows.RemoveAt(0); if (rows.Count == 0) { break; } row = rows.First().Elements <Cell>().ToList(); cellContent = null; foreach (Cell cell in row.Where(x => row.IndexOf(x) < assembliesColumn)) { cellContent = TextInCell(cell); if (!string.IsNullOrEmpty(TextInCell(cell))) { break; } } } } return(component); }