private static PageSectionInfo CreatePageSectionInfoIndirect(ControllerInfo controller, string pageID, int ordinal, LayoutSectionInfo section, PageModuleInfo[] modules) { return new PageSectionInfo { ID = section.ID, ControllerID = controller.ID, IsPresent = modules != null, Modules = modules, PageID = pageID, Ordinal = ordinal }; }
internal PageSectionInfo SectionAdd(string pageId, LayoutSectionInfo section) { var page = Index() .Where(p => p.ID.Equals(pageId, StringComparison.InvariantCultureIgnoreCase)) .FirstOrDefault(); return SectionAdd(new PageSectionInfo { ControllerID = page.ControllerID, ID = section.ID, IsPresent = true, Modules = LayoutModulesToPageModule(page, section.Modules), Ordinal = section.Ordinal, PageID = pageId, }); }
public LayoutSectionInfo SectionUp(LayoutSectionInfo section) { var layout = Get(section.LayoutID); var prior = layout.Sections .TakeWhile(s => !s.ID.Equals(section.ID, StringComparison.InvariantCultureIgnoreCase)) .Reverse() .FirstOrDefault(); if (prior != null) { using (var stream = File.Open(Path.Combine(layoutFilepath, "_" + layout.ID + ".cshtml"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var reader = new StreamReader(stream)) { var text = new StringBuilder(reader.ReadToEnd()); var sectionText = GetSectionText(section.ID, text); var priorText = GetSectionText(prior.ID, text); var subst = Guid.NewGuid().ToString(); text = text .Replace(priorText, subst) .Replace(sectionText, priorText) .Replace(subst, sectionText); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); using (var writer = new StreamWriter(stream)) { writer.Write(text.ToString()); writer.Flush(); } } } } // NOTE: this requires no page-level changes return section; }
public LayoutSectionInfo SectionRemove(LayoutSectionInfo section) { var layout = Get(section.LayoutID); using (var stream = File.Open(Path.Combine(layoutFilepath, "_" + layout.ID + ".cshtml"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var reader = new StreamReader(stream)) { var text = new StringBuilder(reader.ReadToEnd()); var sectionText = GetSectionText(section.ID, text); text = text .Replace("@" + sectionText, ""); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); using (var writer = new StreamWriter(stream)) { writer.Write(text.ToString()); writer.Flush(); } } } UpdateDependentPages(section.LayoutID, (pageController, page) => { pageController.SectionRemove(new PageSectionInfo { ControllerID = page.ControllerID, ID = section.ID, Ordinal = section.Ordinal, PageID = page.ID, }); }); return section; }
public LayoutSectionInfo SectionDown(LayoutSectionInfo section) { var layout = Get(section.LayoutID); var next = layout.Sections .Reverse() .TakeWhile(s => !s.ID.Equals(section.ID, StringComparison.InvariantCultureIgnoreCase)) .LastOrDefault(); if (next != null) { SectionUp(next); } // NOTE: this requires no page-level changes return section; }
public LayoutSectionInfo SectionAdd(LayoutSectionInfo section) { // TODO: if section already exists, fail var layout = Get(section.LayoutID); var prior = layout.Sections.LastOrDefault(); using (var stream = File.Open(Path.Combine(layoutFilepath, "_" + layout.ID + ".cshtml"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { using (var reader = new StreamReader(stream)) { var text = reader.ReadToEnd(); text = text.Replace( @"</body>", Environment.NewLine + @"@RenderSection(""" + section.ID + @""". required: false)" + Environment.NewLine + @"</body>"); stream.Seek(0, SeekOrigin.Begin); stream.SetLength(0); using (var writer = new StreamWriter(stream)) { writer.Write(text); writer.Flush(); } } } UpdateDependentPages(section.LayoutID, (pageController, page) => { pageController.SectionAdd(new PageSectionInfo { ControllerID = page.ControllerID, ID = section.ID, Ordinal = section.Ordinal, PageID = page.ID, }); }); return section; }