Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/ASP.NET/VB/TouchBoard/App_Code/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/ASP.NET/VB/TouchBoard/App_Code/FacebookWidget.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.SessionState
Imports System.Xml.Linq

Public Class FacebookWidget
	Private Const SessionKey As String = "FacebookWidget1"
	Private Const FacebookXml As String = "~/App_Data/Facebook.xml"

	Public Shared ReadOnly Property LastFeedItem() As FacebookFeedItem
		Get
			If Session(SessionKey) Is Nothing Then
				Session(SessionKey) = LoadActualData()
			End If
			Return CType(Session(SessionKey), FacebookFeedItem)
		End Get
	End Property
	Public Shared Function SelectLastFeedItemComments() As List(Of FacebookFeedItem)
		Return LastFeedItem.Comments
	End Function
	Private Shared Function LoadActualData() As FacebookFeedItem
		Dim doc As XDocument = XDocument.Load(HttpContext.Current.Server.MapPath(FacebookXml))
		Dim lastItem = doc.Root.Elements("item").Last()
		Dim commentList = New List(Of FacebookFeedItem)()
		For Each comment In lastItem.Element("comments").Elements("item")
			commentList.Add(New FacebookFeedItem() With {.Author = comment.Attribute("author").Value, .Description = comment.Value, .Time = comment.Attribute("time").Value, .ImageKey = comment.Attribute("authorImage").Value})
		Next comment
		Return New FacebookFeedItem() With {.Author = lastItem.Attribute("author").Value, .Description = lastItem.Element("description").Value, .Time = lastItem.Attribute("time").Value, .LikesCount = Integer.Parse(lastItem.Attribute("likes").Value), .ImageKey = lastItem.Attribute("authorImage").Value, .Comments = commentList}
	End Function

	Private Shared ReadOnly Property Session() As HttpSessionState
		Get
			Return HttpContext.Current.Session
		End Get
	End Property
End Class

Public Class FacebookFeedItem
	Public Sub New()
		Comments = New List(Of FacebookFeedItem)()
	End Sub
	Private privateAuthor As String
	Public Property Author() As String
		Get
			Return privateAuthor
		End Get
		Set(ByVal value As String)
			privateAuthor = value
		End Set
	End Property
	Private privateDescription As String
	Public Property Description() As String
		Get
			Return privateDescription
		End Get
		Set(ByVal value As String)
			privateDescription = value
		End Set
	End Property
	Private privateTime As String
	Public Property Time() As String
		Get
			Return privateTime
		End Get
		Set(ByVal value As String)
			privateTime = value
		End Set
	End Property
	Private privateLikesCount As Integer
	Public Property LikesCount() As Integer
		Get
			Return privateLikesCount
		End Get
		Set(ByVal value As Integer)
			privateLikesCount = value
		End Set
	End Property
	Private privateImageKey As String
	Public Property ImageKey() As String
		Get
			Return privateImageKey
		End Get
		Set(ByVal value As String)
			privateImageKey = value
		End Set
	End Property
	Private privateComments As List(Of FacebookFeedItem)
	Public Property Comments() As List(Of FacebookFeedItem)
		Get
			Return privateComments
		End Get
		Set(ByVal value As List(Of FacebookFeedItem))
			privateComments = value
		End Set
	End Property
End Class