public void GetCachedItem_Null_Test() { object target = CacheFactory.GetCachedItem(CacheFactory.GetCacheKey(CACHE_MANAGER, "NULL_KEY"), () => (null as object)); Assert.IsNull(target); }
internal static List <INotificationTask> GetNotificationTask(int PortalID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.NotificationTask + "PortalID" + PortalID); List <INotificationTask> NotificationTasks = CacheFactory.Get(CacheKey); if (NotificationTasks == null) { List <INotificationTask> ServiceInterfaceAssemblies = new List <INotificationTask>(); string[] binAssemblies = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")).Where(c => c.EndsWith(".dll") && (c.Contains("Vanjaro.UXManager.Extensions") || c.Contains("Vanjaro.Core.Extensions"))).ToArray(); foreach (string Path in binAssemblies) { try { //get all assemblies IEnumerable <INotificationTask> AssembliesToAdd = from t in System.Reflection.Assembly.LoadFrom(Path).GetTypes() where t != (typeof(INotificationTask)) && (typeof(INotificationTask).IsAssignableFrom(t)) select Activator.CreateInstance(t) as INotificationTask; ServiceInterfaceAssemblies.AddRange(AssembliesToAdd.ToList <INotificationTask>()); } catch { continue; } } NotificationTasks = ServiceInterfaceAssemblies; CacheFactory.Set(CacheKey, ServiceInterfaceAssemblies); } return(NotificationTasks); }
private static List <IImageProvider> GetAvailableProviders() { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.ImageProvider); List <IImageProvider> Items = CacheFactory.Get(CacheKey); if (Items == null) { List <IImageProvider> ServiceInterfaceAssemblies = new List <IImageProvider>(); string[] binAssemblies = Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")).Where(c => c.EndsWith(".dll") && c.Contains("Vanjaro")).ToArray(); foreach (string Path in binAssemblies) { try { //get all assemblies IEnumerable <IImageProvider> AssembliesToAdd = from t in System.Reflection.Assembly.LoadFrom(Path).GetTypes() where t != (typeof(IImageProvider)) && (typeof(IImageProvider).IsAssignableFrom(t)) select Activator.CreateInstance(t) as IImageProvider; ServiceInterfaceAssemblies.AddRange(AssembliesToAdd.ToList <IImageProvider>()); } catch { continue; } } Items = ServiceInterfaceAssemblies; CacheFactory.Set(CacheKey, ServiceInterfaceAssemblies); } return(Items.Where(x => x.Available).ToList()); }
public void GetCachedItem_String_Test() { const string TEST_STRING = "Frodo Lives!"; string target = CacheFactory.GetCachedItem(CacheFactory.GetCacheKey(CACHE_MANAGER, "STRING_KEY"), () => TEST_STRING); Assert.AreEqual(TEST_STRING, target); }
public void GetCachedItem_Object_Test() { object expected = new object(); object target = CacheFactory.GetCachedItem(CacheFactory.GetCacheKey(CACHE_MANAGER, "OBJECT_KEY"), () => expected); Assert.AreEqual(expected, target); }
internal static List <WorkflowPermission> GetWorkflowPermissionsByID(int ID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetWorkflowPermissionsByID", ID); List <WorkflowPermission> _WorkflowPerm = CacheFactory.Get(CacheKey) as List <WorkflowPermission>; if (_WorkflowPerm == null) { _WorkflowPerm = WorkflowPermission.Query("where WorkflowID=@0", ID).ToList(); CacheFactory.Set(CacheKey, _WorkflowPerm); } return(_WorkflowPerm); }
internal static Pages Get(int TabID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Page + "ALL", TabID); Pages Page = CacheFactory.Get(CacheKey); if (Page == null) { Page = Pages.Query("Where TabID=@0", TabID).FirstOrDefault(); CacheFactory.Set(CacheKey, Page); } return(Page); }
internal static List <Pages> GetAllByState(int State) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Page + "GetAllByState", State); List <Pages> _Pages = CacheFactory.Get(CacheKey) as List <Pages>; if (_Pages == null) { _Pages = Pages.Query("Where StateID=@0", State).ToList(); CacheFactory.Set(CacheKey, _Pages); } return(_Pages); }
internal static List <ThemeEditorValue> GetThemeEditorValues(int PortalId, string CategoryGuid) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.ThemeManager, PortalId, "Values", CategoryGuid); List <ThemeEditorValue> result = CacheFactory.Get(CacheKey); if (result == null) { result = JsonConvert.DeserializeObject <List <ThemeEditorValue> >(File.ReadAllText(GetThemeEditorValueJsonPath(PortalId, CategoryGuid))); CacheFactory.Set(CacheKey, result); } return(result); }
internal static List <CustomBlock> GetAll(int PortalID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.CustomBlock + "ALL", PortalID); List <CustomBlock> Custom_Block = CacheFactory.Get(CacheKey); if (Custom_Block == null) { Custom_Block = CustomBlock.Query("where PortalID=@0", PortalID).ToList(); CacheFactory.Set(CacheKey, Custom_Block); } return(Custom_Block); }
internal static List <Pages> GetAllByTabID(int TabID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Page + "GetAllByTabID", TabID); List <Pages> _Pages = CacheFactory.Get(CacheKey) as List <Pages>; if (_Pages == null) { _Pages = Pages.Query("Where TabID=@0", TabID).ToList(); CacheFactory.Set(CacheKey, _Pages); } return(_Pages); }
internal static WorkflowState GetStateByID(int ID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetStateByID", ID); WorkflowState WorkflowState = CacheFactory.Get(CacheKey); if (WorkflowState == null) { WorkflowState = WorkflowState.Query("where StateID=@0", ID).FirstOrDefault(); CacheFactory.Set(CacheKey, WorkflowState); } return(WorkflowState); }
internal static List <WorkflowState> GetAllStatesbyWorkflowID(int WorkflowId) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetAllStatesbyWorkflowID", WorkflowId); List <WorkflowState> WorkflowStates = CacheFactory.Get(CacheKey) as List <WorkflowState>; if (WorkflowStates == null) { WorkflowStates = WorkflowState.Query("where WorkflowId=@0", WorkflowId).ToList(); CacheFactory.Set(CacheKey, WorkflowStates); } return(WorkflowStates); }
internal static List <Setting> GetSettings(int PortalID, int TabID, string Identifier) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Settings, Identifier, PortalID, TabID); List <Setting> data = CacheFactory.Get(CacheKey); if (data == null) { data = Setting.Fetch("WHERE PortalID=@0 and TabID=@1 AND Identifier=@2", PortalID, TabID, Identifier); CacheFactory.Set(CacheKey, data); } return(data); }
internal static CustomBlock Get(int PortalID, string Name) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.CustomBlock, PortalID, Name); CustomBlock CustomBlock = CacheFactory.Get(CacheKey); if (CustomBlock == null) { CustomBlock = CustomBlock.Query("where PortalID=@0 and Name=@1", PortalID, Name).FirstOrDefault(); CacheFactory.Set(CacheKey, CustomBlock); } return(CustomBlock); }
internal static Workflow GetWorkflowbyID(int WorkflowId) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetWorkflowbyID", WorkflowId); Workflow Workflow = CacheFactory.Get(CacheKey); if (Workflow == null) { Workflow = Workflow.Query("where ID=@0", WorkflowId).FirstOrDefault(); CacheFactory.Set(CacheKey, Workflow); } return(Workflow); }
internal static List <WorkflowLog> GetPagesWorkflowLogs(int TabID, int Version) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetPagesWorkflowLogs", TabID, Version); List <WorkflowLog> WorkflowLogs = CacheFactory.Get(CacheKey) as List <WorkflowLog>; if (WorkflowLogs == null) { WorkflowLogs = WorkflowLog.Query("Where Tabid=@0 and Version=@1", TabID, Version).ToList(); CacheFactory.Set(CacheKey, WorkflowLogs); } return(WorkflowLogs); }
public static Dictionary <string, string> GetGlobalConfigs(PortalSettings PortalSettings, string Block, bool IsGlobal = true, string BlockDirectory = "Blocks") { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.GlobalConfig, PortalSettings.PortalId, Block); Dictionary <string, string> result = CacheFactory.Get(CacheKey); if (result == null) { result = new Dictionary <string, string>(); string FolderPath = Globals.ApplicationMapPath + @"\portals\_default\" + GetTheme() + BlockDirectory + "\\" + Block + "\\"; if (Directory.Exists(FolderPath)) { string markup = string.Empty; if (File.Exists(FolderPath + Block + ".html")) { markup += File.ReadAllText(FolderPath + Block + ".html"); } if (IsGlobal && File.Exists(FolderPath + Block + ".config.html")) { markup += File.ReadAllText(FolderPath + Block + ".config.html"); } if (!string.IsNullOrEmpty(markup)) { HtmlDocument html = new HtmlDocument(); html.LoadHtml(markup); IEnumerable <HtmlNode> query = html.DocumentNode.Descendants("div"); foreach (HtmlNode item in query.ToList()) { if (item.Attributes.Where(a => a.Name == "data-block-guid").FirstOrDefault() != null) { foreach (HtmlAttribute attr in item.Attributes) { if (result.ContainsKey(attr.Name)) { result[attr.Name] = attr.Value; } else { result.Add(attr.Name, attr.Value); } } } } } } CacheFactory.Set(CacheKey, result); } return(result); }
internal static List <WorkflowPermissionInfo> GetPermissionByCode(string Code) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetPermissionByCode", Code); List <WorkflowPermissionInfo> _WorkflowStatePermInfo = CacheFactory.Get(CacheKey) as List <WorkflowPermissionInfo>; if (_WorkflowStatePermInfo == null) { using (VanjaroRepo db = new VanjaroRepo()) { _WorkflowStatePermInfo = db.Query <WorkflowPermissionInfo>("SELECT p.* FROM " + Data.Scripts.CommonScript.DnnTablePrefix + "Permission AS p WHERE p.PermissionCode = @0", Code).ToList(); } CacheFactory.Set(CacheKey, _WorkflowStatePermInfo); } return(_WorkflowStatePermInfo); }
internal static List <StringValue> GetStatesforReview(int PortalID, int UserID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetStatesforReview" + "PortalID", UserID, PortalID); List <StringValue> result = CacheFactory.Get(CacheKey) as List <StringValue>; if (result == null) { Sql Query = WorkflowScript.GetStatesforPendingReview(PortalID, UserID); using (VanjaroRepo db = new VanjaroRepo()) { result = db.Fetch <StringValue>(Query).ToList(); } CacheFactory.Set(CacheKey, result); } return(result); }
internal static List <Pages> GetAllPublishedPages(int portalID, string Locale) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Page, portalID, "AllPublishedPages", Locale); List <Pages> pages = CacheFactory.Get(CacheKey); if (pages == null || pages.Count == 0) { Sql Query = PageScript.GetAllPublishedPages(portalID, Locale); using (VanjaroRepo db = new VanjaroRepo()) { pages = db.Fetch <Pages>(Query).ToList(); } CacheFactory.Set(CacheKey, pages); } return(pages); }
internal static List <WorkflowPage> GetReviewPagesbyUserID(int UserID, int Page, int PageSize, int StateID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetReviewPagesbyUserID", UserID, Page, PageSize, StateID); List <WorkflowPage> Pages = CacheFactory.Get(CacheKey) as List <WorkflowPage>; if (Pages == null) { Sql Query = WorkflowScript.GetPagesByUserID(UserID, Page, PageSize, StateID); using (VanjaroRepo db = new VanjaroRepo()) { Pages = db.Fetch <WorkflowPage>(Query).ToList(); } CacheFactory.Set(CacheKey, Pages); } return(Pages); }
internal static List <WorkflowPage> GetPagesbyUserID(int PortalID, int UserID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetPagesbyUserID" + "PortalID", UserID, PortalID); List <WorkflowPage> WorkflowPages = CacheFactory.Get(CacheKey) as List <WorkflowPage>; if (WorkflowPages == null) { Sql Query = WorkflowScript.GetPagesByUserID(PortalID, UserID); using (VanjaroRepo db = new VanjaroRepo()) { WorkflowPages = db.Fetch <WorkflowPage>(Query).ToList(); } CacheFactory.Set(CacheKey, WorkflowPages); } return(WorkflowPages); }
public static dynamic GetApps(int PortalID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.DesktopModules, PortalID); List <ModuleDefDTO> ModuleDefDTOs = CacheFactory.Get(CacheKey); if (ModuleDefDTOs == null) { ModuleDefDTOs = new List <ModuleDefDTO>(); foreach (KeyValuePair <string, PortalDesktopModuleInfo> DesktopModule in ControlBarController.Instance.GetCategoryDesktopModules(PortalID, "All", "")) { if (!IgnorePackage(DesktopModule.Value.DesktopModule.ModuleName)) { ModuleDefDTOs.Add(new ModuleDefDTO { ModuleID = DesktopModule.Value.DesktopModuleID, ModuleName = DesktopModule.Key, ModuleImage = GetDeskTopModuleImage(PortalID, DesktopModule.Value.DesktopModuleID) }); } } try { dynamic visuInstance = GetInstance("VisualizerFactory"); if (visuInstance != null) { dynamic visualizers = visuInstance.GetMethod("GetAllByPortalID", new Type[] { typeof(int) }).Invoke(null, new object[] { PortalID }); foreach (dynamic visualizer in visualizers) { ModuleDefDTOs.Add(new ModuleDefDTO { UniqueID = visualizer.VisualizerID, ModuleID = ModuleDefDTOs.Where(c => c.ModuleName == "Live Visualizer").FirstOrDefault().ModuleID, ModuleName = visualizer.Name, ModuleImage = visualizer.ImageIcon.Url }); } } } catch (Exception ex) { Exceptions.LogException(ex); } CacheFactory.Set(CacheKey, ModuleDefDTOs); } return(ModuleDefDTOs); }
internal static int GetReviewPagesCountByUserID(int UserID, int Page, int PageSize, int StateID) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetReviewPagesCountByUserID", UserID, Page, PageSize, StateID); int? Count = CacheFactory.Get(CacheKey); if (Count == null) { Count = 0; Sql Query = WorkflowScript.GetPagesCountByUserID(UserID, StateID); using (VanjaroRepo db = new VanjaroRepo()) { Count = db.Fetch <int>(Query).FirstOrDefault(); } CacheFactory.Set(CacheKey, Count); } return(Count.Value); }
public static async Task <string> GetVideos(string Source, string Keyword, int PageNo, int PageSize, Dictionary <string, object> AdditionalData) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Videos, Source, Keyword, PageNo, PageSize); string Videos = CacheFactory.Get(CacheKey); if (Videos == null) { IVideoProvider provider = GetAvailableProviders().Where(p => p.Name == Source).FirstOrDefault(); if (provider == null) { return(Videos); } Videos = await provider.GetVideos(Keyword, PageNo, PageSize, AdditionalData); CacheFactory.Set(CacheKey, Videos); } return(Videos); }
public static async Task <string> GetImages(string Source, string Keyword, int PageNo, int PageSize) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Images, Source, Keyword, PageNo, PageSize); string Images = CacheFactory.Get(CacheKey); if (Images == null) { IImageProvider provider = GetAvailableProviders().Where(p => p.Name == Source).FirstOrDefault(); if (provider == null) { return(Images); } Images = await provider.GetImages(Keyword, PageNo, PageSize); CacheFactory.Set(CacheKey, Images); } return(Images); }
public static ThemeEditorWrapper GetThemeEditors(int PortalID, string CategoryGuid) { string ThemeEditorJsonPath = GetThemeEditorJsonPath(PortalID, CategoryGuid); if (!File.Exists(ThemeEditorJsonPath)) { File.Create(ThemeEditorJsonPath).Dispose(); } string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.ThemeManager, PortalID, CategoryGuid); ThemeEditorWrapper result = CacheFactory.Get(CacheKey); if (result == null) { result = JsonConvert.DeserializeObject <ThemeEditorWrapper>(File.ReadAllText(ThemeEditorJsonPath)); CacheFactory.Set(CacheKey, result); } return(result); }
internal static List <int> GetAllTabIdByPortalID(int PortalID, bool OnlyPublished) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Page + PortalID + "DistinctIds", OnlyPublished); List <int> DistinctIDs = CacheFactory.Get(CacheKey); if (DistinctIDs == null) { if (OnlyPublished) { DistinctIDs = Pages.Query("Where PortalID=@0 and IsPublished=@1", PortalID, OnlyPublished).Select(e => e.TabID).Distinct().ToList(); } else { DistinctIDs = Pages.Query("Where PortalID=@0", PortalID).Select(e => e.TabID).Distinct().ToList(); } CacheFactory.Set(CacheKey, DistinctIDs); } return(DistinctIDs); }
internal static List <Workflow> GetAll(int PortalID, bool IncludeDeleted) { string CacheKey = CacheFactory.GetCacheKey(CacheFactory.Keys.Workflow + "GetAll", PortalID, IncludeDeleted); List <Workflow> Workflows = CacheFactory.Get(CacheKey) as List <Workflow>; if (Workflows == null) { if (IncludeDeleted) { Workflows = Workflow.Query("where PortalID is null or PortalID=@0", PortalID).ToList(); } else { Workflows = Workflow.Query("where (PortalID is null or PortalID=@0) and IsDeleted=@1", PortalID, IncludeDeleted).ToList(); } CacheFactory.Set(CacheKey, Workflows); } return(Workflows); }