/// <summary>
 /// Logs the use out, clears session and redirects the user to the login page.
 /// </summary>
 public static void LogOut(IAuthenticationManager auth = null, bool logThis = false)
 {
     try
     {
         if (logThis)
         {
             try
             {
                 var funMemUser = GetCurrentlyLoggedInUser();
                 if (funMemUser != null)
                 {
                     HttpContext.Current.Session[SS_CURRENT_USER] = funMemUser;
                     MyServiceLocator.GetInstance <IAuditTrailLogger>().AuditLogin(EventType.Logout);
                 }
             }
             catch { }
         }
         HttpContext.Current.Session.Clear();
         HttpContext.Current.Session.Abandon();
         if (auth == null)
         {
             auth = HttpContext.Current.GetOwinContext().Authentication;
         }
         auth.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
     }
     catch (Exception ex)
     {
         Utilities.Logger.Log(ex);
     }
 }
Beispiel #2
0
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            // Save log entries
            var logLogic = new LogLogic();

            logLogic.FlushRequestLogs();

            // Stop if static resource
            var webHelper = new WebHelper(filterContext.HttpContext);

            if (webHelper.IsStaticResource())
            {
                return;
            }

            // Close DB connections
            var mgr = MyServiceLocator.GetInstance <IDbSessionCleanup>();

            mgr.CloseDbConnections();
        }
Beispiel #3
0
 public LogLogic() : base(MyServiceLocator.GetInstance <ICoreDAO <Log> >())
 {
 }
Beispiel #4
0
 public EmailAccountLogic()
     : base(MyServiceLocator.GetInstance <ICoreDAO <EmailAccount> >())
 {
 }
Beispiel #5
0
 public ScheduledTaskEngine(string institutionCode) : base(MyServiceLocator.GetInstance <ICoreDAO <ScheduledTask> >(), institutionCode)
 {
 }
Beispiel #6
0
 public QueuedEmailLogic(string institutionCode)
     : base(MyServiceLocator.GetInstance <ICoreDAO <QueuedEmail> >(), institutionCode)
 {
     emailAccountLogic = new EmailAccountLogic();
 }
 static WebUtilities()
 {
     InstitutionEngine = MyServiceLocator.GetInstance <IInstitutionDAO <Institution> >();
     IdentityUserDAO   = MyServiceLocator.GetInstance <IAppUserDAO <IdentityUser> >();
 }
Beispiel #8
0
 public SystemSettingLogic() : base(MyServiceLocator.GetInstance <ICoreDAO <SystemSetting> >())
 {
 }
Beispiel #9
0
 public ActionAccessPrivilegeLogic() : base(MyServiceLocator.GetInstance <IPrivilegeDAO <ActionAccessPrivilege> >())
 {
 }
Beispiel #10
0
 public AppUserLogic(string institutionCode) : base(institutionCode, MyServiceLocator.GetInstance <IAppUserDAO>())
 {
 }
Beispiel #11
0
 public AuditLogLogic(string institutionCode) : base(MyServiceLocator.GetInstance <ICoreDAO <AuditLog> >(), institutionCode)
 {
 }
Beispiel #12
0
 public UserLoginLogic(string institutionCode)
     : base(MyServiceLocator.GetInstance <ICoreDAO <UserLogin> >(), institutionCode)
 {
 }
Beispiel #13
0
        /// <summary>
        /// Initializes the task manager
        /// </summary>
        public void Initialize()
        {
            _logger.Trace("Initializing task manager. {0} task threads will be cleared and new ones built.", _taskThreads.Count);
            _taskThreads.Clear();

            var allInstitutions = MyServiceLocator.GetInstance <IInstitutionDAO>()
                                  .RetrieveAllActive();
            List <Institution> institutions;

            if (allInstitutions == null)
            {
                institutions = new List <Institution>(1)
                {
                    new Institution {
                        Code = Utilities.INST_DEFAULT_CODE
                    }
                };
            }
            else
            {
                institutions = new List <Institution>(1 + allInstitutions.Count);
                institutions.Add(new Institution {
                    Code = Utilities.INST_DEFAULT_CODE, Name = "Core"
                });
                institutions.AddRange(allInstitutions);
            }
            _logger.Trace("Tasks will be queued for {0} institutions", institutions.Count);
            foreach (var institution in institutions)
            {
                try
                {
                    var taskService   = new ScheduledTaskEngine(institution.Code);
                    var scheduleTasks = taskService.RetrieveAllActive();

                    _logger.Trace("{0} task(s) will be queued for '{1}'", scheduleTasks.Count, institution.Name);
                    if (scheduleTasks.Count > 0)
                    {
                        //group by threads with the same seconds
                        foreach (var scheduleTaskGrouped in scheduleTasks.GroupBy(x => x.Seconds))
                        {
                            //create a thread
                            var taskThread = new TaskThread(institution.Code)
                            {
                                Seconds = scheduleTaskGrouped.Key,
                            };
                            foreach (var scheduleTask in scheduleTaskGrouped)
                            {
                                taskThread.AddTask(scheduleTask);
                            }
                            _taskThreads.Add(taskThread);
                        }

                        //sometimes a task period could be set to several hours (or even days).
                        //in this case a probability that it'll be run is quite small (an application could be restarted)
                        //we should manually run the tasks which weren't run for a long time
                        var notRunTasks = scheduleTasks
                                          //find tasks with "run period" more than 30 minutes
                                          .Where(x => x.Seconds >= _notRunTasksInterval)
                                          .Where(x => !x.LastStartUtc.HasValue || x.LastStartUtc.Value.AddSeconds(x.Seconds) < DateTime.UtcNow)
                        ;
                        //create a thread for the tasks which weren't run for a long time
                        if (notRunTasks.Any())
                        {
                            var taskThread = new TaskThread(institution.Code)
                            {
                                RunOnlyOnce = true,
                                Seconds     = 60 * 5 //let's run such tasks in 5 minutes after application start
                            };
                            foreach (var scheduleTask in notRunTasks)
                            {
                                taskThread.AddTask(scheduleTask);
                            }
                            _taskThreads.Add(taskThread);
                        }

                        _logger.Trace($"Done queueing the {scheduleTasks.Count} task(s) for '{institution.Name}'");
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error("Error while queueing task(s) for '{0}': \n{1}\n", institution.Name, ex.GetFullExceptionMessage());
                }
            }

            _isInitialized = true;
            _logger.Trace("Done initializing.");
        }