Example #1
0
 public PermissionService(IUnitOfWork2 unitOfWork, ICustomCache <string, IEnumerable <string> > permissionsCache)
 {
     _usersDbSet       = unitOfWork.GetDbSet <ApplicationUser>();
     _rolesDbSet       = unitOfWork.GetDbSet <ApplicationRole>();
     _permissionsDbSet = unitOfWork.GetDbSet <Permission>();
     _permissionsCache = permissionsCache;
 }
        public ShroomsUserManager(IUserStore <ApplicationUser> store,
                                  IDataProtectionProvider dataProtectionProvider,
                                  IIdentityMessageService emailService,
                                  ShroomsClaimsIdentityFactory claimsIdentityFactory,
                                  ICustomCache <string, IEnumerable <string> > permissionsCache)
            : base(store)
        {
            _permissionsCache     = permissionsCache;
            UserValidator         = new ShroomsUserValidator(this);
            ClaimsIdentityFactory = claimsIdentityFactory;
            EmailService          = emailService;

            UserValidator = new ShroomsUserValidator(this)
            {
                RequireUniqueEmail             = true,
                AllowOnlyAlphanumericUserNames = false
            };

            PasswordValidator = new ShroomsPasswordValidator
            {
                RequiredLength          = 6,
                RequireNonLetterOrDigit = false,
                RequireDigit            = true,
                RequireLowercase        = true,
                RequireUppercase        = true
            };

            UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
        }
 public UserDeprecatedController(IMapper mapper,
                                 IUnitOfWork unitOfWork,
                                 ShroomsUserManager userManager,
                                 IImpersonateService impersonateService,
                                 IAdministrationUsersService administrationUsersService,
                                 IPermissionService permissionService,
                                 IOrganizationService organizationService,
                                 IUserService userService,
                                 ICustomCache <string, IEnumerable <string> > permissionsCache,
                                 IRoleService roleService,
                                 IProjectsService projectService,
                                 IKudosService kudosService,
                                 IPictureService pictureService)
 {
     _mapper                       = mapper;
     _unitOfWork                   = unitOfWork;
     _roomRepository               = _unitOfWork.GetRepository <Room>();
     _applicationUserRepository    = _unitOfWork.GetRepository <ApplicationUser>();
     _rolesRepository              = unitOfWork.GetRepository <ApplicationRole>();
     _examsRepository              = _unitOfWork.GetRepository <Exam>();
     _skillsRepository             = _unitOfWork.GetRepository <Skill>();
     _jobPositionsRepository       = _unitOfWork.GetRepository <JobPosition>();
     _qualificationLevelRepository = _unitOfWork.GetRepository <QualificationLevel>();
     _impersonateService           = impersonateService;
     _administrationUsersService   = administrationUsersService;
     _permissionService            = permissionService;
     _organizationService          = organizationService;
     _permissionsCache             = permissionsCache;
     _userService                  = userService;
     _userManager                  = userManager;
     _roleService                  = roleService;
     _projectService               = projectService;
     _kudosService                 = kudosService;
     _pictureService               = pictureService;
 }
Example #4
0
 public CacheFilter(CacheType cacheType, bool includeUrl, int numMinutes, ICustomCache cache)
 {
     _includeUrl = includeUrl;
     _numMinutes = numMinutes;
     _cacheType  = cacheType;
     _cache      = cache;
 }
Example #5
0
        public static T Set <T>(this ICustomCache cache, object key, T value)
        {
            ICacheEntry entry = cache.CreateEntry(key);

            entry.Value = value;
            entry.Dispose();

            return(value);
        }
Example #6
0
        public static T Set <T>(this ICustomCache cache, object key, T value, TimeSpan absoluteExpirationRelativeToNow)
        {
            ICacheEntry entry = cache.CreateEntry(key);

            entry.AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow;
            entry.Value = value;
            entry.Dispose();

            return(value);
        }
Example #7
0
        public static T Set <T>(this ICustomCache cache, object key, T value, DateTimeOffset absoluteExpiration)
        {
            ICacheEntry entry = cache.CreateEntry(key);

            entry.AbsoluteExpiration = absoluteExpiration;
            entry.Value = value;
            entry.Dispose();

            return(value);
        }
Example #8
0
        public static TItem GetOrCreate <TItem>(this ICustomCache cache, object key, Func <ICacheEntry, TItem> factory)
        {
            if (!cache.TryGetValue(key, out object result))
            {
                ICacheEntry entry = cache.CreateEntry(key);
                result = factory(entry);
                entry.SetValue(result);
                entry.Dispose();
            }

            return((TItem)result);
        }
Example #9
0
        public static T Set <T>(this ICustomCache cache, object key, T value, MemoryCacheEntryOptions options)
        {
            using (ICacheEntry entry = cache.CreateEntry(key))
            {
                if (options != null)
                {
                    entry.SetOptions(options);
                }

                entry.Value = value;
            }

            return(value);
        }
Example #10
0
        public void TestInitializer()
        {
            var uow = Substitute.For <IUnitOfWork2>();

            _usersDbSet       = Substitute.For <DbSet <ApplicationUser>, IQueryable <ApplicationUser>, IDbAsyncEnumerable <ApplicationUser> >();
            _permissionsDbSet = Substitute.For <DbSet <Permission>, IQueryable <Permission>, IDbAsyncEnumerable <Permission> >();

            uow.GetDbSet <ApplicationUser>().Returns(_usersDbSet);
            uow.GetDbSet <Permission>().Returns(_permissionsDbSet);

            _permissionCache = Substitute.For <ICustomCache <string, IList <string> > >();

            _permissionService = new PermissionService(uow, _permissionCache);
        }
Example #11
0
 public ICustomCache GetCustomCacheInstance(string Type)
 {
     if (mycacheObject == null)
     {
         if (Type == "SQL")
         {
             mycacheObject = new SQLCustomCache();
         }
         else
         {
             mycacheObject = new FileSystemCustomCache();
         }
     }
     return(mycacheObject);
 }
Example #12
0
 /// <summary>
 /// Used to close cache in order to start a new session
 /// </summary>
 internal static void ClearSession()
 {
     lock (static_lock_variable)
     {
         if (cache_map_writer != null)
         {
             cache_map_writer.WriteEndElement();
             cache_map_writer.WriteEndDocument();
             cache_map_writer.Close();
             cache_map_writer = null;
         }
         custom_cache = null;
         cache_map    = null;
     }
 }
Example #13
0
 /// <summary>
 /// Used to close cache in order to start a new session
 /// </summary>
 static void clear_session()
 {
     lock (static_lock_variable)
     {
         if (cache_map_writer != null)
         {
             cache_map_writer.Close();
             cache_map_writer.Dispose();
             cache_map_writer = null;
         }
         cache_dir    = null;
         custom_cache = null;
         cache_map    = null;
     }
 }
Example #14
0
        public RolesController(IMapper mapper,
                               IUnitOfWork unitOfWork,
                               IPermissionService permissionService,
                               ICustomCache <string, IEnumerable <string> > permissionsCache,
                               IRoleService roleService,
                               ShroomsUserManager userManager = null,
                               ShroomsRoleManager roleManager = null)
        {
            _mapper                    = mapper;
            _unitOfWork                = unitOfWork;
            _permissionsCache          = permissionsCache;
            _permissionService         = permissionService;
            _roleService               = roleService;
            _roleRepository            = unitOfWork.GetRepository <ApplicationRole>();
            _permissionRepository      = unitOfWork.GetRepository <Permission>();
            _applicationUserRepository = unitOfWork.GetRepository <ApplicationUser>();

            _roleManager = roleManager;
            _userManager = userManager;
        }
 public ValuesController(ICustomCache cache)
 {
     _cache = cache;
 }
Example #16
0
 static CacheManager()
 {
     // alternatly use Ioc container like Unity to create the object
     _cache = new CustomCache();
 }
Example #17
0
 /// <summary>
 /// Used to close cache in order to start a new session
 /// </summary>
 internal static void ClearSession()
 {
     lock (static_lock_variable)
     {
         if (cache_map_writer != null)
         {
             cache_map_writer.WriteEndElement();
             cache_map_writer.WriteEndDocument();
             cache_map_writer.Close();
             cache_map_writer = null;
         }
         custom_cache = null;
         cache_map = null;
     }
 }
Example #18
0
 //internal static CacheInfo GetCacheInfo(string url)
 //{
 //    lock (static_lock_variable)
 //    {
 //        if (url == null)
 //            return null;
 //        return (CacheInfo)cache_map[url];
 //    }
 //}
 /// <summary>
 /// 
 /// </summary>
 /// <returns>false if cashe was not restored due to any reason</returns>
 static bool restore_cache()
 {
     lock (static_lock_variable)
     {
         try
         {
             cache_map = new Dictionary<string,CacheInfo>();
             custom_cache = (ICustomCache)CustomizationApi.CreateCustomCache();
             DirectoryInfo di = new DirectoryInfo(Log.WorkDir);
             DirectoryInfo[] session_dis = di.GetDirectories("Session*", SearchOption.TopDirectoryOnly);
             Array.Sort(session_dis, new Session.CompareDirectoryInfo());
             for (int i = session_dis.Length - 1; i >= 0; i--)
             {
                 DirectoryInfo d = session_dis[i];
                 if (!Directory.Exists(d.FullName + "\\" + Log.DownloadDirName))
                     continue;
                 if (d.FullName == Log.SessionDir)
                     continue;
                 string cm_file = d.FullName + "\\" + Log.DownloadDirName + "\\" + CACHE_MAP_FILE_NAME;
                 if (!File.Exists(cm_file))
                 {
                     Log.Main.Error("Could not open cache map: " + d.FullName + "\\" + CACHE_MAP_FILE_NAME);
                     continue;
                 }
                 try
                 {
                     XmlTextReader sr = new XmlTextReader(cm_file);
                     string session_name = Regex.Replace(d.FullName, @".*[\/\\](?=.+)", "", RegexOptions.Compiled| RegexOptions.Singleline);
                     while (sr.Read())
                     {
                         if (sr.NodeType == XmlNodeType.Element && sr.Name == "File")
                         {
                             string url = sr.GetAttribute("url");
                             string response_url = sr.GetAttribute("response_url");
                             string path = sr.GetAttribute("path");
                             if (!path.Contains(session_name)) path = "\\" + session_name + "\\" + Log.DownloadDirName + "\\" + path;
                             bool text;
                             if (!bool.TryParse(sr.GetAttribute("text"), out text))
                                 text = true;
                             if (DoNotRestoreErrorFiles)
                             {
                                 string error = sr.GetAttribute("error");
                                 if (error != null)
                                     continue;
                             }
                             add2cache_map(url, path, response_url);
                         }
                     }
                 }
                 catch (XmlException e)
                 {
                     if (!e.Message.Contains("Unexpected end of file has occurred."))
                         Log.Main.Error(e);
                 }
             }
             return true;
         }
         catch (Exception e)
         {
             LogMessage.Exit(e);
         }
         return false;
     }
 }
Example #19
0
 public PermissionService(IUnitOfWork2 unitOfWork, ICustomCache <string, IEnumerable <string> > permissionsCache)
 {
     _permissionsDbSet = unitOfWork.GetDbSet <Permission>();
     _permissionsCache = permissionsCache;
 }
Example #20
0
        //internal static CacheInfo GetCacheInfo(string url)
        //{
        //    lock (static_lock_variable)
        //    {
        //        if (url == null)
        //            return null;
        //        return (CacheInfo)cache_map[url];
        //    }
        //}

        /// <summary>
        ///
        /// </summary>
        /// <returns>false if cashe was not restored due to any reason</returns>
        static bool restore_cache()
        {
            lock (static_lock_variable)
            {
                try
                {
                    cache_map    = new Dictionary <string, CacheInfo>();
                    custom_cache = (ICustomCache)CustomizationApi.CreateCustomCache();
                    DirectoryInfo   di          = new DirectoryInfo(Log.WorkDir);
                    DirectoryInfo[] session_dis = di.GetDirectories("Session*", SearchOption.TopDirectoryOnly);
                    Array.Sort(session_dis, new Session.CompareDirectoryInfo());
                    for (int i = session_dis.Length - 1; i >= 0; i--)
                    {
                        DirectoryInfo d = session_dis[i];
                        if (!Directory.Exists(d.FullName + "\\" + Log.DownloadDirName))
                        {
                            continue;
                        }
                        if (d.FullName == Log.SessionDir)
                        {
                            continue;
                        }
                        string cm_file = d.FullName + "\\" + Log.DownloadDirName + "\\" + CACHE_MAP_FILE_NAME;
                        if (!File.Exists(cm_file))
                        {
                            Log.Main.Error("Could not open cache map: " + d.FullName + "\\" + CACHE_MAP_FILE_NAME);
                            continue;
                        }
                        try
                        {
                            XmlTextReader sr           = new XmlTextReader(cm_file);
                            string        session_name = Regex.Replace(d.FullName, @".*[\/\\](?=.+)", "", RegexOptions.Compiled | RegexOptions.Singleline);
                            while (sr.Read())
                            {
                                if (sr.NodeType == XmlNodeType.Element && sr.Name == "File")
                                {
                                    string url          = sr.GetAttribute("url");
                                    string response_url = sr.GetAttribute("response_url");
                                    string path         = sr.GetAttribute("path");
                                    if (!path.Contains(session_name))
                                    {
                                        path = "\\" + session_name + "\\" + Log.DownloadDirName + "\\" + path;
                                    }
                                    bool text;
                                    if (!bool.TryParse(sr.GetAttribute("text"), out text))
                                    {
                                        text = true;
                                    }
                                    if (DoNotRestoreErrorFiles)
                                    {
                                        string error = sr.GetAttribute("error");
                                        if (error != null)
                                        {
                                            continue;
                                        }
                                    }
                                    add2cache_map(url, path, response_url);
                                }
                            }
                        }
                        catch (XmlException e)
                        {
                            if (!e.Message.Contains("Unexpected end of file has occurred."))
                            {
                                Log.Main.Error(e);
                            }
                        }
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    LogMessage.Exit(e);
                }
                return(false);
            }
        }