コード例 #1
0
        private MemoryBin NewBin(int initialSize, IGrowthStrategy strategy)
        {
            MemoryStorage storage = new MemoryStorage(strategy);
            MemoryBin     bin     = (MemoryBin)storage.Open(new BinConfiguration(Uri, false, initialSize
                                                                                 , false));

            return(bin);
        }
コード例 #2
0
        public virtual void TestConstantStrategy()
        {
            int       growth = 100;
            MemoryBin bin    = NewBin(InitialSize, new ConstantGrowthStrategy(growth));

            Write(bin, 0, InitialSize + 1, growth + InitialSize);
            Write(bin, 0, growth + InitialSize + 1, InitialSize + (2 * growth));
        }
コード例 #3
0
 public TransportObjectContainer(ObjectContainerBase parent, MemoryBin memoryFile)
     : base(parent.Config())
 {
     _memoryBin           = memoryFile;
     _parent              = parent;
     _lock                = parent.Lock();
     _showInternalClasses = parent._showInternalClasses;
     Open();
 }
コード例 #4
0
        public virtual void TestDoublingStrategy()
        {
            MemoryBin bin = NewBin(0, new DoublingGrowthStrategy());

            Write(bin, 0, 1, 1);
            Write(bin, 0, 2, 2);
            Write(bin, 0, 3, 4);
            bin = NewBin(InitialSize, new DoublingGrowthStrategy());
            Write(bin, 0, InitialSize + 1, 2 * InitialSize);
        }
コード例 #5
0
        public virtual void TestGrowth()
        {
            int[] values = new int[] { 42, 47, 48 };
            MemoryBinGrowthTestCase.MockGrowthStrategy strategy = new MemoryBinGrowthTestCase.MockGrowthStrategy
                                                                      (values);
            MemoryBin bin = NewBin(InitialSize, strategy);

            Write(bin, 0, InitialSize + 1, values[0]);
            Write(bin, values[0], 1, values[1]);
            Write(bin, values[1], 1, values[2]);
            strategy.Verify();
        }
コード例 #6
0
        public static SerializedGraph Marshall(ObjectContainerBase serviceProvider, object
                                               obj)
        {
            MemoryBin memoryBin = new MemoryBin(223, GrowthStrategy());
            TransportObjectContainer carrier = NewTransportObjectContainer(serviceProvider, memoryBin
                                                                           );

            carrier.ProduceClassMetadata(carrier.Reflector().ForObject(obj));
            carrier.Store(obj);
            int id = (int)carrier.GetID(obj);

            carrier.Close();
            return(new SerializedGraph(id, memoryBin.Data()));
        }
コード例 #7
0
        public static object Unmarshall(ObjectContainerBase serviceProvider, byte[] bytes
                                        , int id)
        {
            if (id <= 0)
            {
                return(null);
            }
            MemoryBin memoryBin = new MemoryBin(bytes, GrowthStrategy());
            TransportObjectContainer carrier = NewTransportObjectContainer(serviceProvider, memoryBin
                                                                           );
            object obj = carrier.GetByID(id);

            carrier.Activate(carrier.Transaction, obj, new FullActivationDepth());
            carrier.Close();
            return(obj);
        }
コード例 #8
0
        public virtual void Test()
        {
            var origStorage         = new MemoryStorage();
            var origConfig          = Config(origStorage);
            IObjectContainer origDb = Db4oEmbedded.OpenFile(origConfig, BinUri);

            origDb.Store(new Item(ItemName));
            origDb.Close();
            var origBin = origStorage.Bin(BinUri);
            var data    = origBin.Data();

            Assert.AreEqual(data.Length, origBin.Length());
            var newBin     = new MemoryBin(data, new DoublingGrowthStrategy());
            var newStorage = new MemoryStorage();

            newStorage.Bin(BinUri, newBin);
            IObjectContainer newDb = Db4oEmbedded.OpenFile(Config(newStorage), BinUri);
            var result             = newDb.Query(typeof(Item));

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(ItemName, ((Item)result.Next())._name
                            );
            newDb.Close();
        }
コード例 #9
0
        public virtual void Test()
        {
            MemoryStorage          origStorage = new MemoryStorage();
            IEmbeddedConfiguration origConfig  = Config(origStorage);
            IObjectContainer       origDb      = Db4oEmbedded.OpenFile(origConfig, BinUri);

            origDb.Store(new MemoryBinIsReusableTestCase.Item(ItemName));
            origDb.Close();
            MemoryBin origBin = origStorage.Bin(BinUri);

            byte[] data = origBin.Data();
            Assert.AreEqual(data.Length, origBin.Length());
            MemoryBin     newBin     = new MemoryBin(data, new DoublingGrowthStrategy());
            MemoryStorage newStorage = new MemoryStorage();

            newStorage.Bin(BinUri, newBin);
            IObjectContainer newDb  = Db4oEmbedded.OpenFile(Config(newStorage), BinUri);
            IObjectSet       result = newDb.Query(typeof(MemoryBinIsReusableTestCase.Item));

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(ItemName, ((MemoryBinIsReusableTestCase.Item)result.Next())._name
                            );
            newDb.Close();
        }
コード例 #10
0
 private void Write(MemoryBin bin, int pos, int count, int expectedSize)
 {
     bin.Write(pos, new byte[count], count);
     Assert.AreEqual(expectedSize, bin.BufferSize());
 }
コード例 #11
0
        private static TransportObjectContainer NewTransportObjectContainer(ObjectContainerBase
                                                                            serviceProvider, MemoryBin memoryBin)
        {
            TransportObjectContainer container = new TransportObjectContainer(serviceProvider
                                                                              , memoryBin);

            container.DeferredOpen();
            return(container);
        }