public DocumentEntry AddDocument(SolutionEntry solution) { var document = _entryFactory.CreateDocument(solution); solution.Documents.Add(document); return(document); }
public DocumentEntry AddDocumentAfter(SolutionEntry solution, DocumentEntry after) { var document = _entryFactory.CreateDocument(solution); int index = solution.Documents.IndexOf(after); solution.Documents.Insert(index + 1, document); return(document); }
public SolutionEntry Deserialize(string path) { string solutionName = System.IO.Path.GetFileNameWithoutExtension(path); var dict = new Dictionary <string, List <Tuple <string, string> > >(); var solution = new SolutionEntry() { Name = solutionName, Documents = new ObservableCollection <DocumentEntry>() }; using (var zip = ZipFile.Open(path, ZipArchiveMode.Read)) { foreach (var entry in zip.Entries) { var e = entry.FullName.Split(entryNameSeparator); if (e.Length == 1) { string key = e[0]; if (!dict.ContainsKey(key)) { dict.Add(key, new List <Tuple <string, string> >()); } } else if (e.Length == 2) { string key = e[0]; string data = e[1]; string content = null; using (var reader = new StreamReader(entry.Open())) { content = reader.ReadToEnd(); } if (!dict.ContainsKey(key)) { dict.Add(key, new List <Tuple <string, string> >()); } dict[key].Add(new Tuple <string, string>(data, content)); } } } foreach (var item in dict) { var document = _entryFactory.CreateDocument(solution, item.Key); solution.Documents.Add(document); foreach (var tuple in item.Value) { var page = _entryFactory.CreatePage(document, tuple.Item2, tuple.Item1); document.Pages.Add(page); } } return(solution); }
public DocumentEntry CreateDocument(SolutionEntry solution, string name = null) { var document = new DocumentEntry() { Name = name == null?string.Concat("Document", solution.Documents.Count) : name, Pages = new ObservableCollection <PageEntry>(), Solution = solution }; return(document); }
public void Serialize(SolutionEntry solution, string path) { using (FileStream fs = new FileStream(path, FileMode.Create)) { using (ZipArchive zip = new ZipArchive(fs, ZipArchiveMode.Update)) { foreach (var document in solution.Documents) { if (document.Pages.Count <= 0) { AddDocumentEntry(zip, document.Name); } foreach (var page in document.Pages) { AddPageEntry(zip, document.Name, page.Name, page.Content); } } } } }