Exemplo n.º 1
0
        /// <summary>
        /// RetreiveThreatProperties method implementation
        /// </summary>
        protected virtual ThreatInformations RetreiveThreatProperties(ThreatInformations infos)
        {
            Dictionary <string, DateTime> dic = DecodeThreatData(infos.BLOB);
            var xnextupdate = dic["NextUpdate"];

            infos.NextUpdate = xnextupdate;
            return(infos);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Backgroud RefreshThreatMethod  method
        /// </summary>
        private void RefreshThreatMethod()
        {
            using (_threatcanceller.Token.Register(Thread.CurrentThread.Abort))
            {
                while (!_threatmustexit)
                {
                    try
                    {
                        lock (_threatlock)
                        {
                            ThreatInformations infos = GetThreatCache();
                            if (infos.CanDownload && ((DateTime.Now > Convert.ToDateTime(infos.NextUpdate)) || (!File.Exists(SystemUtilities.ThreatCacheFile))))
                            {
                                try
                                {
                                    infos.BLOB = GetThreatBlob().Result;
                                }
                                catch
                                {
                                    infos.BLOB = null;
                                }
                                if (!string.IsNullOrEmpty(infos.BLOB))
                                {
                                    DateTime oldnextupdate = infos.NextUpdate;

                                    RetreiveThreatProperties(infos);
                                    if ((infos.NextUpdate > oldnextupdate) || (!File.Exists(SystemUtilities.ThreatCacheFile)))
                                    {
                                        SetThreatCache(infos);
                                    }
                                }
                            }
                        }
                        Thread.Sleep(new TimeSpan(0, 12, 0, 0)); // every 12 hours
                    }
                    catch (ThreadAbortException ex)
                    {
                        _threatmustexit = true;
                        _log.WriteEntry(string.Format("error on refresh Threat method : {0}.", ex.Message), EventLogEntryType.Error, 1014);
                    }
                    catch (Exception ex)
                    {
                        _log.WriteEntry(string.Format("error on refresh Threat method : {0}.", ex.Message), EventLogEntryType.Error, 1014);
                        Thread.Sleep(new TimeSpan(0, 12, 0, 0)); // every 12 hours
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// GetBLOBPayloadCache method implementation
        /// </summary>
        protected virtual ThreatInformations GetThreatCache()
        {
            ThreatInformations infos = new ThreatInformations();

            if (File.Exists(SystemUtilities.ThreatCacheFile))
            {
                infos.BLOB = File.ReadAllText(SystemUtilities.ThreatCacheFile);
                return(RetreiveThreatProperties(infos));
            }
            else
            {
                infos.CanDownload = true;
                infos.BLOB        = null;
            }
            return(infos);
        }
Exemplo n.º 4
0
 /// <summary>
 /// SetBLOBPayloadCache method implmentation
 /// </summary>
 public void SetThreatCache(ThreatInformations infos)
 {
     File.WriteAllText(SystemUtilities.ThreatCacheFile, infos.BLOB);
     ManagementService.UpdateMFAThreatDetectionData(null);
 }