/// <summary> /// Returns time retrieved from NTP server. /// </summary> /// <param name="hostName">NTP server host name.</param> /// <exception cref="ArgumentNullException">Host name cannot be null.</exception> /// <exception cref="ArgumentOutOfRangeException">Host name cannot be empty.</exception> /// <exception cref="InvalidOperationException">Cannot retrieve time from NTP server.</exception> public static async Task <DateTime> RetrieveTimeAsync(string hostName) { using (var client = new TrivialNtpClient(hostName)) { return(await client.RetrieveTimeAsync()); } }
/// <summary> /// Returns if time retrieval has been successful with time given as output parameter. /// </summary> /// <param name="hostName">NTP server host name.</param> /// <param name="time">Time if successful.</param> /// <exception cref="ArgumentNullException">Host name cannot be null.</exception> /// <exception cref="ArgumentOutOfRangeException">Host name cannot be empty.</exception> public static bool TryRetrieveTime(string hostName, out DateTime time) { using (var client = new TrivialNtpClient(hostName)) { return(client.TryRetrieveTime(out time)); } }
/// <summary> /// Returns the current time as received from NTP server. /// </summary> /// <param name="hostName">NTP server host name.</param> /// <exception cref="ArgumentNullException">Host name cannot be null.</exception> /// <exception cref="ArgumentOutOfRangeException">Host name cannot be empty.</exception> /// <exception cref="InvalidOperationException">Cannot retrieve time from NTP server.</exception> public static DateTime RetrieveTime(string hostName) { using (var client = new TrivialNtpClient(hostName)) { return(client.RetrieveTime()); } }