Exemple #1
0
 private bool TryGetLayoutFromText(string text, out LayoutInfo layout)
 {
     layout = default(LayoutInfo);
     var match = LayoutRegex.Match(text);
     if (match != null && match.Groups.Count > 0)
     {
         var layoutID = match.Groups[1].Value;
         if (!string.IsNullOrEmpty(layoutID))
         {
             layout = Layouts.Get(layoutID);
         }
     }
     return layout != null;
 }
 public LayoutInfo SetDefault(LayoutInfo layout)
 {
     var path = Path.Combine(Path.GetFullPath(Path.Combine(layoutFilepath, @"..\..")), "_ViewStart.cshtml");
     using (var stream = File.Open(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
     {
         using (var reader = new StreamReader(stream))
         {
             var text = reader.ReadToEnd();
             text = ViewStartLayoutMatchRegex.Replace(text, @"Layout = ""~/Views/Shared/Layouts/_" + layout.ID + @".cshtml"";");
             stream.Seek(0, SeekOrigin.Begin);
             stream.SetLength(0);
             using (var writer = new StreamWriter(stream))
             {
                 writer.Write(text);
                 writer.Flush();
             }
         }
     }
     return layout;
 }