Ejemplo n.º 1
0
        public void VelocityDB_SaveKunde_Test()
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                try
                {
                    session.BeginUpdate();
                    var kunde = new KundeVelocityDB();
                    kunde.Kto          = "4711";
                    kunde.KtoFoerderer = "4712";
                    kunde.Periode      = 2016006;
                    session.Persist(kunde);
                    session.Commit();
                }
                catch (Exception e)
                {
                    session.Abort();
                }
            }

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();

                var kunden = session.AllObjects <KundeVelocityDB>();
                var query  = from k in kunden
                             where k.Kto.Contains("4711")
                             select k;

                Assert.AreEqual("4711", query.First()?.Kto);
                Assert.AreEqual("4712", query.First()?.KtoFoerderer);
                Assert.AreEqual(2016006, query.First()?.Periode);
            }
        }
Ejemplo n.º 2
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();
     }
 }
Ejemplo n.º 3
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menuItem = (MenuItem)e.Source;
            Document myItem   = (Document)menuItem.DataContext;

            session.BeginUpdate();
            try
            {
                IndexRoot indexRoot = (IndexRoot)session.Open(Oid.Encode(IndexRoot.PlaceInDatabase, 1, 1));
                int       index;
                if (indexRoot.repository.documentSet.TryGetKey(myItem, ref myItem))
                {
                    index = myItem.Remove(indexRoot, session);
                }
                else
                {
                    index = -1; // weird case - should not happen
                }
                inDbListBox.ItemsSource = indexRoot.repository.documentSet.ToList <Document>();
                updateDataGrids(indexRoot, index);
                session.Commit();
            }
            catch
            {
                session.Abort();
            }
        }
Ejemplo n.º 4
0
        static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath

        static int Main(string[] args)
        {
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
                try
                {
                    session.BeginUpdate();
                    Company company = new Company();
                    company.Name = "MyCompany";
                    session.Persist(company);
                    Employee employee1 = new Employee();
                    employee1.Employer  = company;
                    employee1.FirstName = "John";
                    employee1.LastName  = "Walter";
                    session.Persist(employee1);
                    session.Commit();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.Message);
                    session.Abort();
                }
            }
            Retrieve();
            return(0);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            SessionBase.BaseDatabasePath = @"d:/Databases";
            bool dirExist = Directory.Exists(Path.Combine(SessionBase.BaseDatabasePath, s_systemDir));

            if (!dirExist)
            {
                ImdbImport.ImprortImdb(s_systemDir);
            }
            KevinBaconNumbers kevinBaconNumbers = new KevinBaconNumbers();

            using (SessionNoServer session = new SessionNoServer(s_systemDir))
            {
                try
                {
                    session.BeginRead();
                    kevinBaconNumbers.calculateNumbers(session);
                    kevinBaconNumbers.printResults();
                    session.Commit();
                }
                catch (Exception e)
                {
                    session.Abort();
                    Console.WriteLine(e.ToString());
                }
            }
        }
Ejemplo n.º 6
0
    static readonly string systemDir = "QuickStart"; // appended to SessionBase.BaseDatabasePath

    static int Main(string[] args)
    {
      using (SessionNoServer session = new SessionNoServer(systemDir))
      {
        Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
        try
        {
          session.BeginUpdate();
          Company company = new Company();
          company.Name = "MyCompany";
          session.Persist(company);
          Employee employee1 = new Employee();
          employee1.Employer = company;
          employee1.FirstName = "John";
          employee1.LastName = "Walter";
          session.Persist(employee1);
          session.Commit();
        }
        catch (Exception ex)
        {
          Trace.WriteLine(ex.Message);
          session.Abort();
        }
      }
      Retrieve();
      return 0;
    }
Ejemplo 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;
     }
 }
Ejemplo n.º 8
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();
   }
 }
Ejemplo n.º 9
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();
     }
 }
Ejemplo n.º 10
0
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var nome  = this.Nome.Text;
            var idade = int.Parse(this.Idade.Text);

            using (SessionNoServer session = new SessionNoServer("OODBMS_FOLDER"))
            {
                try
                {
                    session.BeginUpdate();
                    var empregado = new Empregado(nome, idade, Guid.NewGuid().ToString());
                    session.Persist(empregado);
                    session.Commit();
                }
                catch (Exception ex)
                {
                    session.Abort();
                    return;
                }
            }

            this.Close();
        }
        public void CarregarEmpregados()
        {
            using (var session = new SessionNoServer("OODBMS_FOLDER"))
            {
                try
                {
                    session.BeginRead();
                    var empregados = session.AllObjects <Empregado>();

                    Empregados.Items.Clear();
                    foreach (var empregado in empregados)
                    {
                        Empregados.Items.Add(empregado);
                    }

                    session.Commit();
                }
                catch (Exception e)
                {
                    session.Abort();
                }
            }
        }
Ejemplo n.º 12
0
        public static void ImprortImdb(string systemDir)
        {
            ImdbImport imdbImport = new ImdbImport();

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                try
                {
                    session.BeginUpdate();
                    File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"), true);
                    ImdbRoot imdbRoot = new ImdbRoot(session);
                    session.Persist(imdbRoot);
                    imdbImport.ParseActors(session, imdbRoot);
                    imdbImport.ParseActresses(session, imdbRoot);
                    foreach (ActingPerson acting in imdbRoot.ActorSet)
                    {
                        if (!imdbRoot.ActingByNameSet.Add(acting))
                        {
                            Console.WriteLine("Dublicate ActingPerson found (in ActorSet): " + acting.Name);
                        }
                    }
                    foreach (ActingPerson acting in imdbRoot.ActressSet)
                    {
                        if (!imdbRoot.ActingByNameSet.Add(acting))
                        {
                            Console.WriteLine("Dublicate ActingPerson found (in ActressSet): " + acting.Name);
                        }
                    }
                    session.Commit();
                }
                catch (Exception e)
                {
                    session.Abort();
                    Console.WriteLine(e.ToString());
                }
            }
        }
Ejemplo n.º 13
0
    static void importEntireWikipedia()
    {
      const ushort btreeNodeSize = 10000;
      Console.WriteLine(DateTime.Now.ToString() + ", start importing Wikipedia text");
      //System.Xml.Schema.XmlSchema docSchema;
      //using (System.Xml.XmlTextReader schemaReader = new System.Xml.XmlTextReader("c:\\export-0_5.xsd"))
      //{
      //  docSchema = System.Xml.Schema.XmlSchema.Read(schemaReader, ValidationCallBack);
      // }
      int docCount = 0;
      using (SessionNoServer session = new SessionNoServer(s_systemDir, 5000, false, false, CacheEnum.No)) // turn of page and object caching
      {
        Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
        //GCSettings.LatencyMode = GCLatencyMode.Batch;// try to keep the WeakIOptimizedPersistableReference objects around longer
        Placement documentPlacement = new Placement(Document.PlaceInDatabase, 1003, 1, 500, 1000, false, false, 1000, false);
        Placement contentPlacement = new Placement(Document.PlaceInDatabase, 1, 1, 500, UInt16.MaxValue, false, false, 1, false);
        XmlComment xmlComment;
        XmlElement xmlElement;
        XmlEntity xmlEntity;
        XmlText xmlText;
        XmlWhitespace xmlWhitespace;
        session.BeginUpdate();
        File.Copy(s_licenseDbFile, System.IO.Path.Combine(session.SystemDirectory, "4.odb"), true);
        // register all database schema classes used by the application in advance to avoid lock conflict later in parallell indexing
        session.RegisterClass(typeof(Repository));
        session.RegisterClass(typeof(IndexRoot));
        session.RegisterClass(typeof(Document));
        session.RegisterClass(typeof(Lexicon));
        session.RegisterClass(typeof(DocumentText));
        session.RegisterClass(typeof(Word));
        session.RegisterClass(typeof(WordGlobal));
        session.RegisterClass(typeof(WordHit));
        session.RegisterClass(typeof(BTreeSet<Document>));
        session.RegisterClass(typeof(OidShort));
        session.RegisterClass(typeof(BTreeMap<Word, WordHit>));
        session.RegisterClass(typeof(HashCodeComparer<Word>));
        session.RegisterClass(typeof(BTreeSetOidShort<Word>));
        session.RegisterClass(typeof(BTreeMapOidShort<Word, WordHit>));
        Database db = session.OpenDatabase(IndexRoot.PlaceInDatabase, false, false);
        if (db != null)
        {
          outputSomeInfo(session);
          session.Abort();
          return;
        }
        session.NewDatabase(IndexRoot.PlaceInDatabase, 0, "IndexRoot");
        session.NewDatabase(Lexicon.PlaceInDatabase, 0, "Lexicon");
        session.NewDatabase(Repository.PlaceInDatabase, 0, "Repository");
        for (UInt32 i = 40; i <= 186; i++)
        {
          session.NewDatabase(i, 512, "Document"); // pre allocate 146 Document databases presized to 512MB each
        }
        //session.SetTraceDbActivity(Lexicon.PlaceInDatabase);
        //session.SetTraceAllDbActivity();
        XmlDocument xmlDocument = new XmlDocument("enwiki-latest-pages-articles.xml");
        IndexRoot indexRoot = new IndexRoot(btreeNodeSize, session);
        indexRoot.Persist(session, indexRoot, true);
        Document doc = null;
        bool titleElement = false;
        bool pageText = false;
        UInt32 currentDocumentDatabaseNum = documentPlacement.StartDatabaseNumber;
        using (FileStream fs = new FileStream(s_wikipediaXmlFile, FileMode.Open))
        {
          //using (GZipStream zipStream = new GZipStream(fs, CompressionMode.Decompress)) // if input was a .gz file
          {
            using (System.Xml.XmlTextReader textReader = new System.Xml.XmlTextReader(fs))
            {
              while (textReader.Read())
              {
                System.Xml.XmlNodeType nodeType = textReader.NodeType;
                switch (nodeType)
                {
                  case System.Xml.XmlNodeType.Attribute:
                    break;
                  case System.Xml.XmlNodeType.CDATA:
                    break;
                  case System.Xml.XmlNodeType.Comment:
                    xmlComment = new XmlComment(textReader.Value, xmlDocument);
                    break;
                  case System.Xml.XmlNodeType.Document:
                    break;
                  case System.Xml.XmlNodeType.DocumentFragment:
                    break;
                  case System.Xml.XmlNodeType.DocumentType:
                    break;
                  case System.Xml.XmlNodeType.Element:
                    xmlElement = new XmlElement(textReader.Prefix, textReader.LocalName, textReader.NamespaceURI, xmlDocument);
                    if (textReader.LocalName == "title")
                      titleElement = true;
                    else if (textReader.LocalName == "text")
                      pageText = true;
                    break;
                  case System.Xml.XmlNodeType.EndElement:
                    if (textReader.LocalName == "title" && doc != null)
                      titleElement = false;
                    else if (textReader.LocalName == "text" && doc != null)
                      pageText = false;
                    break;
                  case System.Xml.XmlNodeType.EndEntity:
                    break;
                  case System.Xml.XmlNodeType.Entity:
                    xmlEntity = new XmlEntity(textReader.LocalName, xmlDocument);
                    break;
                  case System.Xml.XmlNodeType.EntityReference:
                    break;
                  case System.Xml.XmlNodeType.None:
                    break;
                  case System.Xml.XmlNodeType.Notation:
                    break;
                  case System.Xml.XmlNodeType.ProcessingInstruction:
                    break;
                  case System.Xml.XmlNodeType.SignificantWhitespace:
                    break;
                  case System.Xml.XmlNodeType.Text:
                    xmlText = new XmlText(textReader.Value, xmlDocument);
                    if (titleElement)
                    {
                      doc = new Document(textReader.Value, indexRoot, session);
                      doc.Persist(documentPlacement, session, true);
                      if (doc.DatabaseNumber != currentDocumentDatabaseNum)
                      {
                        session.FlushUpdates(session.OpenDatabase(currentDocumentDatabaseNum));
                        Console.WriteLine("Database: " + currentDocumentDatabaseNum +" is completed, done importing article " + docCount + " number of lines: " + textReader.LineNumber);
                        currentDocumentDatabaseNum = doc.DatabaseNumber;
                      }
                      //doc.Page.Database.Name = doc.Name;
                    }
                    else if (doc != null && pageText)
                    {
#if DEBUGx
                      Console.WriteLine(doc.Name + " line: " + textReader.LineNumber);
#endif
                      //if (textReader.LineNumber > 1000000)
                      //{
                      //  session.Commit();
                      //  return;
                      //}
                      DocumentText content = new DocumentText(textReader.Value, doc);
                      if (doc.DatabaseNumber != contentPlacement.TryDatabaseNumber)
                        contentPlacement = new Placement(doc.DatabaseNumber, (ushort)contentPlacement.StartPageNumber, 1, contentPlacement.MaxObjectsPerPage, contentPlacement.MaxPagesPerDatabase, false, false, 1, false);
                      content.Persist(contentPlacement, session, false);
                      Debug.Assert(content.DatabaseNumber == doc.DatabaseNumber);
                      doc.Content = content;
                      indexRoot.repository.documentSet.AddFast(doc);
                      if (++docCount % 1000000 == 0)
                      {
                        //session.Commit(false); // skip recovery check, we do it in BeginUpdate which is enough
                        Console.WriteLine("Done importing article " + docCount + " number of lines: " + textReader.LineNumber);
                        //session.BeginUpdate();
                      }
                    }
                    break;
                  case System.Xml.XmlNodeType.Whitespace:
                    xmlWhitespace = new XmlWhitespace(textReader.Value, xmlDocument);
                    break;
                  case System.Xml.XmlNodeType.XmlDeclaration:
                    break;
                };
              }
              Console.WriteLine("Finished importing article " + docCount + " number of lines: " + textReader.LineNumber);
            }
          }
        }
        session.Commit();
      }
      Console.WriteLine(DateTime.Now.ToString() + ", done importing Wikipedia text");
    }
Ejemplo n.º 14
0
        protected void RegisterButton_Click(object sender, EventArgs e)
        {
            try
            {
                using (SessionNoServer session = new SessionNoServer(s_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 = session.AllObjects <Root>(false).FirstOrDefault();
                    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)
                        //{
                        //  string verifiedEmail = (string)Session["EmailVerificationEmail"];
                        //int emailVerification = (int)Session["EmailVerification"];
                        //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;
                        //}
                        //}
                        customer.idNumber = root.NewCustomerNumber();
                        session.Persist(customer);
                        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();
            }
        }
Ejemplo n.º 15
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.Now;
                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();
            }
        }
Ejemplo n.º 16
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();
   }
 }
Ejemplo n.º 17
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;
   }
 }
Ejemplo n.º 18
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();
      }
    }
Ejemplo n.º 19
0
    static readonly string s_systemDir = "Indexes"; // appended to SessionBase.BaseDatabasePath

    static void Main(string[] args)
    {
      try
      {
        Trace.Listeners.Add(new ConsoleTraceListener());
        string brandName = "Toyota";
        string color = "Blue";
        int maxPassengers = 5;
        int fuelCapacity = 40;
        double litresPer100Kilometers = 5;
        DateTime modelYear = new DateTime(2003, 1, 1);
        string modelName = "Highlander";
        int maxSpeed = 200;
        int odometer = 100000;
        string registrationState = "Texas";
        string registrationPlate = "TX343434";
        string insurancePolicy = "CAA7878787";
        DriversLicense license = new DriversLicense("California", "B7788888", DateTime.Now + new TimeSpan(1825, 0, 0, 0));
        Person person = new Person("Mats Persson", license);
        InsuranceCompany insuranceCompany = new InsuranceCompany("Allstate", "858727878");
        Car car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
          odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        { // cleanup data from a possible prior run
          session.BeginUpdate();
          foreach (Database db in session.OpenAllDatabases(true))
            if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber)
              session.DeleteDatabase(db);
          session.Commit();
          File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
          //session.AddToIndexInSeperateThread = false;
          session.BeginUpdate();
          session.Persist(car);
          registrationState = "Maine";
          car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
          odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
          session.Persist(car);
          color = "Red";
          maxPassengers = 5;
          fuelCapacity = 50;
          litresPer100Kilometers = 8;
          modelYear = new DateTime(2006, 1, 1);
          brandName = "Toyota";
          modelName = "Tacoma";
          maxSpeed = 210;
          odometer = 50000;
          registrationState = "Texas";
          registrationPlate = "TX343433";
          insurancePolicy = "CAA7878777";
          car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
            odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
          session.Persist(car);
          color = "Black";
          maxPassengers = 5;
          fuelCapacity = 60;
          litresPer100Kilometers = 3;
          modelYear = new DateTime(2001, 1, 1);
          brandName = "Lincoln";
          modelName = "Town Car";
          maxSpeed = 220;
          odometer = 250000;
          registrationState = "Texas";
          registrationPlate = "TX543433";
          insurancePolicy = "CAA7878775";
          car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
            odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
          session.Persist(car);
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.BeginRead();
          Console.WriteLine("Blue Cars");
          BTreeSet<Car> bTree = session.Index<Car>("color");
          foreach (Car c in (from aCar in bTree where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          Console.WriteLine("Cars in fuel efficiency order");
          foreach (Car c in session.Index<Car>("litresPer100Kilometers"))
            Console.WriteLine(c.ToStringDetails(session));
          Console.WriteLine("Vehicles ordered modelYear, brandName, modelName, color");
          foreach (Vehicle v in session.Index<Vehicle>())
            Console.WriteLine(v.ToStringDetails(session));
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          session.BeginUpdate();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Car c = (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar).First();
          c.Color = "Green";
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          session.BeginUpdate();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Car c = (from aCar in session.Index<Car>("color") where aCar.Color == "Green" select aCar).First();
          UInt64 id = c.Id;
          session.DeleteObject(id);
          session.Abort();
          session.BeginUpdate();
          session.DeleteObject(id);
          session.Commit();
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Console.WriteLine("Blue Cars");
          foreach (Car c in (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          for (int i = 0; i < 10000; i++)
          { // add some junk to make search harder
            car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, i,
            odometer, registrationState, registrationPlate + i, insuranceCompany, insurancePolicy);
            session.Persist(car);
          }
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
          Console.WriteLine("Blue Cars");
          foreach (Car c in (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          Car c = (from aCar in session.Index<Car>("color") where aCar.Color == "Blue" select aCar).First();
          c.Unpersist(session);
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          foreach (Car c in session.Index<Car>())
            Console.WriteLine(c.ToStringDetails(session));
          Console.WriteLine("Blue Cars");
          foreach (Car c in (from aCar in session.Index<Car>() where aCar.Color == "Blue" select aCar))
            Console.WriteLine(c.ToStringDetails(session));
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          InsuranceCompany prior = insuranceCompany;
          try
          {
            for (int i = 0; i < 100000; i++)
            {
              insuranceCompany = new InsuranceCompany("AAA", "858787878");
              session.Persist(insuranceCompany);
            }
            Debug.Assert(false); // should not get here
          }
          catch (UniqueConstraintException)
          {
          }
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }
        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
          var q = from company in session.Index<InsuranceCompany>("name", db) where company.Name == "AAA" select company;
          foreach (InsuranceCompany company in q)
            Console.WriteLine(company.ToStringDetails(session)); // only one will match
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginUpdate();
          Customer joe = new Customer("Joe");
          session.Persist(joe);
          Customer karim = new Customer("Karim");
          session.Persist(karim);
          Customer tony = new Customer("Tony");
          session.Persist(tony);
          Customer wayne = new Customer("Wayne");
          session.Persist(wayne);
          Order order = new Order(joe);
          Payment payment = new Payment(order);
          order = new Order(karim);
          payment = new Payment(order);
          payment = new Payment(order);
          payment = new Payment(order);
          order = new Order(tony);
          payment = new Payment(order);
          payment = new Payment(order);
          order = new Order(wayne);
          payment = new Payment(order);
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

        using (SessionNoServer session = new SessionNoServer(s_systemDir))
        {
          session.TraceIndexUsage = true;
          Stopwatch sw = new Stopwatch();
          sw.Start();
          session.BeginRead();
          var karim = (from customer in session.Index<Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
          var karimOrders = karim.Orders;
          var karimOrderFromOrders = (from order in session.Index<Order>("m_customer") where order.Customer == karim select order).ToArray();
          session.Commit();
          session.BeginUpdate();
          karim = (from customer in session.Index<Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
          karim.StreetAddress = "1623 Bonita Ave";
          session.Commit();
          sw.Stop();
          Console.WriteLine(sw.Elapsed);
        }

      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
      }
    }
Ejemplo n.º 20
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();
      }
    }
Ejemplo n.º 21
0
 public static void ImprortImdb(string systemDir)
 {
   ImdbImport imdbImport = new ImdbImport();
   using (SessionNoServer session = new SessionNoServer(systemDir))
   {
     try
     {
       session.BeginUpdate();
       File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"), true);
       ImdbRoot imdbRoot = new ImdbRoot(session);
       session.Persist(imdbRoot);
       imdbImport.ParseActors(session, imdbRoot);
       imdbImport.ParseActresses(session, imdbRoot);
       foreach (ActingPerson acting in imdbRoot.ActorSet)
         if (!imdbRoot.ActingByNameSet.Add(acting))
           Console.WriteLine("Dublicate ActingPerson found (in ActorSet): " + acting.Name);          
       foreach (ActingPerson acting in imdbRoot.ActressSet)
         if (!imdbRoot.ActingByNameSet.Add(acting))
           Console.WriteLine("Dublicate ActingPerson found (in ActressSet): " + acting.Name);
       session.Commit();
     }
     catch (Exception e)
     {
       session.Abort();
       Console.WriteLine(e.ToString());
     }
   }
 }
Ejemplo n.º 22
0
 static void Main(string[] args)
 {
   SessionBase.BaseDatabasePath = @"d:/Databases";
   bool dirExist = Directory.Exists(Path.Combine(SessionBase.BaseDatabasePath, s_systemDir));
   if (!dirExist)
     ImdbImport.ImprortImdb(s_systemDir);
   KevinBaconNumbers kevinBaconNumbers = new KevinBaconNumbers();
   using (SessionNoServer session = new SessionNoServer(s_systemDir))
   {
     try
     {
       session.BeginRead();
       kevinBaconNumbers.calculateNumbers(session);
       kevinBaconNumbers.printResults();
       session.Commit();
     }
     catch (Exception e)
     {
       session.Abort();
       Console.WriteLine(e.ToString());
     }
   }
 }
Ejemplo n.º 23
0
        static void ImportEntireWikipedia()
        {
            const ushort btreeNodeSize = 10000;

            Console.WriteLine(DateTime.Now.ToString() + ", start importing Wikipedia text");
            //System.Xml.Schema.XmlSchema docSchema;
            //using (System.Xml.XmlTextReader schemaReader = new System.Xml.XmlTextReader("c:\\export-0_5.xsd"))
            //{
            //  docSchema = System.Xml.Schema.XmlSchema.Read(schemaReader, ValidationCallBack);
            // }
            int docCount = 0;

            using (SessionNoServer session = new SessionNoServer(s_systemDir, 5000, false, false, CacheEnum.No)) // turn of page and object caching
            {
                Console.WriteLine($"Running with databases in directory: {session.SystemDirectory}");
                //GCSettings.LatencyMode = GCLatencyMode.Batch;// try to keep the WeakIOptimizedPersistableReference objects around longer
                XmlComment    xmlComment;
                XmlElement    xmlElement;
                XmlEntity     xmlEntity;
                XmlText       xmlText;
                XmlWhitespace xmlWhitespace;
                session.BeginUpdate();
                // register all database schema classes used by the application in advance to avoid lock conflict later in parallel indexing
                Database db = session.OpenDatabase(IndexRoot.PlaceInDatabase, false, false);
                if (db != null)
                {
                    outputSomeInfo(session);
                    session.Abort();
                    return;
                }
                //session.SetTraceDbActivity(Lexicon.PlaceInDatabase);
                //session.SetTraceAllDbActivity();
                XmlDocument xmlDocument = new XmlDocument("enwiki-latest-pages-articles.xml");
                IndexRoot   indexRoot   = new IndexRoot(btreeNodeSize, session);
                indexRoot.Persist(session, indexRoot, true);
                UInt32   currentDocumentDatabaseNum = 0;
                Document doc          = null;
                bool     titleElement = false;
                bool     pageText     = false;
                using (FileStream fs = new FileStream(s_wikipediaXmlFile, FileMode.Open))
                {
                    //using (GZipStream zipStream = new GZipStream(fs, CompressionMode.Decompress)) // if input was a .gz file
                    {
                        using (System.Xml.XmlTextReader textReader = new System.Xml.XmlTextReader(fs))
                        {
                            while (textReader.Read())
                            {
                                System.Xml.XmlNodeType nodeType = textReader.NodeType;
                                switch (nodeType)
                                {
                                case System.Xml.XmlNodeType.Attribute:
                                    break;

                                case System.Xml.XmlNodeType.CDATA:
                                    break;

                                case System.Xml.XmlNodeType.Comment:
                                    xmlComment = new XmlComment(textReader.Value, xmlDocument);
                                    break;

                                case System.Xml.XmlNodeType.Document:
                                    break;

                                case System.Xml.XmlNodeType.DocumentFragment:
                                    break;

                                case System.Xml.XmlNodeType.DocumentType:
                                    break;

                                case System.Xml.XmlNodeType.Element:
                                    xmlElement = new XmlElement(textReader.Prefix, textReader.LocalName, textReader.NamespaceURI, xmlDocument);
                                    if (textReader.LocalName == "title")
                                    {
                                        titleElement = true;
                                    }
                                    else if (textReader.LocalName == "text")
                                    {
                                        pageText = true;
                                    }
                                    break;

                                case System.Xml.XmlNodeType.EndElement:
                                    if (textReader.LocalName == "title" && doc != null)
                                    {
                                        titleElement = false;
                                    }
                                    else if (textReader.LocalName == "text" && doc != null)
                                    {
                                        pageText = false;
                                    }
                                    break;

                                case System.Xml.XmlNodeType.EndEntity:
                                    break;

                                case System.Xml.XmlNodeType.Entity:
                                    xmlEntity = new XmlEntity(textReader.LocalName, xmlDocument);
                                    break;

                                case System.Xml.XmlNodeType.EntityReference:
                                    break;

                                case System.Xml.XmlNodeType.None:
                                    break;

                                case System.Xml.XmlNodeType.Notation:
                                    break;

                                case System.Xml.XmlNodeType.ProcessingInstruction:
                                    break;

                                case System.Xml.XmlNodeType.SignificantWhitespace:
                                    break;

                                case System.Xml.XmlNodeType.Text:
                                    xmlText = new XmlText(textReader.Value, xmlDocument);
                                    if (titleElement)
                                    {
                                        doc = new Document(textReader.Value, indexRoot, session);
                                        session.Persist(doc);
                                        if (doc.DatabaseNumber != currentDocumentDatabaseNum)
                                        {
                                            if (currentDocumentDatabaseNum > 0)
                                            {
                                                session.FlushUpdates();
                                                Console.WriteLine("Database: " + currentDocumentDatabaseNum + " is completed, done importing article " + docCount + " number of lines: " + textReader.LineNumber);
                                            }
                                            currentDocumentDatabaseNum = doc.DatabaseNumber;
                                        }
                                        //doc.Page.Database.Name = doc.Name;
                                    }
                                    else if (doc != null && pageText)
                                    {
#if DEBUGx
                                        Console.WriteLine(doc.Name + " line: " + textReader.LineNumber);
#endif
                                        //if (textReader.LineNumber > 1000000)
                                        //{
                                        //  session.Commit();
                                        //  return;
                                        //}
                                        DocumentText content = new DocumentText(textReader.Value, doc);
                                        session.Persist(content, 10000);
                                        doc.Content = content;
                                        indexRoot.Repository.DocumentSet.AddFast(doc);
                                        if (++docCount % 1000000 == 0)
                                        {
                                            //session.Commit(false); // skip recovery check, we do it in BeginUpdate which is enough
                                            Console.WriteLine("Done importing article " + docCount + " number of lines: " + textReader.LineNumber);
                                            //session.BeginUpdate();
                                        }
                                    }
                                    break;

                                case System.Xml.XmlNodeType.Whitespace:
                                    xmlWhitespace = new XmlWhitespace(textReader.Value, xmlDocument);
                                    break;

                                case System.Xml.XmlNodeType.XmlDeclaration:
                                    break;
                                }
                                ;
                            }
                            Console.WriteLine("Finished importing article " + docCount + " number of lines: " + textReader.LineNumber);
                        }
                    }
                }
                session.Commit();
            }
            Console.WriteLine(DateTime.Now.ToString() + ", done importing Wikipedia text");
        }
Ejemplo n.º 24
0
        static void importEntireWikipedia()
        {
            const ushort btreeNodeSize = 10000;

            Console.WriteLine(DateTime.Now.ToString() + ", start importing Wikipedia text");
            //System.Xml.Schema.XmlSchema docSchema;
            //using (System.Xml.XmlTextReader schemaReader = new System.Xml.XmlTextReader("c:\\export-0_5.xsd"))
            //{
            //  docSchema = System.Xml.Schema.XmlSchema.Read(schemaReader, ValidationCallBack);
            // }
            int docCount = 0;

            using (SessionNoServer session = new SessionNoServer(s_systemDir, 5000, false, false, CacheEnum.No)) // turn of page and object caching
            {
                Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
                //GCSettings.LatencyMode = GCLatencyMode.Batch;// try to keep the WeakIOptimizedPersistableReference objects around longer
                Placement     documentPlacement = new Placement(Document.PlaceInDatabase, 1003, 1, 500, 1000, false, false, 1000, false);
                Placement     contentPlacement  = new Placement(Document.PlaceInDatabase, 1, 1, 500, UInt16.MaxValue, false, false, 1, false);
                XmlComment    xmlComment;
                XmlElement    xmlElement;
                XmlEntity     xmlEntity;
                XmlText       xmlText;
                XmlWhitespace xmlWhitespace;
                session.BeginUpdate();
                File.Copy(s_licenseDbFile, System.IO.Path.Combine(session.SystemDirectory, "4.odb"), true);
                // register all database schema classes used by the application in advance to avoid lock conflict later in parallell indexing
                session.RegisterClass(typeof(Repository));
                session.RegisterClass(typeof(IndexRoot));
                session.RegisterClass(typeof(Document));
                session.RegisterClass(typeof(Lexicon));
                session.RegisterClass(typeof(DocumentText));
                session.RegisterClass(typeof(Word));
                session.RegisterClass(typeof(WordGlobal));
                session.RegisterClass(typeof(WordHit));
                session.RegisterClass(typeof(BTreeSet <Document>));
                session.RegisterClass(typeof(OidShort));
                session.RegisterClass(typeof(BTreeMap <Word, WordHit>));
                session.RegisterClass(typeof(HashCodeComparer <Word>));
                session.RegisterClass(typeof(BTreeSetOidShort <Word>));
                session.RegisterClass(typeof(BTreeMapOidShort <Word, WordHit>));
                Database db = session.OpenDatabase(IndexRoot.PlaceInDatabase, false, false);
                if (db != null)
                {
                    outputSomeInfo(session);
                    session.Abort();
                    return;
                }
                session.NewDatabase(IndexRoot.PlaceInDatabase, 0, "IndexRoot");
                session.NewDatabase(Lexicon.PlaceInDatabase, 0, "Lexicon");
                session.NewDatabase(Repository.PlaceInDatabase, 0, "Repository");
                for (UInt32 i = 40; i <= 186; i++)
                {
                    session.NewDatabase(i, 512, "Document"); // pre allocate 146 Document databases presized to 512MB each
                }
                //session.SetTraceDbActivity(Lexicon.PlaceInDatabase);
                //session.SetTraceAllDbActivity();
                XmlDocument xmlDocument = new XmlDocument("enwiki-latest-pages-articles.xml");
                IndexRoot   indexRoot   = new IndexRoot(btreeNodeSize, session);
                indexRoot.Persist(session, indexRoot, true);
                Document doc          = null;
                bool     titleElement = false;
                bool     pageText     = false;
                UInt32   currentDocumentDatabaseNum = documentPlacement.StartDatabaseNumber;
                using (FileStream fs = new FileStream(s_wikipediaXmlFile, FileMode.Open))
                {
                    //using (GZipStream zipStream = new GZipStream(fs, CompressionMode.Decompress)) // if input was a .gz file
                    {
                        using (System.Xml.XmlTextReader textReader = new System.Xml.XmlTextReader(fs))
                        {
                            while (textReader.Read())
                            {
                                System.Xml.XmlNodeType nodeType = textReader.NodeType;
                                switch (nodeType)
                                {
                                case System.Xml.XmlNodeType.Attribute:
                                    break;

                                case System.Xml.XmlNodeType.CDATA:
                                    break;

                                case System.Xml.XmlNodeType.Comment:
                                    xmlComment = new XmlComment(textReader.Value, xmlDocument);
                                    break;

                                case System.Xml.XmlNodeType.Document:
                                    break;

                                case System.Xml.XmlNodeType.DocumentFragment:
                                    break;

                                case System.Xml.XmlNodeType.DocumentType:
                                    break;

                                case System.Xml.XmlNodeType.Element:
                                    xmlElement = new XmlElement(textReader.Prefix, textReader.LocalName, textReader.NamespaceURI, xmlDocument);
                                    if (textReader.LocalName == "title")
                                    {
                                        titleElement = true;
                                    }
                                    else if (textReader.LocalName == "text")
                                    {
                                        pageText = true;
                                    }
                                    break;

                                case System.Xml.XmlNodeType.EndElement:
                                    if (textReader.LocalName == "title" && doc != null)
                                    {
                                        titleElement = false;
                                    }
                                    else if (textReader.LocalName == "text" && doc != null)
                                    {
                                        pageText = false;
                                    }
                                    break;

                                case System.Xml.XmlNodeType.EndEntity:
                                    break;

                                case System.Xml.XmlNodeType.Entity:
                                    xmlEntity = new XmlEntity(textReader.LocalName, xmlDocument);
                                    break;

                                case System.Xml.XmlNodeType.EntityReference:
                                    break;

                                case System.Xml.XmlNodeType.None:
                                    break;

                                case System.Xml.XmlNodeType.Notation:
                                    break;

                                case System.Xml.XmlNodeType.ProcessingInstruction:
                                    break;

                                case System.Xml.XmlNodeType.SignificantWhitespace:
                                    break;

                                case System.Xml.XmlNodeType.Text:
                                    xmlText = new XmlText(textReader.Value, xmlDocument);
                                    if (titleElement)
                                    {
                                        doc = new Document(textReader.Value, indexRoot, session);
                                        doc.Persist(documentPlacement, session, true);
                                        if (doc.DatabaseNumber != currentDocumentDatabaseNum)
                                        {
                                            session.FlushUpdates(session.OpenDatabase(currentDocumentDatabaseNum));
                                            Console.WriteLine("Database: " + currentDocumentDatabaseNum + " is completed, done importing article " + docCount + " number of lines: " + textReader.LineNumber);
                                            currentDocumentDatabaseNum = doc.DatabaseNumber;
                                        }
                                        //doc.Page.Database.Name = doc.Name;
                                    }
                                    else if (doc != null && pageText)
                                    {
#if DEBUGx
                                        Console.WriteLine(doc.Name + " line: " + textReader.LineNumber);
#endif
                                        //if (textReader.LineNumber > 1000000)
                                        //{
                                        //  session.Commit();
                                        //  return;
                                        //}
                                        DocumentText content = new DocumentText(textReader.Value, doc);
                                        if (doc.DatabaseNumber != contentPlacement.TryDatabaseNumber)
                                        {
                                            contentPlacement = new Placement(doc.DatabaseNumber, (ushort)contentPlacement.StartPageNumber, 1, contentPlacement.MaxObjectsPerPage, contentPlacement.MaxPagesPerDatabase, false, false, 1, false);
                                        }
                                        content.Persist(contentPlacement, session, false);
                                        Debug.Assert(content.DatabaseNumber == doc.DatabaseNumber);
                                        doc.Content = content;
                                        indexRoot.repository.documentSet.AddFast(doc);
                                        if (++docCount % 1000000 == 0)
                                        {
                                            //session.Commit(false); // skip recovery check, we do it in BeginUpdate which is enough
                                            Console.WriteLine("Done importing article " + docCount + " number of lines: " + textReader.LineNumber);
                                            //session.BeginUpdate();
                                        }
                                    }
                                    break;

                                case System.Xml.XmlNodeType.Whitespace:
                                    xmlWhitespace = new XmlWhitespace(textReader.Value, xmlDocument);
                                    break;

                                case System.Xml.XmlNodeType.XmlDeclaration:
                                    break;
                                }
                                ;
                            }
                            Console.WriteLine("Finished importing article " + docCount + " number of lines: " + textReader.LineNumber);
                        }
                    }
                }
                session.Commit();
            }
            Console.WriteLine(DateTime.Now.ToString() + ", done importing Wikipedia text");
        }
Ejemplo n.º 25
0
        static readonly string s_systemDir     = "Indexes"; // appended to SessionBase.BaseDatabasePath

        static void Main(string[] args)
        {
            try
            {
                Trace.Listeners.Add(new ConsoleTraceListener());
                string           brandName              = "Toyota";
                string           color                  = "Blue";
                int              maxPassengers          = 5;
                int              fuelCapacity           = 40;
                double           litresPer100Kilometers = 5;
                DateTime         modelYear              = new DateTime(2003, 1, 1);
                string           modelName              = "Highlander";
                int              maxSpeed               = 200;
                int              odometer               = 100000;
                string           registrationState      = "Texas";
                string           registrationPlate      = "TX343434";
                string           insurancePolicy        = "CAA7878787";
                DriversLicense   license                = new DriversLicense("California", "B7788888", DateTime.Now + new TimeSpan(1825, 0, 0, 0));
                Person           person                 = new Person("Mats Persson", license);
                InsuranceCompany insuranceCompany       = new InsuranceCompany("Allstate", "858727878");
                Car              car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                               odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                { // cleanup data from a possible prior run
                    session.BeginUpdate();
                    foreach (Database db in session.OpenAllDatabases(true))
                    {
                        if (db.DatabaseNumber >= 10 || db.DatabaseNumber == SessionBase.IndexDescriptorDatabaseNumber)
                        {
                            session.DeleteDatabase(db);
                        }
                    }
                    session.Commit();
                    File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
                    //session.AddToIndexInSeperateThread = false;
                    session.BeginUpdate();
                    session.Persist(car);
                    registrationState = "Maine";
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                  odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    color                  = "Red";
                    maxPassengers          = 5;
                    fuelCapacity           = 50;
                    litresPer100Kilometers = 8;
                    modelYear              = new DateTime(2006, 1, 1);
                    brandName              = "Toyota";
                    modelName              = "Tacoma";
                    maxSpeed               = 210;
                    odometer               = 50000;
                    registrationState      = "Texas";
                    registrationPlate      = "TX343433";
                    insurancePolicy        = "CAA7878777";
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                  odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    color                  = "Black";
                    maxPassengers          = 5;
                    fuelCapacity           = 60;
                    litresPer100Kilometers = 3;
                    modelYear              = new DateTime(2001, 1, 1);
                    brandName              = "Lincoln";
                    modelName              = "Town Car";
                    maxSpeed               = 220;
                    odometer               = 250000;
                    registrationState      = "Texas";
                    registrationPlate      = "TX543433";
                    insurancePolicy        = "CAA7878775";
                    car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, maxSpeed,
                                  odometer, registrationState, registrationPlate, insuranceCompany, insurancePolicy);
                    session.Persist(car);
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.BeginRead();
                    Console.WriteLine("Blue Cars");
                    BTreeSet <Car> bTree = session.Index <Car>("color");
                    foreach (Car c in (from aCar in bTree where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    Console.WriteLine("Cars in fuel efficiency order");
                    foreach (Car c in session.Index <Car>("litresPer100Kilometers"))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    Console.WriteLine("Vehicles ordered modelYear, brandName, modelName, color");
                    foreach (Vehicle v in session.Index <Vehicle>())
                    {
                        Console.WriteLine(v.ToStringDetails(session));
                    }
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    session.BeginUpdate();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                    c.Color = "Green";
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    session.BeginUpdate();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Car    c  = (from aCar in session.Index <Car>("color") where aCar.Color == "Green" select aCar).First();
                    UInt64 id = c.Id;
                    session.DeleteObject(id);
                    session.Abort();
                    session.BeginUpdate();
                    session.DeleteObject(id);
                    session.Commit();
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Console.WriteLine("Blue Cars");
                    foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    for (int i = 0; i < 10000; i++)
                    { // add some junk to make search harder
                        car = new Car(color, maxPassengers, fuelCapacity, litresPer100Kilometers, modelYear, brandName, modelName, i,
                                      odometer, registrationState, registrationPlate + i, insuranceCompany, insurancePolicy);
                        session.Persist(car);
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    // these LINQ statements will trigger a binary search lookup (not a linear search) of the matching Car objects in the BTreeSet
                    Console.WriteLine("Blue Cars");
                    foreach (Car c in (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    Car c = (from aCar in session.Index <Car>("color") where aCar.Color == "Blue" select aCar).First();
                    c.Unpersist(session);
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    foreach (Car c in session.Index <Car>())
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    Console.WriteLine("Blue Cars");
                    foreach (Car c in (from aCar in session.Index <Car>() where aCar.Color == "Blue" select aCar))
                    {
                        Console.WriteLine(c.ToStringDetails(session));
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    InsuranceCompany prior = insuranceCompany;
                    try
                    {
                        for (int i = 0; i < 100000; i++)
                        {
                            insuranceCompany = new InsuranceCompany("AAA", "858787878");
                            session.Persist(insuranceCompany);
                        }
                        Debug.Assert(false); // should not get here
                    }
                    catch (UniqueConstraintException)
                    {
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    Database db = session.OpenDatabase(session.DatabaseNumberOf(typeof(InsuranceCompany)));
                    var      q  = from company in session.Index <InsuranceCompany>("name", db) where company.Name == "AAA" select company;
                    foreach (InsuranceCompany company in q)
                    {
                        Console.WriteLine(company.ToStringDetails(session)); // only one will match
                    }
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }

                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginUpdate();
                    Customer joe = new Customer("Joe");
                    session.Persist(joe);
                    Customer karim = new Customer("Karim");
                    session.Persist(karim);
                    Customer tony = new Customer("Tony");
                    session.Persist(tony);
                    Customer wayne = new Customer("Wayne");
                    session.Persist(wayne);
                    Order   order   = new Order(joe);
                    Payment payment = new Payment(order);
                    order   = new Order(karim);
                    payment = new Payment(order);
                    payment = new Payment(order);
                    payment = new Payment(order);
                    order   = new Order(tony);
                    payment = new Payment(order);
                    payment = new Payment(order);
                    order   = new Order(wayne);
                    payment = new Payment(order);
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }

                using (SessionNoServer session = new SessionNoServer(s_systemDir))
                {
                    session.TraceIndexUsage = true;
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    session.BeginRead();
                    var karim                = (from customer in session.Index <Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
                    var karimOrders          = karim.Orders;
                    var karimOrderFromOrders = (from order in session.Index <Order>("m_customer") where order.Customer == karim select order).ToArray();
                    session.Commit();
                    session.BeginUpdate();
                    karim = (from customer in session.Index <Customer>("m_name") where customer.Name == "Karim" select customer).FirstOrDefault();
                    karim.StreetAddress = "1623 Bonita Ave";
                    session.Commit();
                    sw.Stop();
                    Console.WriteLine(sw.Elapsed);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }