1: private void OnPostServing(object sender, ServingEventArgs e)
2: { 3: IPublishable ipub = ((IPublishable)sender);
4:
5: string body = String.Empty;
6:
7: //Check For Single Post View, When viewing Specific Post, basically through post.aspx
8: if (e.Location == ServingLocation.SinglePost)
9: { 10: if (File.Exists(_FileName))
11: { 12: string pattern = _settings.GetSingleValue("ExecludedIPs"); 13: string ip = HttpContext.Current.Request.UserHostAddress;
14: bool matchedIp = (!string.IsNullOrEmpty(pattern) && Regex.IsMatch(ip, pattern));
15:
16: //Do not count view of authenticated users and users who have IPs match execluded IPs pattern
17: if (!matchedIp && !HttpContext.Current.Request.IsAuthenticated)
18: { 19: int viewCount;
20: //Fetch out total views of current viewing post.
21: Dictionary<string, int> posts = IncrementPostViewCount(ipub.Id.ToString(), out viewCount);
22:
23: //Save list of posts in Xml File with new counted post.
24: WriteToXml(posts);
25:
26: //Override the body of the post (temporary) to display total views
27: body = String.Format("<br/> Views({0})", viewCount); 28: }
29: else
30: { 31: int viewCount = GetPostViewCount(ipub.Id.ToString());
32:
33: //Override the body of the post (temporary) to display total views
34: body = String.Format("<br/> Views({0})", viewCount); 35: }
36: }
37: }
38: //Check For Post List View, basically through main default.aspx or using postlist.ascx usercontrol
39: else if (e.Location == ServingLocation.PostList)
40: { 41: int viewCount = GetPostViewCount(ipub.Id.ToString());
42:
43: //Override the body of the post (temporary) to display total views
44: body = String.Format("<br/> Views({0})", viewCount); 45: }
46:
47: if (bool.Parse(_settings.GetSingleValue("AuthenticatedOnly")) && !HttpContext.Current.Request.IsAuthenticated) 48: return;
49:
50: e.Body += body;
51: }