예제 #1
0
        /// <summary>
        /// Job that updates the JobPulse setting with the current date/time.
        /// This will allow us to notify an admin if the jobs stop running.
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void  Execute(IJobExecutionContext context)
        {
            // get the job map
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // delete accounts that have not been confirmed in X hours
            int      userExpireHours       = Int32.Parse(dataMap.GetString("HoursKeepUnconfirmedAccounts"));
            DateTime userAccountExpireDate = DateTime.Now.Add(new TimeSpan(userExpireHours * -1, 0, 0));

            UserService userService = new UserService();

            foreach (var user in userService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDate < userAccountExpireDate))
            {
                userService.Delete(user, null);
            }

            userService.Save(null, null);

            // purge exception log
            int      exceptionExpireDays = Int32.Parse(dataMap.GetString("DaysKeepExceptions"));
            DateTime exceptionExpireDate = DateTime.Now.Add(new TimeSpan(userExpireHours * -1, 0, 0));

            ExceptionLogService exceptionLogService = new ExceptionLogService();

            foreach (var exception in exceptionLogService.Queryable().Where(e => e.ExceptionDate < exceptionExpireDate))
            {
                exceptionLogService.Delete(exception, null);
            }

            exceptionLogService.Save(null, null);
        }
예제 #2
0
        /// <summary> 
        /// Job that updates the JobPulse setting with the current date/time.
        /// This will allow us to notify an admin if the jobs stop running.
        /// 
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            // get the job map
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // delete accounts that have not been confirmed in X hours
            int userExpireHours = Int32.Parse( dataMap.GetString( "HoursKeepUnconfirmedAccounts" ) );
            DateTime userAccountExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1,0,0 ) );

            UserService userService = new UserService();

            foreach (var user in userService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDate < userAccountExpireDate))
            {
                userService.Delete( user, null );
            }

            userService.Save( null, null );

            // purge exception log
            int exceptionExpireDays = Int32.Parse( dataMap.GetString( "DaysKeepExceptions" ) );
            DateTime exceptionExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1, 0, 0 ) );

            ExceptionLogService exceptionLogService = new ExceptionLogService();

            foreach ( var exception in exceptionLogService.Queryable().Where( e => e.ExceptionDate < exceptionExpireDate ) )
            {
                exceptionLogService.Delete( exception, null );
            }

            exceptionLogService.Save( null, null );
        }
예제 #3
0
        /// <summary>
        /// Job that executes routine Rock cleanup tasks
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void  Execute(IJobExecutionContext context)
        {
            // get the job map
            JobDataMap dataMap = context.JobDetail.JobDataMap;

            // delete accounts that have not been confirmed in X hours
            int      userExpireHours       = Int32.Parse(dataMap.GetString("HoursKeepUnconfirmedAccounts"));
            DateTime userAccountExpireDate = DateTime.Now.Add(new TimeSpan(userExpireHours * -1, 0, 0));

            var userLoginService = new UserLoginService();

            foreach (var user in userLoginService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDateTime < userAccountExpireDate).ToList())
            {
                userLoginService.Delete(user, null);
                userLoginService.Save(user, null);
            }

            // purge exception log
            int      exceptionExpireDays = Int32.Parse(dataMap.GetString("DaysKeepExceptions"));
            DateTime exceptionExpireDate = DateTime.Now.Add(new TimeSpan(exceptionExpireDays * -1, 0, 0, 0));

            ExceptionLogService exceptionLogService = new ExceptionLogService();

            foreach (var exception in exceptionLogService.Queryable().Where(e => e.ExceptionDateTime < exceptionExpireDate).ToList())
            {
                exceptionLogService.Delete(exception, null);
                exceptionLogService.Save(exception, null);
            }

            // purge audit log
            int          auditExpireDays = Int32.Parse(dataMap.GetString("AuditLogExpirationDays"));
            DateTime     auditExpireDate = DateTime.Now.Add(new TimeSpan(auditExpireDays * -1, 0, 0, 0));
            AuditService auditService    = new AuditService();

            foreach (var audit in auditService.Queryable().Where(a => a.DateTime < auditExpireDate).ToList())
            {
                auditService.Delete(audit, null);
                auditService.Save(audit, null);
            }

            // clean the cached file directory

            //get the attributes
            string   cacheDirectoryPath  = dataMap.GetString("BaseCacheDirectory");
            int      cacheExpirationDays = int.Parse(dataMap.GetString("DaysKeepCachedFiles"));
            DateTime cacheExpirationDate = DateTime.Now.Add(new TimeSpan(cacheExpirationDays * -1, 0, 0, 0));

            //if job is being run by the IIS scheduler and path is not null
            if (context.Scheduler.SchedulerName == "RockSchedulerIIS" && !String.IsNullOrEmpty(cacheDirectoryPath))
            {
                //get the physical path of the cache directory
                cacheDirectoryPath = System.Web.Hosting.HostingEnvironment.MapPath(cacheDirectoryPath);
            }

            //if directory is not blank and cache expiration date not in the future
            if (!String.IsNullOrEmpty(cacheDirectoryPath) && cacheExpirationDate <= DateTime.Now)
            {
                //Clean cache directory
                CleanCacheDirectory(cacheDirectoryPath, cacheExpirationDate);
            }

            // clean out any temporary binary files
            BinaryFileService binaryFileService = new BinaryFileService();

            foreach (var binaryFile in binaryFileService.Queryable().Where(bf => bf.IsTemporary == true).ToList())
            {
                if (binaryFile.LastModifiedDateTime < DateTime.Now.AddDays(-1))
                {
                    binaryFileService.Delete(binaryFile, null);
                    binaryFileService.Save(binaryFile, null);
                }
            }
        }