270 lines
8.5 KiB
C#
270 lines
8.5 KiB
C#
// /**
|
|
// * File: Program.cs
|
|
// * Author: haraldwolff
|
|
// *
|
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|
// *
|
|
// *
|
|
// **/
|
|
using System;
|
|
using ln.types.odb.ng.storage;
|
|
using ln.types.odb.ng;
|
|
using ln.logging;
|
|
using System.Linq;
|
|
using ln.types.threads;
|
|
using System.Collections.Generic;
|
|
using ln.types.odb.ng.mappings;
|
|
using System.Net;
|
|
using ln.types.odb.ng.storage.session;
|
|
|
|
namespace ln.types.test
|
|
{
|
|
class MainClass
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
IPv6 maskTest = IPv6.Parse("255.255.255.255");
|
|
Console.WriteLine("Mask Test: {0} => {1}", maskTest.ToCIDR(), maskTest.Network.ToCIDR());
|
|
for (int n=0;n<31;n++)
|
|
{
|
|
maskTest = new IPv6(maskTest, maskTest.Netmask-1);
|
|
Console.WriteLine("Mask Test: {0} => {1}", maskTest.ToCIDR(), maskTest.Network.ToCIDR());
|
|
}
|
|
|
|
ParseIPv6("1.2.3.4");
|
|
ParseIPv6("10.112.0.0/10");
|
|
|
|
|
|
ParseIPv6("::1234:5678:9ABC:DEF0");
|
|
ParseIPv6("1234:5678:9ABC:DEF0::");
|
|
|
|
ParseIPv6("::");
|
|
ParseIPv6(IPv6.V4Space.ToCIDR());
|
|
ParseIPv6("::ffff:127.0.0.1");
|
|
ParseIPv6("2001:db8::1428:57ab");
|
|
|
|
IPv6 ip = IPv6.V4Space;
|
|
|
|
Console.WriteLine("IPv4Space: {0}",ip.ToCIDR());
|
|
|
|
for (int n = 0; n < 10; n++)
|
|
{
|
|
ip++;
|
|
Console.WriteLine("+1: {0}", ip.ToCIDR());
|
|
}
|
|
|
|
for (int n = 0; n < 32; n++)
|
|
{
|
|
ip += 256;
|
|
Console.WriteLine("+256: {0}", ip.ToCIDR());
|
|
}
|
|
|
|
for (int n = 0; n < 32; n++)
|
|
{
|
|
ip += 1<<14;
|
|
Console.WriteLine("+(1<<14): {0}", ip.ToCIDR());
|
|
}
|
|
|
|
Console.WriteLine("->IPAddress: {0}", (IPAddress)ip);
|
|
|
|
IPAddress ip4 = IPAddress.Parse("10.112.1.254");
|
|
Console.WriteLine("IP4 = {0} => {1}",ip4,(IPv6)ip4);
|
|
|
|
IPv6 ten = IPv6.Parse("::ffff:10.0.0.0/104");
|
|
Console.WriteLine("Splitting Network: {0}",ten.ToCIDR());
|
|
foreach (IPv6 subnet in ten.Split(8))
|
|
Console.WriteLine(" {0}", subnet.ToCIDR());
|
|
|
|
IPv6 v6 = IPv6.Parse("2001:470:7408::/48");
|
|
Console.WriteLine("Splitting Network: {0}", v6.ToCIDR());
|
|
foreach (IPv6 subnet in v6.Split(4))
|
|
Console.WriteLine(" {0}", subnet.ToCIDR());
|
|
}
|
|
|
|
public static void ParseIPv6(string source)
|
|
{
|
|
IPv6 ip = IPv6.Parse(source);
|
|
Console.WriteLine("IPv6: {0,40} => {1} [ {3,24} ] = {2}", source, ip.ToString(false),ip,ip.Network.ToCIDR());
|
|
Console.WriteLine("CIDR: {0}", ip.ToCIDR());
|
|
Console.WriteLine("(IPAddress) = {0}", (IPAddress)ip);
|
|
}
|
|
|
|
public static void TestStorage(IStorageContainer container)
|
|
{
|
|
using (IStorage storage = container.GetStorage("test"))
|
|
{
|
|
|
|
if (!storage.IsOpen)
|
|
storage.Open();
|
|
|
|
foreach (Guid documentID in storage.GetDocumentIDs())
|
|
{
|
|
Logging.Log(LogLevel.INFO, "DocumentID: {0}", documentID);
|
|
Document doc = storage.Load(documentID);
|
|
Logging.Log(LogLevel.INFO, doc.ToString());
|
|
doc["FeldC"] = doc["FeldC"].AsLong + 1;
|
|
storage.Save(doc);
|
|
}
|
|
|
|
Document document = new Document();
|
|
|
|
document["FeldA"] = "Ich bin das Feld A";
|
|
document["FeldB"] = "Ich bin das Feld B";
|
|
document["FeldC"] = new Random().Next();
|
|
|
|
storage.Save(document);
|
|
storage.Save(document);
|
|
}
|
|
}
|
|
public static void TestMapper(IStorageContainer container)
|
|
{
|
|
Mapper mapper = new Mapper(container);
|
|
|
|
Logging.Log(LogLevel.INFO, "Cleaning up Person store");
|
|
foreach (Guid documentID in mapper.GetDocumentIDs<Person>())
|
|
mapper.Delete<Person>(documentID);
|
|
|
|
Logging.Log(LogLevel.INFO, "Storage counts {0} entities", mapper.GetDocumentIDs<Person>().Count());
|
|
|
|
Person[] persons = new Person[15000];
|
|
for (int n = 0; n < persons.Length; n++)
|
|
persons[n] = new Person();
|
|
|
|
Logging.Log(LogLevel.INFO, "Created {0} persons", persons.Length);
|
|
|
|
Timing.Meassure("store persons", () =>
|
|
{
|
|
foreach (Person person in persons)
|
|
mapper.Save(person);
|
|
});
|
|
|
|
Guid[] documentIDs = mapper.GetDocumentIDs<Person>().ToArray();
|
|
Random random = new Random();
|
|
|
|
//for (int n = 0; n < 20; n++)
|
|
//{
|
|
// Guid choosenID = documentIDs[random.Next(documentIDs.Length)];
|
|
// Person person = mapper.Load<Person>(choosenID);
|
|
|
|
// Logging.Log(LogLevel.INFO, "Querying: {0}", person.FirstName);
|
|
|
|
// IEnumerable<Guid> ids = Timing.Meassure(() => mapper.GetDocumentIDs<Person>(Query.Equals<Person>("MiddleNames[]", person.FirstName)));
|
|
// Guid[] matchedIDs = ids.ToArray();
|
|
|
|
// Logging.Log(LogLevel.INFO, "Found {0} persons.", matchedIDs.Length);
|
|
//}
|
|
|
|
IODBMapping pMapping = mapper.GetMapping<Person>();
|
|
|
|
Person p1 = new Person();
|
|
Document pd1 = pMapping.MapValue(mapper, p1) as Document;
|
|
|
|
p1.MiddleNames[1] = "N/A";
|
|
|
|
Document pd2 = pMapping.MapValue(mapper, p1) as Document;
|
|
|
|
DocumentChanges documentChanges = new DocumentChanges(pd1, pd2);
|
|
Logging.Log(LogLevel.INFO, "DocumentChanges: \n{0}",String.Join("\n",documentChanges.Changes.Select((x)=>x.ToString())));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapper.EnsureIndex<Person>("MiddleNames[]");
|
|
mapper.EnsureIndex<Person>("FirstName");
|
|
|
|
Logging.Log(LogLevel.INFO, "using indeces");
|
|
|
|
for (int n = 0; n < 20; n++)
|
|
{
|
|
Guid choosenID = documentIDs[random.Next(documentIDs.Length)];
|
|
Person person = mapper.Load<Person>(choosenID);
|
|
|
|
IEnumerable<Guid> ids = Timing.Meassure(() => mapper.GetDocumentIDs<Person>(Query.Equals<Person>("MiddleNames[]", person.FirstName)));
|
|
Guid[] matchedIDs = ids.ToArray();
|
|
Logging.Log(LogLevel.INFO, "Queried '{0}' with {1,4} matches", person.FirstName, matchedIDs.Length);
|
|
|
|
}
|
|
|
|
for (int n = 0; n < 20; n++)
|
|
{
|
|
Guid choosenID = documentIDs[random.Next(documentIDs.Length)];
|
|
Person person = mapper.Load<Person>(choosenID);
|
|
|
|
IEnumerable<Guid> ids = Timing.Meassure(() => mapper.GetDocumentIDs<Person>(
|
|
Query.AND(
|
|
Query.Equals<Person>("MiddleNames[]", person.FirstName),
|
|
Query.Equals<Person>("FirstName", person.FirstName)
|
|
)
|
|
)
|
|
);
|
|
Guid[] matchedIDs = ids.ToArray();
|
|
Logging.Log(LogLevel.INFO, "Queried complex '{0}' with {1,4} matches", person.FirstName, matchedIDs.Length);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
class Person
|
|
{
|
|
static Random random = new Random();
|
|
|
|
static string[] firstNames = new string[]
|
|
{
|
|
"Harald","Simone","Viola","Antigona","Peter","Paul","Maria","Karel","Bruno","Ilse","Sonja","Ute","Justus","Niclas","Pascal"
|
|
};
|
|
static string[] lastNames = new string[]
|
|
{
|
|
"Wolff","Thobaben","Schmidt","Seefeld","van der Heide","Schuhmacher","Brommer","Günther","Freilauf","Unger","Thomalla","Christensen","Person","Forghammer"
|
|
};
|
|
|
|
public string FirstName;
|
|
public string LastName;
|
|
public String[] MiddleNames;
|
|
public int Age;
|
|
|
|
public Person()
|
|
{
|
|
FirstName = firstNames[random.Next(firstNames.Length)];
|
|
LastName = lastNames[random.Next(lastNames.Length)];
|
|
MiddleNames = new string[]
|
|
{
|
|
firstNames[random.Next(firstNames.Length)],
|
|
firstNames[random.Next(firstNames.Length)],
|
|
firstNames[random.Next(firstNames.Length)]
|
|
};
|
|
|
|
Age = random.Next(120);
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("[Person FirstName={0} LastName={1} Age={2}]",FirstName,LastName,Age);
|
|
}
|
|
|
|
}
|
|
|
|
class MapableClass
|
|
{
|
|
public int ANumber { get; set; }
|
|
public String MyString;
|
|
|
|
public MapableClass()
|
|
{
|
|
ANumber = new Random().Next();
|
|
MyString = ANumber.ToString();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return String.Format("[MapableClass ANumber={0} MyString={1}]",ANumber,MyString);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|