本文整理汇总了C#中KeyValueDB.StartReadOnlyTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# KeyValueDB.StartReadOnlyTransaction方法的具体用法?C# KeyValueDB.StartReadOnlyTransaction怎么用?C# KeyValueDB.StartReadOnlyTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyValueDB
的用法示例。
在下文中一共展示了KeyValueDB.StartReadOnlyTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadOnlyTransactionThrowsOnWriteAccess
public void ReadOnlyTransactionThrowsOnWriteAccess()
{
using (var fileCollection = new InMemoryFileCollection())
using (IKeyValueDB db = new KeyValueDB(fileCollection))
{
using (var tr = db.StartReadOnlyTransaction())
{
Assert.Throws<BTDBTransactionRetryException>(() => tr.CreateKey(new byte[1]));
}
}
}
示例2: Main
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Need to have just one parameter with directory of ObjectDB");
return;
}
var action = "dump";
if (args.Length > 1)
{
action = args[1].ToLowerInvariant();
}
switch (action)
{
case "dump":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc))
using (var odb = new ObjectDB())
{
odb.Open(kdb, false);
using (var tr = odb.StartTransaction())
{
var visitor = new ToStringVisitor();
var iterator = new ODBIterator(tr, visitor);
iterator.Iterate();
var text = visitor.ToString();
Console.WriteLine(text);
}
}
break;
}
case "stat":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc))
{
Console.WriteLine(kdb.CalcStats());
}
break;
}
case "compact":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc, new SnappyCompressionStrategy(), 100 * 1024 * 1024, null))
{
Console.WriteLine("Starting first compaction");
while (kdb.Compact(new CancellationToken()))
{
Console.WriteLine(kdb.CalcStats());
Console.WriteLine("Another compaction needed");
}
Console.WriteLine(kdb.CalcStats());
}
break;
}
case "export":
{
using (var dfc = new OnDiskFileCollection(args[0]))
using (var kdb = new KeyValueDB(dfc))
using (var tr = kdb.StartReadOnlyTransaction())
using (var st = File.Create(Path.Combine(args[0], "export.dat")))
{
KeyValueDBExportImporter.Export(tr, st);
}
break;
}
default:
{
Console.WriteLine($"Unknown action: {action}");
break;
}
}
}