Beispiel #1
0
 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
     };
 }
Beispiel #2
0
        public PageModuleInfo ModuleUp(PageModuleInfo module)
        {
            var path = Path.Combine(viewsFilepath, module.ControllerID, module.PageID + ".cshtml");
            using (var stream = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                using (var reader = new StreamReader(stream))
                {
                    var text = new StringBuilder(reader.ReadToEnd());
                    var sectionText = GetSectionText(module.SectionID, text.ToString());
                    var matches = PageModuleRegex.Matches(sectionText);
                    var modules = matches.OfType<Match>()
                        .Select(match => match.Groups[1].Value)
                        .ToList();
                    for (int i = 0; i < modules.Count; i++)
                    {
                        if (modules[i].Equals(module.ID))
                        {
                            if (i > 0)
                            {
                                modules[i] = modules[i - 1];
                                modules[i - 1] = module.ID;
                                {
                                    text = text.Replace(
                                        sectionText,
                                        string.Format(@"@section {0} {{{1}{2}}}",
                                            module.SectionID,
                                            Environment.NewLine,
                                            ModuleListToString(modules)));

                                    stream.Seek(0, SeekOrigin.Begin);
                                    stream.SetLength(0);
                                    using (var writer = new StreamWriter(stream))
                                    {
                                        writer.Write(text.ToString());
                                        writer.Flush();
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }
            return module;
        }