public void LoadQuery(ILevelSetQuery query)
 {
     lock (Synch)
     {
         foreach (LevelMetadata level in allLevels)
         {
             query.LevelAdded(level);
         }
     }
 }
 public bool StartFetchingMore(ILevelSetQuery query)
 {
     if (pagingOpCount == 0 && !pagingEndReached)
     {
         // This is a bit of a hack/limitation. For the moment, the community server only
         // supports filtering by genre and sorting on the basic fields. For this limitation
         // to be removed, we must support all sorters and filters on the server side, and
         // send them up with every query.
         LevelSetSorterBasic      basicSorter = query.Sorter as LevelSetSorterBasic;
         LevelSetFilterByKeywords filter      = query.Filter as LevelSetFilterByKeywords;
         if (String.IsNullOrEmpty(filter.SearchString) ||
             filter.SearchString.Split(new[] { ' ' }, System.StringSplitOptions.RemoveEmptyEntries).Length < 1)
         {
             //if no keywords do old style display
             if (0 != Web.Community.Async_GetPageOfLevels(
                     filter != null ? filter.FilterGenres : Genres.All,
                     basicSorter != null ? basicSorter.SortBy : SortBy.Date,
                     basicSorter != null ? basicSorter.SortDirection : SortDirection.Descending,
                     pagingFirst,
                     kPagingPageSize,
                     FetchComplete,
                     query))
             {
                 pagingOpCount += 1;
                 return(true);
             }
         }
         else
         {
             //use keyword search version
             if (0 != Web.Community.Async_GetSearchPageOfLevels(
                     filter != null ? filter.FilterGenres : Genres.All,
                     filter.SearchString,
                     basicSorter != null ? basicSorter.SortBy : SortBy.Date,
                     basicSorter != null ? basicSorter.SortDirection : SortDirection.Descending,
                     pagingFirst,
                     kPagingPageSize,
                     FetchComplete,
                     query))
             {
                 pagingOpCount += 1;
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #3
0
 public LevelSetCursor(
     ILevelBrowser browser,
     Guid desiredSelection,
     ILevelSetQuery query,
     LevelSetCursorShifted shiftCallback,
     LevelSetCursorJumped jumpCallback,
     LevelSetCursorAddition additionCallback,
     LevelSetCursorRemoval removalCallback,
     int size)
 {
     Query                 = query;
     this.Browser          = browser;
     this.desiredSelection = desiredSelection;
     this.shiftCallback    = shiftCallback;
     this.jumpCallback     = jumpCallback;
     this.additionCallback = additionCallback;
     this.removalCallback  = removalCallback;
     this.size             = size;
 }
        private void FetchComplete(AsyncResult ar)
        {
            AsyncResult_GetPageOfLevels result = (AsyncResult_GetPageOfLevels)ar;

            if (result.Success)
            {
                int count = 0;
                foreach (LevelMetadata level in result.Page.Listing)
                {
                    if (IndexOf(level.WorldId) == -1)
                    {
                        LevelBrowserState state = new LevelBrowserState();
                        state.level        = level;
                        level.BrowserState = state;

                        level.Browser = this;
                        allLevels.Add(level);
                        LevelAdded(level);
                        count += 1;
                    }
                }

                if (result.Page.First >= result.Page.Total)
                {
                    pagingEndReached = true;
                }

                pagingFirst += count;
            }
            else
            {
                // An error occured, stop trying.
                pagingEndReached = true;
            }

            ILevelSetQuery query = (ILevelSetQuery)ar.Param;

            query.NotifyFetchComplete();

            pagingOpCount -= 1;
        }
        public void CloseCursor(ref ILevelSetCursor icursor)
        {
            LevelSetCursor cursor = icursor as LevelSetCursor;

            if (cursor != null)
            {
                lock (Synch)
                {
                    int index = queries.IndexOf(cursor.Query);

                    if (index >= 0)
                    {
                        ILevelSetQuery query = queries[index];
                        if (0 == query.RemoveCursor(cursor))
                        {
                            queries.RemoveAt(index);
                        }
                    }
                }

                icursor = null;
            }
        }