If you start to explore Windows 8 system folders, you will quickly find a set of the same files presented in various locations:
What are these files? They are generated by Extensible Storage Engine (ESE), indexed sequential access data storage technology. ESE runtime has been a part of Windows since version 2000, empowering such products as Exchange, Active Directory and Desktop Search.
Windows 8 is not an exception. ESE is used by Zune Music, Zune Video, app repository and is available as a native API for all Windows Store app developers.
How to start
While ESE APIs can be used directly, C# developers may find using of a managed wrapper called ManagedEsent more convenient. All code samples in this post use ManagedEsent.
ManagedEsent supports Windows 8 starting from version 1.8. At this moment binaries for v1.8 are not available for download and you will need to compile sources by yourself or download assembly compiled by me to start using library .
The following code samples demonstrate how to create DatabaseRepository class that allows to instantiate ESE database, put, get and delete data. The data are represented by Event class:
public class Event
{
public Guid Id { get; set; }
public string Description { get; set; }
public double Price { get; set; }
public DateTime StartTime { get; set; }
}
Database
Creation of database includes two steps: creation of ESE instance and creation of database itself. Instances can include up to six databases and provide shared transaction log for all attached databases.
Create and configure instance
private Instance _instance;
private string _instancePath;
private string _databasePath;
private const string DatabaseName = "Database";
public void CreateInstance()
{
_instancePath = Path.Combine(ApplicationData.Current.LocalFolder.Path, DatabaseName);
_databasePath = Path.Combine(_instancePath, "database.edb");
_instance = new Instance(_databasePath);
// configure instance
_instance.Parameters.CreatePathIfNotExist = true;
_instance.Parameters.TempDirectory = Path.Combine(_instancePath, "temp");
_instance.Parameters.SystemDirectory = Path.Combine(_instancePath, "system");
_instance.Parameters.LogFileDirectory = Path.Combine(_instancePath, "logs");
_instance.Parameters.Recovery = true;
_instance.Parameters.CircularLog = true;
_instance.Init();
}
Create database
The following function creates database file and configures database schema to store Events.
Read more: LunarFrog
QR:
0 comments:
Post a Comment