Example #1
0
        static CertificatesMonitor()
        {
            _enquiries = new MemoryCache("CertificatesMonitor");

            using (var db = new NotificationCenterContext())
            {
                _notificationEventId = db.NotificationEvents.Single(ne => ne.RaiseCriteria == NotificationRaiseCriteria.ExpiredCertificate).Id;

                var baseOffset = DateTimeOffset.Now.AddHours(24);
                var now        = DateTime.UtcNow;

                foreach (var c in db.ClientCertificates.Where(c => c.ValidFrom <= now && c.ValidUntil >= now))
                {
                    _enquiries.Set(c.ClientId.ToString(), c.ValidUntil, new CacheItemPolicy()
                    {
                        AbsoluteExpiration = c.ValidUntil,
                        RemovedCallback    = ReCheckCertificate
                    });
                }
            }
        }
Example #2
0
        private static void ReCheckCertificate(CacheEntryRemovedArguments arg)
        {
            var key      = int.Parse(arg.CacheItem.Key);
            var oldState = (DateTime)arg.CacheItem.Value;

            using (var db1 = new NotificationCenterContext())
            {
                var cc = db1.ClientCertificates.Single(c => c.ClientId == key);

                db1.Notifications.Add(new Notification()
                {
                    CreatedOn           = DateTime.UtcNow,
                    Message             = $"Certificate {cc.SetialNumber} expired.",
                    NotificationEventId = _notificationEventId,
                    ReferenceRecord     = key,
                    Deleted             = false,
                    Seen = false
                });

                db1.SaveChanges();
            }
        }
Example #3
0
 public void Dispose()
 {
     _db?.Dispose();
     _db = null;
 }
Example #4
0
 public ServiceBase()
 {
     _db = new NotificationCenterContext();
 }