예제 #1
0
        public void ModelInfo()
        {
            ModelInfo model = new ModelInfo();
            BomTable  bt    = new BomTable()
            {
                BomName = Guid.NewGuid().ToString(),
                Header  = new List <string>()
                {
                    Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                },
                TotalCols = 2,
                TotalRow  = 10,
                //Rows = new List<BomTableRow>()
            };

            //for (int i = 0; i < 10; i++)
            //{
            //    BomTableRow row = new BomTableRow();

            //    //for (int j = 0; j < 10; j++)
            //    //{
            //    //    row.Cells.Add("Value " + j.ToString());
            //    //}

            //    bt.Rows.Add(row);

            //}
            model.BomTables = new List <BomTable>();
            model.BomTables.Add(bt);

            try
            {
                using (SessionNoServerShared session = new SessionNoServerShared(s_systemDir))
                {
                    session.BeginUpdate();
                    //session.Persist(model.BomTables);
                    session.Persist(model);
                    session.Commit();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }

            try
            {
                using (SessionNoServerShared session = new SessionNoServerShared(s_systemDir))
                {
                    session.BeginRead();
                    //var models1 = session.AllObjects<List<BomTable>>().ToList();
                    var models = session.AllObjects <ModelInfo>().ToList();
                    session.Commit();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }
        }
예제 #2
0
        public void LocalDateTest()
        {
            LocalDate d1      = new LocalDate(2016, 1, 10);
            LocalDate d2      = new LocalDate(2016, 1, 1);
            LocalDate d1other = new LocalDate(2016, 1, 10);

            Assert.AreNotEqual(d1, d2);
            Assert.AreEqual(d1, d1other);

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                LocalDateField test1 = new LocalDateField("def", d1);
                session.Persist(test1);
                LocalDateField test = new LocalDateField("abc", d2);
                session.Persist(test);
                var result1 = session.AllObjects <LocalDateField>().First(t => t.Field2.Equals(d2)); // this works
                session.Commit();
            }

            using (var session = new SessionNoServerShared(systemDir))
            {
                session.BeginRead();
                var result2 = session.AllObjects <LocalDateField>().First(t =>
                {
                    var l = t.Field2;
                    return(l.Equals(d2));
                }); // this should work and doesnt
                session.Commit();
            }
        }
예제 #3
0
        public void hashCodeComparerStringTest()
        {
            Oid id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                Placement place = new Placement(223, 1, 1, UInt16.MaxValue, UInt16.MaxValue);
                session.Compact();
                session.BeginUpdate();
                HashCodeComparer <string> hashCodeComparer = new HashCodeComparer <string>();
                BTreeSet <string>         bTree            = new BTreeSet <string>(hashCodeComparer, session);
                bTree.Persist(place, session);
                id = bTree.Oid;
                for (int i = 0; i < 100000; i++)
                {
                    bTree.Add(i.ToString());
                }
                session.Commit();
            }
            using (var session = new SessionNoServerShared(systemDir))
            {
                session.BeginRead();
                BTreeSet <string> bTree = (BTreeSet <string>)session.Open(id);
                int count = 0;
                foreach (string str in bTree)
                {
                    count++;
                }
                Assert.True(100000 == count);
                session.Commit();
            }
        }
예제 #4
0
 public void FixedSizeManyTest(int howMany)
 {
     using (var session = new SessionNoServer(systemDir))
     {
         session.BeginUpdate();
         FixedSize fixedSize;
         FixedSize fixedSizePrior = new FixedSize();
         for (int i = 0; i < howMany; i++)
         {
             fixedSize = new FixedSize();
             fixedSize.Persist(session, fixedSizePrior);
             fixedSizePrior = fixedSize;
         }
         session.Commit();
     }
     using (var session = new SessionNoServerShared(systemDir))
     {
         session.BeginRead();
         Database db = session.OpenDatabase(FixedSize.PlaceInDatabase);
         foreach (Page page in db)
         {
             if (page.PageNumber > 0)
             {
                 foreach (FixedSize fixedSize in page)
                 {
                     --howMany;
                     Assert.NotNull(fixedSize);
                 }
             }
         }
         session.Commit();
     }
 }
예제 #5
0
        public void LazyLoadDepth()
        {
            UInt64 id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                LazyLoadByDepth lazy = null;
                for (uint i = 1; i <= 100; i++)
                {
                    lazy = new LazyLoadByDepth(i, lazy);
                }
                session.Persist(lazy);
                id = lazy.Id;
                session.Commit();
            }

            using (var session = new SessionNoServerShared(systemDir))
            {
                UInt32 ct = 100;
                session.BeginRead();
                LazyLoadByDepth lazy = (LazyLoadByDepth)session.Open(id, false, false, 0); // load only the root of the object graph
                Assert.AreEqual(ct--, lazy.MyCt);
                Assert.IsNull(lazy.MyRefPeek);
                Assert.NotNull(lazy.MyRef);
                Assert.NotNull(lazy.MyRefPeek);
                lazy = lazy.MyRef;
                Assert.AreEqual(ct--, lazy.MyCt);
                Assert.IsNull(lazy.MyRefPeek);
                Assert.NotNull(lazy.MyRef);
                Assert.NotNull(lazy.MyRefPeek);
                lazy = lazy.MyRef;
                Assert.AreEqual(ct--, lazy.MyCt);
                Assert.IsNull(lazy.MyRefPeek);
                Assert.NotNull(lazy.MyRef);
                Assert.NotNull(lazy.MyRefPeek);
                lazy = lazy.MyRef;
                Assert.AreEqual(ct--, lazy.MyCt);
                Assert.IsNull(lazy.MyRefPeek);
                Assert.NotNull(lazy.MyRef);
                Assert.NotNull(lazy.MyRefPeek);
                session.Commit();
            }
        }
예제 #6
0
        public void SingleReaderSingleUpdater2()
        {
            UInt64 id;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                Man man = new Man();
                man.Persist(session, man);
                id = man.Id;
                session.Commit();
                session.BeginUpdate();
                man.Age = ++man.Age;
                using (var session2 = new SessionNoServerShared(systemDir))
                {
                    session2.BeginRead();
                    Man man2 = (Man)session2.Open(id);
                    Assert.Less(man2.Age, man.Age);
                    session2.Commit();
                }
                session.Commit();
            }
            System.GC.Collect();
        }
예제 #7
0
        public void AllSupported()
        {
            UInt64          id;
            AllSupported    allSuported, allSupported2;
            AllSuportedSub1 allSuportedSub1, allSuportedSub2;
            AllSuportedSub2 allSuportedSub2_1, allSuportedSub2_2;
            AllSuportedSub3 allSuportedSub3_1, allSuportedSub3_2;
            AllSuportedSub4 allSuportedSub4;

            AllSupported[,] a1              = new AllSupported[10, 5];
            AllSupported[,,] a2             = new AllSupported[8, 4, 3];
            AllSupported[,,,] a3            = new AllSupported[7, 6, 2, 1];
            Dictionary <int, string>[,,] a4 = new Dictionary <int, string> [2, 4, 33];
            string s1str = DataMember.TypeToString(a1.GetType());
            string s2str = DataMember.TypeToString(a2.GetType());
            string s3str = DataMember.TypeToString(a3.GetType());
            string s4str = DataMember.TypeToString(a4.GetType());
            bool   typeUpdated;

            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                Type t1 = DataMember.StringToType(s1str, session, out typeUpdated);
                Type t2 = DataMember.StringToType(s2str, session, out typeUpdated);
                Type t3 = DataMember.StringToType(s3str, session, out typeUpdated);
                Type t4 = DataMember.StringToType(s4str, session, out typeUpdated);
                Assert.AreEqual(t1, a1.GetType());
                Assert.AreEqual(t2, a2.GetType());
                Assert.AreEqual(t3, a3.GetType());
                Assert.AreEqual(t4, a4.GetType());
                allSuportedSub4 = new AllSuportedSub4();
                session.Persist(allSuportedSub4);
                id = allSuportedSub4.Id;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                allSuportedSub4 = (AllSuportedSub4)session.Open(id);
                Assert.NotNull(allSuportedSub4);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSuportedSub1 = new AllSuportedSub1(3);
                allSuportedSub1.Persist(session, allSuportedSub1);
                foreach (var o in allSuportedSub1.PetListOidShort)
                {
                    session.Persist(o, allSuportedSub1);
                }
                id = allSuportedSub1.Id;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                allSuportedSub2 = (AllSuportedSub1)session.Open(id);
                Assert.NotNull(allSuportedSub2);
                Assert.AreEqual(allSuportedSub2.m_type[0], typeof(Pet));
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSuportedSub2_1 = new AllSuportedSub2(3);
                allSuportedSub2_1.Persist(session, allSuportedSub2_1);
                id = allSuportedSub2_1.Id;
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginRead();
                allSuportedSub2_2 = (AllSuportedSub2)session.Open(id);
                Assert.NotNull(allSuportedSub2_2);
                session.Commit();
            }
            using (SessionNoServer session = new SessionNoServer(systemDir))
            {
                session.BeginUpdate();
                allSuportedSub3_1 = new AllSuportedSub3(3);
                allSuportedSub3_1.Persist(session, allSuportedSub3_1);
                id = allSuportedSub3_1.Id;
                session.Commit();
            }
            using (var session = new SessionNoServerShared(systemDir))
            {
                session.BeginRead();
                allSuportedSub3_2 = (AllSuportedSub3)session.Open(id);
                Assert.NotNull(allSuportedSub3_2);
                session.Commit();
            }

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

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

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

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

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

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

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