开发者

Silverlight Isolated Storage Best Practices?

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? Iso开发者_如何转开发lated storage is, by nature, user specific, correct?

Thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜