本文整理汇总了C#中IDatabase.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# IDatabase.Commit方法的具体用法?C# IDatabase.Commit怎么用?C# IDatabase.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDatabase
的用法示例。
在下文中一共展示了IDatabase.Commit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateDatabase
static void PopulateDatabase(IDatabase db, string startDir)
{
DatabaseRoot dbRoot = (DatabaseRoot)db.Root;
// scan all directories starting with startDir
var dirsToVisit = new List<string>() { startDir };
int insertedCount = 0;
while (dirsToVisit.Count > 0)
{
var dirPath = dirsToVisit[0];
dirsToVisit.RemoveAt(0);
// accessing directory information might fail e.g. if we
// don't have access permissions so we'll skip all
try
{
DirectoryInfo dirInfo = new DirectoryInfo(dirPath);
foreach (var di in dirInfo.EnumerateDirectories())
{
dirsToVisit.Add(di.FullName);
}
foreach (var fi in dirInfo.EnumerateFiles())
{
var fe = new FileEntry
{
Path = fi.FullName,
Size = fi.Length,
CreationTimeUtc = fi.CreationTimeUtc,
LastAccessTimeUtc = fi.LastAccessTimeUtc,
LastWriteTimeUtc = fi.LastWriteTimeUtc
};
string name = Path.GetFileName(fe.Path);
dbRoot.FileSizeIndex.Put(fe.Size, fe);
dbRoot.FileNameIndex.Put(name, fe);
dbRoot.FileLastWriteTimeIndex.Put(fe.LastWriteTimeUtc, fe);
++insertedCount;
if (insertedCount % 10000 == 0)
{
Console.WriteLine(String.Format("Inserted {0} FileEntry objects", insertedCount));
db.Commit();
}
}
}
catch
{
}
}
// commit the changes if we're done creating a database
db.Commit();
// when we're finished, each index should have the same
// number of items in it, equal to number of inserted objects
Debug.Assert(dbRoot.FileSizeIndex.Count == insertedCount);
Debug.Assert(dbRoot.FileNameIndex.Count == insertedCount);
Debug.Assert(dbRoot.FileLastWriteTimeIndex.Count == insertedCount);
}
示例2: RemoveOneFileEntry
// change showMemoryStatsto true to see object stats on the console
// before and after removal
static void RemoveOneFileEntry(IDatabase db, DatabaseRoot dbRoot, bool showMemoryStats = false)
{
if (showMemoryStats)
{
Console.WriteLine("Memory stats before removal:");
DumpMemoryUsage(db.GetMemoryUsage().Values);
}
// we pick one object and remove it from all 3 indexes
if (dbRoot.FileSizeIndex.Count == 0)
return;
FileEntry toRemove = null;
foreach (var fe in dbRoot.FileSizeIndex)
{
toRemove = fe;
break;
}
// Remove an object with a given key from all 3 indexes.
// We still need to provide the object because those are
// non-unique indexes, so the same key might point to many
// objects and we only want to remove this specific object.
string name = Path.GetFileName(toRemove.Path);
dbRoot.FileNameIndex.Remove(name, toRemove);
dbRoot.FileSizeIndex.Remove(toRemove.Size, toRemove);
dbRoot.FileLastWriteTimeIndex.Remove(toRemove.LastWriteTimeUtc, toRemove);
// changes are not reflected in the database until we commit
db.Commit();
if (showMemoryStats)
{
Console.WriteLine("Memory stats after removal:");
DumpMemoryUsage(db.GetMemoryUsage().Values);
}
}
示例3: MyCommit
void MyCommit(IDatabase db, bool serializable)
{
if (serializable)
{
db.EndThreadTransaction();
db.BeginThreadTransaction(TransactionMode.Serializable);
}
else
{
db.Commit();
}
}