/// <summary> /// Check in event handler. /// </summary> protected void btnCheckIn_Click(object sender, EventArgs e) { LayoutInfo li = this.PagePlaceholder.LayoutInfo; PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo; if ((li != null) || (pti != null)) { string filename = ""; string tmpFileName = ""; if (li != null) { tmpFileName = li.LayoutCheckedOutFilename; } else { tmpFileName = pti.PageTemplateLayoutCheckedOutFileName; } if (HttpContext.Current != null) { filename = HttpContext.Current.Server.MapPath(tmpFileName); } StreamReader sr = StreamReader.New(filename); // Read away the directive lines int skiplines = LayoutInfoProvider.GetLayoutDirectives().Split('\n').Length - 1; for (int i = 0; i < skiplines; i++) { sr.ReadLine(); } string newcode = sr.ReadToEnd(); sr.Close(); File.Delete(filename); if (li != null) { li.LayoutCheckedOutByUserID = 0; li.LayoutCheckedOutFilename = ""; li.LayoutCheckedOutMachineName = ""; li.LayoutCode = newcode; LayoutInfoProvider.SetLayoutInfo(li); } else { pti.PageTemplateLayoutCheckedOutByUserID = 0; pti.PageTemplateLayoutCheckedOutFileName = ""; pti.PageTemplateLayoutCheckedOutMachineName = ""; pti.PageTemplateLayout = newcode; PageTemplateInfoProvider.SetPageTemplateInfo(pti); } txtLayout.Text = newcode; } }
/// <summary> /// Check out layout event handler. /// </summary> protected void btnCheckOut_Click(object sender, EventArgs e) { // Ensure version before check-out using (CMSActionContext context = new CMSActionContext()) { context.AllowAsyncActions = false; // Save first if (!SaveLayout()) { return; } } LayoutInfo li = this.PagePlaceholder.LayoutInfo; PageTemplateInfo pti = this.PagePlaceholder.PageTemplateInfo; if ((li != null) || (pti != null)) { try { string filename = ""; string tmpCode = ""; LayoutTypeEnum layoutType = LayoutTypeEnum.Ascx; if (li != null) { filename = LayoutInfoProvider.GetLayoutUrl(li.LayoutCodeName, null, li.LayoutType); layoutType = li.LayoutType; tmpCode = li.LayoutCode; } else { filename = PageTemplateInfoProvider.GetLayoutUrl(pti.CodeName, null, pti.PageTemplateLayoutType); layoutType = pti.PageTemplateLayoutType; tmpCode = pti.PageTemplateLayout; } // Write the code to the file string fullfilename = ""; if (HttpContext.Current != null) { fullfilename = HttpContext.Current.Server.MapPath(filename); DirectoryHelper.EnsureDiskPath(fullfilename, HttpContext.Current.Server.MapPath("~/")); } StringBuilder sb = new StringBuilder(); if (layoutType == LayoutTypeEnum.Ascx) { sb.Append(LayoutInfoProvider.GetLayoutDirectives()); } sb.Append(tmpCode); string content = HTMLHelper.EnsureLineEnding(sb.ToString(), "\r\n"); File.WriteAllText(fullfilename, content); // Set the layout data if (li != null) { // Shared layout li.LayoutCheckedOutByUserID = user.UserID; li.LayoutCheckedOutMachineName = ""; if (HttpContext.Current != null) { li.LayoutCheckedOutMachineName = HTTPHelper.MachineName; } li.LayoutCheckedOutFilename = filename; LayoutInfoProvider.SetLayoutInfo(li); } else { // Page template layout pti.PageTemplateLayoutCheckedOutByUserID = user.UserID; pti.PageTemplateLayoutCheckedOutMachineName = ""; if (HttpContext.Current != null) { pti.PageTemplateLayoutCheckedOutMachineName = HTTPHelper.MachineName; } pti.PageTemplateLayoutCheckedOutFileName = filename; PageTemplateInfoProvider.SetPageTemplateInfo(pti); } } catch { return; } } }