private async Task InitializeImpl()
{
try
{
_comments = await Comments.GetInstance();
_links = await Links.GetInstance();
_subreddits = await Subreddits.GetInstance();
_statistics = await UsageStatistics.GetInstance();
//tell the key value pair infrastructure to allow duplicates
//we dont really have a key, all we actually wanted was an ordered queue
//the duplicates mechanism should give us that
_actionsDb = await DB.CreateAsync(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\actions_v2.ism", DBCreateFlags.None,
ushort.MaxValue - 100,
new DBKey[] { new DBKey(8, 0, DBKeyFlags.KeyValue, "default", true, false, false, 0) });
_historyDb = await DB.CreateAsync(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\history_v2.ism", DBCreateFlags.None);
_settingsDb = await DB.CreateAsync(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\settings_v2.ism", DBCreateFlags.None);
_blobStoreDb = await DB.CreateAsync(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\blobs_v3.ism", DBCreateFlags.None, 0,
new DBKey[]
{
new DBKey(4, 0, DBKeyFlags.Integer, "default", false, false, false, 0),
new DBKey(8, 4, DBKeyFlags.AutoTime, "timestamp", false, true, false, 1)
});
_imageAPIDb = await DB.CreateAsync(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\image_api_v1.ism", DBCreateFlags.None, 64000);
_imageDb = await DB.CreateAsync(Windows.Storage.ApplicationData.Current.LocalFolder.Path + "\\image_v1.ism", DBCreateFlags.None, 0);
//get our initial action queue state
var actionCursor = await _actionsDb.SeekAsync(_actionsDb.GetKeys().First(), "action", DBReadFlags.AutoLock | DBReadFlags.WaitOnLock);
_hasQueuedActions = actionCursor != null;
_settingsCache = new Dictionary<string, string>();
//load all of the settings up front so we dont spend so much time going back and forth
var cursor = await _settingsDb.SeekAsync(DBReadFlags.NoLock);
if (cursor != null)
{
using (cursor)
{
do
{
_settingsCache.Add(cursor.GetKeyString(), cursor.GetString());
} while (await cursor.MoveNextAsync());
}
}
var historyCursor = await _historyDb.SeekAsync(DBReadFlags.NoLock);
if (historyCursor != null)
{
using (historyCursor)
{
do
{
_clickHistory.Add(historyCursor.GetString());
if (_terminateSource.IsCancellationRequested)
return;
} while (await historyCursor.MoveNextAsync());
}
}
}
catch (Exception e)
{
Debug.WriteLine(DBError.TranslateError((uint)e.HResult));
}
}