< Summary

Information
Class: Program
Assembly: NtpServiceConsole
File(s): D:\a\ntp-service\ntp-service\NtpServiceConsole\Program.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 34
Coverable lines: 34
Total lines: 59
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Main()0%620%

File(s)

D:\a\ntp-service\ntp-service\NtpServiceConsole\Program.cs

#LineLine coverage
 1///<summary>
 2///.NET 8.0 version of console application for NTP Service
 3using System;
 4using NtpServiceLibrary;
 5using NtpServiceConsole;
 6
 7/// <summary>
 8/// Entry point for the NtpServiceConsole application.
 9/// This console application retrieves the current time from an NTP server and displays it.
 10/// It attempts to read configuration from the Windows Registry, falling back to default settings if necessary.
 11/// Works as a test client for the NTP service library.
 12/// </summary>
 13class Program
 14{
 15    /// <summary>
 16    /// Main method for the console application.
 17    /// Initializes logging, loads settings, retrieves NTP time, and displays results.
 18    /// Handles and reports errors gracefully.
 19    /// </summary>
 20    static void Main()
 021    {
 22        try
 023        {
 024            var serviceName = "NtpService";
 025            var logger = new ConsoleLogger(serviceName);
 026            Settings settings = new Settings();
 27            try
 028            {
 029                var settingsProvider = new RegistrySettingsProvider(serviceName, logger);
 030                settings = settingsProvider.Read();
 031            }
 032            catch (NullReferenceException)
 033            {
 034                Console.WriteLine("WARNING: Registry settings for {0} does not exist, falling back to default ones:\n{1}
 035            }
 036            catch (Exception ex)
 037            {
 038                Console.WriteLine("WARNING: Unknown exception occured while attempting to read {0} settings, falling bac
 039                    "Error details:\n{2}", serviceName, settings, ex);
 040            }
 041            if (settings != null)
 042            {
 043                var currentTime = NtpTime.RetrieveNTPTime((string)settings.NTPServer, (int)settings.NTPPort);
 044                Console.WriteLine("Current date and time from NTP server: " + currentTime.ToLocalTime());
 045            }
 46            else
 047            {
 048                Console.WriteLine("ERROR: Cannot get neither default nor registry settings for {0}", serviceName);
 049            }
 050            TimeSpan timeSpan = new TimeSpan(6, 0, 0);
 051            Console.WriteLine("{0:%h} hours {0:%m} minutes {0:%m} seconds", timeSpan);
 52
 053        }
 054        catch (Exception ex)
 055        {
 056            Console.WriteLine("An error occurred: " + ex.Message);
 057        }
 058    }
 59}

Methods/Properties

Main()