siva prasad sandireddy. why isolated storage? introduction data compartment isolated storage...

17
SIVA PRASAD SANDIREDDY

Upload: sydney-green

Post on 18-Jan-2016

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

SIVA PRASAD SANDIREDDY

Page 2: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

WHY ISOLATED STORAGE? INTRODUCTION DATA COMPARTMENT ISOLATED STORAGE TASKS STORES OF ISOLATED STORAGE ANTISPATING OUT OF SPACE CREATING FILES AND DIRECTORIES FINDING EXESTING FILES AND DIRECTORIES READ AND WRITE TO FILES DELETING FILES AND DIRECTORIES System.IO.IsolatedStorage Namespace REFERENCES

Page 3: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

Many programmers use the config file to keep the application configuration data.

It is a read only mechanism. In earlier days, .ini files or registry was used

to save application specific data. We can also use ordinary files but security

is the major issue.

Page 4: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

. NET introduces a concept called Isolated Storage. Isolated Storage is a kind of virtual folder. Users never need to know where exactly the file is stored. All have to do is, tell the .NET framework to store files in Isolated Storage.

using System.IO; using System.IO.IsolatedStorage; using System.Diagnostics;

Page 5: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

It is not a specific storage location; it consists of one or more isolated storage files, called stores, which contain the actual  directory locations where data is stored.

The data saved in the store can be any kind of data, from user preference information to application state.

Data compartment is transparent for developer. Stores usually reside on the client  but a server application could use isolated stores.

Page 6: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

Administrators can limit how much isolated storage an application or a user has available, based on an appropriate trust level.

To create or access isolated storage, code must be granted the appropriate

IsolatedStorageFilePermission. To access isolated storage, code must have

all necessary native platform operating system rights since storage location is different depending on sys operating system.

Page 7: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

Three main classes are necessary to perform tasks that involve isolated storage:

IsolatedStorageFile, which derives from IsolatedStorage, provides basic management of stored assembly and application files

IsolatedStorageFileStream, which derives from System.IO.FileStream, provides access to the files in a store.

IsolatedStorageScope is an enumeration that enables you to create and select a store with the appropriate isolation type.

Page 8: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

A store exposes a virtual file system within a data compartment. To create and retrieve stores, IsolatedStorageFile provides three static method.

Methods  GetUserStoreForAssembly or GetUserStoreForDomain  retrieve a store .

The GetStore method can be used to specify that a store should roam with a roaming user profile.

Page 9: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

Enumerating stores :  IsolatedStorageFile.GetEnumerator method uses to

calculate the size of all isolated storage for the user. You can enumerate all isolated stores for the current

user using the IsolatedStorageFile static method GetEnumerator. GetEnumerator takes an IsolatedStorageScope value and returns an IsolatedStorageFile enumerator. User is the only IsolatedStorageScope value supported.

GetEnumerator returns an array ofIsolatedStorageFiles that are defined for the current user.

Page 10: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

Deleting stores:  IsolatedStorageFile.Remove method can be used

in two different ways to delete isolated stores. 1) The instance method Remove does not take

any arguments and deletes the store that calls it. No permissions are required for this operation.

2) The static method Remove takes the IsolatedStorageScope value User, and deletes all the stores for the user running the code.

Page 11: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

Code that uses isolated storage is constrained by a quota that specifies the maximum size for the data compartment. This value is specified by Administrators.

If the maximum allowed size is exceeded IsolatedStorageException is thrown and the operation fails.

IsolatedStorage.CurrentSize and IsolatedStorage.MaximumSize. These two properties can be used to determine whether writing to the store will cause the maximum allowed size of the store to be exceeded.

Page 12: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

To create a directory, CreateDirectory(use) instance method of IsolatedStorageFile.  if

you specify a directory name that contains invalid characters, an IsolatedStorageException is generated.

To create and open a file, use the IsolatedStorageFileStream constructors, passing in the file name, the FileMode value OpenOrCreate, and the store in which you want the file created.

Files are case in sensitive.

Page 13: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

Using the GetDirectoryNames instance method of IsolatedStorageFile. Both single-character (?) and multi-character (*) wildcard characters are supported. 

To search for a file, use the GetFileNames instance method of IsolatedStorageFile.

For example, if there is a match on the directory RootDir/SubDir/SubSubDir, SubSubDir will be returned in the results array.

Page 14: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

There are a number of ways to open a file within a store using the IsolatedStorageFileStream class.

Once an IsolatedStorageFileStream has been obtained, it can be used to get a StreamReader or StreamWriter. With the StreamReader and StreamWriter, we can read and write to a file in a store as we would to any other file

Page 15: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

The IsolatedStoreFile class supplies two instance methods for deleting directories and files, DeleteDirectory and DeleteFile.

 AnIsolatedStorageFileException is thrown if you try to delete a file or directory that does not exist.

If a wildcard character is included in the name, then DeleteDirectory throws an IsolatedStorageFileException while DeleteFile throws an ArgumentException.

DeleteDirectory fails if the directory contains any files or subdirectories.

Page 16: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

This name space contains 4 classes:IsolatedStorage : Represents the abstract base

class from which all isolated storage implementations must derive.

IsolatedStorageException : The exception that is thrown when an operation in isolated storage fails.

IsolatedStorageFile: Represents an isolated storage area containing files and directories.

IsolatedStorageFileStream : Exposes a file within isolated storage.

Page 17: SIVA PRASAD SANDIREDDY.  WHY ISOLATED STORAGE?  INTRODUCTION  DATA COMPARTMENT  ISOLATED STORAGE TASKS  STORES OF ISOLATED STORAGE  ANTISPATING

http://msdn.microsoft.com http://devcity.net/articles/42/1/

isolatedstorage.aspx http://www.codeproject.com/KB/dotnet/

IsolatedStorage.aspx http://msdn.microsoft.com/en-us/library/

8dzkff1s(v=VS.80).aspx