本文整理汇总了C#中SessionNoServer.BeginRead方法的典型用法代码示例。如果您正苦于以下问题:C# SessionNoServer.BeginRead方法的具体用法?C# SessionNoServer.BeginRead怎么用?C# SessionNoServer.BeginRead使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionNoServer
的用法示例。
在下文中一共展示了SessionNoServer.BeginRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static readonly string s_systemDir = "JsonExportImport"; // appended to SessionBase.BaseDatabasePath
static void Main(string[] args)
{
try
{
int personCt = 0;
using (SessionBase session = new SessionNoServer(s_systemDirToImport))
{
session.BeginRead();
IEnumerable<string> personStringEnum = session.ExportToJson<Person>();
using (SessionBase sessionImport = new SessionNoServer(s_systemDir))
{
sessionImport.BeginUpdate();
foreach (string json in personStringEnum)
{
Person person = sessionImport.ImportJson<Person>(json);
sessionImport.Persist(person);
personCt++;
}
session.Commit();
sessionImport.Commit();
Console.WriteLine("Imported " + personCt + " from Json strings");
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例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: Main
static void Main(string[] args)
{
CreateData();
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginRead();
int ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 10000).Count;
Console.WriteLine([email protected]"GeoObj located in San Diego by 10000 meter radius: {ct}");
ct = GeoHashQuery.SearchGeoHashIndex(session, 32.715736, -117.161087, 100000).Count;
Console.WriteLine([email protected]"GeoObj located in San Diego by 100000 meter radius: {ct}");
ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 10000).Count;
Console.WriteLine([email protected]"GeoObj located in New York City by 10000 meter radius: {ct}");
ct = GeoHashQuery.SearchGeoHashIndex(session, 40.730610, -73.935242, 100000).Count;
Console.WriteLine([email protected]"GeoObj located in New York City by 100000 meter radius: {ct}");
// Sweden bounding box
ct = GeoHashQuery.SearchGeoHashIndex(session, 55.34, 10.96, 69.06, 24.17).Count;
Console.WriteLine([email protected]"GeoObj located in Sweden: {ct}");
// Alaska bounding box
ct = GeoHashQuery.SearchGeoHashIndex(session, 51.21, -169.01, 71.39, -129.99).Count;
Console.WriteLine([email protected]"GeoObj located in Alaska: {ct}");
// California bounding box
ct = GeoHashQuery.SearchGeoHashIndex(session, 32.53, -124.42, 42.01, -114.13).Count;
Console.WriteLine([email protected]"GeoObj located in California: {ct}");
// USA bounding box
//GeoHashQuery.SearchGeoHashIndex(session, 18.9, -67.0, 71.4, 172.4);
//Console.WriteLine([email protected]"Persons located in USA: {ct}");
}
}
示例4: 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();
}
}
示例5: LocalDateTest
public void LocalDateTest()
{
LocalDate d1 = new LocalDate(2016, 1, 10);
LocalDate d2 = new LocalDate(2016, 1, 1);
LocalDate d1other = new LocalDate(2016, 1, 10);
Assert.AreNotEqual(d1, d2);
Assert.AreEqual(d1, d1other);
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
LocalDateField test1 = new LocalDateField("def", d1);
session.Persist(test1);
LocalDateField test = new LocalDateField("abc", d2);
session.Persist(test);
var result1 = session.AllObjects<LocalDateField>().First(t => t.Field2.Equals(d2)); // this works
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginRead();
var result2 = session.AllObjects<LocalDateField>().First(t =>
{
var l = t.Field2;
return l.Equals(d2);
}); // this should work and doesnt
session.Commit();
}
}
示例6: Verify
public void Verify(string dir)
{
using (SessionNoServer session = new SessionNoServer(dir))
{
session.BeginRead();
session.Verify();
session.Commit();
}
}
示例7: CsvExport
public void CsvExport()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.Compact();
session.BeginRead();
session.ExportToCSV(csvExportDir);
session.Commit();
}
}
示例8: Get
// GET api/database/suppliertracking/15
public string Get(string path, UInt32 id)
{
using (SessionNoServer session = new SessionNoServer(path))
{
session.BeginRead();
Database db = session.OpenDatabase(id);
string dbName = db.ToString();
session.Commit();
return dbName;
}
}
示例9: OneMillionFindSingleRecordInTheMiddle
public void OneMillionFindSingleRecordInTheMiddle()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginRead();
var result = (from ComputerFileData computerFileData in session.AllObjects<ComputerFileData>()
where computerFileData.FileID == 500000
select computerFileData).First();
session.Commit();
}
}
示例10: Get
public string Get(string path, int id = 0)
{
using (SessionNoServer session = new SessionNoServer(path))
{
session.BeginRead();
Graph graph = Graph.Open(session, id);
using (MemoryStream ms = new MemoryStream())
{
graph.ExportToGraphJson(ms);
session.Commit();
return Encoding.UTF8.GetString(ms.ToArray());
}
}
}
示例11: Get
/// <summary>
/// Get the names of all persitent types used.
/// </summary>
/// <param name="path">Path to database directory on server relativer to server setting <see cref="SessionBase.BaseDatabasePath"/></param>
/// <returns>All type names registered in the database schema</returns>
public IEnumerable<string> Get(string path)
{
using (SessionNoServer session = new SessionNoServer(path))
{
session.BeginRead();
Database db = session.OpenDatabase(1);
var e = db.AllObjects<VelocityDbType>(false);
var types = session.ExportToJson<VelocityDbType>(false, false);
List<string> stringList = new List<String>();
foreach (VelocityDbType t in e)
yield return t.Type.ToGenericTypeString();
session.Commit();
}
}
示例12: 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;
}
}
示例13: 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;
}
示例14: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
const UInt32 numberOfPersons = 10000;
const ushort nodeMaxSize = 5000;
const ushort comparisonByteArraySize = sizeof(UInt64); // enough room to hold entire idNumber of a Person
const bool comparisonArrayIsCompleteKey = true;
const bool addIdCompareIfEqual = false;
Person person;
session.BeginUpdate();
session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
//mySession.SetTraceAllDbActivity();
BTreeSet<string> stringSet = new BTreeSet<string>(null, session);
BTreeSetOidShort<string> stringSetShort = new BTreeSetOidShort<string>(null, session);
BTreeMap<string, string> stringMap = new BTreeMap<string, string>(null, session);
BTreeMapOidShort<string, string> stringMapShort = new BTreeMapOidShort<string, string>(null, session);
CompareByField<Person> compareByField = new CompareByField<Person>("idNumber", session, addIdCompareIfEqual);
BTreeSet<Person> bTree = new BTreeSet<Person>(compareByField, session, nodeMaxSize, comparisonByteArraySize, comparisonArrayIsCompleteKey);
session.Persist(bTree); // Persist the root of the BTree so that we have something persisted that can be flushed to disk if memory available becomes low
for (int i = 0; i < numberOfPersons; i++)
{
person = new Person();
// session.Persist(person);
bTree.AddFast(person);
}
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.UseExternalStorageApi = true;
session.BeginRead();
BTreeSet<Person> bTree = session.AllObjects<BTreeSet<Person>>().First();
foreach (Person person in (IEnumerable<Person>)bTree)
{
if (person.IdNumber > 196988888791402)
{
Console.WriteLine(person);
break;
}
}
session.Commit();
}
}
示例15: Main
static void Main(string[] args)
{
try
{
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
DatabaseLocation localLocation = new DatabaseLocation(Dns.GetHostName(), Path.Combine(session.SystemDirectory, "desEncryptedLocation"), desEncryptedStartDatabaseNumber, UInt32.MaxValue,
session, PageInfo.compressionKind.LZ4, PageInfo.encryptionKind.desEncrypted);
session.BeginUpdate();
session.NewLocation(localLocation);
localLocation.DesKey = SessionBase.TextEncoding.GetBytes("5d9nndwy"); // Des keys are 8 bytes long
Person robinHood = new Person("Robin", "Hood", 30);
Person billGates = new Person("Bill", "Gates", 56, robinHood);
Person steveJobs = new Person("Steve", "Jobs", 56, billGates);
robinHood.BestFriend = billGates;
session.Persist(steveJobs);
steveJobs.Friends.Add(billGates);
steveJobs.Friends.Add(robinHood);
billGates.Friends.Add(billGates);
robinHood.Friends.Add(steveJobs);
session.Commit();
}
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{ // Des keys are not persisted in DatabaseLocation (for safety). Instead they are stored as *.des files
// in the users document directory of the user that created the DatabaseLocation. These files can be copied
// to other user's document directory when acccess is desired for other users.
// Path to user document dir is given by C#: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
session.BeginRead();
var allPersonsEnum = session.AllObjects<Person>();
foreach (Person obj in allPersonsEnum)
{
Person person = obj as Person;
if (person != null)
Console.WriteLine(person.FirstName);
}
session.Commit();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}