コード例 #1
0
        public void Test_IsInPage_PageSize1_In()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the IsInPage function with a page size of 1 on an item that appears on the specified page.", LogLevel.Debug))
            {
                int i         = 1;
                int pageIndex = 1;
                int pageSize  = 1;

                PagingLocation location = new PagingLocation(pageIndex, pageSize);

                bool isInPage = location.IsInPage(i);


                Assert.IsTrue(isInPage, "Returned false when it should have been true.");
            }
        }
コード例 #2
0
        protected virtual IEntity[] GetPage(IObjectSet objectSet, PagingLocation location)
        {
            int i = 0;

            List <IEntity> list = new List <IEntity>();

            // Loop through each index in the object set
            for (i = 0; i < objectSet.Count; i++)
            {
                // If it's not in the current page then skip it
                if (location.IsInPage(i))
                {
                    // Add the entity to the collection
                    list.Add((IEntity)objectSet[i]);
                }
            }

            location.AbsoluteTotal = i;

            return(list.ToArray());
        }
コード例 #3
0
        public void Test_IsInPage_PageSize1_In()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the IsInPage function with a page size of 1 on an item that appears on the specified page.", LogLevel.Debug))
            {

                int i = 1;
                int pageIndex = 1;
                int pageSize = 1;

                PagingLocation location = new PagingLocation(pageIndex, pageSize);

                bool isInPage = location.IsInPage(i);

                Assert.IsTrue(isInPage, "Returned false when it should have been true.");
            }
        }
コード例 #4
0
        /// <summary>
        /// Retrieves a single page (at the specified location) of the specified type of entities from the corresponding data store.
        /// </summary>
        /// <param name="type">The type of entities to retrieve.</param>
        /// <param name="location">The coordinates of the page being retrieved.</param>
        /// <param name="sortExpression">The sort expression to apply before retrieving the page.</param>
        /// <returns>An array of the entities, including only the current page.</returns>
        public override IEntity[] GetPageOfEntities(Type type, PagingLocation location, string sortExpression)
        {
            // Create the collection
            List <IEntity> entities = new List <IEntity>();

            using (LogGroup logGroup = LogGroup.Start("Retrieving a page of entities.", NLog.LogLevel.Debug))
            {
                if (type == null)
                {
                    throw new ArgumentNullException("type");
                }

                if (location == null)
                {
                    throw new ArgumentNullException("location");
                }

                // Output the parameters to the log
                LogWriter.Debug("Type: " + type.ToString());
                LogWriter.Debug("Page index: " + location.PageIndex);
                LogWriter.Debug("Page size: " + location.PageSize);
                LogWriter.Debug("Sort expression: " + sortExpression);

                // Get the corresponding data store
                Db4oDataStore store = (Db4oDataStore)GetDataStore(type);

                if (store == null)
                {
                    throw new Exception("Can't find data store.");
                }

                if (store.ObjectContainer == null)
                {
                    throw new Exception("store.ObjectContainer is null");
                }

                // Create the query object
                IQuery query = store.ObjectContainer.Query();

                // Constrain the query to the specified type
                query.Constrain(type);

                // Apply the sorting to the query
                ApplySorting(query, type, sortExpression);

                // Execute the query and get the object set
                IObjectSet os = query.Execute();

                if (os == null)
                {
                    throw new Exception("IObjectSet is null");
                }

                int i = 0;

                // Loop through each index in the object set
                for (i = 0; i < os.Count; i++)
                {
                    // ONLY execute during debug because it slows the indexing down
                    if (new ModeDetector().IsDebug)
                    {
                        LogWriter.Debug("At absolute position " + i + ": " + ((IEntity)os[i]).ToString());
                    }

                    // If it's not in the current page then skip it
                    if (location.IsInPage(i))
                    {
                        // Add the entity to the collection
                        entities.Add((IEntity)os[i]);
                    }
                }

                // Set the absolute total to the paging location
                // This is the total count including items on ALL pages, not just the current one
                location.AbsoluteTotal = i;

                LogWriter.Debug("Absolute count: " + location.AbsoluteTotal.ToString());

                LogWriter.Debug("Entities count (single page): " + entities.Count.ToString());
            }

            // Return the entities
            return(Release(entities.ToArray()));
        }