Exemple #1
0
 public void AddQuestion(Question question)
 {
     questions.Add(question);
 }
Exemple #2
0
 public void AddQuestion(Question question)
 {
     questions.Add(question);
 }
        private Response FindResponse(Question question)
        {
            if (!Options.UseCache)
            {
                return null;
            }

            Response response;
            var key = GetQuestionKey(question);
            lock (m_responses)
            {
                var result = m_responses.TryGetValue(key, out response);
                if (!result)
                {
                    return null;
                }
            }

            var timeAlive = (int)((DateTime.Now.Ticks - response.TimeStamp.Ticks) / TimeSpan.TicksPerSecond);
            foreach (var rr in response.ResourceRecords)
            {
                rr.TimeLived = timeAlive;
                if (rr.TTL == 0)
                {
                    return null;
                }
            }
            return response;
        }
        public Response Query(string hostName, QType type, QClass @class)
        {
            if (String.IsNullOrWhiteSpace(hostName))
            {
                throw new ArgumentException("Invalid host name", "hostName");
            }

            var question = new Question(hostName, type, @class);
            var response = FindResponse(question);
            if (response != null)
            {
                return response;
            }

            var request = new Request();
            request.AddQuestion(question);
            response = GetResponse(request);
            return response;
        }
 private static string GetQuestionKey(Question question)
 {
     var result = String.Format(
         CultureInfo.InvariantCulture,
         "{0}-{1}-{2}",
         question.QClass,
         question.QType,
         question.QName);
     return result;
 }