Exemple #1
0
        public CodecMatch(CodecRegistration codecRegistration, float score, int matchingParameters)
        {
            if (codecRegistration == null)
            {
                throw new ArgumentNullException("codecRegistration");
            }

            CodecRegistration      = codecRegistration;
            Score                  = score;
            MatchingParameterCount = matchingParameters;
        }
 static int CalculateDistance(IMember member, CodecRegistration registration)
 {
     if (registration.ResourceType == null)
     {
         return(-1);
     }
     if (registration.IsStrict)
     {
         return((member.Type.CompareTo(registration.ResourceType) == 0) ? 0 : -1);
     }
     return(member.Type.CompareTo(registration.ResourceType));
 }
Exemple #3
0
        public CodecMatch(CodecRegistration codecRegistration, float score, int matchingParameters)
        {
            if (codecRegistration == null)
            {
                throw new ArgumentNullException(nameof(codecRegistration));
            }

            CodecRegistration      = codecRegistration;
            Score                  = score;
            MatchingParameterCount = matchingParameters;
            MediaType              = CodecRegistration.MediaType;
            WeightedScore          = Score * CodecRegistration.MediaType.Quality;
        }
Exemple #4
0
        float CalculateScoreFor(IEnumerable <IMember> types, CodecRegistration registration)
        {
            float score = 0;

            foreach (var requestedType in types)
            {
                int typeComparison = CalculateDistance(requestedType.Type, registration);
                if (typeComparison == -1)
                {
                    return(-1);
                }
                float typeScore = 1f / (1f + typeComparison);
                score += typeScore;
            }
            return(score);
        }
 public void Add(CodecRegistration codecRegistration)
 {
     _codecs.Add(codecRegistration.MediaType, codecRegistration);
 }