Exemplo n.º 1
0
 /// <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());
     }
 }
Exemplo n.º 2
0
 /// <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));
     }
 }
Exemplo n.º 3
0
 /// <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());
     }
 }