HTML 5中的Silverlight本地存储等效项

问题描述 投票:0回答:3

我想在客户端的计算机上存储配置,该配置是每个设备(不是每个浏览器)持久存储,并在所有支持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/

html5 silverlight local-storage indexeddb fileapi
3个回答
1
投票

如果用户清除缓存,则无法保留数据,甚至接近的唯一方法是将数据存储在服务器端(与用户配置文件相关),然后在应用程序连接和发送参数(例如用户代理和屏幕res)将特定配置重新下载到缓存中。

此外,我怀疑有一种方法可以实现与每个Web浏览器的完全兼容(在大多数情况下也是如此),但是在存储方面,Web存储是与当前浏览器最兼容的方法。 http://caniuse.com/#feat=namevalue-storage


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();
}

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;
© www.soinside.com 2019 - 2024. All rights reserved.