Exemplo n.º 1
0
 public void SetTopic(string name, Topic topic)
 {
     if (topic == null)
         HttpContext.Current.Cache.Remove(BASE_TOPIC_CACHE_KEY + name);
     else
         HttpContext.Current.Cache.Add(BASE_TOPIC_CACHE_KEY + name, topic, null, Cache.NoAbsoluteExpiration, new TimeSpan(Settings.TopicExpirationDays, 0, 0, 0), CacheItemPriority.High, null);
 }
Exemplo n.º 2
0
        private static bool IsFinalStep(Topic endTopic, Topic currentTopic)
        {
            if (RegularExpressions.DisambiguationTopicRegex.IsMatch(endTopic.Name))
            {
                //The end topic is very specific
                //(i.e. contains disambiguation like: Canadian_Bacon_(film)
                //Therefore the final step must match exactly
                if (endTopic.Name.EqualsOrdinalIgnoreCase(currentTopic.Name))
                    return true;
            }

            if (RegularExpressions.DisambiguationTopicRegex.IsMatch(currentTopic.Name))
            {
                //The end topic is very specific
                //(i.e. contains disambiguation like: Canadian_Bacon_(film)
                //but since the ending topic of the puzzle is not
                //then we'll just remove the disambiguation portion from the name
                var ambiguousTopicName = RegularExpressions.DisambiguationTopicRegex.Match(currentTopic.Name).Groups["Topic"].Value;
                if(endTopic.Name.EqualsOrdinalIgnoreCase(ambiguousTopicName))
                    return true;
            }

            //If we get here then try to compare the page titles in the event of a redirect. Otherwise just compare the topics
            return endTopic.PageTitle.EqualsOrdinalIgnoreCase(currentTopic.PageTitle)
                || endTopic.Name.EqualsOrdinalIgnoreCase(currentTopic.Name);
        }
Exemplo n.º 3
0
        private Topic CreateTopic(string topicUrl, HtmlDocument htmlDocument)
        {
            var topic = new Topic
            {
                DateCreated = DateTime.Now,
                Name = GetTopicNameFromUrl(topicUrl),
            };

            var titleNode = htmlDocument.GetElementbyId("firstHeading");
            topic.PageTitle = titleNode != null ? titleNode.InnerHtml : string.Empty;

            CreateRelatedTopics(topic, htmlDocument);

            _topicCache.SetTopic(topic.Name, topic);
            _topicCache.SetTopicHtml(topic.Name, GetHtmlFromDocument(htmlDocument));

            return topic;
        }
Exemplo n.º 4
0
 public GameResult(Topic currentTopic)
 {
     CurrentTopic = currentTopic;
     Success = true;
 }
Exemplo n.º 5
0
        private void CreateRelatedTopics(Topic topic, HtmlDocument htmlDocument)
        {
            var relatedTopics = GetRelatedTopics(htmlDocument);

            //Remove current topic from list
            relatedTopics = relatedTopics.Where(x => !x.Equals(GetTopicNameFromUrl(topic.Name), StringComparison.OrdinalIgnoreCase));

            topic.RelatedTopics = relatedTopics.ToList();
        }