Mini Kabibi Habibi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Xml.Linq;
public class FacebookWidget {
const string SessionKey = "FacebookWidget1";
const string FacebookXml = "~/App_Data/Facebook.xml";
public static FacebookFeedItem LastFeedItem {
get {
if(Session[SessionKey] == null)
Session[SessionKey] = LoadActualData();
return (FacebookFeedItem)Session[SessionKey];
}
}
public static List<FacebookFeedItem> SelectLastFeedItemComments() {
return LastFeedItem.Comments;
}
static FacebookFeedItem LoadActualData() {
XDocument doc = XDocument.Load(HttpContext.Current.Server.MapPath(FacebookXml));
var lastItem = doc.Root.Elements("item").Last();
var commentList = new List<FacebookFeedItem>();
foreach(var comment in lastItem.Element("comments").Elements("item"))
commentList.Add(new FacebookFeedItem() {
Author = comment.Attribute("author").Value,
Description = comment.Value,
Time = comment.Attribute("time").Value,
ImageKey = comment.Attribute("authorImage").Value
});
return new FacebookFeedItem() {
Author = lastItem.Attribute("author").Value,
Description = lastItem.Element("description").Value,
Time = lastItem.Attribute("time").Value,
LikesCount = int.Parse(lastItem.Attribute("likes").Value),
ImageKey = lastItem.Attribute("authorImage").Value,
Comments = commentList
};
}
static HttpSessionState Session { get { return HttpContext.Current.Session; } }
}
public class FacebookFeedItem {
public FacebookFeedItem() {
Comments = new List<FacebookFeedItem>();
}
public string Author { get; set; }
public string Description { get; set; }
public string Time { get; set; }
public int LikesCount { get; set; }
public string ImageKey { get; set; }
public List<FacebookFeedItem> Comments { get; set; }
}