// // ==================================================================================================== public static string get(CPBaseClass cp, PageTemplateModel template) { try { string addonList = ""; foreach (var rule in DbBaseModel.createList <AddonTemplateRuleModel>(cp, "(templateId=" + template.id + ")")) { AddonModel addon = DbBaseModel.create <AddonModel>(cp, rule.addonId); if (addon != null) { addonList += System.Environment.NewLine + "\t\t" + "<IncludeAddon name=\"" + addon.name + "\" guid=\"" + addon.ccguid + "\" />"; } } return("" + System.Environment.NewLine + "\t" + "<Template" + " name=\"" + System.Net.WebUtility.HtmlEncode(template.name) + "\"" + " guid=\"" + template.ccguid + "\"" + " issecure=\"" + GenericController.getYesNo(template.isSecure) + "\"" + " >" + addonList + System.Environment.NewLine + "\t\t" + "<BodyHtml>" + ExportController.tabIndent(cp, ExportController.EncodeCData(template.bodyHTML)) + "</BodyHtml>" + System.Environment.NewLine + "\t" + "</Template>"); } catch (Exception ex) { cp.Site.ErrorReport(ex, "GetAddonNode"); return(string.Empty); } }
public ActionResult Files(string theme, int?siteId, string returnUrl) { if (!siteId.HasValue) { siteId = _services.SiteContext.CurrentSite.Id; } if (theme.IsEmpty()) { theme = _settingService.LoadSetting <ThemeSettings>(siteId.Value).DefaultDesktopTheme; } if (!_themeRegistry.ThemeManifestExists(theme) || _themeRegistry.GetThemeManifest(theme).MobileTheme) { return(HttpNotFound()); } var model = new PageTemplateModel { Name = theme, SiteId = siteId.Value }; var cssDirectory = Path.Combine(Server.MapPath("~/Themes"), theme, "Content"); foreach (var file in Directory.GetFiles(cssDirectory, "*.less", SearchOption.AllDirectories)) { var fileName = file.Replace(cssDirectory, "").Trim('\\'); model.CssFiles.Add(new CssFileViewModel { Name = fileName.Replace('\\', '|'), LastUpdated = System.IO.File.GetLastWriteTime(file) }); } var viewDirectory = Path.Combine(Server.MapPath("~/Themes"), theme, "Views"); foreach (var file in Directory.GetFiles(viewDirectory, "*.cshtml", SearchOption.AllDirectories)) { var fileName = file.Replace(viewDirectory, "").Trim('\\'); if (fileName.IndexOf('\\') < 0) { continue; } var ctrl = fileName.Split('\\')[0]; var act = fileName.Split('\\').Last(); model.ViewFiles.Add(new ViewFileViewModel { Name = fileName.Replace('\\', '|'), Controller = ctrl, Action = act.Remove(act.LastIndexOf('.')), LastUpdated = System.IO.File.GetLastWriteTime(file) }); } return(View(model)); }
public JsonResult Manage(PageTemplateModel model, GridManagingModel manageModel) { if (ModelState.IsValid || manageModel.Operation == GridOperationEnums.Del) { return(Json(_pageTemplateServices.ManagePageTemplate(manageModel.Operation, model))); } return(Json(new ResponseModel { Success = false, Message = GetFirstValidationResults(ModelState).Message })); }
/// <summary> /// Manage Site Setting /// </summary> /// <param name="operation">the operation</param> /// <param name="model">the page template model</param> /// <returns></returns> public ResponseModel ManagePageTemplate(GridOperationEnums operation, PageTemplateModel model) { ResponseModel response; Mapper.CreateMap <PageTemplateModel, PageTemplate>(); PageTemplate pageTemplate; switch (operation) { case GridOperationEnums.Edit: pageTemplate = GetById(model.Id); pageTemplate.Name = model.Name; pageTemplate.ParentId = model.ParentName.ToNullableInt(); response = HierarchyUpdate(pageTemplate); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::UpdateSuccessfully:::Update page template successfully.") : _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::UpdateFailure:::Update page template failed. Please try again later."))); case GridOperationEnums.Add: pageTemplate = Mapper.Map <PageTemplateModel, PageTemplate>(model); pageTemplate.ParentId = model.ParentName.ToNullableInt(); pageTemplate.Content = Configurations.CurlyBracketRenderBody; response = HierarchyInsert(pageTemplate); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::CreateSuccessfully:::Create page template successfully.") : _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::CreateFailure:::Create page template failed. Please try again later."))); case GridOperationEnums.Del: response = Delete(model.Id); return(response.SetMessage(response.Success ? _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::DeleteSuccessfully:::Delete page template successfully.") : _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::DeleteFailure:::Delete page template failed. Please try again later."))); } return(new ResponseModel { Success = false, Message = _localizedResourceServices.T("AdminModule:::PageTemplates:::Messages:::ObjectNotFounded:::Page template is not founded.") }); }
/// <summary> /// Changes paginated method signatures to return Page type. /// </summary> /// <param name="serviceClient"></param> public virtual void NormalizePaginatedMethods(ServiceClient serviceClient) { if (serviceClient == null) { throw new ArgumentNullException("serviceClient"); } foreach (var method in serviceClient.Methods.Where(m => m.Extensions.ContainsKey(AzureExtensions.PageableExtension))) { string nextLinkName = null; var ext = method.Extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer; if (ext == null) { continue; } nextLinkName = (string)ext["nextLinkName"]; string itemName = (string)ext["itemName"] ?? "value"; foreach (var responseStatus in method.Responses.Where(r => r.Value.Body is CompositeType).Select(s => s.Key).ToArray()) { var compositType = (CompositeType)method.Responses[responseStatus].Body; var sequenceType = compositType.Properties.Select(p => p.Type).FirstOrDefault(t => t is SequenceType) as SequenceType; // if the type is a wrapper over page-able response if (sequenceType != null) { compositType.Extensions[AzureExtensions.PageableExtension] = true; var pageTemplateModel = new PageTemplateModel(compositType, serviceClient, nextLinkName, itemName); if (!pageModels.Contains(pageTemplateModel)) { pageModels.Add(pageTemplateModel); } } } } }
//==================================================================================================== /// <summary> /// main_GetPageDynamicLinkWithArgs /// </summary> /// <param name="contentControlID"></param> /// <param name="PageID"></param> /// <param name="DefaultLink"></param> /// <param name="IsRootPage"></param> /// <param name="templateId"></param> /// <param name="SectionID"></param> /// <param name="MenuLinkOverRide"></param> /// <param name="UseContentWatchLink"></param> /// <returns></returns> internal string main_GetPageDynamicLinkWithArgs(int contentControlID, int PageID, string DefaultLink, bool IsRootPage, int templateId, int SectionID, string MenuLinkOverRide, bool UseContentWatchLink) { string resultLink = ""; try { if (!string.IsNullOrEmpty(MenuLinkOverRide)) { // // -- redirect to this page record resultLink = "?rc=" + contentControlID + "&ri=" + PageID; } else { if (UseContentWatchLink) { // // -- Legacy method - lookup link from a table set during the last page hit resultLink = getContentWatchLinkByID(contentControlID, PageID, DefaultLink, false); } else { // // -- Current method - all pages are in the Template, Section, Page structure if (templateId != 0) { PageTemplateModel template = DbBaseModel.create <PageTemplateModel>(core.cpParent, templateId); if (template != null) { resultLink = ""; // template.Link } } if (string.IsNullOrEmpty(resultLink)) { // // -- not found, use default if (!string.IsNullOrEmpty(DefaultLink)) { // // if default given, use that resultLink = DefaultLink; } else { // // -- fallback, use content watch resultLink = getContentWatchLinkByID(contentControlID, PageID, "", false); } } if ((PageID == 0) || (IsRootPage)) { // // -- Link to Root Page, no bid, and include sectionid if not 0 if (IsRootPage && (SectionID != 0)) { resultLink = GenericController.modifyLinkQuery(resultLink, "sid", SectionID.ToString(), true); } resultLink = GenericController.modifyLinkQuery(resultLink, rnPageId, "", false); } else { resultLink = GenericController.modifyLinkQuery(resultLink, rnPageId, GenericController.encodeText(PageID), true); if (PageID != 0) { resultLink = GenericController.modifyLinkQuery(resultLink, "sid", "", false); } } } } resultLink = GenericController.encodeVirtualPath(resultLink, core.appConfig.cdnFileUrl, appRootPath, core.webServer.requestDomain); } catch (Exception ex) { LogController.logError(core, ex); throw; } return(resultLink); }
private string GetPagingSetting(Dictionary<string, object> extensions, string valueTypeName) { var ext = extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer; string nextLinkName = (string)ext["nextLinkName"] ?? "nextLink"; string itemName = (string)ext["itemName"] ?? "value"; string className = (string)ext["className"]; if (string.IsNullOrEmpty(className)) { className = valueTypeName + "Paged"; ext["className"] = className; } var pageModel = new PageTemplateModel(className, nextLinkName, itemName, valueTypeName); if (!pageModels.Contains(pageModel)) { pageModels.Add(pageModel); } return className; }
private string GetPagingSetting(CompositeType body, Dictionary<string, object> extensions, string valueTypeName, IDictionary<int, string> typePageClasses, String methodName) { var ext = extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer; bool ignoreNextLink = false; if (ext["nextLinkName"] != null && ext["nextLinkName"].Type == Newtonsoft.Json.Linq.JTokenType.Null) { ignoreNextLink = true; } string nextLinkName = (string)ext["nextLinkName"] ?? "nextLink"; string itemName = (string)ext["itemName"] ?? "value"; nextLinkName = nextLinkName.Replace(".", "\\\\."); itemName = itemName.Replace(".", "\\\\."); bool findNextLink = false; bool findItem = false; foreach (var property in body.ComposedProperties) { if (property.SerializedName == nextLinkName) { findNextLink = true; } else if (property.SerializedName == itemName) { findItem = true; } } if (!ignoreNextLink && !findNextLink) { throw new KeyNotFoundException(String.Format(CultureInfo.InvariantCulture, "Couldn't find the nextLink property specified by extension on operation {0} and property {1}", methodName, body.SerializedName)); } if (!findItem) { throw new KeyNotFoundException("Couldn't find the item property specified by extension"); } string className; var hash = (nextLinkName + "#" + itemName).GetHashCode(); if (!typePageClasses.ContainsKey(hash)) { className = (string)ext["className"]; if (string.IsNullOrEmpty(className)) { if (typePageClasses.Count > 0) { className = valueTypeName + String.Format(CultureInfo.InvariantCulture, "Paged{0}", typePageClasses.Count); } else { className = valueTypeName + "Paged"; } } typePageClasses.Add(hash, className); } className = typePageClasses[hash]; ext["className"] = className; var pageModel = new PageTemplateModel(className, nextLinkName, itemName, valueTypeName); if (!pageModels.Contains(pageModel)) { pageModels.Add(pageModel); } return className; }
private string GetPagingSetting(CompositeType body, Dictionary <string, object> extensions, string valueTypeName, IDictionary <int, string> typePageClasses, String methodName) { var ext = extensions[AzureExtensions.PageableExtension] as Newtonsoft.Json.Linq.JContainer; bool ignoreNextLink = false; if (ext["nextLinkName"] != null && ext["nextLinkName"].Type == Newtonsoft.Json.Linq.JTokenType.Null) { ignoreNextLink = true; } string nextLinkName = (string)ext["nextLinkName"] ?? "nextLink"; string itemName = (string)ext["itemName"] ?? "value"; nextLinkName = nextLinkName.Replace(".", "\\\\."); itemName = itemName.Replace(".", "\\\\."); bool findNextLink = false; bool findItem = false; foreach (var property in body.ComposedProperties) { if (property.SerializedName == nextLinkName) { findNextLink = true; } else if (property.SerializedName == itemName) { findItem = true; } } if (!ignoreNextLink && !findNextLink) { throw new KeyNotFoundException(String.Format(CultureInfo.InvariantCulture, "Couldn't find the nextLink property specified by extension on operation {0} and property {1}", methodName, body.SerializedName)); } if (!findItem) { throw new KeyNotFoundException("Couldn't find the item property specified by extension"); } string className; var hash = (nextLinkName + "#" + itemName).GetHashCode(); if (!typePageClasses.ContainsKey(hash)) { className = (string)ext["className"]; if (string.IsNullOrEmpty(className)) { if (typePageClasses.Count > 0) { className = valueTypeName + String.Format(CultureInfo.InvariantCulture, "Paged{0}", typePageClasses.Count); } else { className = valueTypeName + "Paged"; } } typePageClasses.Add(hash, className); } className = typePageClasses[hash]; ext["className"] = className; var pageModel = new PageTemplateModel(className, nextLinkName, itemName, valueTypeName); if (!pageModels.Contains(pageModel)) { pageModels.Add(pageModel); } return(className); }
// //==================================================================================================== /// <summary> /// Import a file and process the html. Save the result. /// </summary> /// <param name="cp"></param> /// <param name="htmlSourceTempPathFilename"></param> /// <param name="importTypeId"></param> /// <param name="layoutId">If not 0, the imported html will be saved to the record in this table.</param> /// <param name="pageTemplateId">If not 0, the imported html will be saved to the record in this table.</param> /// <param name="emailTemplateId">If not 0, the imported html will be saved to the record in this table.</param> /// <param name="emailId">If not 0, the imported html will be saved to the record in this table.</param> /// <param name="userMessageList">If there were any processing errors caused by the data, return them here. These can be presented to the user.</param> /// <returns></returns> public static bool processImportFile(CPBaseClass cp, string htmlSourceTempPathFilename, ImporttypeEnum importTypeId, int layoutId, int pageTemplateId, int emailTemplateId, int emailId, ref List <string> userMessageList) { try { if (System.IO.Path.GetExtension(htmlSourceTempPathFilename).Equals(".zip")) { // // -- upload file is a zip and unzip to temp and copy assets to wwwroot cp.TempFiles.UnzipFile(htmlSourceTempPathFilename); cp.TempFiles.DeleteFile(htmlSourceTempPathFilename); // // -- copy non-html files to wwwroot copyNonHtmlFilesToWWW(cp, cp.TempFiles.GetPath(htmlSourceTempPathFilename), ""); } // // -- import all html files in the root folder string tempPath = cp.TempFiles.GetPath(htmlSourceTempPathFilename); bool htmlFileFound = false; foreach (var file in cp.TempFiles.FileList(tempPath)) { if (file.Extension.ToLowerInvariant().Equals(".html")) { // // -- process each html file one at a time userMessageList.Add("Processing file " + cp.CdnFiles.GetFilename(file.Name)); string newRecordName = Path.GetFileNameWithoutExtension(file.Name); htmlFileFound = true; HtmlDocument htmlDoc = new HtmlDocument(); htmlDoc.Load(cp.TempFiles.PhysicalFilePath + tempPath + file.Name, Encoding.UTF8); if (htmlDoc == null) { // // -- body tag not found, import the whole document userMessageList.Add("The file is empty."); return(false); } // // -- get record names for each import type string layoutRecordName = string.Empty; string pageTemplateRecordName = string.Empty; string emailTemplateRecordName = string.Empty; string emailRecordName = string.Empty; // // -- search for meta name=template|layout content=recordaname var metadataList = htmlDoc.DocumentNode.SelectNodes("//meta"); if (metadataList != null) { foreach (var metadataNode in metadataList) { switch (metadataNode.GetAttributeValue("name", String.Empty).ToLowerInvariant()) { case "layout": { layoutRecordName = metadataNode.GetAttributeValue("content", String.Empty); break; } case "template": case "pagetemplate": { pageTemplateRecordName = metadataNode.GetAttributeValue("content", String.Empty); break; } case "emailtemplate": { emailTemplateRecordName = metadataNode.GetAttributeValue("content", String.Empty); break; } case "email": { emailRecordName = metadataNode.GetAttributeValue("content", String.Empty); break; } default: { break; } } } } // // -- process the document html if (!processHtmlDoc(cp, htmlDoc, importTypeId, ref userMessageList)) { return(false); } // // -- save manual layout LayoutModel layout = null; { if (importTypeId.Equals(ImporttypeEnum.LayoutForAddon) && layoutId.Equals(0) & string.IsNullOrWhiteSpace(layoutRecordName)) { // // -- layout type but no layout selected, and no layout imported, use filename layoutRecordName = newRecordName; } if (importTypeId.Equals(ImporttypeEnum.LayoutForAddon) && !layoutId.Equals(0)) { layout = DbBaseModel.create <LayoutModel>(cp, layoutId); if (layout == null) { userMessageList.Add("The layout selected could not be found."); return(false); } layout.layout.content = htmlDoc.DocumentNode.OuterHtml; layout.save(cp); } // // -- save meta layout if ((layout == null) && !string.IsNullOrWhiteSpace(layoutRecordName)) { layout = DbBaseModel.createByUniqueName <LayoutModel>(cp, layoutRecordName); if (layout == null) { layout = DbBaseModel.addDefault <LayoutModel>(cp); layout.name = layoutRecordName; } layout.layout.content = htmlDoc.DocumentNode.OuterHtml; layout.save(cp); userMessageList.Add("Saved Layout '" + layoutRecordName + "'."); } } // // -- save page template PageTemplateModel pageTemplate = null; { if (importTypeId.Equals(ImporttypeEnum.PageTemplate) && pageTemplateId.Equals(0) & string.IsNullOrWhiteSpace(pageTemplateRecordName)) { // // -- layout type but no layout selected, and no layout imported, use filename pageTemplateRecordName = newRecordName; } if (importTypeId.Equals(ImporttypeEnum.PageTemplate) && !pageTemplateId.Equals(0)) { pageTemplate = DbBaseModel.create <PageTemplateModel>(cp, pageTemplateId); if (pageTemplate == null) { userMessageList.Add("The template selected could not be found."); return(false); } pageTemplate.bodyHTML = htmlDoc.DocumentNode.OuterHtml; pageTemplate.save(cp); userMessageList.Add("Saved Page Template '" + pageTemplateRecordName + "'."); } // // -- save meta template if ((pageTemplate == null) && !string.IsNullOrWhiteSpace(pageTemplateRecordName)) { pageTemplate = DbBaseModel.createByUniqueName <PageTemplateModel>(cp, pageTemplateRecordName); if (pageTemplate == null) { pageTemplate = DbBaseModel.addDefault <PageTemplateModel>(cp); pageTemplate.name = pageTemplateRecordName; } // // -- try to resolve the various relative urls possible into the primary url, then to a reoot relative url string urlProtocolDomainSlash = "https://" + cp.Site.DomainPrimary + "/"; string bodyhtml = htmlDoc.DocumentNode.OuterHtml; bodyhtml = genericController.convertLinksToAbsolute(bodyhtml, urlProtocolDomainSlash); bodyhtml = bodyhtml.Replace(urlProtocolDomainSlash, "/"); // pageTemplate.bodyHTML = bodyhtml; pageTemplate.save(cp); userMessageList.Add("Saved Page Template '" + pageTemplateRecordName + "'."); } } // // -- save email template EmailTemplateModel emailTemplate = null; { if (importTypeId.Equals(ImporttypeEnum.EmailTemplate) && emailTemplateId.Equals(0) & string.IsNullOrWhiteSpace(emailTemplateRecordName)) { // // -- type but no layout selected, and no layout imported, use filename emailTemplateRecordName = newRecordName; } if (importTypeId.Equals(ImporttypeEnum.EmailTemplate) && !emailTemplateId.Equals(0)) { emailTemplate = DbBaseModel.create <EmailTemplateModel>(cp, emailTemplateId); if (emailTemplate == null) { userMessageList.Add("The template selected could not be found."); return(false); } emailTemplate.bodyHTML = htmlDoc.DocumentNode.OuterHtml; emailTemplate.save(cp); } // // -- save meta template if ((emailTemplate == null) && !string.IsNullOrWhiteSpace(emailTemplateRecordName)) { emailTemplate = DbBaseModel.createByUniqueName <EmailTemplateModel>(cp, emailTemplateRecordName); if (emailTemplate == null) { emailTemplate = DbBaseModel.addDefault <EmailTemplateModel>(cp); emailTemplate.name = emailTemplateRecordName; } emailTemplate.bodyHTML = htmlDoc.DocumentNode.OuterHtml; emailTemplate.save(cp); userMessageList.Add("Saved Email Template '" + emailTemplateRecordName + "'."); } } // // -- save email EmailModel email = null; { if (importTypeId.Equals(5) && emailId.Equals(0) & string.IsNullOrWhiteSpace(emailRecordName)) { // // -- layout type but no layout selected, and no layout imported, use filename emailRecordName = newRecordName; } if (!emailId.Equals(0)) { email = DbBaseModel.create <EmailModel>(cp, emailId); if (email == null) { userMessageList.Add("The email selected could not be found."); return(false); } email.copyFilename.content = htmlDoc.DocumentNode.OuterHtml; email.save(cp); userMessageList.Add("Saved Email '" + emailRecordName + "'."); } // // -- save meta template if ((email == null) && !string.IsNullOrWhiteSpace(emailRecordName)) { email = DbBaseModel.createByUniqueName <EmailModel>(cp, emailRecordName); if (email == null) { email = DbBaseModel.addDefault <EmailModel>(cp); email.name = emailRecordName; } email.copyFilename.content = htmlDoc.DocumentNode.OuterHtml; email.save(cp); userMessageList.Add("Saved Email '" + emailRecordName + "'."); } } } } if (!htmlFileFound) { userMessageList.Add("No files were found with .HTML extension. Only files with .HTML extensions are imported."); return(false); } return(true); } catch (Exception ex) { cp.Site.ErrorReport(ex); throw; } }