예제 #1
0
 /// <summary>
 /// Returns true if this registration matches the endpoint
 /// model provided.
 /// </summary>
 /// <param name="registration"></param>
 /// <param name="endpoint"></param>
 /// <returns></returns>
 public static bool Matches(this EndpointRegistration registration, EndpointModel endpoint)
 {
     return(endpoint != null &&
            registration.EndpointUrl == endpoint.Url &&
            registration.AlternativeUrls.DecodeAsList().ToHashSetSafe().SetEqualsSafe(
                endpoint.AlternativeUrls) &&
            registration.SecurityMode == (endpoint.SecurityMode ?? SecurityMode.Best) &&
            registration.SecurityPolicy == endpoint.SecurityPolicy &&
            endpoint.Certificate.SequenceEqualsSafe(
                registration.Certificate.DecodeAsByteArray()));
 }
예제 #2
0
        /// <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>
 /// Deep clone
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static EndpointModel Clone(this EndpointModel model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new EndpointModel {
         ServerThumbprint = model.ServerThumbprint,
         AlternativeUrls = model.AlternativeUrls.ToHashSetSafe(),
         SecurityMode = model.SecurityMode,
         SecurityPolicy = model.SecurityPolicy,
         User = model.User.Clone(),
         Url = model.Url
     });
 }
 /// <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);
     }
     return
         (that.HasSameSecurityProperties(model) &&
          that.Url == model.Url &&
          that.AlternativeUrls.SetEqualsSafe(model.AlternativeUrls));
 }
예제 #5
0
 /// <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?.ToArray(),
         AlternativeUrls = model.AlternativeUrls.ToHashSetSafe(),
         SecurityMode = model.SecurityMode,
         SecurityPolicy = model.SecurityPolicy,
         User = model.User.Clone(),
         Url = model.Url
     });
 }
 /// <summary>
 /// Returns true if this registration matches the endpoint
 /// model provided.
 /// </summary>
 /// <param name="endpoint"></param>
 /// <returns></returns>
 public bool Matches(EndpointModel endpoint)
 {
     return(endpoint != null &&
            EndpointUrl == endpoint.Url &&
            AlternativeUrls.DecodeAsList().ToHashSetSafe().SetEqualsSafe(
                endpoint.AlternativeUrls) &&
            CredentialType == (endpoint.User?.Type ?? Models.CredentialType.None) &&
            JToken.DeepEquals(Credential, endpoint.User?.Value) &&
            SecurityMode == (endpoint.SecurityMode ?? Models.SecurityMode.Best) &&
            SecurityPolicy == endpoint.SecurityPolicy &&
            endpoint.ClientCertificate.SequenceEqualsSafe(
                ClientCertificate.DecodeAsByteArray()) &&
            endpoint.ServerThumbprint.SequenceEqualsSafe(
                ServerThumbprint.DecodeAsByteArray()));
 }
 /// <summary>
 /// Equality comparison
 /// </summary>
 /// <param name="model"></param>
 /// <param name="that"></param>
 /// <returns></returns>
 public static bool HasSameSecurityProperties(this EndpointModel model, EndpointModel that)
 {
     if (model == that)
     {
         return(true);
     }
     if (model == null || that == null)
     {
         return(false);
     }
     return
         (that.User.IsSameAs(model.User) &&
          that.ServerThumbprint.SequenceEqualsSafe(model.ServerThumbprint) &&
          that.SecurityPolicy == model.SecurityPolicy &&
          (that.SecurityMode ?? SecurityMode.Best) ==
          (model.SecurityMode ?? SecurityMode.Best));
 }
예제 #8
0
 /// <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);
 }
        /// <summary>
        /// Create Union with endpoint
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="model"></param>
        public static void UnionWith(this EndpointModel model,
                                     EndpointModel endpoint)
        {
            if (endpoint == null)
            {
                return;
            }

            if (model.Url == null)
            {
                model.Url = endpoint.Url;
            }

            if (model.AlternativeUrls == null)
            {
                model.AlternativeUrls = endpoint.AlternativeUrls;
            }
            else
            {
                model.AlternativeUrls = model.AlternativeUrls.MergeWith(
                    endpoint.AlternativeUrls);
            }
        }
예제 #10
0
        /// <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);

            hashCode = (hashCode * -1521134295) +
                       EqualityComparer <CredentialType?> .Default.GetHashCode(
                endpoint.User?.Type ?? CredentialType.None);

            hashCode = (hashCode * -1521134295) +
                       JToken.EqualityComparer.GetHashCode(endpoint.User?.Value);
            return(hashCode);
        }