/// <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);
     }
 }
Exemple #2
0
        public void Init()
        {
            var container = new Container();

            var baseContainer = new BaseContainer(null, container);

            // Very Important
            MyServiceLocator.SetIoCContainer(baseContainer.Container);

            client = new SmtpClient
            {
                EnableSsl             = true,
                UseDefaultCredentials = false,
                DeliveryMethod        = SmtpDeliveryMethod.Network,

                //Gmail
                //Host = "smtp.gmail.com",
                //Port = 587,
                //Credentials = new NetworkCredential("*****@*****.**", "october2014"),

                //GoDaddysmtpout
                Host        = "relay-hosting.secureserver.net",
                Port        = 25,
                Credentials = new NetworkCredential("*****@*****.**", "Sw882@1"),
            };

            //Gmail
            //sender = "*****@*****.**";

            //GoDaddy
            sender = "*****@*****.**";
        }
Exemple #3
0
        protected void Application_Start()
        {
            var container = new Container();

            // Simple Injector for MVC
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
            container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
            container.RegisterMvcIntegratedFilterProvider();

            // Simple Injector - other services
            var baseContainer = new BaseContainer(container: container);

            var resolver = new SimpleInjectorDependencyResolver(baseContainer.Container);

            DependencyResolver.SetResolver(resolver);

            // Very Important
            MyServiceLocator.SetIoCContainer(baseContainer.Container);
            MyMvcServiceLocator.SetIoCContainer(resolver);

            // Initialize MVC settings
            AppStartInitializer.Initialize();

            NHSessionManager.AddEntityAssemblies(new[] { "MultiTenancyFramework.Mvc" });
        }
Exemple #4
0
        static void Init()
        {
            var baseContainer = new BaseContainer();

            MyServiceLocator.SetIoCContainer(baseContainer.Container);

            // Initialize MVC settings
            //AppStartInitializer.Initialize();

            NHSessionManager.AddEntityAssemblies(new[] { "ConsoleTests" });
            var fileRules = new Dictionary <string, Tuple <string, LoggingLevel> > {
                { "NHibernate.SQL", new Tuple <string, LoggingLevel>("${shortdate}_nh.log", LoggingLevel.Debug) }
            };

            LoggerConfigurationManager.ConfigureNLog(true, fileRules);
        }
Exemple #5
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();
        }
Exemple #6
0
 public MyServiceHost() : base()
 {
     MyServiceLocator.SetAsDefaultServiceLocator();
 }
Exemple #7
0
 public ScheduledTaskEngine(string institutionCode) : base(MyServiceLocator.GetInstance <ICoreDAO <ScheduledTask> >(), institutionCode)
 {
 }
Exemple #8
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> >();
 }
 public override void RuntimeInitialize(MethodBase method)
 {
     _log = MyServiceLocator.Get();
 }
Exemple #11
0
 public SystemSettingLogic() : base(MyServiceLocator.GetInstance <ICoreDAO <SystemSetting> >())
 {
 }
Exemple #12
0
 public ActionAccessPrivilegeLogic() : base(MyServiceLocator.GetInstance <IPrivilegeDAO <ActionAccessPrivilege> >())
 {
 }
Exemple #13
0
 public AppUserLogic(string institutionCode) : base(institutionCode, MyServiceLocator.GetInstance <IAppUserDAO>())
 {
 }
Exemple #14
0
 public AuditLogLogic(string institutionCode) : base(MyServiceLocator.GetInstance <ICoreDAO <AuditLog> >(), institutionCode)
 {
 }
Exemple #15
0
 public UserLoginLogic(string institutionCode)
     : base(MyServiceLocator.GetInstance <ICoreDAO <UserLogin> >(), institutionCode)
 {
 }
Exemple #16
0
 public EmailAccountLogic()
     : base(MyServiceLocator.GetInstance <ICoreDAO <EmailAccount> >())
 {
 }
Exemple #17
0
 public LogLogic() : base(MyServiceLocator.GetInstance <ICoreDAO <Log> >())
 {
 }
Exemple #18
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.");
        }