using NHibernate; using Tanshu.Accounts.Entities; using System.Linq; using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Configuration; using Tanshu.Accounts.Entities.Auth; namespace Tanshu.Accounts.Repository { public class Cache { private static IList cache = null; private static Dictionary locations = new Dictionary(); private static string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant(); private static IList roles = null; private static bool _log = false; public static IList ProductGroups() { if (cache == null) { using (var bi = new ProductGroupBI()) { var list = bi.SaleList(); foreach (var item in list) { NHibernateUtil.Initialize(item.Products); } cache = list; } } return cache; } public static PrintLocation BasePrinter { get { if (!locations.ContainsKey(location.GetHashCode())) { using (var bi = new PrintLocationBI()) { var loc = bi.Get(x => x.Location == location && x.ProductGroup == null); locations.Add(location.GetHashCode(), loc); } } return locations[location.GetHashCode()]; } } public static PrintLocation KotPrinter(Guid productGroupID) { if (!locations.ContainsKey(location.GetHashCode() ^ productGroupID.GetHashCode())) { using (var bi = new PrintLocationBI()) { var loc = bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ?? bi.Get(x => x.Location == location && x.ProductGroup == null); locations.Add(location.GetHashCode() ^ productGroupID.GetHashCode(), loc); } } return locations[location.GetHashCode() ^ productGroupID.GetHashCode()]; } public static IList UserRoles(Guid userID) { if (roles == null) { using (var bi = new UserBI()) { roles = bi.Roles(userID); } } return roles; } public static void ClearRoles() { roles = null; } public static void Invalidate() { cache = null; locations = new Dictionary(); } public static bool Log { get { return _log; } set { _log = value; } } } }