public HttpResponseMessage RestoreStyleSheet(RestoreCssRequest request) { if (!PortalSettings.Current.UserInfo.IsSuperUser && PortalSettings.Current.UserInfo.PortalID != request.PortalId) { throw new SecurityException("No Permission"); } else { try { PortalInfo portal = PortalController.Instance.GetPortal(request.PortalId); if (portal != null) { if (File.Exists(portal.HomeDirectoryMapPath + "portal.css")) { // delete existing style sheet File.Delete(portal.HomeDirectoryMapPath + "portal.css"); } // copy file from Host if (File.Exists(Globals.HostMapPath + "portal.css")) { File.Copy(Globals.HostMapPath + "portal.css", portal.HomeDirectoryMapPath + "portal.css"); } ClientResourceManager.ClearFileExistsCache($"{Globals.ApplicationPath}/{portal.HomeDirectory}/portal.css"); } var content = this.LoadStyleSheet(request.PortalId); return(this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true, StyleSheetContent = content })); } catch (Exception exc) { Logger.Error(exc); return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } } }
internal static ActionResult Update(int PortalID, string StyleSheetContent) { ActionResult actionResult = new ActionResult(); try { string strUploadDirectory = string.Empty; string relativePath = string.Empty; PortalInfo objPortal = PortalController.Instance.GetPortal(PortalID); if (objPortal != null) { strUploadDirectory = objPortal.HomeDirectoryMapPath; relativePath = $"{Globals.ApplicationPath}/{objPortal.HomeDirectory}/portal.css"; } //reset attributes if (File.Exists(strUploadDirectory + "portal.css")) { File.SetAttributes(strUploadDirectory + "portal.css", FileAttributes.Normal); } //write CSS file if (!string.IsNullOrEmpty(StyleSheetContent.Replace("\n", ""))) { using (StreamWriter writer = File.CreateText(strUploadDirectory + "portal.css")) { writer.WriteLine(StyleSheetContent); } } else if (File.Exists(strUploadDirectory + "portal.css")) { File.Delete(strUploadDirectory + "portal.css"); } //Clear client resource cache string overrideSetting = PortalController.GetPortalSetting(ClientResourceSettings.OverrideDefaultSettingsKey, PortalID, "False"); if (bool.TryParse(overrideSetting, out bool overridePortal)) { if (overridePortal) { // increment this portal version only PortalController.IncrementCrmVersion(PortalID); } else { // increment host version, do not increment other portal versions though. HostController.Instance.IncrementCrmVersion(false); } } ClientResourceManager.ClearFileExistsCache(relativePath); actionResult.IsSuccess = true; return(actionResult); } catch (Exception ex) { actionResult.AddError("", "", ex); return(actionResult); } }
public HttpResponseMessage UpdateStyleSheet(UpdateCssRequest request) { if (!PortalSettings.Current.UserInfo.IsSuperUser && PortalSettings.Current.UserInfo.PortalID != request.PortalId) { throw new SecurityException("No Permission"); } else { try { string strUploadDirectory = string.Empty; var relativePath = string.Empty; PortalInfo objPortal = PortalController.Instance.GetPortal(request.PortalId); if (objPortal != null) { strUploadDirectory = objPortal.HomeDirectoryMapPath; relativePath = $"{Globals.ApplicationPath}/{objPortal.HomeDirectory}/portal.css"; } // reset attributes if (File.Exists(strUploadDirectory + "portal.css")) { File.SetAttributes(strUploadDirectory + "portal.css", FileAttributes.Normal); } // write CSS file using (var writer = File.CreateText(strUploadDirectory + "portal.css")) { writer.WriteLine(request.StyleSheetContent); } // Clear client resource cache var overrideSetting = PortalController.GetPortalSetting(ClientResourceSettings.OverrideDefaultSettingsKey, request.PortalId, "False"); bool overridePortal; if (bool.TryParse(overrideSetting, out overridePortal)) { if (overridePortal) { // increment this portal version only PortalController.IncrementCrmVersion(request.PortalId); } else { // increment host version, do not increment other portal versions though. HostController.Instance.IncrementCrmVersion(false); } } ClientResourceManager.ClearFileExistsCache(relativePath); return(this.Request.CreateResponse(HttpStatusCode.OK, new { Success = true })); } catch (Exception exc) { Logger.Error(exc); return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)); } } }