/// <summary>
 ///     <para>Adds new objects to the list.</para>
 /// </summary>
 /// <param name="instances">
 ///     <para>The objects to add.</para>
 /// </param>
 public void AddRange(IEnumerable <T> instances)
 {
     if (instances == null)
     {
         throw new ArgumentNullException("instances");
     }
     using (var enm = instances.GetEnumerator())
     {
         if (!enm.MoveNext())
         {
             return;
         }
         SetCursorAndCheckPopulated();
         using (var item = Storage.StreamPool.GetItem())
         {
             var stream = item.Item;
             Serializer.Serialize(stream, enm.Current);
             Cursor.Put(SerializingObjectStorage.GetWriteBuffer(stream), true);
             while (enm.MoveNext())
             {
                 stream.Position = 0;
                 Serializer.Serialize(stream, enm.Current);
                 Cursor.Put(SerializingObjectStorage.GetWriteBuffer(stream), true);
             }
         }
     }
 }
 /// <summary>
 ///     <para>Adds a new object to the list.</para>
 /// </summary>
 /// <param name="instance">
 ///     <para>The object to add.</para>
 /// </param>
 public void Add(T instance)
 {
     SetCursorAndCheckPopulated();
     using (var item = Storage.StreamPool.GetItem())
     {
         var stream = item.Item;
         Serializer.Serialize(stream, instance);
         Cursor.Put(SerializingObjectStorage.GetWriteBuffer(stream), true);
     }
 }
 /// <summary>
 ///     <para>Removes all objects from the list.</para>
 /// </summary>
 public void Clear()
 {
     using (var item = Storage.StreamPool.GetItem())
     {
         var stream = item.Item;
         stream.Write(BitConverter.GetBytes(Expires.Ticks), 0, sizeof(long));
         Serializer.Serialize(stream, _header);
         Storage.Storage.Put(_keySpace, Key,
                             SerializingObjectStorage.GetWriteBuffer(stream));
     }
 }
예제 #4
0
        /// <summary>
        ///     <para>Adds a new object to the list.</para>
        /// </summary>
        /// <param name="instance">
        ///     <para>The object to add.</para>
        /// </param>
        public void Add(T instance)
        {
            var pos    = (int)_stream.Position;
            var lenStm = (int)_stream.Length;

            _stream.Position = lenStm;
            Serializer.Serialize(_stream, instance);
            var buffer = SerializingObjectStorage.GetWriteBuffer(_stream);

            Storage.Storage.Put(_keySpace, Key, lenStm, 0, buffer.RestrictOffset(lenStm));
            _stream.Position = pos;
        }
 /// <summary>
 ///     <para>Initializes a new instance of the <see cref="ObjectListForMultiples{T, THeader}"/> class
 ///		for a new list.</para>
 /// </summary>
 /// <param name="storage">
 ///     <para>The <see cref="SerializingObjectStorage"/> containing the list.</para>
 /// </param>
 /// <param name="keySpace">
 ///     <para>The <see cref="DataBuffer"/> keyspace the list is stored in.</para>
 /// </param>
 /// <param name="key">
 ///     <para>The single <see cref="StorageKey"/> all the binary entries are
 /// stored under.</para>
 /// </param>
 /// <param name="creator">
 ///     <para>The <see cref="Func{T}"/> that produces new <typeparamref name="T"/>
 ///		instances for deserialization.</para>
 /// </param>
 /// <param name="header">
 ///     <para>The header <typeparamref name="THeader"/> instance to be stored.</para>
 /// </param>
 /// <param name="expires">The expiration <see cref="DateTime"/> of the new list.</param>
 public ObjectListForMultiples(SerializingObjectStorage storage, DataBuffer keySpace,
                               StorageKey key, Func <T> creator, THeader header, DateTime expires)
     : this(storage, keySpace, key, creator, (inst, itemValue) =>
 {
     inst.Expires = expires;
     inst._header = header;
     var stream = itemValue.Item;
     stream.Write(BitConverter.GetBytes(expires.Ticks), 0, sizeof(long));
     Serializer.Serialize(stream, header);
     inst.Storage.Storage.Put(keySpace, key,
                              SerializingObjectStorage.GetWriteBuffer(stream));
 })
 { }
예제 #6
0
 /// <summary>
 ///     <para>Initializes a new instance of the <see cref="ObjectListForSingles{T, THeader}"/> class
 ///		for a new list.</para>
 /// </summary>
 /// <param name="storage">
 ///     <para>The <see cref="SerializingObjectStorage"/> containing the list.</para>
 /// </param>
 /// <param name="keySpace">
 ///     <para>The <see cref="DataBuffer"/> keyspace the list is stored in.</para>
 /// </param>
 /// <param name="key">
 ///     <para>The single <see cref="StorageKey"/> all the binary entries are
 /// stored under.</para>
 /// </param>
 /// <param name="creator">
 ///     <para>The <see cref="Func{T}"/> that produces new <typeparamref name="T"/>
 ///		instances for deserialization.</para>
 /// </param>
 /// <param name="header">
 ///     <para>The header <typeparamref name="THeader"/> instance to be stored.</para>
 /// </param>
 /// <param name="expires">The expiration <see cref="DateTime"/> of the new list.</param>
 public ObjectListForSingles(SerializingObjectStorage storage, DataBuffer keySpace,
                             StorageKey key, Func <T> creator, THeader header, DateTime expires)
     : this(storage, keySpace, key, creator)
 {
     _header = header;
     Expires = expires;
     _stream = _pooled.Item;
     _stream.Write(BitConverter.GetBytes(expires.Ticks), 0, sizeof(long));
     Serializer.Serialize(_stream, header);
     _headerLength = _stream.Position;
     storage.Storage.Put(keySpace, key,
                         SerializingObjectStorage.GetWriteBuffer(_stream));
 }
예제 #7
0
        /// <summary>
        ///     <para>Adds new objects to the list.</para>
        /// </summary>
        /// <param name="instances">
        ///     <para>The objects to add.</para>
        /// </param>
        public void AddRange(IEnumerable <T> instances)
        {
            if (instances == null)
            {
                throw new ArgumentNullException("instances");
            }
            var pos    = (int)_stream.Position;
            var lenStm = (int)_stream.Length;

            _stream.Position = lenStm;
            foreach (var instance in instances)
            {
                Serializer.Serialize(_stream, instance);
            }
            var buffer = SerializingObjectStorage.GetWriteBuffer(_stream);

            Storage.Storage.Put(_keySpace, Key, lenStm, 0, buffer.RestrictOffset(lenStm));
            _stream.Position = pos;
        }