Silverlight 隔离存储最佳实践?

发布于 2024-11-05 10:43:24 字数 343 浏览 0 评论 0原文

我刚刚开始真正进入 Silverlight 开发,并且有一个特定的用例,我需要为特定用户的“会话”存储几个对象或字符串的集合。 我希望它是特定于用户的并且可以在整个 Silverlight 应用程序中访问。

我的第一个想法是在 App.xaml 上添加静态属性。

用户登录时,我将从 API 调用中检索该用户有权访问的对象列表,然后将这些对象存储在 App.xaml 的静态属性中。

然后我可以在整个 xaml 页面中访问这些属性。

我的问题是,这真的是针对特定用户的吗? 这是最佳实践吗? 在这种情况下我应该使用独立存储吗? 隔离存储有哪些限制? 隔离存储本质上是特定于用户的,对吗?

谢谢

I'm just starting to really get into Silverlight development and I have a certain use case where I need to store a couple collections of objects or strings for a specific user's "sessions".
I want this to be user specific and accessible throughout the Silverlight application.

My first thought was to add static properties on the App.xaml.

On user login, I'm retrieving lists of objects that this user has access to from an API call, then storing those in the static properties of the App.xaml.

Then I can access those properties throughout the xaml pages.

My question is, is this truly user specific?
Is this best practice?
Should I use isolated storage in this case instead?
What are the limitations of isolated storage?
Isolated storage is, by nature, user specific, correct?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情丝乱 2024-11-12 10:43:24

独立存储与用户配置文件一起存储在登录用户的计算机上。您可以存储每个网站和/或网站内每个应用程序的数据;网站本质上被定义为 XAP 文件源 URL,例如 http://www.somedomain.com。应用程序将是实际完全限定的 XAP 源,例如 http://www.somedomain.com/ClientBin /App.Xap

同一登录用户可以通过 IE、Safari 等访问由 Firefox 编写的独立存储。默认情况下您有 1 MB。

当您使用 IS 存储数据时,您将使用流(二进制或文本)写入文件,但写入的文件不会以您在用户文件系统上保存的名称存储。默认情况下,您可以获得 1 MB 的存储空间,但您可以向用户请求更多存储空间。您应该询问您需要什么以及当前使用的间距。您只能通过用户交互(例如单击按钮)要求用户增加配额。最好的做法是只询问您需要的内容。

var is = IsolatedStorageFile.GetUserStoreForApplication();
var freespace = is.AvailableFreeSpace;
var whatyouneed = 10485760; // Request 10 MB
is.IncreaseQuotaTo( is.Quota + whatyouneed );

您还应该处理用户拒绝向您提供您请求的空间的情况。

您永远不应该假设存储的内容将始终存在,因为用户可以通过 Silverlight 插件清除其 IS。此外,您可以完全清除 IS 或删除不再需要的文件。请记住这一点,因为用户无法仅删除 IS 中的某些项目,也没有“dir”命令或方法来查看您存储了哪些文件;你需要知道这个名字。

Isolated storage is stored with the user profile on the machine of the logged in user. You can store data per website and/or per application within website; a website is essentially defined as a XAP file source URL such as http://www.somedomain.com. An application would be an actual fully qualified XAP source such as http://www.somedomain.com/ClientBin/App.Xap.

Isolated storage written from Firefox will be accessible from IE, Safari, etc. on that same logged in user. By default you have 1 MB.

When you store data using IS, you will write files using streams (binary or text) but the written files are not stored in the names you save them on the user filesystem. By default you get get 1 MB for storage, but you can request more storage from the user. You should ask for what you need plus the currently used spaced. You can only ask the user to increase the quota as the result of a user interaction such as a button click. It is a best practice for you to only ask for what you need.

var is = IsolatedStorageFile.GetUserStoreForApplication();
var freespace = is.AvailableFreeSpace;
var whatyouneed = 10485760; // Request 10 MB
is.IncreaseQuotaTo( is.Quota + whatyouneed );

You should also handle situations where the user refuses to give you the space you request.

You should never assume that something stored will always be there as users can clear out their IS through the Silverlight plugin. Also, you can either clear out IS completely or delete the files you no longer need. Keep this in mind as there is no way for a user to delete only certain items in the IS nor is there a "dir" command or way to see what files you have stored; you need to know the name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文