0
我使用像緩存localStorage的留存數據:到期的localStorage + Windows Phone的
public void AddtoFavorite(Flight FavoriteFlight)
{
try
{
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Favorite.xml", FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(Flight));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
{
serializer.Serialize(xmlWriter, FavoriteFlight);
}
}
}
}
catch (Exception ex)
{
}
}
而且這種方法獲取數據:
public FavoriteFlight GetFavorite()
{
FavoriteFlight result = new FavoriteFlight();
result.VisibleFavorite = false;
try
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("Favorite.xml", FileMode.Open))
{
XmlSerializer serializer = new XmlSerializer(typeof(Flight));
Flight fav=(Flight)serializer.Deserialize(stream);
result.FlightFavorite = fav;
result.Date = result.FlightFavorite.ArrivalOrDepartDateTime.ToString("dd/MM/yyyy");
result.VisibleFavorite = true;
return result;
}
}
}
catch
{
return result;
}
}
我需要的是localStorage的每24小時到期提到本地存儲的價值,你怎麼做到這一點?
問候