internal static int UpdateSatesOrder(List <WorkflowState> wStates, Workflow wflow, bool IncrementOrder, int?DeletedWorkflowStateOrder) { int Order = -1; if (IncrementOrder) { WorkflowState wState = wStates.LastOrDefault(); Order = wState.Order; wState.Order++; wState.Update(); CacheFactory.Clear(CacheFactory.Keys.Workflow); return(Order); } else { if (DeletedWorkflowStateOrder.HasValue) { wStates = wStates.Where(ws => ws.Order > DeletedWorkflowStateOrder).ToList(); } foreach (WorkflowState wState in wStates) { wState.Order--; wState.Update(); } CacheFactory.Clear(CacheFactory.Keys.Workflow); return(DeletedWorkflowStateOrder.Value); } }
internal static void RemoveHistory(int TabID, int MaxVersion) { List <int> pages = GetAllByTabID(TabID).OrderByDescending(a => a.Version).Select(a => a.Version).Distinct().Take(MaxVersion).ToList(); if (pages.Count > 0) { Pages.Delete("Where TabID=@0 and Version not in (" + string.Join(",", pages) + ")", TabID); CacheFactory.Clear(CacheFactory.Keys.Page); List <Pages> Core_pages = GetAllByTabID(TabID).OrderByDescending(a => a.Version).ToList(); foreach (KeyValuePair <int, ModuleInfo> item in ModuleController.Instance.GetTabModules(TabID)) { bool IsDelete = true; foreach (Pages page in Core_pages) { if (page.Content.Contains("mid=\"" + item.Key + "\"") && page.Content.Contains("<app id=\"" + item.Key + "\">")) { IsDelete = false; } } if (IsDelete && item.Value.ModuleTitle != Components.Constants.AccountLogin) { if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["m2v"]) && !HttpUtility.ParseQueryString(HttpContext.Current.Request.UrlReferrer.Query).AllKeys.Contains("skinsrc") && !HttpUtility.ParseQueryString(HttpContext.Current.Request.UrlReferrer.Query).AllKeys.Contains("m2v") && !HttpContext.Current.Request.UrlReferrer.AbsoluteUri.Contains("m2v/")) { DeleteModule(TabID, item.Key); } } } } }
internal static void AddWorkflowLog(int PortalID, int ModuleID, int UserID, Pages Page, string Action, string Comment) { if (!string.IsNullOrEmpty(Comment)) { WorkflowLog wlog = new WorkflowLog { PortalID = PortalID, ModuleID = ModuleID, ReviewedBy = UserID, ReviewedOn = DateTime.UtcNow, StateID = Page.StateID.Value, Comment = Comment, TabID = Page.TabID, Version = Page.Version }; if (Action.ToLower() == "approve" || Action.ToLower() == "publish") { wlog.Approved = true; } else if (Action.ToLower() == "reject") { wlog.Approved = false; } wlog.Insert(); CacheFactory.Clear(CacheFactory.Keys.Workflow); } }
public static void Update(Pages page, int UserID) { if (page.ID == 0) { page.CreatedBy = UserID; page.UpdatedBy = UserID; page.CreatedOn = DateTime.UtcNow; page.UpdatedOn = DateTime.UtcNow; page.Insert(); CacheFactory.Clear(CacheFactory.Keys.Page); RemoveHistory(page.TabID, WorkflowManager.GetMaxRevisions(page.TabID)); } else { page.UpdatedBy = UserID; page.UpdatedOn = DateTime.UtcNow; page.Update(); CacheFactory.Clear(CacheFactory.Keys.Page); } //For TabIndexer if (page.IsPublished) { TabInfo tabinfo = TabController.Instance.GetTab(page.TabID, page.PortalID); if (tabinfo != null) { TabController.Instance.UpdateTab(tabinfo); } } }
public static void UpdateDesignElement(PortalSettings PortalSettings, Dictionary <string, string> Attributes) { if (Attributes.ContainsKey("data-block-global") && Attributes["data-block-global"] == "true") { StringBuilder sb = new StringBuilder(); sb.Append("<div"); foreach (KeyValuePair <string, string> item in Attributes) { if (item.Key.StartsWith("data-block")) { sb.Append(" ").Append(item.Key).Append("=\"" + item.Value + "\""); } } sb.Append("></div>"); string FolderPath = HttpContext.Current.Server.MapPath("~/Portals/_default/vThemes/" + ThemeManager.GetCurrentThemeName() + "/Blocks/" + Attributes["data-block-type"] + "/"); if (Directory.Exists(FolderPath)) { if (!File.Exists(FolderPath + Attributes["data-block-type"] + ".config.html")) { File.Create(FolderPath + Attributes["data-block-type"].ToLower() + ".config.html").Dispose(); } if (File.Exists(FolderPath + Attributes["data-block-type"] + ".config.html")) { File.WriteAllText(FolderPath + Attributes["data-block-type"] + ".config.html", sb.ToString()); CacheFactory.Clear(CacheFactory.Keys.GlobalConfig); } } } }
internal static void UpdateValue(int PortalID, int TabID, string Identifier, string Name, string Value) { CacheFactory.Clear(CacheFactory.Keys.Settings); Setting s = GetSetting(PortalID, TabID, Identifier, Name); if (s == null) { s = new Setting { TabID = TabID, Identifier = Identifier, Name = Name, PortalID = PortalID, Value = Value }; s.Insert(); } else { s.Value = Value; s.Update(); } CacheFactory.Clear(CacheFactory.Keys.Settings); }
internal static void ClearAllWorkflowPermissionsID(int workflowID) { foreach (WorkflowPermission permission in GetWorkflowPermissionsByID(workflowID)) { permission.Delete(); } CacheFactory.Clear(CacheFactory.Keys.Workflow); }
internal static void UpdateWorkflowPermissions(List <WorkflowPermission> Permissions) { foreach (WorkflowPermission permission in Permissions) { permission.Insert(); } CacheFactory.Clear(CacheFactory.Keys.Workflow); }
internal static void ClearAllWorkflowStatePermissionsByStateID(int StateID) { foreach (WorkflowStatePermission permission in GetStatePermissionsByStateID(StateID)) { permission.Delete(); } CacheFactory.Clear(CacheFactory.Keys.Workflow); }
internal static void Delete(int PortalID, string Guid) { foreach (CustomBlock item in GetAll(PortalID).Where(p => p.Guid.ToLower() == Guid.ToLower()).ToList()) { CustomBlock.Delete("where ID=@0", item.ID); } CacheFactory.Clear(CacheFactory.Keys.CustomBlock); }
private static void UpdateThemeEditorJson(string CategoryGuid, ThemeEditorWrapper ThemeEditorWrapper) { string ThemeEditorJsonPath = GetThemeEditorJsonPath(PortalSettings.Current.PortalId, CategoryGuid); if (ThemeEditorJsonPath.EndsWith("theme.editor.custom.json")) { ThemeEditorWrapper.DeveloperMode = true; } string Content = JsonConvert.SerializeObject(ThemeEditorWrapper); File.WriteAllText(ThemeEditorJsonPath, Content); CacheFactory.Clear(CacheFactory.Keys.ThemeManager); }
internal static WorkflowState UpdateWorkflowState(WorkflowState WorkflowState) { if (WorkflowState.StateID == 0) { WorkflowState.Insert(); } else { WorkflowState.Update(); } CacheFactory.Clear(CacheFactory.Keys.Workflow); return(WorkflowState); }
internal static void DeleteWorkflow(Workflow wflow) { foreach (WorkflowState state in GetAllStatesbyWorkflowID(wflow.ID)) { WorkflowLog.Delete("Where StateID=@0", state.StateID); WorkflowStatePermission.Delete("Where StateID=@0", state.StateID); state.Delete(); } WorkflowPermission.Delete("Where Workflowid=@0", wflow.ID); wflow.Delete(); CacheFactory.Clear(CacheFactory.Keys.Workflow); }
internal static void AddUpdate(CustomBlock CustomBlock) { if (string.IsNullOrEmpty(CustomBlock.Html)) { CustomBlock.Html = ""; } CustomBlock.Category = CustomBlock.Category.ToLower(); if (CustomBlock.ID > 0) { CustomBlock.Update(); } else { CustomBlock.Insert(); } CacheFactory.Clear(CacheFactory.Keys.CustomBlock); }
internal static void DeleteWorkflowState(int WorkflowStateId, int WorkflowId) { try { WorkflowState wState = GetAllStatesbyWorkflowID(WorkflowId).Where(a => a.StateID == WorkflowStateId).FirstOrDefault(); if (wState != null && !wState.IsFirst && !wState.IsLast) { ClearAllWorkflowStatePermissionsByStateID(wState.StateID); wState.Delete(); List <WorkflowState> wStates = GetAllStatesbyWorkflowID(WorkflowId).OrderBy(o => o.Order).ToList(); if (wStates.Count >= 2) { Workflow wflow = GetWorkflowbyID(WorkflowId); UpdateSatesOrder(wStates, wflow, false, wState.Order); CacheFactory.Clear(CacheFactory.Keys.Workflow); } } } catch (Exception ex) { Exceptions.LogException(ex); } }
public static HttpResponseMessage ExportCustomBlock(int PortalID, string GUID) { HttpResponseMessage Response = new HttpResponseMessage(); CustomBlock customBlock = BlockManager.GetByLocale(PortalID, GUID, null); if (customBlock != null) { string Theme = Core.Managers.ThemeManager.GetCurrentThemeName(); ExportTemplate exportTemplate = new ExportTemplate { Guid = Guid.NewGuid().ToString(), Type = TemplateType.BlockTemplate.ToString(), UpdatedOn = DateTime.UtcNow, Templates = new List <Layout>(), ThemeName = Theme, ThemeGuid = "49A70BA1-206B-471F-800A-679799FF09DF" }; Dictionary <string, string> Assets = new Dictionary <string, string>(); Layout layout = new Layout(); layout.Blocks = new List <CustomBlock>() { customBlock }; if (layout.Blocks != null) { foreach (CustomBlock block in layout.Blocks) { if (!string.IsNullOrEmpty(block.Html)) { block.Html = PageManager.TokenizeTemplateLinks(PageManager.DeTokenizeLinks(block.Html, PortalID), false, Assets); } if (!string.IsNullOrEmpty(block.Css)) { block.Css = PageManager.DeTokenizeLinks(block.Css, PortalID); } } CacheFactory.Clear(CacheFactory.GetCacheKey(CacheFactory.Keys.CustomBlock + "ALL", PortalID)); } layout.Name = customBlock.Name; layout.Content = ""; layout.SVG = ""; layout.ContentJSON = ""; layout.Style = ""; layout.StyleJSON = ""; layout.Type = ""; exportTemplate.Templates.Add(layout); string serializedExportTemplate = JsonConvert.SerializeObject(exportTemplate); if (!string.IsNullOrEmpty(serializedExportTemplate)) { byte[] fileBytes = null; using (MemoryStream memoryStream = new MemoryStream()) { using (ZipArchive zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { AddZipItem("ExportTemplate.json", Encoding.ASCII.GetBytes(serializedExportTemplate), zip); if (Assets != null && Assets.Count > 0) { foreach (KeyValuePair <string, string> asset in Assets) { string FileName = asset.Key.Replace(PageManager.ExportTemplateRootToken, ""); string FileUrl = asset.Value; if (FileUrl.StartsWith("/")) { FileUrl = string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, FileUrl); } AddZipItem("Assets/" + FileName, new WebClient().DownloadData(FileUrl), zip); } } } fileBytes = memoryStream.ToArray(); } string fileName = customBlock.Name + "_BlockTemplate.zip"; Response.Content = new ByteArrayContent(fileBytes.ToArray()); Response.Content.Headers.Add("x-filename", fileName); Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); Response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; Response.StatusCode = HttpStatusCode.OK; } } return(Response); }
internal static HttpResponseMessage Export(int PortalID, string Name) { HttpResponseMessage Response = new HttpResponseMessage(); string Theme = Core.Managers.ThemeManager.GetCurrentThemeName(); ExportTemplate exportTemplate = new ExportTemplate { Guid = Guid.NewGuid().ToString(), Type = TemplateType.SiteTemplate.ToString(), UpdatedOn = DateTime.UtcNow, Templates = new List <Layout>(), ThemeName = Theme, ThemeGuid = "49A70BA1-206B-471F-800A-679799FF09DF" }; Dictionary <string, string> Assets = new Dictionary <string, string>(); foreach (Core.Data.Entities.Pages page in Core.Managers.PageManager.GetAllPublishedPages(PortalID, null)) { Dnn.PersonaBar.Pages.Services.Dto.PageSettings pageSettings = Dnn.PersonaBar.Pages.Components.PagesController.Instance.GetPageSettings(page.TabID); Layout layout = new Layout { Content = Core.Managers.PageManager.TokenizeTemplateLinks(page.Content, false, Assets) }; HtmlDocument html = new HtmlDocument(); html.LoadHtml(layout.Content); IEnumerable <HtmlNode> query = html.DocumentNode.Descendants("div"); foreach (HtmlNode item in query.ToList()) { if (item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault() != null && !string.IsNullOrEmpty(item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value) && item.Attributes.Where(a => a.Name == "data-block-type").FirstOrDefault().Value.ToLower() == "global") { string guid = item.Attributes.Where(a => a.Name == "data-guid").FirstOrDefault().Value.ToLower(); Core.Data.Entities.CustomBlock Block = Core.Managers.BlockManager.GetByLocale(PortalID, guid, null); if (Block != null) { if (layout.Blocks == null) { layout.Blocks = new List <Core.Data.Entities.CustomBlock>(); } layout.Blocks.Add(Block); } } } if (layout.Blocks != null) { foreach (Core.Data.Entities.CustomBlock block in layout.Blocks) { if (!string.IsNullOrEmpty(block.Html)) { block.Html = Core.Managers.PageManager.TokenizeTemplateLinks(Core.Managers.PageManager.DeTokenizeLinks(block.Html, PortalID), false, Assets); } if (!string.IsNullOrEmpty(block.Css)) { block.Css = Core.Managers.PageManager.DeTokenizeLinks(block.Css, PortalID); } } CacheFactory.Clear(CacheFactory.GetCacheKey(CacheFactory.Keys.CustomBlock + "ALL", PortalID)); } layout.Name = pageSettings.Name; layout.Content = html.DocumentNode.OuterHtml; layout.SVG = ""; layout.ContentJSON = Core.Managers.PageManager.TokenizeTemplateLinks(page.ContentJSON, true, Assets); layout.Style = page.Style; layout.StyleJSON = page.StyleJSON; layout.Type = pageSettings.PageType = pageSettings.PageType.ToLower() == "url" ? "URL" : (pageSettings.DisableLink && pageSettings.IncludeInMenu) ? "Folder" : "Standard"; exportTemplate.Templates.Add(layout); } string serializedExportTemplate = JsonConvert.SerializeObject(exportTemplate); if (!string.IsNullOrEmpty(serializedExportTemplate)) { byte[] fileBytes = null; using (MemoryStream memoryStream = new MemoryStream()) { using (ZipArchive zip = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) { AddZipItem("ExportTemplate.json", Encoding.ASCII.GetBytes(serializedExportTemplate), zip); //AddZipItem(ScreenShotFileInfo.FileName, ToByteArray(FileManager.Instance.GetFileContent(ScreenShotFileInfo)), zip); if (Assets != null && Assets.Count > 0) { foreach (KeyValuePair <string, string> asset in Assets) { string FileName = asset.Key.Replace(Vanjaro.Core.Managers.PageManager.ExportTemplateRootToken, ""); string FileUrl = asset.Value; if (FileUrl.StartsWith("/")) { FileUrl = string.Format("{0}://{1}{2}", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Authority, FileUrl); } AddZipItem("Assets/" + FileName, new WebClient().DownloadData(FileUrl), zip); } } if (!string.IsNullOrEmpty(Theme)) { string FolderPath = HttpContext.Current.Server.MapPath("~/Portals/" + PortalID + "/vThemes/" + Theme); if (Directory.Exists(FolderPath)) { foreach (string file in Directory.EnumerateFiles(FolderPath, "*", SearchOption.AllDirectories)) { if (!file.ToLower().Contains("theme.backup.css")) { AddZipItem("Theme" + file.Replace(FolderPath, "").Replace("\\", "/"), File.ReadAllBytes(file), zip); } } } } } fileBytes = memoryStream.ToArray(); } string fileName = Name + "_SiteTemplate.zip"; Response.Content = new ByteArrayContent(fileBytes.ToArray()); Response.Content.Headers.Add("x-filename", fileName); Response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); Response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fileName }; Response.StatusCode = HttpStatusCode.OK; } return(Response); }
public static void Save(string CategoryGuid, List <ThemeEditorValue> ThemeEditorValues) { File.WriteAllText(GetThemeEditorValueJsonPath(PortalSettings.Current.PortalId, CategoryGuid), JsonConvert.SerializeObject(ThemeEditorValues)); CacheFactory.Clear(CacheFactory.Keys.ThemeManager); }
internal static void Delete(int TabID) { Pages.Delete("Where TabID=@0", TabID); CacheFactory.Clear(); }
internal static void Delete(int TabID, int Version) { Pages.Delete("Where TabID=@0 and Version=@1", TabID, Version); CacheFactory.Clear(); }
internal static Workflow UpdateWorkflow(Workflow workflow) { Workflow wflow = new Workflow(); if (workflow.ID == 0) { wflow.Description = workflow.Description; wflow.IsDeleted = workflow.IsDeleted; wflow.Name = workflow.Name; wflow.CreatedBy = workflow.CreatedBy; wflow.CreatedOn = workflow.CreatedOn; wflow.PortalID = workflow.PortalID; wflow.Revisions = 5; wflow.Insert(); UpdateWorkflowState(new WorkflowState { WorkflowID = wflow.ID, IsActive = true, Name = "Draft", Notify = true, Order = 1 }); WorkflowState wState = UpdateWorkflowState(new WorkflowState { WorkflowID = wflow.ID, IsActive = true, Name = "Ready for Review", Notify = true, Order = 2 }); if (wState != null) { DNNModulePermissionInfo DnnPermissionInfo = Vanjaro.Common.Manager.PermissionManager.GetPermissionInfo(PageWorkflowPermission.PERMISSION_CODE).Where(p => p.PermissionKey == PageWorkflowPermission.PERMISSION_REVIEWCONTENT).FirstOrDefault(); WorkflowStatePermission statePerm = new WorkflowStatePermission { StateID = wState.StateID, PermissionID = DnnPermissionInfo.PermissionID, AllowAccess = true }; int PortalID = workflow.PortalID.HasValue ? workflow.PortalID.Value : PortalSettings.Current.PortalId; statePerm.RoleID = RoleController.Instance.GetRoleByName(PortalID, "Administrators").RoleID; statePerm.UserID = null; statePerm.CreatedBy = workflow.CreatedBy; statePerm.CreatedOn = workflow.CreatedOn; statePerm.UpdatedBy = workflow.CreatedBy; statePerm.UpdatedOn = workflow.CreatedOn; statePerm.Insert(); } UpdateWorkflowState(new WorkflowState { WorkflowID = wflow.ID, IsActive = true, Name = "Published", Notify = true, Order = 3 }); } else { wflow = GetWorkflowbyID(workflow.ID); if (wflow != null) { wflow.Description = workflow.Description; wflow.IsDeleted = workflow.IsDeleted; wflow.Name = workflow.Name; wflow.CreatedBy = wflow.CreatedBy; wflow.CreatedOn = wflow.CreatedOn; wflow.DeletedBy = workflow.DeletedBy; wflow.DeletedOn = workflow.DeletedOn; wflow.Revisions = workflow.Revisions; wflow.PortalID = wflow.ID == 1 ? null : workflow.PortalID; wflow.Update(); } } CacheFactory.Clear(CacheFactory.Keys.Workflow); return(wflow); }