Exemplo n.º 1
0
 public void SetLimitationTime()
 {
     BanLimitationTime = new List <IDateProvider <DateTime, Trigger, StrongString> >(BanList.Length);
     for (int i = 0; i < BanLimitationTime.Count; i++)
     {
         BanLimitationTime[i] = DateProvider.GetUnlimited();
     }
 }
Exemplo n.º 2
0
            //------------------------------------------
            public static IDateProvider <DateTime, Trigger, StrongString> GetNistTime()
            {
                /*
                 *
                 *
                 *
                 * var client = new TcpClient("time.nist.gov", 13);
                 * using (var streamReader = new StreamReader(client.GetStream()))
                 *  {
                 *   var response = streamReader.ReadToEnd();
                 *
                 *   var utcDateTimeString = response.Substring(7, 17);
                 *   var localDateTime = DateTime.ParseExact(utcDateTimeString, "yy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
                 *   return localDateTime;
                 *  }
                 */
                // This Part is Closed! Don't use this code plz! {ALi.w}
                //DateTime dateTime = DateTime.MinValue;

                //HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://nist.time.gov/actualtime.cgi?lzbc=siqm9b");
                //request.Method = "GET";
                //request.Accept = "text/html, application/xhtml+xml, */*";
                //request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
                //request.ContentType = "application/x-www-form-urlencoded";
                //request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); //No caching
                //HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                //if (response.StatusCode == HttpStatusCode.OK)
                //{
                //StreamReader stream = new StreamReader(response.GetResponseStream());
                //string html = stream.ReadToEnd();//<timestamp time=\"1395772696469995\" delay=\"1395772696469995\"/>
                //string time = Regex.Match(html, @"(?<=\btime="")[^""]*").Value;
                //double milliseconds = Convert.ToInt64(time) / 1000.0;
                //dateTime = new DateTime(1970, 1, 1).AddMilliseconds(milliseconds).ToLocalTime();
                //}
                //return dateTime;
                var myHttpWebRequest =
                    (HttpWebRequest)WebRequest.Create(AppSettings.TimeRequestURL);

                try
                {
                    return
                        (ToDateTime(myHttpWebRequest.GetResponse().Headers[AppSettings.DateHeaderKey].ToStrong()));
                }
                catch
                {
                    ThereIsServer.ServerSettings.HasConnectionClosed = true;
                    NoInternetConnectionSandBox.PrepareConnectionClosedSandBox();
                    return(DateProvider.GetUnlimited());
                }
            }