我想在客户端的计算机上存储配置,该计算机是每个设备(不是每个浏览器)保留的,并且可以在所有支持HTML 5的浏览器中访问它。我可以使用Silverlight' Isolated Storage存储此配置,其中所有带有此插件的浏览器都可以读取它。我看到的(我的理解)以下HTML 5技术的缺点
本地存储:Data will be deleted if user clears cache
IndexedDB:Data won't be shared across browsers
文件API:Can't read any arbitrary file without permission of user.用户可能必须拖放文件才能让我读取它,我将在文件中存储一些配置,所以我不希望用户拖动每次我想阅读配置文件时删除文件
是否有任何项目可以帮助我或某些"设计模式"我可以在这种情况下使用?
我应该看看HTML 5以外的东西吗?
通过以下操作但没有成功: https://softwareengineering.stackexchange.com/questions/156682/how-to-move-silverlight-app-to-html5 https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills http://www.manasinc.com/silverlight-and-html5-comparison/
答案 0 :(得分:1)
如果用户清除缓存,则无法保留数据,甚至接近的唯一方法是将数据存储在服务器端(与用户配置文件相关),然后在应用程序连接和发送参数时(例如用户代理和屏幕res)将特定配置重新下载到缓存中。
此外,我怀疑有一种方法可以实现与每个Web浏览器的完全兼容性(与大多数情况一样),但是在存储方面,Web存储是与当前浏览器最兼容的方法。 http://caniuse.com/#feat=namevalue-storage
答案 1 :(得分:0)
// To save (Silverlight Out of browser)
// This code is used when you have a Silvelight runs out of browser and typical local storage won't work, you can create an xml file saved on local c drive and retrieve that data when restarting the app.
XDocument doc = new XDocument(
new XElement("Root",
new XElement("userinit", "john doe")
));
string path = "C:\\Windows\\Temp\\setup.xml";
using (StreamWriter writetext = new StreamWriter(path))
{
doc.Save(writext);
}
// to read, read the same file you save to the saved setup
string path = "C:\\Windows\\Temp\\setup.xml";
//<?xml version="1.0" encoding="utf-8"?>
//<Root>
// <userinit>john doe</userinit>
//</Root>
// from the xml you can extract your saved data
string result = sting.Empty;
if (File.Exists(path))
{
System.IO.StreamReader read = new StreamReader(path);
result = read.ReadToEnd();
}
答案 2 :(得分:0)
// for in browser app
// to save
// you can create a local storage file in the form of xml
// this file will persist as long as you don't clear the browsing history
XDocument doc = new XDocument(
new XElement("Root",
new XElement("userinit", "john doe")
));
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("setup.xml", FileMode.Create, isoStore))
{
doc.Save(isoStream);
}
}
// to read
// the saved xml will be
//<Root><userinit>john doe</userinit></Root>
// you can extract data from there
//
string lineOfData = String.Empty;
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.FileExists("setup.xml"))
return;
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream("setup.xml", FileMode.Open, isf))
{
using (StreamReader sr = new StreamReader(isfs))
{
lineOfData = sr.ReadToEnd();
}
}
}
// get the data from xml
string initials;
XDocument xdoc = XDocument.Parse(lineOfData);
var q = (from c in xdoc.Descendants("userinit")
select c).Single();
_Initial = q.Value;
initials = _Initial;