Exemplo n.º 1
0
 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();
   }
 }
Exemplo n.º 2
0
 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
     }
   });
 }
Exemplo n.º 3
0
 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();
   }
 }
Exemplo n.º 4
0
 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();
     }
   }
 }
Exemplo n.º 5
0
 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();
   }
 }
Exemplo n.º 6
0
 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;
   }
 }
Exemplo n.º 7
0
 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;
   }
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
 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();
     }
 }
Exemplo n.º 10
0
 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();
   }
 }
Exemplo n.º 11
0
 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();
   }
 }
Exemplo n.º 12
0
 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 = "******" + i.ToString();
       user = new User(user, email, first, last, userName);
       user.Persist(session, priorUser ?? user);
       issueTracker.UserSet.Add(user);
       priorUser = user;
       session.Commit();
     }
 }
Exemplo n.º 13
0
    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();
      }
    }
Exemplo n.º 14
0
    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();
      }
    }
Exemplo n.º 15
0
 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();
     }
   });
 }
Exemplo n.º 16
0
 public void SingleReaderSingleUpdater2()
 {
   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;
     using (SessionNoServer session2 = new SessionNoServer(systemDir))
     {
       session2.BeginRead();
       Man man2 = (Man)session2.Open(id);
       Assert.Less(man2.Age, man.Age);
       session2.Commit();
     }
     session.Commit();
   }
   System.GC.Collect();
 }
Exemplo n.º 17
0
 protected void ForgotPasswordLinkButton_Click(object sender, EventArgs e)
 {
   try
   {
     using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true))
     {
       session.BeginRead();
       Root root = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false);
       if (root == null)
       {
         ErrorMessage.Text = "The entered email address is not registered with this website";
         session.Abort();
         return;
       }
       CustomerContact lookup = new CustomerContact(Email.Text, null);
       if (!root.customersByEmail.TryGetKey(lookup, ref lookup))
       {
         ErrorMessage.Text = "The entered email address is not registered with this website";
         session.Abort();
         return;
       }
       session.Commit();
       MailMessage message = new MailMessage("*****@*****.**", Email.Text);
       message.Subject = "Your password to VelocityWeb";
       message.Body = "Password is: " + lookup.password;
       SmtpClient client = new SmtpClient("smtpout.secureserver.net", 80);
       System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("*****@*****.**", "xxxx");
       client.Credentials = SMTPUserInfo;
       client.Send(message);
       ErrorMessage.Text = "Email with your password was send to: " + Email.Text;
     }
   }
   catch (System.Exception ex)
   {
     ErrorMessage.Text = ex.ToString();
   }
 }
Exemplo n.º 18
0
 public void HashSetAddNonPersisted()
 {
   UInt64 id;
   Person person = null;
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginUpdate();
     var hashSet = new HashSet<Person>();
     for (int i = 0; i < 100; i++)
     {
       var p = new Person();
       session.Persist(p);
       hashSet.Add(p);
       if (i == 47)
       {
         person = p;
         Assert.IsFalse(hashSet.Add(person));
       }
     }
     id = session.Persist(hashSet);
     Assert.IsTrue(hashSet.Contains(person));
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     session.BeginRead();
     var hashSet = session.Open<HashSet<Person>>(id);
     Assert.AreEqual(100, hashSet.Count);
     int ct = 0;
     foreach (Person p in hashSet)
       ct++;
     Assert.IsTrue(hashSet.Contains(person));
     Assert.IsFalse(hashSet.Add(person));
     Assert.AreEqual(100, ct);
     session.Commit();
   }
 }
Exemplo n.º 19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Session["EmailVerification"]      = -1;
         Session["EmailVerificationEmail"] = "none";
         Page.Header.Title = "VelocityDB - Register";
         continueUrl       = Request.QueryString["ReturnUrl"];
         HowFoundRadioButtonList.DataSource    = AllHowFound();
         HowFoundRadioButtonList.SelectedIndex = 0;
         HowFoundRadioButtonList.DataBind();
         DataCache.UnauthorizedPerformanceCounter = true;
         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)
                 {
                     Placement placementRoot = new Placement(Root.PlaceInDatabase, 1, 1, 1000, 1000, true);
                     velocityDbroot = new Root(session, 10000);
                     velocityDbroot.Persist(placementRoot, session);
                 }
                 else
                 {
                     string user = this.User.Identity.Name;
                     if (user != null && user.Length > 0)
                     {
                         CustomerContact lookup = new CustomerContact(user, null);
                         if (velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer))
                         {
                             EmailVerificationValidator.Enabled = false;
                             CompanyName.Text      = existingCustomer.company;
                             FirstName.Text        = existingCustomer.firstName;
                             LastName.Text         = existingCustomer.lastName;
                             Email.Text            = existingCustomer.email;
                             Address.Text          = existingCustomer.address;
                             AddressLine2.Text     = existingCustomer.addressLine2;
                             City.Text             = existingCustomer.city;
                             ZipCode.Text          = existingCustomer.zipCode;
                             State.Text            = existingCustomer.state;
                             Country.SelectedValue = existingCustomer.countryCode;
                             Phone.Text            = existingCustomer.phone;
                             Fax.Text             = existingCustomer.fax;
                             MobilePhone.Text     = existingCustomer.mobile;
                             SkypeName.Text       = existingCustomer.skypeName;
                             Website.Text         = existingCustomer.webSite;
                             UserName.Text        = existingCustomer.userName;
                             Password.Text        = existingCustomer.password;
                             PasswordConfirm.Text = existingCustomer.password;
                             HowFoundRadioButtonList.SelectedIndex = (int)existingCustomer.howFoundVelocityDb;
                             HowFoundTextBox.Text = existingCustomer.howFoundOther;
                         }
                         else if (Request.IsLocal)
                         {
                             EmailVerificationValidator.Enabled = false;
                         }
                     }
                 }
                 session.Commit();
             }
         }
         catch (System.Exception ex)
         {
             errors.Text = ex.ToString();
         }
     }
 }
Exemplo n.º 20
0
        static int Main(string[] args)
        {
            if (args.Length == 0)
            {
                System.Console.WriteLine("ERROR, no boot path specified. Restart Verify and add bootup database path as a command line parameter");
                return(1);
            }
            int ct = 0;

            try
            {
                using (SessionNoServer session = new SessionNoServer(args[0]))
                {
                    DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case
                    session.BeginRead();
                    List <Database> dbList = session.OpenAllDatabases();
                    foreach (Database db in dbList)
                    {
                        foreach (Page page in db)
                        {
                            foreach (IOptimizedPersistable iPers in page)
                            {
                                object obj = iPers.WrappedObject;
                                ++ct;
                                if (iPers.WrappedObject is IOptimizedPersistable)
                                {
                                    UInt64 id = iPers.Id;
                                    OptimizedPersistable pObj = iPers as OptimizedPersistable;
                                    if (pObj != null)
                                    {
                                        session.LoadFields(pObj);
                                        foreach (OptimizedPersistable fObj in pObj.OptimizedPersistableFieldValues())
                                        {
                                            session.LoadFields(fObj);
                                        }
                                        foreach (object value in pObj.GetFieldValues())
                                        {
                                            WeakIOptimizedPersistableReferenceBase weakRef = value as WeakIOptimizedPersistableReferenceBase;
                                            if (weakRef != null)
                                            {
                                                if (session.Open(weakRef.Id) == null)
                                                {
                                                    throw new UnexpectedException("WeakRefence object is null");
                                                }
                                            }
                                        }
                                    }
                                }
                                else if (obj is string)
                                {
                                    continue;
                                }
                                else if (obj is Array)
                                {
                                    continue;
                                }
                                IEnumerable anEnum = obj as IEnumerable;
                                if (anEnum != null)
                                {
                                    foreach (object o in anEnum)
                                    {
                                    }
                                }
                            }
                        }
                    }
                    session.Commit();
                }
                Console.WriteLine("OK, verfied " + ct + " objects");
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("FAILED, verfied " + ct + " objects");
                Console.WriteLine(ex.ToString());
                return(-1);
            }
        }
Exemplo n.º 21
0
        protected void RegisterButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true))
                {
                    session.BeginUpdate();
                    CustomerContact customer = new CustomerContact(CompanyName.Text, FirstName.Text, LastName.Text, Email.Text, Address.Text, AddressLine2.Text,
                                                                   City.Text, ZipCode.Text, State.Text, Country.SelectedItem.Text, Country.SelectedItem.Value, Phone.Text, Fax.Text, MobilePhone.Text,
                                                                   SkypeName.Text, Website.Text, UserName.Text, Password.Text, HowFoundTextBox.Text, HowFoundRadioButtonList.SelectedIndex, session);
                    Root            root = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false);
                    CustomerContact lookup;
                    string          user = this.User.Identity.Name;
                    if (user != null && user.Length > 0)
                    {
                        lookup = new CustomerContact(user, null);
                        root.customersByEmail.TryGetKey(lookup, ref existingCustomer);
                    }
                    else
                    {
                        lookup = new CustomerContact(customer.email, customer.userName);
                        if (!root.customersByEmail.TryGetKey(lookup, ref existingCustomer))
                        {
                            root.customersByUserName.TryGetKey(lookup, ref existingCustomer);
                        }
                    }
                    if (existingCustomer != null)
                    {
                        existingCustomer.Update();

                        if (existingCustomer.email != customer.email)
                        {
                            string verifiedEmail     = (string)Session["EmailVerificationEmail"];
                            int    emailVerification = (int)Session["EmailVerification"];
                            if (Request.IsLocal == false)
                            {
                                if (emailVerification < 0 || verifiedEmail != customer.email)
                                {
                                    errors.Text = "Email was not verified for new user registration";
                                    session.Abort();
                                    return;
                                }
                                int enteredVerificationNumber;
                                int.TryParse(EmailVerification.Text, out enteredVerificationNumber);
                                if (emailVerification != enteredVerificationNumber)
                                {
                                    errors.Text = "Entered Email Verification number is " + enteredVerificationNumber + " does match the emailed verification number: " + emailVerification;
                                    Session["EmailVerification"] = -1;
                                    session.Abort();
                                    return;
                                }
                            }
                            if (existingCustomer.password != customer.password && user != existingCustomer.email)
                            {
                                errors.Text = "Entered Email address already registered";
                                session.Abort();
                                return;
                            }
                            existingCustomer.priorVerifiedEmailSet.Add(existingCustomer.email);
                            root.customersByEmail.Remove(existingCustomer);
                            existingCustomer.email = customer.email;
                            root.customersByEmail.Add(existingCustomer);
                        }
                        if (existingCustomer.userName != customer.userName)
                        {
                            lookup = new CustomerContact(user, customer.userName);
                            if (root.customersByUserName.TryGetKey(lookup, ref lookup))
                            {
                                errors.Text = "Entered User Name is already in use";
                                session.Abort();
                                return;
                            }
                            // remove and add to get correct sorting order
                            root.customersByUserName.Remove(existingCustomer);
                            existingCustomer.userName = customer.userName;
                            root.customersByUserName.Add(existingCustomer);
                        }
                        existingCustomer.company            = customer.company;
                        existingCustomer.firstName          = customer.firstName;
                        existingCustomer.lastName           = customer.lastName;
                        existingCustomer.address            = customer.address;
                        existingCustomer.addressLine2       = customer.addressLine2;
                        existingCustomer.city               = customer.city;
                        existingCustomer.zipCode            = customer.zipCode;
                        existingCustomer.state              = customer.state;
                        existingCustomer.country            = Country.SelectedItem.Text;
                        existingCustomer.countryCode        = Country.SelectedItem.Value;
                        existingCustomer.phone              = customer.phone;
                        existingCustomer.fax                = customer.fax;
                        existingCustomer.mobile             = customer.mobile;
                        existingCustomer.skypeName          = customer.skypeName;
                        existingCustomer.webSite            = customer.webSite;
                        existingCustomer.password           = customer.password;
                        existingCustomer.howFoundOther      = customer.howFoundOther;
                        existingCustomer.howFoundVelocityDb = customer.howFoundVelocityDb;
                    }
                    else
                    {
                        if (Request.IsLocal == false)
                        {
                            int    emailVerification = (int)Session["EmailVerification"];
                            string verifiedEmail     = (string)Session["EmailVerificationEmail"];
                            if (emailVerification < 0 || verifiedEmail != customer.email)
                            {
                                errors.Text = "Email was not verified for new user registration";
                                session.Abort();
                                return;
                            }
                            int enteredVerificationNumber;
                            int.TryParse(EmailVerification.Text, out enteredVerificationNumber);
                            if (emailVerification != enteredVerificationNumber)
                            {
                                errors.Text = "Entered Email Verification number is " + enteredVerificationNumber + " does match the emailed verification number: " + emailVerification;
                                Session["EmailVerification"] = -1;
                                session.Abort();
                                return;
                            }
                        }
                        Placement placementCustomer = new Placement(customer.PlacementDatabaseNumber);
                        customer.idNumber = root.NewCustomerNumber();
                        customer.Persist(placementCustomer, session);
                        root.customersByEmail.Add(customer);
                        root.customersByUserName.Add(customer);
                    }
                    session.Commit();
                    string redirectUrl = FormsAuthentication.GetRedirectUrl(Email.Text, false);
                    try
                    {
                        string      path;
                        MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**");
                        if (existingCustomer == null)
                        {
                            path            = HttpContext.Current.Server.MapPath("~/Save") + "/new" + DateTime.Now.Ticks + ".txt";
                            message.Subject = "VelocityWeb new prospect: " + customer.Email;
                        }
                        else
                        {
                            customer        = existingCustomer;
                            path            = HttpContext.Current.Server.MapPath("~/Save") + "/updated" + DateTime.Now.Ticks + ".txt";
                            message.Subject = "VelocityWeb updated prospect: " + customer.Email;
                        }
                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(path))
                        {
                            file.Write("{0}\t", "Email");
                            file.Write("{0}\t", "FirstName");
                            file.Write("{0}\t", "LastName");
                            file.Write("{0}\t", "Address");
                            file.Write("{0}\t", "Address2");
                            file.Write("{0}\t", "City");
                            file.Write("{0}\t", "Company");
                            file.Write("{0}\t", "Country");
                            file.Write("{0}\t", "countryCode");
                            file.Write("{0}\t", "Fax");
                            file.Write("{0}\t", "HowFoundUs");
                            file.Write("{0}\t", "HowFoundUsOther");
                            file.Write("{0}\t", "Mobile");
                            file.Write("{0}\t", "Password");
                            file.Write("{0}\t", "Phone");
                            file.Write("{0}\t", "Skype");
                            file.Write("{0}\t", "State");
                            file.Write("{0}\t", "UserName");
                            file.Write("{0}\t", "WebSite");
                            file.WriteLine("{0}\t", "ZipCode");
                            file.Write("{0}\t", customer.Email);
                            file.Write("{0}\t", customer.FirstName);
                            file.Write("{0}\t", customer.LastName);
                            file.Write("{0}\t", customer.Address);
                            file.Write("{0}\t", customer.Address2);
                            file.Write("{0}\t", customer.City);
                            file.Write("{0}\t", customer.Company);
                            file.Write("{0}\t", customer.Country);
                            file.Write("{0}\t", customer.countryCode);
                            file.Write("{0}\t", customer.Fax);
                            file.Write("{0}\t", customer.HowFoundUs);
                            file.Write("{0}\t", customer.HowFoundUsOther);
                            file.Write("{0}\t", customer.Mobile);
                            file.Write("{0}\t", customer.Password);
                            file.Write("{0}\t", customer.Phone);
                            file.Write("{0}\t", customer.Skype);
                            file.Write("{0}\t", customer.State);
                            file.Write("{0}\t", customer.UserName);
                            file.Write("{0}\t", customer.WebSite);
                            file.WriteLine("{0}\t", customer.ZipCode);
                        }
                        Session["UserName"]  = customer.UserName;
                        Session["Email"]     = Email.Text;
                        Session["FirstName"] = customer.FirstName;
                        Session["LastName"]  = customer.LastName;
                        message.Body         = path;
                        Attachment data = new Attachment(path);
                        message.Attachments.Add(data);
                        SmtpClient client = new SmtpClient("smtpout.secureserver.net", 80);
                        System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("*****@*****.**", "xxxx"); // Add credentials if the SMTP server requires them.
                        client.Credentials = SMTPUserInfo;
                        client.Send(message);
                    }
                    catch (System.Exception ex)
                    {
                        string errorPath = HttpContext.Current.Server.MapPath("~/Errors");
                        using (StreamWriter outfile = new StreamWriter(errorPath + @"\errors.txt", true))
                        {
                            outfile.Write(ex.ToString());
                        }
                    }
                    if (redirectUrl == null || redirectUrl.Length == 0)
                    {
                        Response.Redirect("~/Secure/Issues.aspx");
                    }
                    FormsAuthentication.RedirectFromLoginPage(Email.Text, false);
                }
            }
            catch (System.Exception ex)
            {
                errors.Text = ex.ToString();
            }
        }
Exemplo n.º 22
0
 public void LookupCompareFields(int bTreeDatabaseNumber)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Person personPrior = null, person;
     session.BeginRead();
     BTreeSet<Person> bTree = (BTreeSet<Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
     BTreeSetIterator<Person> itr = bTree.Iterator();
     int ct = 0;
     while ((person = itr.Next()) != null)
     {
       if (personPrior != null)
       {
         Assert.LessOrEqual(personPrior.m_firstName, person.m_firstName);
       }
       ct++;
       personPrior = person;
     }
     int ct2 = 0;
     personPrior = null;
     foreach (Person pers in (IEnumerable<Person>)bTree)
     {
       if (personPrior != null)
       {
         Assert.LessOrEqual(personPrior.m_firstName, pers.m_firstName);
       }
       ct2++;
       personPrior = pers;
     }
     session.Commit();
     Assert.AreEqual(ct, ct2);
   }
 }
Exemplo n.º 23
0
 public void CreateCompareStruct(int number)
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.BeginUpdate();
     BTreeSetOidShort<Oid> bTree = new BTreeSetOidShort<Oid>(null, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     for (int i = 0; i < number; i++)
     {
       bTree.Add(new Oid((ulong) i));
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeSetOidShort<Oid> bTree = (BTreeSetOidShort<Oid>) session.Open(id);
     int count = 0;
     int prior = 0;
     foreach (Oid oid in bTree)
     {
       count++;
       Assert.True(oid.Id == (ulong) prior++);
     }
     Assert.True(number == count);
     session.Commit();
   }
 }   
Exemplo n.º 24
0
    public void Create1Vertices(bool vertexIdSetPerVertexType)
    {
      DataCache.MaximumMemoryUse = 10000000000; // 10 GB
      bool dirExist = Directory.Exists(systemDir);
      try
      {
        if (Directory.Exists(systemDir))
          Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
        Directory.CreateDirectory(systemDir);
        File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
      }
      catch
      {
        File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
      }

      using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
      {
        session.BeginUpdate();
        Graph g = new Graph(session, vertexIdSetPerVertexType);
        session.Persist(g);
        VertexType userType = g.NewVertexType("User");
        VertexType otherType = g.NewVertexType("Other");
        PropertyType userNamePropertyType = g.NewVertexProperty(userType, "NAME", DataType.String, PropertyKind.Indexed);
        VertexType powerUserType = g.NewVertexType("PowerUser", userType);
        EdgeType userFriendEdgeType = g.NewEdgeType("Friend", true, userType, userType);
        EdgeType userBestFriendEdgeType = g.NewEdgeType("Best Friend", true, userType, userType, userFriendEdgeType);
        EdgeType otherEdgeType = g.NewEdgeType("Other", true, userType, userType);
        PropertyType bestFriendPropertyType = g.NewEdgeProperty(userFriendEdgeType, "START", DataType.DateTime, PropertyKind.Indexed);
        Vertex kinga = userType.NewVertex();
        Vertex robin = userType.NewVertex();
        Vertex mats = powerUserType.NewVertex();
        Vertex chiran = powerUserType.NewVertex();
        Vertex other = otherType.NewVertex();
        Edge bestFriend = kinga.AddEdge(userBestFriendEdgeType, robin);
        Edge otherEdge = kinga.AddEdge(otherEdgeType, robin);
        DateTime now = DateTime.UtcNow;
        mats.SetProperty("Address", 1);
        bestFriend.SetProperty(bestFriendPropertyType, now);
        kinga.SetProperty(userNamePropertyType, "Kinga");
        if (g.VertexIdSetPerType == false)
          mats.SetProperty(userNamePropertyType, "Mats");
        else
        {
          try
          {
            mats.SetProperty(userNamePropertyType, "Mats");
            Assert.Fail("Invalid property for VertexType not handled");
          }
          catch (Exception)
          {
          }
        }
        try
        {
          other.SetProperty(userNamePropertyType, "Mats");
          Assert.Fail("Invalid property for VertexType not handled");
        }
        catch (Exception)
        {
        }       
        try
        {
          otherEdge.SetProperty(bestFriendPropertyType, now);
          Assert.Fail("Invalid property for VertexType not handled");
        }
        catch (Exception)
        {
        }
        Vertex findMats = userNamePropertyType.GetPropertyVertex("Mats", true);
        var list = userNamePropertyType.GetPropertyVertices("Mats", true).ToList();
        //Edge findWhen = bestFriendPropertyType.GetPropertyEdge(now);
        //var list2 = bestFriendPropertyType.GetPropertyEdges(now);
        Console.WriteLine(findMats);
       // session.Commit();
       // session.BeginRead();
        PropertyType adressProperty = g.FindVertexProperty(powerUserType, "Address");
        Vertex find1 = adressProperty.GetPropertyVertex(1, true);
        session.Abort();
        /*session.BeginUpdate();
        g.Unpersist(session);
        session.Commit();
        dirExist = Directory.Exists(systemDir);
        try
        {
          if (Directory.Exists(systemDir))
            Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
          Directory.CreateDirectory(systemDir);
          File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
        }
        catch
        {
          File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
        }*/

      }

      using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
      {
        session.BeginUpdate();
        session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.None;
        Graph g = new Graph(session, vertexIdSetPerVertexType);
        session.Persist(g);
        Graph g2 = new Graph(session);
        session.Persist(g2);
        Graph g3 = new Graph(session);
        session.Persist(g3);
        UInt32 dbNum = session.DatabaseNumberOf(typeof(Graph));
        Graph g4 = (Graph)session.Open(dbNum, 2, 1, true); // g4 == g
        Graph g5 = (Graph)session.Open(dbNum, 2, 2, true); // g5 == g2
        Graph g6 = (Graph)session.Open(dbNum, 2, 3, true); // g6 == g3
        for (int i = 4; i < 8; i++)
        {
          Graph gt = new Graph(session);
          session.Persist(gt);
        }
        Graph g7 = new Graph(session);
        Placement place = new Placement(dbNum, 15);
        session.Persist(place, g7);
        // SCHEMA
        VertexType userType = g.NewVertexType("User");
        VertexType locationType = g.NewVertexType("Location");
        VertexType aVertexType = g.NewVertexType("A");
        VertexType bVertexType = g.NewVertexType("B");
        VertexType cVertexType = g.NewVertexType("C");
        EdgeType uEdge = g.NewEdgeType("unrestricted", true);
        Vertex aVertex = g.NewVertex(aVertexType);
        Vertex bVertex = g.NewVertex(bVertexType);
        Vertex cVertex = g.NewVertex(cVertexType);
        Edge abEdge = (Edge)aVertex.AddEdge("unrestricted", bVertex);
        Edge bcEdge = (Edge)aVertex.AddEdge("unrestricted", cVertex);
        Dictionary<Vertex, HashSet<Edge>> traverse = aVertex.Traverse(uEdge, Direction.Out);
        abEdge.Remove();
        Dictionary<Vertex, HashSet<Edge>> traverse2 = aVertex.Traverse(uEdge, Direction.Out);

        EdgeType friendEdgeType = g.NewEdgeType("Friend", true, userType, userType);
        EdgeType userLocationEdgeType = g.NewEdgeType("UserLocation", true, userType, locationType);

        // DATA
        Random rand = new Random(5);
        for (int i = 0; i < numberOfUserVertices / 100; i++)
        {
          int vId = rand.Next(numberOfUserVertices);
          try
          {
            if (g.VertexIdSetPerType)
              userType.GetVertex(vId);
            else
              g.GetVertex(vId);
            try
            {
              userType.NewVertex(vId);
              Assert.Fail();
            }
            catch (VertexAllreadyExistException)
            {

            }
          }
          catch (VertexDoesNotExistException)
          {
            userType.NewVertex(vId);
            userType.GetVertex(vId);
          }
        }
        for (int i = 0; i < numberOfUserVertices / 10000; i++)
        {
          int vId = rand.Next(numberOfUserVertices);
          try
          {
            Vertex v = userType.GetVertex(vId);
            v.SetProperty("test", 1);
          }
          catch (VertexDoesNotExistException)
          {
          }
        }
        for (int i = 0; i < numberOfUserVertices / 10000; i++)
        {
          int vId = rand.Next(numberOfUserVertices);
          try
          {
            Vertex v = userType.GetVertex(vId);
            userType.RemoveVertex(v);
          }
          catch (VertexDoesNotExistException)
          {
          }
        }
        foreach (Vertex v in userType.GetVertices().ToArray())
          userType.RemoveVertex(v);
        Assert.AreEqual(0, userType.GetVertices().Count());
        for (int i = 100000; i < numberOfUserVertices; i++)
          userType.NewVertex();
        for (int i = 1; i < 100000; i++)
          userType.NewVertex();
        for (int i = 1; i < numberOfLocationVertices; i++)
          locationType.NewVertex();
        session.Commit();
        session.BeginRead();
        foreach (var x in session.AllObjects<BTreeSet<Range<VertexId>>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeSet<EdgeType>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeSet<EdgeIdVertexId>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeMap<EdgeId, VelocityDbList<ElementId>>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeMap<string, PropertyType>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeMap<string, EdgeType>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeMap<string, VertexType>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        foreach (var x in session.AllObjects<BTreeMap<EdgeType, BTreeMap<VertexType, BTreeMap<VertexId, BTreeSet<EdgeIdVertexId>>>>>(false, true))
          Assert.True(x.ToDoBatchAddCount == 0);
        session.Commit();
        Validate();
      }
    }
 [TestCase(false)] // test will fail if pessimistic locking is used
 public void SingleReaderSingleUpdater4(bool useReaderCommit)
 {
     using (SessionNoServer updater = new SessionNoServer(systemDir, 5000))
         using (SessionNoServer reader = new SessionNoServer(systemDir, 5000))
         {
             //updater.SetTraceAllDbActivity();
             //reader.SetTraceAllDbActivity();
             updater.BeginUpdate();
             UInt32   dbNum = updater.DatabaseNumberOf(typeof(Man));
             Database db    = updater.OpenDatabase(dbNum, true, false);
             if (db != null)
             {
                 updater.DeleteDatabase(db);
             }
             updater.Commit();
             updater.BeginUpdate();
             Man man = new Man();
             for (int i = 0; i < 100; i++)
             {
                 man = new Man();
                 updater.Persist(man);
             }
             updater.Commit();
             reader.BeginRead();
             updater.BeginUpdate();
             db = reader.OpenDatabase(dbNum);
             foreach (Page page in db)
             {
                 Assert.True(page.PageInfo.VersionNumber == 1);
             }
             if (useReaderCommit)
             {
                 reader.Commit();
             }
             if (useReaderCommit)
             {
                 reader.BeginRead();
             }
             else
             {
                 reader.ForceDatabaseCacheValidation();
             }
             for (int i = 1; i < 25; i++)
             {
                 db = reader.OpenDatabase(dbNum);
                 foreach (Page page in db)
                 {
                     if (page.PageNumber > 1) // skip AutoPlacemnt page
                     {
                         Assert.True(page.PageInfo.VersionNumber == (ulong)i);
                         Man man2       = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
                         Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
                     }
                 }
                 if (useReaderCommit)
                 {
                     reader.Commit();
                     reader.BeginRead();
                 }
                 else
                 {
                     reader.ForceDatabaseCacheValidation();
                 }
                 updater.Commit();
                 updater.BeginUpdate();
             }
             Database db2 = reader.OpenDatabase(dbNum);
             db = updater.OpenDatabase(dbNum);
             for (int i = 25; i < 50; i++)
             {
                 foreach (Page page in db)
                 {
                     if (page.PageNumber > 1)
                     {
                         Assert.True(page.PageInfo.VersionNumber == (ulong)i);
                         Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
                     }
                 }
                 updater.Commit();
                 updater.BeginUpdate();
                 db2 = reader.OpenDatabase(dbNum);
                 foreach (Page page in db2)
                 {
                     if (page.PageNumber > 1)
                     {
                         //Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1);
                         Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
                     }
                 }
                 reader.ClearPageCache();
                 System.GC.Collect();
             }
             reader.Commit();
             updater.Commit();
         }
 }
Exemplo n.º 26
0
        public MainWindow()
        {
            const ushort btreeNodeSize = 5000;

            GCSettings.LatencyMode = GCLatencyMode.Batch;// try to keep the WeakIOptimizedPersistableReference objects around longer
            dataGridList           = new List <DataGrid>();
            dataTableList          = new List <DataTable>();
            InitializeComponent();
            session = new SessionNoServer(s_systemDir);
            Placement placerIndexRoot = new Placement(IndexRoot.PlaceInDatabase);

            session.BeginUpdate();
            Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
            IndexRoot _indexRoot;
            Database  db = session.OpenDatabase(IndexRoot.PlaceInDatabase, false, false);

            if (db == null)
            {
                _indexRoot = new IndexRoot(btreeNodeSize, session);
                if (Directory.Exists(s_booksDir))
                {
                    string[] directoryTextFiles = Directory.GetFiles(s_booksDir, "*.txt");
                    foreach (string fileName in directoryTextFiles)
                    {
                        listBoxPagesToAdd.Items.Add(fileName);
                    }
                }
                else
                {
                    wordMinCt.Text = 1.ToString();
                    listBoxPagesToAdd.Items.Add("http://www.VelocityDB.com/");
                    // other database products
                    listBoxPagesToAdd.Items.Add("https://foundationdb.com/");
                    listBoxPagesToAdd.Items.Add("http://www.oracle.com/us/products/database/index.html");
                    listBoxPagesToAdd.Items.Add("http://www-01.ibm.com/software/data/db2/");
                    listBoxPagesToAdd.Items.Add("http://www.versant.com/");
                    listBoxPagesToAdd.Items.Add("http://web.progress.com/en/objectstore/");
                    listBoxPagesToAdd.Items.Add("https://www.mongodb.org/");
                    listBoxPagesToAdd.Items.Add("http://cassandra.apache.org/");
                    listBoxPagesToAdd.Items.Add("http://www.sybase.com/");
                    listBoxPagesToAdd.Items.Add("http://www.mcobject.com/perst");
                    listBoxPagesToAdd.Items.Add("http://www.marklogic.com/what-is-marklogic/");
                    listBoxPagesToAdd.Items.Add("http://hamsterdb.com/");
                    listBoxPagesToAdd.Items.Add("http://www.firebirdsql.org/");
                    listBoxPagesToAdd.Items.Add("http://www.h2database.com/");
                    listBoxPagesToAdd.Items.Add("http://www.oracle.com/technology/products/berkeley-db");
                    listBoxPagesToAdd.Items.Add("http://www.scimore.com/");
                    listBoxPagesToAdd.Items.Add("http://www.stsdb.com/");
                    listBoxPagesToAdd.Items.Add("http://www.sqlite.org/about.html");
                    listBoxPagesToAdd.Items.Add("http://www.mysql.com/products/enterprise/techspec.html");
                    listBoxPagesToAdd.Items.Add("http://www.objectivity.com");
                    listBoxPagesToAdd.Items.Add("http://vistadb.net/");
                    listBoxPagesToAdd.Items.Add("http://www.google.com/search?q=object+database&sourceid=ie7&rls=com.microsoft:en-us:IE-SearchBox&ie=&oe=");
                }
                _indexRoot.Persist(session, _indexRoot);
            }
            else
            {
                _indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
            }

            if (_indexRoot.Repository.DocumentSet.Count > 0)
            {
                List <Document> docs = _indexRoot.Repository.DocumentSet.ToList <Document>().Take(50).ToList <Document>();
                inDbListBox.ItemsSource = docs;
            }
            updateDataGrids(_indexRoot);
            session.Commit();
            //verify();
        }
Exemplo n.º 27
0
 public void bCreateDefaultCompareIntKeyPersonValue(int number)
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     Placement personPlace = new Placement((UInt32)number + 1, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.BeginUpdate();
     BTreeMap<int, Person> bTree = new BTreeMap<int, Person>(null, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     Person person;
     for (int i = 0; i < number; i++)
     {
       person = new Person();
       person.Persist(personPlace, session);
       bTree.Add(i, person);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeMap<int, Person> bTree = (BTreeMap<int, Person>)session.Open(id);
     int count = 0;
     int prior = 0;
     foreach (KeyValuePair<int, Person> pair in bTree)
     {
       count++;
       Assert.True(pair.Key == prior++);
       Assert.True(pair.Value != null);
     }
     Assert.True(number == count);
     session.Commit();
   }
 }
Exemplo n.º 28
0
 public void CreateDefaultCompareIntKey(int number)
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.BeginUpdate();
     BTreeSetOidShort<int> bTree = new BTreeSetOidShort<int>(null, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     for (int i = 0; i < number; i++)
     {       
       if (i > 1000 && i < 20000)
         bTree.Add(i);
       else
         bTree.AddFast(i);
     }
     bTree.Clear();
     for (int i = 0; i < number; i++)
     {       
       if (i > 1000 && i < 20000)
         bTree.Add(i);
       else
         bTree.AddFast(i);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeSetOidShort<int> bTree = (BTreeSetOidShort<int>) session.Open(id);
     int count = 0;
     int prior = 0;
     foreach (int i in bTree)
     {
       count++;
       Assert.True(i == prior++);
     }
     Assert.True(number == count);
     session.Commit();
   }
 }
Exemplo n.º 29
0
    public void AllSupported()
    {
      UInt64 id;
      AllSupported allSuported, allSupported2;
      AllSuportedSub1 allSuportedSub1, allSuportedSub2;
      AllSuportedSub2 allSuportedSub2_1, allSuportedSub2_2;
      AllSuportedSub3 allSuportedSub3_1, allSuportedSub3_2;
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        allSuportedSub1 = new AllSuportedSub1(3);
        allSuportedSub1.Persist(session, allSuportedSub1);
        id = allSuportedSub1.Id;
        session.Commit();
      }
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        allSuportedSub2 = (AllSuportedSub1)session.Open(id);
        Assert.NotNull(allSuportedSub2);
        session.Commit();
      }     
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        allSuportedSub2_1 = new AllSuportedSub2(3);
        allSuportedSub2_1.Persist(session, allSuportedSub2_1);
        id = allSuportedSub2_1.Id;
        session.Commit();
      }
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        allSuportedSub2_2 = (AllSuportedSub2)session.Open(id);
        Assert.NotNull(allSuportedSub2_2);
        session.Commit();
      }
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        allSuportedSub3_1 = new AllSuportedSub3(3);
        allSuportedSub3_1.Persist(session, allSuportedSub3_1);
        id = allSuportedSub3_1.Id;
        session.Commit();
      }
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        allSuportedSub3_2 = (AllSuportedSub3)session.Open(id);
        Assert.NotNull(allSuportedSub3_2);
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        var x = new AllSuportedSub5();
        session.Persist(x);
        id = x.Id;
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        var x = (AllSuportedSub5)session.Open(id);
        x.Update();
        x.nullableaDouble = 0.5;
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        var x = (AllSuportedSub5)session.Open(id);
        Assert.NotNull(x);
        Assert.AreEqual(x.nullableaDouble, 0.5);
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        allSuported = new AllSupported(3);
        allSuported.Persist(session, allSuported);
        id = allSuported.Id;
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginUpdate();
        allSupported2 = (AllSupported)session.Open(id);
        allSupported2.Update();
        allSupported2.nullableaDouble = 0.5;
        allSupported2.nullabledateTime = DateTime.MaxValue;
        allSupported2 = null;
        session.Commit();
      }

      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        session.BeginRead();
        allSupported2 = (AllSupported)session.Open(id);
        Assert.NotNull(allSupported2);
        Assert.AreEqual(allSupported2.nullableaDouble, 0.5);
        Assert.AreEqual(allSupported2.nullabledateTime, DateTime.MaxValue);
        session.Commit();
      }
    }
Exemplo n.º 30
0
 public void CreateTicksCompareFieldsOidShort(int numberOfTicks, int nodeSize)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     session.Open(10, 1, 1, false);
     session.Open(10, 1, 2, false);
     session.Open(10, 2, 1, false);
     session.Open(10, 2, 2, false);
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir, 2000, false))
   {
     //session.SetTraceAllDbActivity();
     //session.ClientCache.MinimumAvailableMegaBytes = 1100;
     session.BeginUpdate();
     CompareByField<Tick> compareByField = new CompareByField<Tick>("<Bid>k__BackingField", session, true);
     //compareByField.AddFieldToCompare("<Timestamp>k__BackingField");
     BTreeSetOidShort<Tick> bTree = new BTreeSetOidShort<Tick>(compareByField, session, (UInt16) nodeSize, sizeof(double), true);
     Placement place = new Placement((UInt32)numberOfTicks, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     Placement ticksPlace = new Placement((UInt32)numberOfTicks, 10000, 1, UInt16.MaxValue, UInt16.MaxValue);
     bTree.Persist(place, session);
     int i = 0;
     int dublicates = 0;
     foreach (var record in Tick.GenerateRandom((ulong) numberOfTicks))
     {
       session.Persist(record, ticksPlace);
       if (bTree.Add(record))
         i++;
       else
         dublicates++;
     }
     session.Commit();
     Console.WriteLine("Done creating and sorting with BTreeSetOidShort<Tick>" + i + " Tick objects by Bid value. Number of dublicates (not added to BTreeSet): " + dublicates);
   }
 }
Exemplo n.º 31
0
        static void Main(string[] args)
        {
            long triangles = 0;

            try
            {
                using (SessionNoServer session = new SessionNoServer(systemDir))
                {
                    int numberOfWorkerThreads = -1;
                    if (args.Length > 0)
                    {
                        if (!int.TryParse(args[0], out numberOfWorkerThreads))
                        {
                            Console.WriteLine("First parameter is numberOfWorkerThreads which must be an Int32");
                        }
                    }
                    bool      useLinq       = args.Length > 1;
                    Placement btreePlace    = new Placement(40, 1, 1, 10000, 65500, true);
                    Placement edgeInfoPlace = new Placement(40, 10000, 1, 10000, 65500, true);
                    session.BeginUpdate();
                    BTreeMap <int, int[]>         edges;
                    BTreeMapIterator <int, int[]> edgesItr;
                    int[]    edge   = null;
                    Database edgeDb = session.OpenDatabase(40, false, false);
                    if (edgeDb != null)
                    {
                        session.Commit();
                        session.BeginRead();
                        edges = (BTreeMap <int, int[]>)session.Open(40, 1, 1, false);
                    }
                    else
                    {
                        DatabaseLocation location = session.DatabaseLocations.Default();
                        //location.CompressPages = false; // no compression should make it faster (?)
                        session.NewDatabase(40, 395, "Edges");
                        edges = new BTreeMap <int, int[]>(null, session, 6000);
                        edges.Persist(btreePlace, session, true);
                        edgesItr = edges.Iterator();
                        using (StreamReader stream = new StreamReader(edgesInputFile, true))
                        {
                            int      a;
                            int      b;
                            string   line;
                            string[] fields;
                            while ((line = stream.ReadLine()) != null)
                            {
                                fields = line.Split(' ');
                                if (!int.TryParse(fields[0], out a))
                                {
                                    break;
                                }
                                b = int.Parse(fields[1]);
                                if (a != b)
                                {
                                    if (edgesItr.CurrentKey() == a || edgesItr.GoTo(a))
                                    {
                                        edge = edgesItr.CurrentValue();
                                        Array.Resize(ref edge, edge.Length + 1);
                                        edge[edge.Length - 1] = b;
                                        edgesItr.ReplaceValue(ref edge); // we need to update the value in the BTreeMap
                                    }
                                    else
                                    {
                                        edge    = new int[1];
                                        edge[0] = b;
                                        edges.Add(a, edge);
                                    }
                                }
                            }
                        }
                        edgesItr = edges.Iterator();
                        while (edgesItr.MoveNext())
                        {
                            edge = edgesItr.CurrentValue();
                            Array.Sort(edge);
                            edgesItr.ReplaceValue(ref edge);
                        }
                        session.Commit();
                        session.BeginRead();
                    }
                    Console.WriteLine("Number of Nodes found: " + edges.Count);
                    if (useLinq)
                    {
                        Console.WriteLine("Query using LINQ");
                    }
                    if (numberOfWorkerThreads > 0)
                    {
                        Console.WriteLine("Start of triangle discovery using " + numberOfWorkerThreads + " threads, time is " + DateTime.Now);
                    }
                    else if (numberOfWorkerThreads < 0)
                    {
                        Console.WriteLine("Start of triangle discovery using system automatically selected number of threads, time is " + DateTime.Now);
                    }
                    else
                    {
                        Console.WriteLine("Start of triangle discovery using main thread, time is " + DateTime.Now);
                    }

                    // Start counting triangles !
                    if (numberOfWorkerThreads != 0)
                    {
                        if (useLinq)
                        { // Please help, I have not figured out how to properly do the triangle query using LINQ
                            int[] edge2values = null;
                            if (numberOfWorkerThreads > 0)
                            {
                                triangles = (from KeyValuePair <int, int[]> edgeFrom in edges
                                             from int edgeTo1 in edgeFrom.Value
                                             where edgeFrom.Key < edgeTo1
                                             from int edgeTo2 in edgeFrom.Value
                                             where edgeFrom.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                                             select edge).AsParallel().WithDegreeOfParallelism(numberOfWorkerThreads).Count();
                            }
                            else
                            {
                                triangles = (from KeyValuePair <int, int[]> edgeFrom in edges
                                             from int edgeTo1 in edgeFrom.Value
                                             where edgeFrom.Key < edgeTo1
                                             from int edgeTo2 in edgeFrom.Value
                                             where edgeFrom.Key <edgeTo2 && edgeTo2> edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                                             select edge).AsParallel().Count();
                            }
                        }
                        else
                        {
                            edgesItr = edges.Iterator();
                            ParallelOptions pOptions = new ParallelOptions();
                            pOptions.MaxDegreeOfParallelism = numberOfWorkerThreads;
                            // First type parameter is the type of the source elements
                            // Second type parameter is the type of the local data (subtotal)
                            Parallel.ForEach <KeyValuePair <int, int[]>, long>(edges,                    // source collection
                                                                               pOptions,
                                                                               () => 0,                  // method to initialize the local variable
                                                                               (pair, loop, subtotal) => // method invoked by the loop on each iteration
                            {
                                int nodeId   = pair.Key;
                                int[] nodeTo = pair.Value;
                                int stop     = nodeTo.Length - 1;
                                int i        = stop;
                                int edgeToStart, edgeTo;
                                int pos;
                                while (i >= 0)
                                {
                                    int[] edgeInfo2;
                                    edgeToStart = nodeTo[i--];
                                    if (nodeId < edgeToStart)
                                    {
                                        if (edges.TryGetValue(edgeToStart, out edgeInfo2))
                                        {
                                            for (int j = stop; j >= i; j--)
                                            {
                                                edgeTo = nodeTo[j];
                                                if (edgeToStart < edgeTo)
                                                {
                                                    pos = Array.BinarySearch <int>(edgeInfo2, edgeTo);
                                                    if (pos >= 0)
                                                    { // we know this one is connected to edgeInfo.From because it is part of edgeInfo.To
                                                        subtotal++;
                                                    }
                                                }
                                                else
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                return(subtotal);
                            },
                                                                               // Method to be executed when all loops have completed.
                                                                               // finalResult is the final value of subtotal. supplied by the ForEach method.
                                                                               (finalResult) => Interlocked.Add(ref triangles, finalResult));
                        }
                    }
                    else if (useLinq)
                    {
                        triangles = queryUsingLINQ(edges);
                    }
                    else
                    {
                        triangles = discoverTrianglesSingleCore(edges);
                    }

                    session.Commit();
                }
                Console.WriteLine("Number of Triangles found: " + triangles);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
        }
Exemplo n.º 32
0
 public void UnpersistCompareFields(int bTreeDatabaseNumber)
 {
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginUpdate();
     BTreeSet<Person> bTree = (BTreeSet<Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
     BTreeSetIterator<Person> itr = bTree.Iterator();
     itr.GoToLast();
     itr.Remove();
     session.Abort();
     session.BeginUpdate();
     bTree = (BTreeSet<Person>)session.Open(Oid.Encode((uint)bTreeDatabaseNumber, 1, 1));
     bTree.Unpersist(session);
     session.Commit();
     session.BeginRead();
     Database db = session.OpenDatabase((uint)bTreeDatabaseNumber, false);
     foreach (Page page in db)
       foreach (OptimizedPersistable obj in page)
         if (obj.PageNumber > 0)
           Assert.Fail("No objects should remain in this database");
     session.Commit();
   }
 }
Exemplo n.º 33
0
 [TestCase(false)] // test will fail if pessimistic locking is used
 public void SingleReaderSingleUpdater4(bool useReaderCommit)
 {
   using (SessionNoServer updater = new SessionNoServer(systemDir, 5000)) 
   using (SessionNoServer reader = new SessionNoServer(systemDir, 5000))
   {
     updater.SetTraceAllDbActivity();
     reader.SetTraceAllDbActivity();
     updater.BeginUpdate();
     UInt32 dbNum = updater.DatabaseNumberOf(typeof(Man));
     Database db = updater.OpenDatabase(dbNum, true, false);
     if (db != null)
       updater.DeleteDatabase(db);
     updater.Commit();
     updater.BeginUpdate();
     Man man = new Man();
     for (int i = 0; i < 100; i++)
     {
       man = new Man();
       updater.Persist(man);
     }
     updater.Commit();
     reader.BeginRead();
     updater.BeginUpdate();
     db = reader.OpenDatabase(dbNum);
     foreach (Page page in db)
       Assert.True(page.PageInfo.VersionNumber == 1);
     if (useReaderCommit)
       reader.Commit();
     if (useReaderCommit)
       reader.BeginRead();
     else
       reader.ForceDatabaseCacheValidation();
     for (int i = 1; i < 25; i++)
     {
       db = reader.OpenDatabase(dbNum);
       foreach (Page page in db)
       {
         if (page.PageNumber > 1) // skip AutoPlacemnt page
         {
           Assert.True(page.PageInfo.VersionNumber == (ulong)i);
           Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
           Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
         }
       }
       if (useReaderCommit)
       {
         reader.Commit();
         reader.BeginRead();
       }
       else
         reader.ForceDatabaseCacheValidation();
       updater.Commit();
       updater.BeginUpdate();
     }
     Database db2 = reader.OpenDatabase(dbNum);
     db = updater.OpenDatabase(dbNum);
     for (int i = 25; i < 50; i++)
     {
       foreach (Page page in db)
       {
         if (page.PageNumber > 1)
         {
           Assert.True(page.PageInfo.VersionNumber == (ulong)i);
           Man manUpdated = (Man)updater.Open(dbNum, page.PageNumber, 1, true);
         }
       }
       updater.Commit();
       updater.BeginUpdate();
       db2 = reader.OpenDatabase(dbNum);
       foreach (Page page in db2)
       {
         if (page.PageNumber > 1)
         {
           //Assert.True(page.PageInfo.VersionNumber == (ulong)i + 1);
           Man man2 = (Man)reader.Open(dbNum, page.PageNumber, 1, false);
         }
       }
       reader.ClearPageCache();
       System.GC.Collect();
     }
     reader.Commit();
     updater.Commit();
   }
 }
Exemplo n.º 34
0
 public void aCreateDefaultCompareIntKeyIntValue(int number)
 {
   Oid id;
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     Placement place = new Placement((UInt32)number, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
     session.Compact();
     session.BeginUpdate();
     BTreeMap<int, int> bTree = new BTreeMap<int, int>(null, session);
     bTree.Persist(place, session);
     id = bTree.Oid;
     for (int i = 0; i < number; i++)
     {
       bTree.Add(i, i + 1);
     }
     bTree.Clear();
     for (int i = 0; i < number; i++)
     {
       bTree.Add(i, i + 1);
     }
     session.Commit();
   }
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     session.BeginRead();
     BTreeMap<int, int> bTree = (BTreeMap<int, int>)session.Open(id);
     int count = 0;
     int prior = 0;
     foreach (KeyValuePair<int, int> pair in bTree)
     {
       count++;
       Assert.True(pair.Key == prior++);
       Assert.True(pair.Key == pair.Value - 1);
     }
     Assert.True(number == count);
     session.Commit();
   }
 }
Exemplo n.º 35
0
    static void Main(string[] args)
    {
      long triangles = 0;
      try
      {
        using (SessionNoServer session = new SessionNoServer(systemDir))
        {
          int numberOfWorkerThreads = -1;
          if (args.Length > 0)
          {
            if (!int.TryParse(args[0], out numberOfWorkerThreads))
              Console.WriteLine("First parameter is numberOfWorkerThreads which must be an Int32");
          }
          bool useLinq = args.Length > 1;
          Placement btreePlace = new Placement(40, 1, 1, 10000, 65500, true);
          Placement edgeInfoPlace = new Placement(40, 10000, 1, 10000, 65500, true);
          session.BeginUpdate();
          BTreeMap<int, int[]> edges;
          BTreeMapIterator<int, int[]> edgesItr;
          int[] edge = null;
          Database edgeDb = session.OpenDatabase(40, false, false);
          if (edgeDb != null)
          {
            session.Commit();
            session.BeginRead();
            edges = (BTreeMap<int, int[]>)session.Open(40, 1, 1, false);
          }
          else
          {
            DatabaseLocation location = session.DatabaseLocations.Default();
            //location.CompressPages = false; // no compression should make it faster (?) 
            session.NewDatabase(40, 395, "Edges");
            edges = new BTreeMap<int, int[]>(null, session, 6000);
            edges.Persist(btreePlace, session, true);
            edgesItr = edges.Iterator();
            using (StreamReader stream = new StreamReader(edgesInputFile, true))
            {
              int a;
              int b;
              string line;
              string[] fields;
              while ((line = stream.ReadLine()) != null)
              {
                fields = line.Split(' ');
                if (!int.TryParse(fields[0], out a))
                  break;
                b = int.Parse(fields[1]);
                if (a != b)
                {
                  if (edgesItr.CurrentKey() == a || edgesItr.GoTo(a))
                  {
                    edge = edgesItr.CurrentValue();
                    Array.Resize(ref edge, edge.Length + 1);
                    edge[edge.Length - 1] = b;
                    edgesItr.ReplaceValue(ref edge); // we need to update the value in the BTreeMap
                  }
                  else
                  {
                    edge = new int[1];
                    edge[0] = b;
                    edges.Add(a, edge);
                  }
                }
              }
            }
            edgesItr = edges.Iterator();
            while (edgesItr.MoveNext())
            {
              edge = edgesItr.CurrentValue();
              Array.Sort(edge);
              edgesItr.ReplaceValue(ref edge);
            }
            session.Commit();
            session.BeginRead();
          }
          Console.WriteLine("Number of Nodes found: " + edges.Count);
          if (useLinq)
            Console.WriteLine("Query using LINQ");
          if (numberOfWorkerThreads > 0)           
            Console.WriteLine("Start of triangle discovery using " + numberOfWorkerThreads + " threads, time is " + DateTime.Now);
          else if (numberOfWorkerThreads < 0)
            Console.WriteLine("Start of triangle discovery using system automatically selected number of threads, time is " + DateTime.Now);
          else
            Console.WriteLine("Start of triangle discovery using main thread, time is " + DateTime.Now);

          // Start counting triangles !
          if (numberOfWorkerThreads != 0)
          {
            if (useLinq)
            { // Please help, I have not figured out how to properly do the triangle query using LINQ
              int[] edge2values = null;
              if (numberOfWorkerThreads > 0)
                triangles = (from KeyValuePair<int, int[]> edgeFrom in edges
                           from int edgeTo1 in edgeFrom.Value
                           where edgeFrom.Key < edgeTo1
                           from int edgeTo2 in edgeFrom.Value
                           where edgeFrom.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                           select edge).AsParallel().WithDegreeOfParallelism(numberOfWorkerThreads).Count();
              else
                triangles =  (from KeyValuePair<int, int[]> edgeFrom in edges
                              from int edgeTo1 in edgeFrom.Value
                             where edgeFrom.Key < edgeTo1
                             from int edgeTo2 in edgeFrom.Value
                             where edgeFrom.Key < edgeTo2 && edgeTo2 > edgeTo1 && edges.TryGetValue(edgeTo1, out edge2values) && Array.BinarySearch(edge2values, edgeTo2) >= 0
                             select edge).AsParallel().Count();
            }
            else
            {
              edgesItr = edges.Iterator();
              ParallelOptions pOptions = new ParallelOptions();
              pOptions.MaxDegreeOfParallelism = numberOfWorkerThreads;
              // First type parameter is the type of the source elements
              // Second type parameter is the type of the local data (subtotal)
              Parallel.ForEach<KeyValuePair<int, int[]>, long>(edges, // source collection
                pOptions,
                () => 0, // method to initialize the local variable
                (pair, loop, subtotal) => // method invoked by the loop on each iteration
                {
                  int nodeId = pair.Key;
                  int[] nodeTo = pair.Value;
                  int stop = nodeTo.Length - 1;
                  int i = stop;
                  int edgeToStart, edgeTo;
                  int pos;
                  while (i >= 0)
                  {
                    int[] edgeInfo2;
                    edgeToStart = nodeTo[i--];
                    if (nodeId < edgeToStart)
                    {
                      if (edges.TryGetValue(edgeToStart, out edgeInfo2))
                      {
                        for (int j = stop; j >= i; j--)
                        {
                          edgeTo = nodeTo[j];
                          if (edgeToStart < edgeTo)
                          {
                            pos = Array.BinarySearch<int>(edgeInfo2, edgeTo);
                            if (pos >= 0)
                            { // we know this one is connected to edgeInfo.From because it is part of edgeInfo.To
                              subtotal++;
                            }
                          }
                          else
                            break;
                        }
                      }
                    }
                    else
                      break;
                  }
                  return subtotal;
                },
                // Method to be executed when all loops have completed.
                // finalResult is the final value of subtotal. supplied by the ForEach method.
                (finalResult) => Interlocked.Add(ref triangles, finalResult));
            }
          }
          else if (useLinq)
            triangles = queryUsingLINQ(edges);
          else
            triangles = discoverTrianglesSingleCore(edges);

          session.Commit();

        }
        Console.WriteLine("Number of Triangles found: " + triangles);
      }
      catch (Exception e)
      {
        System.Console.WriteLine(e);
      }
    }
Exemplo n.º 36
0
    public MainWindow()
    {
      const ushort btreeNodeSize = 5000;
      GCSettings.LatencyMode = GCLatencyMode.Batch;// try to keep the WeakIOptimizedPersistableReference objects around longer      
      dataGridList = new List<DataGrid>();
      dataTableList = new List<DataTable>();
      InitializeComponent();
      session = new SessionNoServer(s_systemDir);
      Placement placerIndexRoot = new Placement(IndexRoot.PlaceInDatabase);
      session.BeginUpdate();
      Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
      File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"), true);
      IndexRoot indexRoot;
      Database db = session.OpenDatabase(IndexRoot.PlaceInDatabase, false, false);
      if (db == null)
      {
        session.NewDatabase(IndexRoot.PlaceInDatabase, 0, "IndexRoot");
        session.NewDatabase(Lexicon.PlaceInDatabase, 0, "Lexicon");
        session.NewDatabase(Document.PlaceInDatabase, 0, "Document");
        session.NewDatabase(Repository.PlaceInDatabase, 0, "Repository");
        session.NewDatabase(DocumentText.PlaceInDatabase, 0, "DocumentText");
        session.NewDatabase(Word.PlaceInDatabase, 0, "Word");
        indexRoot = new IndexRoot(btreeNodeSize, session);
        if (Directory.Exists(s_booksDir))
        {
          string[] directoryTextFiles = Directory.GetFiles(s_booksDir, "*.txt");
          foreach (string fileName in directoryTextFiles)
          {
            listBoxPagesToAdd.Items.Add(fileName);
          }
        }
        else
        {
          wordMinCt.Text = 1.ToString();
          listBoxPagesToAdd.Items.Add("http://www.VelocityDB.com/");
          // other database products
          listBoxPagesToAdd.Items.Add("https://foundationdb.com/");
          listBoxPagesToAdd.Items.Add("http://www.oracle.com/us/products/database/index.html");
          listBoxPagesToAdd.Items.Add("http://www-01.ibm.com/software/data/db2/");
          listBoxPagesToAdd.Items.Add("http://www.versant.com/");
          listBoxPagesToAdd.Items.Add("http://web.progress.com/en/objectstore/");
          listBoxPagesToAdd.Items.Add("https://www.mongodb.org/");
          listBoxPagesToAdd.Items.Add("http://cassandra.apache.org/");
          listBoxPagesToAdd.Items.Add("http://www.sybase.com/");
          listBoxPagesToAdd.Items.Add("http://www.mcobject.com/perst");
          listBoxPagesToAdd.Items.Add("http://www.marklogic.com/what-is-marklogic/");
          listBoxPagesToAdd.Items.Add("http://hamsterdb.com/");
          listBoxPagesToAdd.Items.Add("http://www.firebirdsql.org/");
          listBoxPagesToAdd.Items.Add("http://www.h2database.com/");
          listBoxPagesToAdd.Items.Add("http://www.oracle.com/technology/products/berkeley-db");
          listBoxPagesToAdd.Items.Add("http://www.scimore.com/");
          listBoxPagesToAdd.Items.Add("http://www.stsdb.com/");
          listBoxPagesToAdd.Items.Add("http://www.sqlite.org/about.html");
          listBoxPagesToAdd.Items.Add("http://www.mysql.com/products/enterprise/techspec.html");
          listBoxPagesToAdd.Items.Add("http://www.objectivity.com");
          listBoxPagesToAdd.Items.Add("http://vistadb.net/");
          listBoxPagesToAdd.Items.Add("http://www.google.com/search?q=object+database&sourceid=ie7&rls=com.microsoft:en-us:IE-SearchBox&ie=&oe=");
        }
        indexRoot.Persist(session, indexRoot);
      }
      else
        indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));

      if (indexRoot.repository.documentSet.Count > 0)
      {
        List<Document> docs = indexRoot.repository.documentSet.ToList<Document>().Take(50).ToList<Document>();
        inDbListBox.ItemsSource = docs;
      }
      updateDataGrids(indexRoot);
      session.Commit();
      //verify();
    }
Exemplo n.º 37
0
        public void AllSupported()
        {
            UInt64          id;
            AllSupported    allSuported, allSupported2;
            AllSuportedSub1 allSuportedSub1, allSuportedSub2;
            AllSuportedSub2 allSuportedSub2_1, allSuportedSub2_2;
            AllSuportedSub3 allSuportedSub3_1, allSuportedSub3_2;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSuportedSub1 = new AllSuportedSub1(3);
                allSuportedSub1.Persist(session, allSuportedSub1);
                id = allSuportedSub1.Id;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                allSuportedSub2 = (AllSuportedSub1)session.Open(id);
                Assert.NotNull(allSuportedSub2);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSuportedSub2_1 = new AllSuportedSub2(3);
                allSuportedSub2_1.Persist(session, allSuportedSub2_1);
                id = allSuportedSub2_1.Id;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                allSuportedSub2_2 = (AllSuportedSub2)session.Open(id);
                Assert.NotNull(allSuportedSub2_2);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSuportedSub3_1 = new AllSuportedSub3(3);
                allSuportedSub3_1.Persist(session, allSuportedSub3_1);
                id = allSuportedSub3_1.Id;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                allSuportedSub3_2 = (AllSuportedSub3)session.Open(id);
                Assert.NotNull(allSuportedSub3_2);
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                var x = new AllSuportedSub5();
                session.Persist(x);
                id = x.Id;
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                var x = (AllSuportedSub5)session.Open(id);
                x.Update();
                x.nullableaDouble = 0.5;
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                var x = (AllSuportedSub5)session.Open(id);
                Assert.NotNull(x);
                Assert.AreEqual(x.nullableaDouble, 0.5);
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSuported = new AllSupported(3);
                allSuported.Persist(session, allSuported);
                allSuported.m_weakRefArray[0] = new WeakIOptimizedPersistableReference <IOptimizedPersistable>(allSuported);
                allSuported.m_objectArray[0]  = new WeakIOptimizedPersistableReference <IOptimizedPersistable>(allSuported);
                id = allSuported.Id;
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSupported2 = (AllSupported)session.Open(id);
                allSupported2.Update();
                allSupported2.nullableaDouble  = 0.5;
                allSupported2.NullableDateTime = DateTime.MaxValue;
                allSupported2 = null;
                session.Commit();
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                allSupported2 = (AllSupported)session.Open(id);
                Assert.NotNull(allSupported2);
                Assert.AreEqual(allSupported2.nullableaDouble, 0.5);
                Assert.AreEqual(allSupported2.NullableDateTime, DateTime.MaxValue);
                session.Commit();
                session.BeginUpdate();
                allSupported2.NullableDateTime = DateTime.UtcNow;

                session.Commit();
                session.BeginRead();
                allSupported2 = (AllSupported)session.Open(id);
                Assert.AreEqual(DateTimeKind.Utc, allSupported2.NullableDateTime.Value.Kind);
                session.Commit();
            }
        }