コード例 #1
0
        public static void ReadKillBitFromFile(object source, FileSystemEventArgs e)
        {
            int      refreshRate;
            DateTime dateTime;

            if (KillBitHelper.TryReadKillBitFile(out refreshRate, out dateTime))
            {
                KillBitTimer.Singleton.UpdateTimerWithRefreshRate(refreshRate);
            }
        }
コード例 #2
0
 // Token: 0x06000B32 RID: 2866 RVA: 0x0002D310 File Offset: 0x0002B510
 public void Start()
 {
     if (!this.IsStarted)
     {
         this.internalTimer = new Timer(new TimerCallback(KillBitHelper.DownloadKillBitList));
         string   text = ConfigurationManager.AppSettings["KillBitRefreshTimeInSeconds"];
         int      num  = 0;
         int      num2;
         DateTime value;
         long     num4;
         if (KillBitHelper.TryReadKillBitFile(out num2, out value))
         {
             long num3 = (long)(num2 * this.DelayedCheckTimeInSeconds * 1000);
             KillBitTimer.Tracer.TraceInformation(0, 0L, string.Format("This refresh rate is {0} milliseconds.", num3));
             TimeSpan timeSpan = DateTime.UtcNow.Subtract(value);
             if ((double)num3 < timeSpan.TotalMilliseconds)
             {
                 num4 = (long)this.DelayedCheckTimeInSeconds * 1000L;
             }
             else
             {
                 num4 = num3;
             }
         }
         else
         {
             num4 = (long)this.DelayedCheckTimeInSeconds * 1000L;
         }
         if (!string.IsNullOrWhiteSpace(text) && int.TryParse(text, out num) && num > 0)
         {
             this.refreshRateInMillionSecondsFromConfig = num * 1000;
             num4 = (long)this.refreshRateInMillionSecondsFromConfig;
             KillBitTimer.Tracer.TraceInformation(0, 0L, string.Format("This test refresh rate setting is {0} seconds.", num));
         }
         KillBitTimer.Tracer.TraceInformation(0, 0L, string.Format("This time to next download is {0} milliseconds.", num4));
         this.internalTimer.Change(num4, num4);
         this.isStarted = true;
     }
 }
コード例 #3
0
        public static bool TryReadKillBitFile(out int refreshRate, out DateTime lastModifiedTime)
        {
            refreshRate      = -1;
            lastModifiedTime = DateTime.UtcNow;
            Exception ex = null;

            if (File.Exists(KillBitHelper.KillBitFilePath))
            {
                try
                {
                    using (Stream stream = File.Open(KillBitHelper.KillBitFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        if (stream.Length == 0L)
                        {
                            KillBitHelper.Tracer.TraceError(0L, "The local killbit file is empty.");
                            ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_EmptyKillbitListLocalFile, null, new object[]
                            {
                                "ProcessKillBit"
                            });
                        }
                        else
                        {
                            using (XmlReader xmlReader = XmlReader.Create(stream))
                            {
                                lastModifiedTime = File.GetLastWriteTimeUtc(KillBitHelper.KillBitFilePath);
                                return(KillBitHelper.ReadKillBitXmlContent(xmlReader, out refreshRate));
                            }
                        }
                    }
                }
                catch (SecurityException ex2)
                {
                    ex = ex2;
                }
                catch (FileNotFoundException ex3)
                {
                    ex = ex3;
                }
                catch (UriFormatException ex4)
                {
                    ex = ex4;
                }
                catch (IOException ex5)
                {
                    ex = ex5;
                }
                catch (XmlException ex6)
                {
                    ex = ex6;
                }
                if (ex != null)
                {
                    KillBitHelper.Tracer.TraceError <Exception>(0L, "Cannot read killbit refresh rate due to Exception {0}", ex);
                    ExtensionDiagnostics.Logger.LogEvent(ApplicationLogicEventLogConstants.Tuple_FailedToReadKillbitList, null, new object[]
                    {
                        "ProcessKillBit",
                        ExtensionDiagnostics.GetLoggedExceptionString(ex)
                    });
                    return(false);
                }
                return(false);
            }
            return(false);
        }