예제 #1
0
        public void Analyze(IDictionary<string, object> result, ThreadInfo info)
        {
            AskerAnalyzeResult analyzeResult = EnsureTheResult(result);

            var activity = analyzeResult.UserActivities.FirstOrDefault(m => m.User.Id.Equals(info.AuthorId));

            if (activity != null)
            {
                activity.QuestionCount = activity.QuestionCount + 1;
            }
            else
            {
                analyzeResult.UserActivities.Add(new UserActivity { User = info.Author, QuestionCount = 1 });
            }
        }
예제 #2
0
        public void Analyze(IDictionary<string, object> result, ThreadInfo info)
        {
            var body = info.Messages.First().Body;

            if (
                info.Messages.First().Body.ToLowerInvariant().Contains(_keyword) ||
                info.Title.ToLowerInvariant().Contains(_keyword))
            {
                if (!result.ContainsKey(_countResultKey))
                {
                    result.Add(_countResultKey, 0);
                }

                var count = (int)result[_countResultKey];

                result[_countResultKey] = count + 1;
            }
        }
예제 #3
0
        private ThreadInfo MapInfoToModel(Stream stream)
        {
            using (XmlReader reader = XmlReader.Create(stream))
            {
                var xDoc = XDocument.Load(reader);

                var xUsers = xDoc.Element("root").Element("users").Descendants("user");

                var users = (from u in xUsers
                             select new UserInfo
                             {
                                 Id = u.Attribute("id").Value,
                                 DisplayName = u.Element("displayName").Value
                             }).ToList();

                var xMessages = xDoc.Element("root").Element("messages").Descendants("message");

                var messages = (from c in xMessages
                                select new MessageInfo
                                {
                                    Id = c.Attribute("id").Value,
                                    Author = users.Find(m => m.Id.Equals(c.Attribute("authorId").Value)),
                                    CreateOn = DateTime.Parse(c.Element("createdOn").Value),
                                    Body = c.Element("body").Value
                                }).ToList();

                var xThread = xDoc.Element("root").Element("thread");

                var thread = new ThreadInfo
                {
                    Id = xThread.Attribute("id") == null ? string.Empty : xThread.Attribute("id").Value,
                    AuthorId = xThread.Attribute("authorId") == null ? string.Empty : xThread.Attribute("authorId").Value,
                    Title = xThread.Element("topic") == null ? string.Empty : xThread.Element("topic").Value,
                    Url = xThread.Element("url") == null ? string.Empty : xThread.Element("url").Value,
                    CreateOn = DateTime.Parse(xThread.Element("createdOn") == null ? string.Empty : xThread.Element("createdOn").Value), 
                    Answered = Boolean.Parse(xThread.Attribute("answered") == null ? "false" : xThread.Attribute("answered").Value),
                    Views = int.Parse(xThread.Attribute("views") == null ? string.Empty : xThread.Attribute("views").Value),
                    ForumId = xThread.Attribute("discussionGroupId") == null ? string.Empty : xThread.Attribute("discussionGroupId").Value,
                    Messages = messages
                };

                thread.Author = users.Find(x => x.Id.Equals(thread.AuthorId));

                return thread;
            }
        }