MSDN Magazine - March 2009 - (Page 17) first four URLs in the table, but it will have the same site identity, which means these two apps could choose to share data with each other on the client by storing data in their shared site store. Quotas A quota is a limit on the amount of isolated storage space that can be used by an application. This includes the data stored in isolated storage as well as some additional overhead for each directory and new file created (KB each). Unlike the .NET Framework, Silverlight uses a concept called quota groups for managing quotas in isolated storage. A quota group is a group of isolated stores that share the same quota. In Silverlight, stores are grouped by site, so all applications that have the same site identity share the same isolated storage quota. For example, all applications hosted on microsoft.com share the same quota. Isolated storage can have zero or more quota groups. Figure 3 shows two hypothetical quota groups: one for microsoft.com and another for blogs.microsoft.com. Each quota group has at most one shared site store and zero or more application stores. By default, each quota group is assigned a default quota of MB. This should be enough space for applications to store simple settings and text files in isolated storage. However, since the quota is shared across all applications from the same site, the quota can easily be reached if just one of the applications uses a lot of space. If a site hosts several Silverlight applications and each application stores data in isolated storage, the amount of free space can diminish quickly. In addition, if an application needs to save a lot of data on the client, MB of free space won’t always be enough. To address this, if an application needs more space in isolated storage, it can request a larger quota. When an application requests a larger quota, Silverlight prompts the end user to allow or deny the request. The following code shows how to request a larger quota: using (var store = IsolatedStorageFile.GetUserStoreForApplication()) { // 5 MB of isolated storage space is needed int spaceNeeded = 1024 * 1024 * 5; if (store.AvailableFreeSpace < spaceNeeded) { if (store.IncreaseQuotaTo(store.Quota + spaceNeeded)) { // The user accepted the request } } } In this code, the AvailableFreeSpace property is used to determine how much free space is available in isolated storage. The code knows it needs MB of free space. And if MB is not available, it requests a larger quota by calling IncreaseQuotaTo passing it the requested quota size in bytes (in this case the current quota plus the additional space that’s needed). The call to IncreaseQuota must be made from a user-initiated event, such as within a handler for a button-click event. If it is not called from a user-initiated event, Silverlight will not prompt the user and the request will be denied (the method will return false). If called from a user-initiated event and the end user allows the request, IncreaseQuotaTo returns true and the quota for the group is increased to the requested size. Because quotas are per site in Silverlight, you may want to host your Silverlight application differently depending upon the needs msdnmagazine.com March 2009 17 http://www.microsoft.com http://www.microsoft.com http://www.scaleoutsoftware.com http://www.scaleoutsoftware.com http://www.msdnmagazine.com
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.