本文整理汇总了C#中SessionNoServer.Open方法的典型用法代码示例。如果您正苦于以下问题:C# SessionNoServer.Open方法的具体用法?C# SessionNoServer.Open怎么用?C# SessionNoServer.Open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionNoServer
的用法示例。
在下文中一共展示了SessionNoServer.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TwoUpdaters1
public void TwoUpdaters1()
{
Assert.Throws<OptimisticLockingFailed>(() =>
{
UInt64 id;
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Man man = new Man();
man.Persist(session, man);
id = man.Id;
session.Commit();
session.BeginUpdate();
man.Age = ++man.Age;
Database db = session.NewDatabase(3567);
using (SessionNoServer session2 = new SessionNoServer(systemDir))
{
session2.BeginUpdate();
Man man2 = (Man)session2.Open(id);
Assert.Less(man2.Age, man.Age);
man2.Age = ++man.Age;
session2.Commit();
}
session.DeleteDatabase(db);
session.Commit(); // OptimisticLockingFailed here
}
});
}
示例2: SingleReaderSingleUpdater1
public void SingleReaderSingleUpdater1()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Man man = new Man();
man.Persist(session, man);
session.Commit();
}
UInt64 id;
using (SessionNoServer session = new SessionNoServer(systemDir, 5000))
{
session.BeginUpdate();
Man man = new Man();
man.Persist(session, man);
id = man.Id;
using (SessionNoServer session2 = new SessionNoServer(systemDir))
{
session2.BeginRead();
Man man2 = (Man)session2.Open(id);
Assert.Null(man2);
session2.Commit();
}
session.Commit();
}
}
示例3: hashCodeComparerStringTest
public void hashCodeComparerStringTest()
{
Oid id;
using (SessionNoServer session = new SessionNoServer(systemDir))
{
Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
session.Compact();
session.BeginUpdate();
HashCodeComparer<string> hashCodeComparer = new HashCodeComparer<string>();
BTreeSet<string> bTree = new BTreeSet<string>(hashCodeComparer, session);
bTree.Persist(place, session);
id = bTree.Oid;
for (int i = 0; i < 100000; i++)
{
bTree.Add(i.ToString());
}
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginRead();
BTreeSet<string> bTree= (BTreeSet<string>)session.Open(id);
int count = 0;
foreach (string str in bTree)
{
count++;
}
Assert.True(100000 == count);
session.Commit();
}
}
示例4: GermanString
public void GermanString()
{
UInt64 id = 0;
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = new VelocityDbSchema.Person();
person.LastName = "Med vänliga hälsningar";
id = session.Persist(person);
trans.Complete();
}
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
person.LastName = "Mit freundlichen Grüßen";
trans.Complete();
}
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
using (var trans = new TransactionScope())
{
session.BeginUpdate();
VelocityDbSchema.Person person = session.Open<VelocityDbSchema.Person>(id);
person.LastName = "Med vänliga hälsningar";
trans.Complete();
}
}
}
示例5: outputSomeInfo
static void outputSomeInfo(SessionNoServer session)
{
IndexRoot indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
BTreeSetOidShort<Word> wordSet = indexRoot.lexicon.WordSet;
using (StreamWriter writer = new StreamWriter("Wikipedia.txt"))
{
writer.WriteLine("Number of words in Lexicon is: " + wordSet.Count);
foreach (Word word in wordSet)
{
writer.WriteLine(word.aWord + " " + word.DocumentHit.Count);
}
writer.Close();
}
}
示例6: Get
public string Get(string path, UInt64 id)
{
using (SessionNoServer session = new SessionNoServer(path))
{
session.BeginRead();
object obj = session.Open(id);
JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
jsonSettings.TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full;
jsonSettings.TypeNameHandling = TypeNameHandling.All;
jsonSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
jsonSettings.ContractResolver = new FieldsOnlyContractResolver();
string json = JsonConvert.SerializeObject(obj, jsonSettings);
session.Commit();
return json;
}
}
示例7: LoginButton_Click
protected void LoginButton_Click(object sender, EventArgs e)
{
if (Password.Text.Length == 0)
{
ErrorMessage.Text = "Enter your password.";
return;
}
try
{
using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true))
{
session.BeginUpdate();
Root velocityDbroot = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false);
if (velocityDbroot == null)
{
ErrorMessage.Text = "The entered email address is not registered with this website";
session.Abort();
return;
}
CustomerContact lookup = new CustomerContact(Email.Text, null);
if (!velocityDbroot.customersByEmail.TryGetKey(lookup, ref lookup))
{
ErrorMessage.Text = "The entered email address is not registered with this website";
session.Abort();
return;
}
if (lookup.password != Password.Text)
{
ErrorMessage.Text = "The entered password does not match the registered password";
session.Abort();
return;
}
session.Commit();
Session["UserName"] = lookup.UserName;
Session["Email"] = Email.Text;
Session["FirstName"] = lookup.FirstName;
Session["LastName"] = lookup.LastName;
FormsAuthentication.RedirectFromLoginPage(Email.Text, false);
}
}
catch (System.Exception ex)
{
ErrorMessage.Text = ex.ToString() + ex.Message;
}
}
示例8: Main
static int Main(string[] args)
{
UInt64 id;
AllSupported allSupported, allSupported2;
AllSuportedSub4 sub4;
try
{
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
session.BeginUpdate();
File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"), true);
sub4 = new AllSuportedSub4();
session.Persist(sub4);
id = sub4.Id;
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginRead();
sub4 = (AllSuportedSub4)session.Open(id);
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginUpdate();
allSupported = new AllSupported(3);
session.Persist(allSupported);
id = allSupported.Id;
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginRead();
allSupported2 = (AllSupported)session.Open(id);
session.Commit();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return 1;
}
return 0;
}
示例9: Create3Versions
public void Create3Versions(int numberOfVersions)
{
ProductVersion version = null;
ProductVersion priorVersion = null;
for (int i = 0; i < numberOfVersions; i++)
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
IssueTracker issueTracker = (IssueTracker)session.Open(IssueTracker.PlaceInDatabase, 1, 1, false);
User user = issueTracker.UserSet.Keys[rand.Next(issueTracker.UserSet.Keys.Count - 1)];
string v = "version" + i.ToString();
string d = "vdescription" + i.ToString();
version = new ProductVersion(user, v, d, null);
version.Persist(session, priorVersion ?? version);
issueTracker.VersionSet.Add(version);
priorVersion = version;
session.Commit();
}
}
示例10: Create2Users
public void Create2Users(int numberOfUsers)
{
User user = null;
User priorUser = null;
for (int i = 0; i < numberOfUsers; i++)
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
IssueTracker issueTracker = (IssueTracker)session.Open(IssueTracker.PlaceInDatabase, 1, 1, false);
string email = i.ToString() + "@gmail.com";
string first = "first" + i.ToString();
string last = "last" + i.ToString();
string userName = "username" + i.ToString();
user = new User(user, email, first, last, userName);
user.Persist(session, priorUser ?? user);
issueTracker.UserSet.Add(user);
priorUser = user;
session.Commit();
}
}
示例11: ListWrapperTest
public void ListWrapperTest()
{
// max length of an array is int.MaxValue, objects on a page are serialized to a single byte[] so this array must have a length < int.MaxValue
UInt64 id;
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginUpdate();
var f = new FourPerPage(1);
id = session.Persist(f);
Assert.True(f.IsOK());
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginRead();
var f = session.Open<FourPerPage>(id);
Assert.True(f.IsOK());
session.Commit();
}
}
示例12: LargeObject
public void LargeObject()
{
// max length of an array is int.MaxValue, objects on a page are serialized to a single byte[] so this array must have a length < int.MaxValue
UInt64 id;
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginUpdate();
var large = new LargeObject((int) Math.Pow(2, 25)); // Math.Pow(2, 27) too large to handle with ToBase64String for csv export
id = session.Persist(large);
Assert.True(large.IsOK());
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginRead();
var large = session.Open<LargeObject>(id);
Assert.True(large.IsOK());
session.Commit();
}
}
示例13: LazyLoadDepth
public void LazyLoadDepth()
{
UInt64 id;
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
LazyLoadByDepth lazy = null;
for (uint i = 1; i <= 100; i++)
lazy = new LazyLoadByDepth(i, lazy);
session.Persist(lazy);
id = lazy.Id;
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
UInt32 ct = 100;
session.BeginRead();
LazyLoadByDepth lazy = (LazyLoadByDepth)session.Open(id, false, false, 0); // load only the root of the object graph
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
lazy = lazy.MyRef;
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
lazy = lazy.MyRef;
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
lazy = lazy.MyRef;
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
session.Commit();
}
}
示例14: LazyLoadProperty
public void LazyLoadProperty()
{
UInt64 id;
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
LazyLoadPropertyClass lazy = null;
for (uint i = 1; i <= 10000; i++)
lazy = new LazyLoadPropertyClass(i, lazy);
session.Persist(lazy);
id = lazy.Id;
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
UInt32 ct = 10000;
session.BeginRead();
LazyLoadPropertyClass lazy = (LazyLoadPropertyClass)session.Open(id);
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
lazy = lazy.MyRef;
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
lazy = lazy.MyRef;
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
lazy = lazy.MyRef;
Assert.AreEqual(ct--, lazy.MyCt);
Assert.IsNull(lazy.MyRefPeek);
Assert.NotNull(lazy.MyRef);
Assert.NotNull(lazy.MyRefPeek);
session.Commit();
}
}
示例15: TooLargeObject
public void TooLargeObject()
{
Assert.Throws<OverflowException>(() =>
{
UInt64 id;
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginUpdate();
var large = new LargeObject((int)Math.Pow(2, 28));
id = session.Persist(large);
Assert.True(large.IsOK());
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginRead();
var large = session.Open<LargeObject>(id);
Assert.True(large.IsOK());
session.Commit();
}
});
}