コード例 #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();
            }
        }