// Delete canvasdesigner style internal static void DeleteStyle(int pageId) { // Get inherited tuned pageId and path var contentService = ApplicationContext.Current.Services.ContentService; IContent content = contentService.GetById(pageId); int inheritedTunedPageId = CanvasDesignerUtility.GetParentOrSelfTunedPageId(content.Path.Split(','), true); // Path to the less and css files string newResultLessPath = HttpContext.Current.Server.MapPath(string.Format(resultLessPath, inheritedTunedPageId)); string newResultCssPath = HttpContext.Current.Server.MapPath(string.Format(resultCssPath, inheritedTunedPageId)); // Delete all style file for this page System.IO.File.Delete(newResultLessPath); System.IO.File.Delete(newResultCssPath); }
// Save and publish less style internal static void SaveAndPublishStyle(string parameters, int pageId, bool inherited) { // Get inherited tuned pageId and path var contentService = ApplicationContext.Current.Services.ContentService; IContent content = contentService.GetById(pageId); int inheritedTunedPageId = CanvasDesignerUtility.GetParentOrSelfTunedPageId(content.Path.Split(','), true); // Load inherited Less content string inheritedLessContent = string.Empty; using (System.IO.StreamReader sr = new System.IO.StreamReader(HttpContext.Current.Server.MapPath(string.Format(resultLessPath, inheritedTunedPageId)))) { inheritedLessContent = sr.ReadToEnd(); } // Update pageId if parameters have changed if (inherited) { pageId = inheritedTunedPageId; } // Create front directory if necesary if (!Directory.Exists(frontBasePath)) { Directory.CreateDirectory(frontBasePath); } // Prepare parameters and gf block and replace with the new value string newParamBlock = string.Empty; string newGfBlock = string.Empty; foreach (string parameter in parameters.Trim().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) { if (parameter.IndexOf("@import") < 0) { string name = parameter.Substring(0, parameter.IndexOf(":")); string value = parameter.Substring(parameter.IndexOf(":") + 1); if (string.IsNullOrEmpty(value)) { value = "''"; } inheritedLessContent = Regex.Replace(inheritedLessContent, string.Format("{0}:([^;\n]*);", name), string.Format("{0}:{1};", name, value)); } else { newGfBlock += parameter + ";" + Environment.NewLine; } } // Save less file using (System.IO.StreamWriter file = new System.IO.StreamWriter(HttpContext.Current.Server.MapPath(string.Format(resultLessPath, pageId)))) { file.Write(inheritedLessContent); } // Compile the Less file string compiledStyle = GetCssFromLessString(newGfBlock + inheritedLessContent, false, true, true).Replace("@import", "@IMPORT"); // Save compiled file using (System.IO.StreamWriter file = new System.IO.StreamWriter(HttpContext.Current.Server.MapPath(string.Format(resultCssPath, pageId)))) { file.Write(compiledStyle); } }