, , RSS , .
, using :
using System.IO.IsolatedStorage;
using System.IO;
. :
const string RSSFileName = "rss.xml";
:
void SaveRSSToIsolatedStorage(string RSSText)
{
IsolatedStorageFile rssFileStorage =
IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream rssFileStream =
rssFileStorage.CreateFile(RSSFileName);
StreamWriter sw = new StreamWriter
(rssFileStream);
sw.Write(RSSText);
sw.Close();
rssFileStream.Close();
}
string LoadRSSFromIsolatedStorage()
{
IsolatedStorageFile rssFileStorage =
IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream rssFileStream =
rssFileStorage.OpenFile(RSSFileName,
System.IO.FileMode.Open);
StreamReader sr = new StreamReader
(rssFileStream);
string RSS = sr.ReadToEnd();
sr.Close();
rssFileStream.Close();
return RSS;
}
, .
bool IsRSSExist()
{
IsolatedStorageFile rssFileStorage =
IsolatedStorageFile.GetUserStoreForApplication();
return rssFileStorage.FileExists(RSSFileName);
}
:
void ParseRSSAndBindData(string RSSText)
{
XElement twitterElements = XElement.Parse(RSSText);
var postList =
from tweet in twitterElements.Descendants("item")
select new PostMessage
{
title = tweet.Element("title").Value,
pubDate = tweet.Element("pubDate").Value,
link = tweet.Element("link").Value
};
RssList.ItemsSource = postList;
}
:
void client_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
RSSString = e.Result;
ParseRSSAndBindData(RSSString);
SaveRSSToIsolatedStorage(RSSString);
}
}
LoadRSS():
private void LoadRSS()
{
if (IsRSSExist())
{
RSSString = LoadRSSFromIsolatedStorage();
ParseRSSAndBindData(RSSString);
}
else
{
RequestRSS();
}
}
RequestRSS() LoadRSS():
private void RequestRSS()
{
WebClient client = new WebClient();
client.DownloadStringCompleted += new
DownloadStringCompletedEventHandler(
|
|
client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri(RSS));
}
, .
, .
, , , , , . .
, System.Data.Linq, using :
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.ComponentModel;
using System.Collections.ObjectModel;
, , ([Table] [Column] ) 2 INotifyPropertyChanged, INotifyPropertyChanging, .
, DataContext . .
, : http://msdn.microsoft.com/en-us/library/hh202876(v=VS.92).aspx
, MVVM : http://go.microsoft.com/fwlink/?LinkId=219066, http://msdn.microsoft.com/en-us/library/hh286405(v=VS.92).aspx