/// <summary> /// Возвращает поток с данными из указанной секции и всех ее дочерних секций /// </summary> /// <param name="sectionName"></param> /// <returns></returns> public Stream CreateStream(string sectionName) { throwIfDisposed(); if (_sectionStreams.Any(si => si.SectionName == sectionName)) { throw new InvalidOperationException(); } var tmp = _sections.AllChildren.Find(s => s.Section.FullName == sectionName); var sectionIndex = tmp.Index; var section = tmp.ValueOrDefault; NotifiableStream stream = null; if (section == null) { stream = new NotifiableStream(new MemoryStream()); sectionIndex = Math.Max(_sections.AllChildren.Count() - 1, _sectionStreams.EmptyToNull()?.Max(s => s.PositionInBase) ?? 0); } else { stream = new NotifiableStream(readSection()); } hookEvents(stream); var streamInfo = new StreamInfo(sectionName, stream, sectionIndex); _sectionStreams.Add(streamInfo); return(stream); Stream readSection() { var ms = new MemoryStream(); var sw = new StreamWriter(ms); sw.WriteLines(section.Lines); sw.Flush(); ms.Position = 0; return(ms); } }
public StreamInfo(string sectionName, NotifiableStream stream, int positionInBase) { SectionName = sectionName; Stream = stream; PositionInBase = positionInBase; }
void unhookEvents(NotifiableStream stream) { stream.Modified -= updateBaseStream; stream.Closed -= closeBaseStream; }