Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of the IntercomTest class with the specified parameters.
        /// </summary>
        /// <param name="userId">Customer user ID.</param>
        /// <param name="name">Customer name.</param>
        /// <param name="location">Customer location.</param>
        /// <exception cref="ArgumentNullException">Thrown if customer name or location is null.</exception>
        /// <exception cref="ArgumentException">Thrown if customer name is an empty string.</exception>
        public Customer(int userId, string name, GeographicalLocation location)
        {
            UserId = userId;

            if (ReferenceEquals(name, null))
            {
                throw new ArgumentNullException(nameof(name), CreateNameNullMessage());
            }

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException(CreateNameEmptyMessage(), nameof(name));
            }

            Name = name.Trim();

            if (ReferenceEquals(location, null))
            {
                throw new ArgumentNullException(nameof(location), CreateLocationNullMessage());
            }

            Location = location;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the distance from the specified other location, in kilometers.
 /// </summary>
 /// <param name="otherLocation">Other location.</param>
 /// <returns>Distance from the specified location in kilometers.</returns>
 public double DistanceFrom(GeographicalLocation otherLocation)
 {
     return(CalculateDistance(this, otherLocation));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Calculates the distance between the specified geographical locations. The formula from https://en.wikipedia.org/wiki/Great-circle_distance
 /// was used for calculations. Mean Earth radius is cca. 6371 kilometers.
 /// </summary>
 /// <param name="firstLocation">First location.</param>
 /// <param name="secondLocation">Second location.</param>
 /// <returns></returns>
 public static double CalculateDistance(GeographicalLocation firstLocation, GeographicalLocation secondLocation)
 {
     return(Utilty.Calculator.CalculateGreatCircleDistance(firstLocation.RadianLatitude, firstLocation.RadianLongitude,
                                                           secondLocation.RadianLatitude, secondLocation.RadianLongitude, MEAN_EARTH_RADIUS_KM));
 }