예제 #1
0
        /// <summary>
        ///     <para>Initializes a new instance of the <see cref="CursorEnumerator{T, THeader}"/>
        ///		class.</para>
        /// </summary>
        /// <param name="list">
        ///     <para>The underlying cursor based <see cref="ObjectListForMultiples{T, THeader}"/>.</para>
        /// </param>
        public CursorEnumerator(ObjectListForMultiples <T, THeader> list)
        {
            _list = list;
            var dummy = new byte[1];

            if (_list.Cursor.Get(dummy, true) < 0)
            {
                throw new ApplicationException("No header");
            }
        }
        /// <summary>
        ///     <para>Gets a list of objects from the store, or creates one if the list is not found.</para>
        /// </summary>
        /// <typeparam name="T">
        ///     <para>The type of the objects in the list.</para>
        /// </typeparam>
        /// <typeparam name="THeader">
        ///     <para>The type of the list's header information.</para>
        /// </typeparam>
        /// <param name="keySpace">
        ///     <para>The key space of the list.</para>
        /// </param>
        /// <param name="key">
        ///     <para>The key of the list.</para>
        /// </param>
        /// <param name="header">
        ///     <para>A<typeparamref name="THeader"/> containing the
        /// list's header information.</para></param>
        /// <param name="expires">
        ///     <para>The expiration <see cref="DateTime"/> to use if the list must be created.</para>
        /// </param>
        /// <param name="creator">
        ///     <para>Delegate that provides an empty instance for stores that use
        ///		serialization. May be <see langword="null"/> for stores if
        ///		serialization not used or if store can create empty instances of
        ///     <typeparamref name="T"/> on its own.</para>
        /// </param>
        /// <param name="headerCreator">
        ///     <para>Delegate that provides an empty header instance for stores that use
        ///		serialization. May be <see langword="null"/> for stores if
        ///		serialization not used or if store can create empty instances of
        ///     <typeparamref name="THeader"/> on its own.</para>
        /// </param>
        /// <returns>
        ///     <para>The <see cref="StorageEntry{IObjectList}"/> read or created.</para>
        /// </returns>
        public StorageEntry <IObjectList <T, THeader> > GetOrCreateList <T, THeader>(DataBuffer keySpace, StorageKey key, THeader header, DateTime expires,
                                                                                     Func <T> creator, Func <THeader> headerCreator)
        {
            AddKeySpaceInfoForList <T, THeader>(keySpace);
            var allowsMultiple = Storage.GetAllowsMultiple(keySpace);
            IObjectList <T, THeader> list;

            if (Storage.Exists(keySpace, key))
            {
                if (allowsMultiple)
                {
                    var objectList = new ObjectListForMultiples <T, THeader>(this,
                                                                             keySpace, key, creator, headerCreator);
                    expires = objectList.Expires;
                    list    = objectList;
                }
                else
                {
                    var objectList = new ObjectListForSingles <T, THeader>(this,
                                                                           keySpace, key, DataBuffer.Empty, creator, headerCreator);
                    expires = objectList.Expires;
                    list    = objectList;
                }
            }
            else
            {
                if (allowsMultiple)
                {
                    list = new ObjectListForMultiples <T, THeader>(this,
                                                                   keySpace, key, creator, header, expires);
                }
                else
                {
                    list = new ObjectListForSingles <T, THeader>(this,
                                                                 keySpace, key, creator, header, expires);
                }
            }
            return(new StorageEntry <IObjectList <T, THeader> >(list,
                                                                DateTime.MinValue, expires));
        }
 /// <summary>
 ///     <para>Gets a list of objects from the store.</para>
 /// </summary>
 /// <typeparam name="T">
 ///     <para>The type of the objects in the list.</para>
 /// </typeparam>
 /// <typeparam name="THeader">
 ///     <para>The type of the list's header information.</para>
 /// </typeparam>
 /// <param name="keySpace">
 ///     <para>The key space of the list.</para>
 /// </param>
 /// <param name="key">
 ///     <para>The key of the list.</para>
 /// </param>
 /// <param name="creator">
 ///     <para>Delegate that provides an empty instance for stores that use
 ///		serialization. May be <see langword="null"/> for stores if
 ///		serialization not used or if store can create empty instances of
 ///     <typeparamref name="T"/> on its own.</para>
 /// </param>
 /// <param name="headerCreator">
 ///     <para>Delegate that provides an empty header instance for stores that use
 ///		serialization. May be <see langword="null"/> for stores if
 ///		serialization not used or if store can create empty instances of
 ///     <typeparamref name="THeader"/> on its own.</para>
 /// </param>
 /// <returns>
 ///     <para>The <see cref="StorageEntry{IObjectList}"/> containing the fetched list.</para>
 /// </returns>
 public StorageEntry <IObjectList <T, THeader> > GetList <T, THeader>(DataBuffer keySpace, StorageKey key,
                                                                      Func <T> creator, Func <THeader> headerCreator)
 {
     AddKeySpaceInfoForList <T, THeader>(keySpace);
     if (!Storage.Exists(keySpace, key))
     {
         return(StorageEntry <IObjectList <T, THeader> > .NotFound);
     }
     if (Storage.GetAllowsMultiple(keySpace))
     {
         var list = new ObjectListForMultiples <T, THeader>(this,
                                                            keySpace, key, creator, headerCreator);
         return(new StorageEntry <IObjectList <T, THeader> >(list,
                                                             DateTime.MinValue, list.Expires));
     }
     else
     {
         var list = new ObjectListForSingles <T, THeader>(this,
                                                          keySpace, key, DataBuffer.Empty, creator, headerCreator);
         return(new StorageEntry <IObjectList <T, THeader> >(list,
                                                             DateTime.MinValue, list.Expires));
     }
 }
예제 #4
0
 /// <summary>
 ///     <para>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</para>
 /// </summary>
 public void Dispose()
 {
     _list.ClearCursor();
     _list = null;
 }