Exemple #1
0
		private static TransportObjectContainer NewTransportObjectContainer(ObjectContainerBase
			 serviceProvider, MemoryBin memoryBin)
		{
			TransportObjectContainer container = new TransportObjectContainer(serviceProvider
				, memoryBin);
			container.DeferredOpen();
			return container;
		}
 public TransportObjectContainer(ObjectContainerBase parent, MemoryBin memoryFile)
     : base(parent.Config())
 {
     _memoryBin = memoryFile;
     _parent = parent;
     _lock = parent.Lock();
     _showInternalClasses = parent._showInternalClasses;
     Open();
 }
Exemple #3
0
        /// <exception cref="System.IO.IOException"></exception>
        public virtual void Rename(string oldUri, string newUri)
        {
            MemoryBin bin = ((MemoryBin)Sharpen.Collections.Remove(_bins, oldUri));

            if (bin == null)
            {
                throw new IOException("Bin not found: " + oldUri);
            }
            _bins[newUri] = bin;
        }
Exemple #4
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());
		}
Exemple #5
0
		private IBin ProduceStorage(BinConfiguration config)
		{
			IBin storage = Bin(config.Uri());
			if (null != storage)
			{
				return storage;
			}
			MemoryBin newStorage = new MemoryBin(new byte[(int)config.InitialLength()], _growthStrategy
				);
			_bins[config.Uri()] = newStorage;
			return newStorage;
		}
Exemple #6
0
        private IBin ProduceStorage(BinConfiguration config)
        {
            IBin storage = Bin(config.Uri());

            if (null != storage)
            {
                return(storage);
            }
            MemoryBin newStorage = new MemoryBin(new byte[(int)config.InitialLength()], _growthStrategy
                                                 );

            _bins[config.Uri()] = newStorage;
            return(newStorage);
        }
Exemple #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;
		}
 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();
 }
		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();
		}
		private void Write(MemoryBin bin, int pos, int count, int expectedSize)
		{
			bin.Write(pos, new byte[count], count);
			Assert.AreEqual(expectedSize, bin.BufferSize());
		}
		/// <summary>Registers the given bin for this storage with the given URI.</summary>
		/// <remarks>Registers the given bin for this storage with the given URI.</remarks>
		public virtual void Bin(string uri, MemoryBin bin)
		{
			_bins[uri] = bin;
		}
Exemple #12
0
 /// <summary>Registers the given bin for this storage with the given URI.</summary>
 /// <remarks>Registers the given bin for this storage with the given URI.</remarks>
 public virtual void Bin(string uri, MemoryBin bin)
 {
     _bins[uri] = bin;
 }