Esempio n. 1
0
        public void NistParse_NoUtc()
        {
            DateTime time;

            Assert.IsFalse(Ntp.TryParseResponse("56328 13-02-05 18:41:11 00 0 0 248.8", out time), "parsed time");
            Assert.AreEqual(DateTime.MinValue, time);
        }
Esempio n. 2
0
        private object GetState()
        {
            try
            {
                Agent.State response = Config.State;
                Logger.Info(String.Format(CultureInfo.InvariantCulture, "Agent state: {0}", response.ToString()));

                if (BaseMessage.Settings != null)
                {
                    response.SetValue("agent_id", BaseMessage.Settings["agent_id"]);
                    response.SetValue("vm", BaseMessage.Settings["vm"]);
                }

                response.SetValue("job_state", GetJobState());
                response.SetValue("bosh_protocol", "1"); // TODO: response["bosh_protocol"] = Bosh::Agent::BOSH_PROTOCOL
                NtpMessage ntpMessage = Ntp.GetNtpOffset();
                response.SetValue("ntp", JToken.FromObject(ntpMessage));

                return(response.ToHash());
            }
            catch (StateException e)
            {
                throw new MessageHandlerException(e.Message, e);
            }
        }
Esempio n. 3
0
        public void NistParse_NoRegexMatch()
        {
            DateTime time;

            Assert.IsFalse(Ntp.TryParseResponse("56328 13-02-05 18:4:1 00 0 0 248.8 UTC(NIST)", out time), "parsed time");
            Assert.AreEqual(DateTime.MinValue, time);
        }
Esempio n. 4
0
 private static void Time()
 {
     Scheduler.ExecuteJob <SyncLocalClockJob>();
     Timedatectl.Apply();
     Ntp.Prepare();
     ConsoleLogger.Log("[time] ready");
 }
Esempio n. 5
0
        public void NistParse_Success()
        {
            var      response = @"
56328 13-02-05 18:41:11 00 0 0 248.8 UTC(NIST) * 
";
            DateTime time;

            Assert.IsTrue(Ntp.TryParseResponse(response, out time), "Couldn't parse time");
            Assert.AreEqual(new DateTime(2013, 2, 5, 18, 41, 11), time, "time doesn't match");
        }
Esempio n. 6
0
        public virtual void Parse(string jsonStr)
        {
            dynamic s = SimpleJson.SimpleJson.DeserializeObject(jsonStr);

            ErrorCode = Convert.ToInt64(s[@"error_code"]);
            if (ErrorCode != 0)
            {
                ErrorMsg = s[@"error_msg"];
            }
            Time = Ntp.GetTime(Convert.ToString(s[@"time"])).ToLocalTime();
        }
Esempio n. 7
0
        public void TestTime()
        {
            const int i    = 1544520933;
            var       time = Ntp.GetTime($@"{i}").ToLocalTime();

            Console.WriteLine(time.ToString(CultureInfo.CurrentCulture));

            var ans = new DateTime(2018, 12, 11, 17, 35, 33);

            Assert.AreEqual(ans, time);
        }
Esempio n. 8
0
        public void TC002_InvalidNtpServer()
        {
            //Arrange
            string invalidTimeServer = "time.invalidTime.itis";

            //Act
            Ntp currentNtp = Ntp.GetNtpOffset(invalidTimeServer);

            //Assert
            Assert.IsNotNull(currentNtp.Message);
        }
Esempio n. 9
0
        public void TC001_TestNtp()
        {
            //Arrange
            string timeServer = "pool.ntp.org";

            //Act
            Ntp currnetNtp = Ntp.GetNtpOffset(timeServer);

            //Assert
            Assert.AreEqual(null, currnetNtp.Message);
            Assert.AreNotEqual(0, currnetNtp.Offset);
        }
Esempio n. 10
0
        private void buttonPingGoogle_Click(object sender, EventArgs e)
        {
            // this is kind of an odd flow.

            TimeCorrection timeCorrection = null;

            // set up the asyn operation complete with continuation, catch and finally delegates
            // the async operation will use the synchronization context to post the continuation,
            // catch, and finally delegates to run on the UI thread.  Since we are creating this object
            // on the UI thread it will use the UI synchronization context.
            AsyncOperation getTimeCorrectionOperation = new AsyncOperation(() => // on background threadpool thread
            {
                timeCorrection = Ntp.GetTimeCorrectionFromGoogle();
            },
                                                                           () => // continuation on UI thread
            {
                var offset = timeCorrection.CorrectionFactor;

                var totalSeconds = Math.Abs(offset.TotalSeconds);
                if (totalSeconds == 0)
                {
                    MessageBox.Show("Your time is perfect according to Google's servers");
                }
                else if (totalSeconds <= 5)
                {
                    MessageBox.Show("Your time is off by five seconds or less from Google's servers.  You should be just fine.");
                }
                else if (totalSeconds <= 30)
                {
                    MessageBox.Show(string.Format("Your time is off by {0} seconds from Google's servers.  You are probably OK but correcting couldn't hurt.", totalSeconds));
                }
                else
                {
                    MessageBox.Show(string.Format("Your time is off by {0} seconds from Google's servers.  Try correcting the difference and try again.", totalSeconds));
                }
            },
                                                                           ex => MessageBox.Show(ex.Message, "Error"), // catch on UI thread
                                                                           () =>                                       // finally on UI thread
            {
                this.buttonPingGoogle.Visible = true;
                this.progressBarGettingTimeCorrection.Visible = false;
            });


            this.buttonPingGoogle.Visible = false;
            this.progressBarGettingTimeCorrection.Visible = true;

            getTimeCorrectionOperation.Run();
        }
Esempio n. 11
0
 public override void Parse(string jsonStr)
 {
     base.Parse(jsonStr);
     if (ErrorCode == 0)
     {
         dynamic s = SimpleJson.SimpleJson.DeserializeObject(jsonStr);
         LevelName      = s[@"user_info"][@"level_name"];
         SignTime       = Ntp.GetTime(Convert.ToString(s[@"user_info"][@"sign_time"])).ToLocalTime();
         SignBonusPoint = s[@"user_info"][@"sign_bonus_point"];
         UserId         = s[@"user_info"][@"user_id"];
         MissSignNum    = s[@"user_info"][@"miss_sign_num"];
         ContSignNum    = s[@"user_info"][@"cont_sign_num"];
         UserSignRank   = s[@"user_info"][@"user_sign_rank"];
     }
 }
Esempio n. 12
0
 public static void ConnectByAddress(string addr)
 {
     try
     {
         connectedNtpServer = new Ntp(addr);
         MessageBox.Show("Connected to: " + addr);
         isConnected = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show("An error has occurred, please try to connect again!\n" +
                         "Error message: " + ex.Message);
         isConnected = false;
     }
 }
Esempio n. 13
0
        public override void Parse(string jsonStr)
        {
            base.Parse(jsonStr);
            if (ErrorCode == 0)
            {
                dynamic s    = SimpleJson.SimpleJson.DeserializeObject(jsonStr);
                var     list = s[@"forum_list"];
                Forums.Clear();
                foreach (var forum in list)
                {
                    Forums.Add(Forum.Parse(forum.ToString()));
                }

                Tbs  = s[@"anti"][@"tbs"];
                Time = Ntp.GetTime(Convert.ToString(s[@"time"])).ToLocalTime();
            }
        }
Esempio n. 14
0
 public static void ConnectToAddress()
 {
     if (connectedNtpServer != null)
     {
         try
         {
             connectedNtpServer = new Ntp(ServerChooser.FinalServerAddress);
             MessageBox.Show("Connected to: " + ServerChooser.FinalServerAddress);
             isConnected = true;
         }catch (Exception ex)
         {
             MessageBox.Show("An error has occurred, please try to connect again!\n" +
                             "Error message: " + ex.Message);
             isConnected = false;
         }
     }
 }
Esempio n. 15
0
        public void TC003_NullNtpServer()
        {
            //Arrange
            Exception expected   = null;
            Ntp       currentNtp = null;

            //Act
            try
            {
                currentNtp = Ntp.GetNtpOffset(null);
            }
            catch (Exception ex)
            {
                expected = ex;
            }

            //Assert
            Assert.IsNull(currentNtp);
            Assert.IsNotNull(expected);
            Assert.IsInstanceOfType(expected, typeof(ArgumentNullException));
        }
Esempio n. 16
0
 internal NetworkServices(CiscoTelePresenceCodec codec)
     : base(codec)
 {
     _ntp = new Ntp(this, "NTP");
 }
Esempio n. 17
0
 private static void Ntpd()
 {
     Ntp.Set();
     ConsoleLogger.Log("[ntp] ready");
 }