/// <summary>
 /// Deep clone
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static EndpointModel Clone(this EndpointModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new EndpointModel {
         Certificate = model.Certificate,
         AlternativeUrls = model.AlternativeUrls.ToHashSetSafe(),
         SecurityMode = model.SecurityMode,
         SecurityPolicy = model.SecurityPolicy,
         Url = model.Url
     });
 }
        /// <summary>
        /// Get all urls
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static IEnumerable <string> GetAllUrls(this EndpointModel model)
        {
            if (model == null)
            {
                return(null);
            }
            var all = model.Url.YieldReturn();

            if (model.AlternativeUrls != null)
            {
                all = all.Concat(model.AlternativeUrls);
            }
            return(all);
        }
        /// <summary>
        /// Create unique hash
        /// </summary>
        /// <param name="endpoint"></param>
        /// <returns></returns>
        public static int CreateConsistentHash(this EndpointModel endpoint)
        {
            var hashCode = -1971667340;

            hashCode = (hashCode * -1521134295) +
                       endpoint.GetAllUrls().SequenceGetHashSafe();
            hashCode = (hashCode * -1521134295) +
                       endpoint.Certificate.SequenceGetHashSafe();
            hashCode = (hashCode * -1521134295) +
                       EqualityComparer <string> .Default.GetHashCode(endpoint.SecurityPolicy);

            hashCode = (hashCode * -1521134295) +
                       EqualityComparer <SecurityMode?> .Default.GetHashCode(
                endpoint.SecurityMode ?? SecurityMode.Best);

            return(hashCode);
        }
 /// <summary>
 /// Equality comparison
 /// </summary>
 /// <param name="model"></param>
 /// <param name="that"></param>
 /// <returns></returns>
 public static bool IsSameAs(this EndpointModel model, EndpointModel that)
 {
     if (model == that)
     {
         return(true);
     }
     if (model == null || that == null)
     {
         return(false);
     }
     if (!that.HasSameSecurityProperties(model))
     {
         return(false);
     }
     if (!that.GetAllUrls().SequenceEqualsSafe(model.GetAllUrls()))
     {
         return(false);
     }
     return(true);
 }