Exemplo n.º 1
0
        public CodecMatch(CodecRegistration codecRegistration, float score, int matchingParameters)
        {
            if (codecRegistration == null)
            {
                throw new ArgumentNullException("codecRegistration");
            }

            CodecRegistration      = codecRegistration;
            Score                  = score;
            MatchingParameterCount = matchingParameters;
        }
Exemplo n.º 2
0
 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));
 }
Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
0
 public void Add(CodecRegistration codecRegistration)
 {
     _codecs.Add(codecRegistration.MediaType, codecRegistration);
 }