예제 #1
0
        protected override void OnStart(string[] args)
        {
            TokenCleanUpLogger.WriteEntry($@"[{DateTime.Now}] - Starting Service");

            TokenCleanUpTrigger.Enabled = true;
            TokenCleanUpTrigger.Start();
        }
예제 #2
0
        protected override void OnStop()
        {
            TokenCleanUpLogger.WriteEntry($@"[{DateTime.Now}] - Stopping Service");

            // Explicity closing the connection
            TokenCleanUpTrigger.Stop();
            _TokenEF.Database.Connection.Close();
        }
예제 #3
0
        public TokenCleanUpService()
        {
            InitializeComponent();

            TokenCleanUpLogger.WriteEntry($@"[{DateTime.Now}] - Initializing Service");
            _TokenEF = new TokensEntities();

            TokenCleanUpTrigger          = new Timer(60000);
            TokenCleanUpTrigger.Elapsed += new ElapsedEventHandler((sender, eventargs) => CheckTokenStates());
        }
예제 #4
0
        private void CheckTokenStates()
        {
            try
            {
                int changes = (_TokenEF.Token.RemoveRange(
                                   _TokenEF.Token.Where(token => token.exp != null && token.exp < DateTime.Now))).Count();
                _TokenEF.SaveChanges();

                TokenCleanUpLogger.WriteEntry($@"[{DateTime.Now}] - Cleaning operation terminated with {changes} modifications.");
            }
            catch (Exception ex)
            {
                TokenCleanUpLogger.WriteEntry(ex.Message);
                OnStop();
            }
        }