This topic applies to .NET version only
In order to use our special IsolatedStorageFileAdapter the following configuration method should be called.
1private static IConfiguration Configure() 2
{ 3
IConfiguration configuration = Db4oFactory.NewConfiguration(); 4
configuration.MessageLevel(1); 5
configuration.Io(new IsolatedStorageFileAdapter()); 6
return configuration; 7
}
1Private Shared Function Configure() As IConfiguration 2
Dim configuration As IConfiguration = Db4oFactory.NewConfiguration() 3
configuration.MessageLevel(1) 4
configuration.Io(New IsolatedStorageFileAdapter()) 5
Return configuration 6
End Function
In this example we will use debug message level = 1 to see what is happening in the console.
Let's try to save some objects and retrieve them. Remember, that the path in the Isolated Storage is not the path on the file system. For simplicity you can specify the database file with only the file name. For more information about creating directory structure in the Isolated Storage, please refer to the appropriate documentation.
Run the following examples and check the output in the
console to see how the IsolatedStorageFileAdapter
works:
01private static void TestStore() 02
{ 03
IObjectContainer db = Db4oFactory.OpenFile(Configure(), Db4oFileName); 04
try 05
{ 06
Pilot pilot = new Pilot("Michael Schumacher"); 07
db.Set(pilot); 08
System.Console.WriteLine("New pilot added"); 09
} 10
finally 11
{ 12
db.Close(); 13
} 14
}
01private static void TestRetrieve() 02
{ 03
IObjectContainer db = Db4oFactory.OpenFile(Configure(), Db4oFileName); 04
try 05
{ 06
IObjectSet result = db.Get(typeof(Pilot)); 07
ListResult(result); 08
} 09
finally 10
{ 11
db.Close(); 12
} 13
}
01Private Shared Sub TestStore() 02
Dim db As IObjectContainer = Db4oFactory.OpenFile(Configure(), Db4oFileName) 03
Try 04
Dim pilot As New Pilot("Michael Schumacher") 05
db.[Set](pilot) 06
System.Console.WriteLine("New pilot added") 07
Finally 08
db.Close() 09
End Try 10
End Sub
1Private Shared Sub TestRetrieve() 2
Dim db As IObjectContainer = Db4oFactory.OpenFile(Configure(), Db4oFileName) 3
Try 4
Dim result As IObjectSet = db.[Get](GetType(Pilot)) 5
ListResult(result) 6
Finally 7
db.Close() 8
End Try 9
End Sub
There is one more thing to remember: delete file operation does not belong to db4o API, so if we need to delete the database from within the application we will need to use Isolated Storage functions:
1private static void TestDelete() 2
{ 3
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly(); 4
isf.DeleteFile(Db4oFileName); 5
}
1Private Shared Sub TestDelete() 2
Dim isf As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForAssembly() 3
isf.DeleteFile(Db4oFileName) 4
End Sub