< Summary

Information
Class: NtpServiceLibrary.Settings
Assembly: NtpServiceLibrary
File(s): D:\a\ntp-service\ntp-service\NtpServiceLibrary\Settings.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 96
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
ToString()100%11100%

File(s)

D:\a\ntp-service\ntp-service\NtpServiceLibrary\Settings.cs

#LineLine coverage
 1namespace NtpServiceLibrary
 2{
 3    /// <summary>
 4    /// Represents a strongly-typed setting value with change tracking and source information.
 5    /// </summary>
 6    /// <typeparam name="T">Type of the setting value.</typeparam>
 7    public class SettingsValue<T>
 8    {
 9        private T _value;
 10        private string _source = "";
 11        private bool _changed = false;
 12
 13        /// <summary>
 14        /// Initializes a new instance of the <see cref="SettingsValue{T}"/> class with a default value.
 15        /// </summary>
 16        /// <param name="defaultValue">The default value.</param>
 17        public SettingsValue(T defaultValue)
 18        {
 19            _value = defaultValue;
 20        }
 21
 22        /// <summary>
 23        /// Gets the current value.
 24        /// </summary>
 25        public T Get()
 26        {
 27            return _value;
 28        }
 29
 30        public static explicit operator T(SettingsValue<T> value)
 31        {
 32            return value.Get();
 33        }
 34
 35        /// <summary>
 36        /// Sets the value and marks it as changed.
 37        /// </summary>
 38        /// <param name="value">The new value.</param>
 39        /// <param name="source">Optional source description.</param>
 40        public void Set(T value, string source = "")
 41        {
 42            _value = value;
 43            _source = source;
 44            _changed = true;
 45        }
 46
 47        /// <summary>
 48        /// Returns a string representation of the value, including change and source info.
 49        /// </summary>
 50        public override string ToString()
 51        {
 52            return string.Format("{0}{1}{2}",
 53                _value.ToString(),
 54                _changed ? "" : " (default)",
 55                _source != "" ? string.Format(" <{0}>", _source) : ""
 56            );
 57        }
 58    }
 59
 60    /// <summary>
 61    /// Holds all configurable NTP service settings.
 62    /// </summary>
 63    public class Settings
 64    {
 65        internal const string DefaultNTPServer = "pool.ntp.org";
 66        internal const int DefaultNTPPort = 123;
 67        internal const int DefaultNTPPollIntervalHours = 6;
 68
 69        /// <summary>
 70        /// NTP server address.
 71        /// </summary>
 1472        public SettingsValue<string> NTPServer = new SettingsValue<string>(DefaultNTPServer);
 73
 74        /// <summary>
 75        /// NTP server port.
 76        /// </summary>
 1477        public SettingsValue<int> NTPPort = new SettingsValue<int>(DefaultNTPPort);
 78
 79        /// <summary>
 80        /// Poll interval in hours.
 81        /// </summary>
 1482        public SettingsValue<int> NTPPollIntervalHours = new SettingsValue<int>(DefaultNTPPollIntervalHours);
 83
 84        /// <summary>
 85        /// Returns a string representation of all settings.
 86        /// </summary>
 87        public override string ToString()
 1088        {
 1089            return string.Format("Server: {0}\nPort: {1}\nPollIntervalHours: {2}\n",
 1090                NTPServer.ToString(),
 1091                NTPPort.ToString(),
 1092                NTPPollIntervalHours.ToString()
 1093            );
 1094        }
 95    }
 96}

Methods/Properties

.ctor()
ToString()