本文整理汇总了C#中Database.Load方法的典型用法代码示例。如果您正苦于以下问题:C# Database.Load方法的具体用法?C# Database.Load怎么用?C# Database.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DatabaseErrosWithetId
public void DatabaseErrosWithetId()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var core = new FileCore<int, long>(new Seed32(999));
var formatter = TestResourceFactory.CreateJsonFormatterWithoutArrayFormatting();
var stopWatch = new Stopwatch();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", core))
{
db.Load();
using (var t = db.BeginTransaction())
{
var a = TestResourceFactory.CreateRandom();
a.Id = 5;
var obj = JObject.FromObject(a, formatter.Serializer);
db.AddJObj(obj);
}
}
}
示例2: SelectExpressionReturnsItems
public void SelectExpressionReturnsItems()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
var first = objs.FirstOrDefault() as MockClassC;
var select = new WhereExpression(
new CompareToken("ReferenceCode", CompareEnum.Like, first.ReferenceCode),
new CompareToken("Location.X", CompareEnum.Equals, first.Location.X),
new CompareToken("Name", CompareEnum.Like, first.Name.Substring(1, first.Name.Length - 2)));
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
var eval = new ExpressionResolver<int, MockClassA>(db);
db.Load();
using (var t = db.BeginTransaction())
{
objs.ToList().ForEach(o => o.Id = db.Add(o));
t.Commit();
var results = eval.ExecuteSelect(select);
Assert.AreEqual(1, results.Count);
MockClassC.Validate(results[0].ToObject<MockClassC>(), objs.FirstOrDefault() as MockClassC);
}
}
}
示例3: SubscriberInititializes
public void SubscriberInititializes()
{
_testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var pdb = new Database<int, MockClassA>(_testName + ".publisher" + ".database", "Id")
.WithPublishing("Test", new FilePublisher<int, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName))))
{
pdb.Load();
Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
using (var sdb = new Database<int, MockClassA>(_testName + ".subscriber" + ".database", "Id")
.WithSubscription("Test", new FileSubscriber<int, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
{
sdb.Load();
Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
sdb.Flush();
}
pdb.Flush();
}
}
}
示例4: SelectExpressionReturnsFirstItems
public void SelectExpressionReturnsFirstItems()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
var max = objs.Cast<MockClassC>().Max(o => o.Location.X);
var min = objs.Cast<MockClassC>().Min(o => o.Location.X);
var first = objs.FirstOrDefault() as MockClassC;
var select = new WhereExpression(10, true, new CompareToken("Location.X", CompareEnum.Greater, max - min));
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
var eval = new ExpressionResolver<int, MockClassA>(db);
db.Load();
using (var t = db.BeginTransaction())
{
objs.ToList().ForEach(o => o.Id = db.Add(o));
t.Commit();
var results = eval.ExecuteSelect(select);
Assert.LessOrEqual(results.Count, 10);
foreach (var result in results)
MockClassC.Validate(result.ToObject<MockClassC>(), objs.FirstOrDefault(o => o.Id == result.Value<int>("Id")) as MockClassC);
}
}
}
示例5: DatabasedisallowsDuplicateIndexName
public void DatabasedisallowsDuplicateIndexName()
{
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>())
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString())
.WithIndex<string>("catIndex", "CatalogName", new BinConverterString()))
{
db.Load();
}
}
示例6: UpdateFromQuery
public void UpdateFromQuery()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
objs.OfType<MockClassC>().ToList().ForEach(o => o.ReferenceCode = null);
var first = objs.FirstOrDefault() as MockClassC;
var refCode = "R " + new Random().Next();
var select = new ScalarSelectExpression(
new string[] { "Location.Y" },
new CompareToken("Id", CompareEnum.Equals, 1),
new CompareToken("Location.X", CompareEnum.Equals, first.Location.X),
new CompareToken("Name", CompareEnum.Like, first.Name.Substring(1, first.Name.Length - 2)));
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
var eval = new ExpressionResolver<int, MockClassA>(db);
db.Load();
using (var t = db.BeginTransaction())
{
objs.ToList().ForEach(o => o.Id = db.Add(o));
t.Commit();
}
using (var t = db.BeginTransaction())
{
var count = eval.ExecuteUpdate(
new UpdateExpression(
typeof(MockClassC).AssemblyQualifiedName,
select,
new UpdateToken("Location.Y", 133.33, ValueEnum.Float),
new UpdateToken("Location.Z", 222.11, ValueEnum.Float),
new UpdateToken("ReferenceCode", refCode)));
Assert.AreEqual(1, count);
t.Commit();
var results = eval.ExecuteScaler(select);
Assert.AreEqual(1, results.Count);
Assert.AreEqual(133.33f, ((MockClassC)db.Fetch(1)).Location.Y);
Assert.AreEqual(222.11f, ((MockClassC)db.Fetch(1)).Location.Z);
Assert.AreEqual(refCode, ((MockClassC)db.Fetch(1)).ReferenceCode);
}
}
}
示例7: DatabaseDeletesFirstLastWithActiveTransactions
public void DatabaseDeletesFirstLastWithActiveTransactions()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
var ids = new List<int>();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id", new FileCore<int, long>(), new BinConverter32(), new JSONFormatter()))
{
db.Load();
var t = db.BeginTransaction();
objs.ToList().ForEach(o => ids.Add(db.Add(o)));
var last = db.SelectLast(s => true, 1).LastOrDefault();
Assert.IsNotNull(last);
var count = db.Update(s => s.Value<string>("Name") == last.Name
, new System.Action<MockClassA>(a => a.Name = "last"));
Assert.AreEqual(1, count);
var selected = db.Select(s => true);
Assert.AreEqual(100, selected.Count);
count = db.DeleteFirst(s => true, 10);
Assert.AreEqual(10, count);
selected = db.Select(s => true);
Assert.AreEqual(90, selected.Count);
count = db.DeleteLast(s => true, 10);
Assert.AreEqual(10, count);
selected = db.Select(s => true);
Assert.AreEqual(80, selected.Count);
t.Rollback();
}
}
}
示例8: PublisherQueuesTransactionsOnPause
public void PublisherQueuesTransactionsOnPause()
{
_testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
db.Add(TestResourceFactory.CreateRandom());
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database")
.WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
{
db.Load();
Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
using (var fs = File.Create(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause")))
{
fs.Flush();
}
using (var tran = db.BeginTransaction())
{
TestResourceFactory.GetMockClassAObjects(25).ToList().ForEach(m => db.Add(m));
tran.Commit();
}
Thread.Sleep(100);
Assert.AreEqual(0, Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count());
File.Delete(Path.Combine(Environment.CurrentDirectory, _testName, "test.pause"));
Thread.Sleep(3000);
Assert.Greater(Directory.GetFiles(Path.Combine(Environment.CurrentDirectory, _testName), "*.trans").Count(), 0);
db.FlushAll();
}
}
}
示例9: PublisherInititializes
public void PublisherInititializes()
{
_testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id")
.WithPublishing("Test", new FilePublisher<int, MockClassA>(_testName)))
{
db.Load();
Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
db.Flush();
}
}
示例10: Main
private static void Main()
{
var dataDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data");
//Directory.Delete(dataDirectory, true);
using (var db = new Database(dataDirectory,
x =>
{
x.AddProjectionsFromAssemblyContaining<Program>();
x.AddQueriesFromAssemblyContaining<Program>();
}))
{
//CreateData(db);
var player = db.Load<Player>(1);
}
}
示例11: AddOrUpdateWithoutIdAddsWithIdZeroAndUpdatesWithNonZeroId
public void AddOrUpdateWithoutIdAddsWithIdZeroAndUpdatesWithNonZeroId()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
objs.ToList().ForEach(o => o.Id = db.AddOrUpdate(o));
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database"))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNotNull(last);
last.Name = "last";
db.AddOrUpdate(last);
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
var last = db.Fetch(objs.Last().Id);
Assert.IsNotNull(last);
Assert.AreEqual("last", last.Name);
Assert.IsNotNull(db.Fetch(objs.First().Id));
db.FlushAll();
}
}
}
示例12: SubscriberPicksUpTransaction
public void SubscriberPicksUpTransaction()
{
_testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var pdb = new Database<Guid, MockClassA>(_testName + ".publisher" + ".database", "ReplicationID")
.WithPublishing("Test", new FilePublisher<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName))))
{
pdb.Load();
Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
using (var sdb = new Database<Guid, MockClassA>(_testName + ".subscriber" + ".database", "ReplicationID")
.WithSubscription("Test", new FileSubscriber<Guid, MockClassA>(Path.Combine(Environment.CurrentDirectory, _testName), new TimeSpan(0, 0, 0, 0, 500))))
{
sdb.Load();
Assert.IsTrue(Directory.Exists(Path.Combine(Environment.CurrentDirectory, _testName)));
var objects = TestResourceFactory.GetMockClassAObjects(25).OfType<MockClassC>().ToList();
//objects.ForEach(o => o.ReplicationID = Guid.Empty);
using (var tran = pdb.BeginTransaction())
{
objects.ForEach(o => o.ReplicationID = pdb.Add(o));
tran.Commit();
}
var sw = new Stopwatch();
sw.Start();
while (sdb.Fetch(objects.First().ReplicationID) == null && sw.ElapsedMilliseconds < 6000)
Thread.Sleep(750);
Assert.IsNotNull(sdb.Fetch(objects.First().ReplicationID));
sdb.Flush();
}
pdb.Flush();
}
}
}
示例13: TcpListenerRecivesPublisher
public void TcpListenerRecivesPublisher()
{
_testName = System.Reflection.MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
var random = new Random((int)(DateTime.Now.Ticks / 7335));
var port = random.Next(8355, 10000);
using (var fLock = new ManagedFileLock(_testName))
{
Cleanup();
using (var pdb = new Database<int, MockClassA>(_testName + ".database", "Id")
.WithPublishing("Test", new TcpTransactionPublisher<int, MockClassA>(IPAddress.Parse("127.0.0.1"), port, 1, new TcpSettings())))
{
pdb.Load();
using (var sdb = new Database<int, MockClassA>(_testName + ".subscriber" + ".database", "Id")
.WithSubscription("Test", new TcpTransactionSubscriber<int, MockClassA>(port)))
{
sdb.Load();
var obj = TestResourceFactory.CreateRandom();
using (var t = pdb.BeginTransaction())
{
obj.Id = pdb.Add(obj);
t.Commit();
}
var sw = new Stopwatch();
sw.Start();
while (sdb.Fetch(obj.Id) == null && sw.ElapsedMilliseconds < 2000)
Thread.Sleep(100);
Assert.IsNotNull(sdb.Fetch(obj.Id));
sdb.Flush();
}
pdb.Flush();
}
}
}
示例14: DatabaseAddsUpdatesAndQueriesActiveTransaction
public void DatabaseAddsUpdatesAndQueriesActiveTransaction()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objects = TestResourceFactory.GetMockClassAObjects(12);
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
db.Load();
db.BeginTransaction();
foreach (var obj in objects)
db.AddOrUpdate(obj, 0);
var update = db.Fetch(3);
update.Name = "Updated " + update.Id;
db.AddOrUpdate(update, update.Id);
db.FlushAll();
}
using (var db = new Database<int, MockClassA>(_testName + ".database"))
{
db.Load();
db.Update<MockClassA>(u => !u.Value<string>("Name").Contains("Updated"), m => m.Name = "batch " + m.Id);
db.FlushAll();
var old = db.Select(s => s.Value<string>("Name").Contains("Updated"));
Assert.AreEqual(1, old.Count);
Assert.AreEqual("Updated 3", old.Single().Name);
var updates = db.SelectFirst(s => s.Value<string>("Name").Contains("batch"), 11);
Assert.AreEqual(11, updates.Count);
Assert.AreEqual(1, updates.First().Id);
Assert.AreEqual(12, updates.Last().Id);
}
}
示例15: DeletesFromQuery
public void DeletesFromQuery()
{
_testName = MethodInfo.GetCurrentMethod().Name.GetHashCode().ToString();
Cleanup();
var objs = TestResourceFactory.GetMockClassAObjects(100).ToList();
var first = objs.FirstOrDefault() as MockClassC;
var delete = new DeleteExpression(
new CompareToken("ReferenceCode", CompareEnum.Like, first.ReferenceCode.Substring(1, first.ReferenceCode.Length - 2)),
new CompareToken("ReferenceCode", CompareEnum.Equals, first.ReferenceCode),
new CompareToken("ReferenceCode", CompareEnum.NotEquals, first.Name),
new CompareToken("ReferenceCode", CompareEnum.NotEquals, null),
new CompareToken("Name", CompareEnum.Greater, "Z" + first.Name),
new CompareToken("Name", CompareEnum.GreaterOrEqual, first.Name),
new CompareToken("Name", CompareEnum.Lesser, "A" + first.Name.Substring(1, first.Name.Length - 1)),
new CompareToken("Name", CompareEnum.LesserOrEqual, "A" + first.Name));
using (var db = new Database<int, MockClassA>(_testName + ".database", "Id"))
{
var eval = new ExpressionResolver<int, MockClassA>(db);
db.Load();
using (var t = db.BeginTransaction())
{
objs.ToList().ForEach(o => o.Id = db.Add(o));
t.Commit();
}
using (var t = db.BeginTransaction())
{
var results = eval.ExecuteDelete(delete);
Assert.AreEqual(1, results);
t.Commit();
Assert.IsNull(db.Fetch(first.Id));
}
Assert.IsNull(db.Fetch(first.Id));
}
}