public DataResult Parse() { if (Doc.Lists.Count != 2) { return(new DataResult(true, "Неверное число список в DOCX-файле.")); } var dataResult = new DataResult(); var lastItems = new Stack <Class>(); foreach (var i in Doc.Lists[0].Items) { var item = GetClassFrom(i.Text); if (item == null) { return(new DataResult(true, $"Возникла ошибка при чтении строки \"{i.Text}\".")); } item.IndentLevel = i.IndentLevel ?? 0; dataResult.Classes.Add(item); if (lastItems.Count == 0) { lastItems.Push(item); } else if (lastItems.Peek().IndentLevel == item.IndentLevel) { lastItems.Pop(); if (lastItems.Count != 0 && lastItems.Peek().IndentLevel < item.IndentLevel) { item.ParentClasses.Add(lastItems.Peek()); } lastItems.Push(item); } else if (lastItems.Peek().IndentLevel < item.IndentLevel) { item.ParentClasses.Add(lastItems.Peek()); lastItems.Push(item); } else if (lastItems.Peek().IndentLevel > item.IndentLevel) { while (lastItems.Count != 0 && lastItems.Peek().IndentLevel >= item.IndentLevel) { lastItems.Pop(); } if (lastItems.Count != 0 && lastItems.Peek().IndentLevel < item.IndentLevel) { item.ParentClasses.Add(lastItems.Peek()); } lastItems.Push(item); } } foreach (var i in Doc.Lists[1].Items) { var(property, references) = GetAnnotationPropertyFrom(i.Text); if (property == null) { return(new DataResult(true, $"Ошибка при анализе строки \"{i.Text}\"")); } dataResult.AnnotationProperties.Add(property); foreach (var j in references) { dataResult.Classes.Where(x => x.IriAddress == j.Item1).Single().AnnotationProperties.Add(property, j.Item2); } } return(dataResult); }
public XmlCreator(DataResult dataResult) { DataResult = dataResult; }