本文整理汇总了C#中Provider.Lock方法的典型用法代码示例。如果您正苦于以下问题:C# Provider.Lock方法的具体用法?C# Provider.Lock怎么用?C# Provider.Lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Provider
的用法示例。
在下文中一共展示了Provider.Lock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OrphanTest
private static void OrphanTest()
{
CoincidentalConfiguration config = Provider.Configure
.Connection("test.yap")
.ActivationDepth(1)
.Debugging;
using (Provider db = new Provider())
{
if (File.Exists("test.yap")) File.Delete("test.yap");
db.Initialise(config);
UnTracked untracked = db.Store(new UnTracked { Name = "UnTracked" });
UnTracked other = db.Store(new UnTracked { Name = "Other" });
Tracked tracked = db.Store(new Tracked { Name = "Tracked", ReferenceCount = 10 });
Console.WriteLine("Initial reference count = {0}", tracked.ReferenceCount);
try
{
using (db.Lock(tracked)) tracked.ReferenceCount = 10;
}
catch(Exception e)
{
Console.WriteLine("Exception caught: {0}", e.Message);
}
using (db.Lock(untracked)) untracked.Item = tracked;
Console.WriteLine("Single reference added, count = {0}", tracked.ReferenceCount);
using (db.Lock(other)) other.Item = tracked;
Console.WriteLine("Single reference added to other, count = {0}", tracked.ReferenceCount);
using (db.Lock(untracked.ItemList)) untracked.ItemList.Add(tracked);
Console.WriteLine("Added to list, count = {0}", tracked.ReferenceCount);
using (db.Lock(untracked)) untracked.Item = null;
Console.WriteLine("Single reference removed, count = {0}", tracked.ReferenceCount);
}
using (Provider db = new Provider())
{
db.Initialise(config);
UnTracked untracked = db.Get<UnTracked>(u => u.Name == "UnTracked");
Tracked tracked = db.Get<Tracked>(t => t.Name == "Tracked");
Console.WriteLine("Closed and opened new provider, count = {0}", tracked.ReferenceCount);
using (db.Lock(untracked.ItemList)) untracked.ItemList.Remove(tracked);
Console.WriteLine("Removed from list, count = {0}", tracked.ReferenceCount);
using (db.Lock(untracked)) untracked.Item = tracked;
Console.WriteLine("Single reference added, count = {0}", tracked.ReferenceCount);
}
config = config.AutomaticOrphanPurge;
using (Provider db = new Provider())
{
db.Initialise(config);
UnTracked untracked = db.Get<UnTracked>(u => u.Name == "UnTracked");
UnTracked other = db.Get<UnTracked>(u => u.Name == "Other");
Tracked tracked = db.Get<Tracked>(t => t.Name == "Tracked");
Console.WriteLine("Closed and opened new provider with automatic orphan purge enabled, count = {0}", tracked.ReferenceCount);
db.Delete(other);
Console.WriteLine("Deleted other, count = {0}", tracked.ReferenceCount);
using (db.Lock(untracked)) untracked.Item = null;
Console.WriteLine("Single reference removed, count = {0}", tracked.ReferenceCount);
db.Flush();
tracked = db.Get<Tracked>(t => t.Name == "Tracked");
if (tracked == null) Console.WriteLine("Attempted to re-acquire tracked item, but it was successfully purged");
else Console.WriteLine("Managed to re-acquire tracked item, automatic purging failed!");
}
}