Inheritance: Hd.Web.Extensions.PersisterBasePage
Exemplo n.º 1
0
        public void Refresh()
        {
            // create null page
            this.m_modPage = null;
            if (this.onModPageChanged != null)
            {
                this.onModPageChanged.Invoke(this.m_modPage);
            }

            if (this.noSubscriptionsDisplay != null)
            {
                this.noSubscriptionsDisplay.gameObject.SetActive(true);
            }
            if (this.noResultsDisplay != null)
            {
                this.noResultsDisplay.gameObject.SetActive(false);
            }

            IList <int> subscribedModIds = LocalUser.SubscribedModIds;

            ModProfileRequestManager.instance.RequestModProfiles(subscribedModIds,
                                                                 (profiles) => Refresh_OnGetModProfiles(profiles, this.m_nameFieldFilter, this.m_sortDelegate),
                                                                 (requestError) =>
            {
                MessageSystem.QueueMessage(MessageDisplayData.Type.Warning,
                                           "Failed to get subscription data from mod.io servers.\n"
                                           + requestError.displayMessage);
            });
        }
Exemplo n.º 2
0
 protected virtual void OnRequestPage(RequestPageEventArgs e)
 {
     if (RequestPage != null)
     {
         RequestPage.Invoke(this, e);
     }
 }
        public async Task <ActionResult> ChangeRole(string userId, RequestPage ReqPage)
        {
            var user = await UserManager.FindByIdAsync(userId);

            var model = new ChangeRoleViewModel();

            model.UserId      = userId;
            model.Username    = user.UserName;
            model.MyRoles     = new List <MyRoleViewModel>();
            model.RequestPage = ReqPage;
            foreach (var role in _roleManager.Roles)
            {
                if (user.Roles.Any(p => p.RoleId == role.Id))
                {
                    model.MyRoles.Add(new MyRoleViewModel()
                    {
                        RoleId = role.Id, HasGot = true, RoleName = role.Name
                    });
                }
                else
                {
                    model.MyRoles.Add(new MyRoleViewModel()
                    {
                        RoleId = role.Id, HasGot = false, RoleName = role.Name
                    });
                }
            }
            return(PartialView("_AddRole", model));
        }
Exemplo n.º 4
0
 public XmlPort(int id, string name)
     : base(id, name)
 {
     Properties  = new XmlPortProperties(this);
     Nodes       = new XmlPortNodes(this);
     RequestPage = new RequestPage(this);
     Code        = new Code.Variable.Code(this);
 }
Exemplo n.º 5
0
        public void ChangePage(int pageDifferential)
        {
            Debug.Assert(this.modPage != null);

            if (this.m_isTransitioning)
            {
                return;
            }

            int pageSize = this.m_modPageContainer.itemLimit;

            if (pageSize < 0)
            {
                pageSize = APIPaginationParameters.LIMIT_MAX;
            }

            int targetPageIndex         = this.m_modPage.CalculatePageIndex() + pageDifferential;
            int targetPageProfileOffset = targetPageIndex * pageSize;

            Debug.Assert(targetPageIndex >= 0);
            Debug.Assert(targetPageIndex < this.m_modPage.CalculatePageCount());

            int pageItemCount = (int)Mathf.Min(pageSize,
                                               this.m_modPage.resultTotal - targetPageProfileOffset);

            RequestPage <ModProfile> transitionPlaceholder = new RequestPage <ModProfile>()
            {
                size         = pageSize,
                items        = new ModProfile[pageItemCount],
                resultOffset = targetPageProfileOffset,
                resultTotal  = this.m_modPage.resultTotal,
            };

            this.m_transitionPage = transitionPlaceholder;
            this.UpdateTransitionPageDisplay();

            ModProfileRequestManager.instance.FetchModProfilePage(this.m_requestFilter, targetPageProfileOffset, pageSize,
                                                                  (page) =>
            {
                if (this.m_transitionPage == transitionPlaceholder)
                {
                    this.m_transitionPage = page;
                    this.UpdateTransitionPageDisplay();
                }
                if (this.m_modPage == transitionPlaceholder)
                {
                    this.DisplayModPage(page);
                }
            },
                                                                  null);

            PageTransitionDirection transitionDirection = (pageDifferential < 0
                                                           ? PageTransitionDirection.FromLeft
                                                           : PageTransitionDirection.FromRight);

            this.InitiateTargetPageTransition(transitionDirection, null);
            this.UpdatePageButtonInteractibility();
        }
        public void RequestPage_Enter_New_Request_Form()
        {
            RequestPage.GoTo();

            LoginPage.Login("*****@*****.**", "Pass@word1");

            RequestPage.SubmitRequest("Request One", "My request info");

            Assert.IsTrue(HomePage.IsAt, "Failed to redirect to home page");
        }
        /// <summary>Append the response page to the cached data.</summary>
        public virtual void CacheRequestPage(RequestFilter filter, RequestPage <ModProfile> page)
        {
            // early out if shouldn't cache
            if (!this.isCachingPermitted)
            {
                return;
            }

            // asserts
            Debug.Assert(filter != null);
            Debug.Assert(page != null);

            // cache request
            string          filterString = filter.GenerateFilterString();
            RequestPageData cachedData;

            if (this.requestCache.TryGetValue(filterString, out cachedData))
            {
                cachedData.resultTotal = page.resultTotal;

                this.requestCache[filterString] = RequestPageData.Append(cachedData,
                                                                         page.resultOffset,
                                                                         Utility.MapProfileIds(page.items));
            }
            else
            {
                cachedData = new RequestPageData()
                {
                    resultOffset = page.resultOffset,
                    resultTotal  = page.resultTotal,
                    modIds       = Utility.MapProfileIds(page.items),
                };

                this.requestCache.Add(filterString, cachedData);
            }

            // cache profiles
            foreach (ModProfile profile in page.items)
            {
                this.profileCache[profile.id] = profile;
            }

            // store
            if (this.storeIfSubscribed)
            {
                IList <int> subMods = ModManager.GetSubscribedModIds();
                foreach (ModProfile profile in page.items)
                {
                    if (subMods.Contains(profile.id))
                    {
                        CacheClient.SaveModProfile(profile);
                    }
                }
            }
        }
        public void ChangePage(int pageDifferential)
        {
            if (this.isTransitioning)
            {
                return;
            }

            int pageSize                = this.itemsPerPage;
            int targetPageIndex         = this.CurrentPageNumber - 1 + pageDifferential;
            int targetPageProfileOffset = targetPageIndex * pageSize;

            Debug.Assert(targetPageIndex >= 0);
            Debug.Assert(targetPageIndex < this.CurrentPageCount);

            int pageItemCount = (int)Mathf.Min(pageSize,
                                               this.currentPage.resultTotal - targetPageProfileOffset);

            RequestPage <ModProfile> targetPage = new RequestPage <ModProfile>()
            {
                size         = pageSize,
                items        = new ModProfile[pageItemCount],
                resultOffset = targetPageProfileOffset,
                resultTotal  = this.currentPage.resultTotal,
            };

            this.targetPage = targetPage;
            this.UpdateTargetPageDisplay();

            ModProfileRequestManager.instance.FetchModProfilePage(this.GenerateRequestFilter(), targetPageProfileOffset, pageSize,
                                                                  (page) =>
            {
                if (this.targetPage == targetPage)
                {
                    this.targetPage = page;
                    this.UpdateTargetPageDisplay();
                }
                if (this.currentPage == targetPage)
                {
                    this.currentPage = page;
                    this.UpdateCurrentPageDisplay();
                    this.UpdatePageButtonInteractibility();
                }
            },
                                                                  null);

            PageTransitionDirection transitionDirection = (pageDifferential < 0
                                                           ? PageTransitionDirection.FromLeft
                                                           : PageTransitionDirection.FromRight);

            this.InitiateTargetPageTransition(transitionDirection, () =>
            {
                this.UpdatePageButtonInteractibility();
            });
            this.UpdatePageButtonInteractibility();
        }
Exemplo n.º 9
0
        public static void Write(this RequestPage requestPage, CSideWriter writer)
        {
            writer.BeginSection("REQUESTPAGE");
            requestPage.Properties.Write(PropertiesStyle.Object, writer);

#if NAV2017
            requestPage.Controls.Write(writer, 18);
#else
            requestPage.Controls.Write(writer, 16);
#endif
            writer.EndSection();
        }
Exemplo n.º 10
0
        // ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Gets the value to display from a RequestPage.</summary>
        public void DisplayPageTotal(RequestPage <ModProfile> page)
        {
            this.m_resultCount = 0;
            if (page != null)
            {
                this.m_resultCount = page.resultTotal;
            }

            if (this.isActiveAndEnabled)
            {
                this.m_textComponent.text = this.m_resultCount.ToString();
            }
        }
Exemplo n.º 11
0
        // ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Gets the value to display from a RequestPage.</summary>
        public void DisplayPageNumber(RequestPage <ModProfile> page)
        {
            this.m_pageSize    = 0;
            this.m_resultIndex = 0;

            if (page != null)
            {
                this.m_pageSize    = page.size;
                this.m_resultIndex = page.resultOffset;
            }

            this.Refresh();
        }
Exemplo n.º 12
0
        private IEnumerator TransitionPageCoroutine(float mainPaneTargetX, float transitionPaneStartX,
                                                    float transitionLength, Action onTransitionCompleted)
        {
            m_isTransitioning = true;

            this.m_transitionPageContainer.gameObject.SetActive(true);

            float transitionTime = 0f;

            // transition
            while (transitionTime < transitionLength)
            {
                float transPos = Mathf.Lerp(0f, mainPaneTargetX, transitionTime / transitionLength);

                this.m_modPageContainer.GetComponent <RectTransform>().anchoredPosition        = new Vector2(transPos, 0f);
                this.m_transitionPageContainer.GetComponent <RectTransform>().anchoredPosition = new Vector2(transPos + transitionPaneStartX, 0f);

                transitionTime += Time.unscaledDeltaTime;

                yield return(null);
            }

            // flip
            var tempContainer = this.m_modPageContainer;

            this.m_modPageContainer        = this.m_transitionPageContainer;
            this.m_transitionPageContainer = tempContainer;

            var tempPage = modPage;

            this.m_modPage        = this.m_transitionPage;
            this.m_transitionPage = tempPage;

            // finalize
            this.m_modPageContainer.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
            this.m_transitionPageContainer.gameObject.SetActive(false);

            m_isTransitioning = false;

            // notify, etc
            this.UpdatePageButtonInteractibility();
            if (this.onModPageChanged != null)
            {
                this.onModPageChanged.Invoke(this.m_modPage);
            }

            if (onTransitionCompleted != null)
            {
                onTransitionCompleted();
            }
        }
        // ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Gets the value to display from a RequestPage.</summary>
        public void DisplayPageCount(RequestPage <ModProfile> page)
        {
            this.m_resultCount = 0;
            this.m_pageSize    = 1;

            if (page != null &&
                page.size > 0)
            {
                this.m_resultCount = page.resultTotal;
                this.m_pageSize    = page.size;
            }

            this.Refresh();
        }
Exemplo n.º 14
0
        /// <summary>Sets the mod page, updates displays, and notifies event listeners.</summary>
        protected void DisplayModPage(RequestPage <ModProfile> newModPage)
        {
            if (this.m_modPage != newModPage)
            {
                this.m_modPage = newModPage;

                this.UpdateModPageDisplay();
                this.UpdatePageButtonInteractibility();

                if (this.onModPageChanged != null)
                {
                    this.onModPageChanged.Invoke(newModPage);
                }
            }
        }
        private IEnumerator TransitionPageCoroutine(float mainPaneTargetX, float transitionPaneStartX,
                                                    float transitionLength, Action onTransitionCompleted)
        {
            isTransitioning = true;

            targetPageContainer.gameObject.SetActive(true);

            float transitionTime = 0f;

            // transition
            while (transitionTime < transitionLength)
            {
                float transPos = Mathf.Lerp(0f, mainPaneTargetX, transitionTime / transitionLength);

                currentPageContainer.anchoredPosition = new Vector2(transPos, 0f);
                targetPageContainer.anchoredPosition  = new Vector2(transPos + transitionPaneStartX, 0f);

                transitionTime += Time.unscaledDeltaTime;

                yield return(null);
            }

            // flip
            var tempContainer = currentPageContainer;

            currentPageContainer = targetPageContainer;
            targetPageContainer  = tempContainer;

            var tempPage = currentPage;

            currentPage = targetPage;
            targetPage  = tempPage;

            // finalize
            currentPageContainer.anchoredPosition = Vector2.zero;
            targetPageContainer.gameObject.SetActive(false);

            UpdatePageNumberDisplay();

            isTransitioning = false;

            if (onTransitionCompleted != null)
            {
                onTransitionCompleted();
            }
        }
Exemplo n.º 16
0
        protected static RequestPage <ModProfile> CreatePageSubset(RequestPage <ModProfile> sourcePage,
                                                                   int resultOffset,
                                                                   int profileCount)
        {
            Debug.Assert(sourcePage != null);

            RequestPage <ModProfile> subPage = new RequestPage <ModProfile>()
            {
                size         = profileCount,
                resultOffset = resultOffset,
                resultTotal  = sourcePage.resultTotal,
            };

            if (subPage.resultOffset < sourcePage.resultOffset)
            {
                int difference = sourcePage.resultOffset = subPage.resultOffset;

                subPage.resultOffset = sourcePage.resultOffset;
                subPage.size        -= difference;
            }

            // early out for 0
            if (subPage.size <= 0)
            {
                subPage.size  = 0;
                subPage.items = new ModProfile[0];
                return(subPage);
            }

            int sourcePageOffset = subPage.resultOffset - sourcePage.resultOffset;

            int subPageItemCount = subPage.size;

            if (sourcePageOffset + subPageItemCount > sourcePage.items.Length)
            {
                subPageItemCount = sourcePage.items.Length - sourcePageOffset;
            }

            subPage.items = new ModProfile[subPageItemCount];

            Array.Copy(sourcePage.items, sourcePageOffset,
                       subPage.items, 0,
                       subPage.items.Length);

            return(subPage);
        }
        public async Task <IActionResult> FilterCollegeSubjectsSubject(int groupid)
        {
            var result = from Subject in _ctx.RequestSubjects.AsNoTracking().OrderBy(x => x.RequestDate).Where(s => s.Subject.StudyGroupID == groupid)
                         join scName in _ctx.Schools on Subject.Subject.SchoolID equals scName.SchoolID into RequestPage
                         from m in RequestPage.DefaultIfEmpty()
                         select new
            {
                RequestID       = Subject.RequestID,
                ProfileUrlImage = Subject.Owner.ProfileImageUrl,
                Firstname       = Subject.Owner.FirstName,
                Lastname        = Subject.Owner.LastName,
                Price           = Subject.Price,
                Sub             = Subject.Subject.Name,
                Date            = Subject.RequestDate,
                SchoolName      = m.SchoolName
            };

            return(Ok(await result.AsNoTracking().ToListAsync()));
        }
Exemplo n.º 18
0
        /// <summary>Processes the received mod collection and generates a request page.</summary>
        private void OnModsReceived(int resultOffset, int pageSize, int resultTotal,
                                    List <ModProfile> results,
                                    Action <RequestPage <ModProfile> > onSuccess)
        {
            if (onSuccess == null)
            {
                return;
            }

            RequestPage <ModProfile> page = new RequestPage <ModProfile>()
            {
                size         = pageSize,
                resultOffset = resultOffset,
                resultTotal  = resultTotal,
                items        = results.ToArray(),
            };

            onSuccess.Invoke(page);
        }
Exemplo n.º 19
0
        public async Task <IActionResult> RequestCollegeTutorsPage(int page)
        {
            page = page * 24;
            var result = from Tutor in _ctx.Users.AsNoTracking().OrderBy(x => x.SchoolID).Skip(page).Take(24)
                         join scName in _ctx.Schools on Tutor.SchoolID equals scName.SchoolID into RequestPage
                         from m in RequestPage.DefaultIfEmpty()
                         select new
            {
                TutorID         = Tutor.Id,
                TutorStudyGroup = Tutor.StudyGroup.StudyGroupName,
                TutorStudyField = Tutor.StudyField.StudyFieldName,
                ProfileUrlImage = Tutor.ProfileImageUrl,
                Firstname       = Tutor.FirstName,
                Lastname        = Tutor.LastName,
                SchoolName      = m.SchoolName,
                SchoolLogoUrl   = m.SchoolLogo
            };

            return(Ok(await result.AsNoTracking().ToListAsync()));
        }
Exemplo n.º 20
0
        public static void Write(this RequestPage requestPage, CSideWriter writer)
        {
            if (writer.CodeStyle.DoNotPrintEmptyRequestPage)
            {
                if (!requestPage.Controls.Any() && !requestPage.Properties.Any(p => p.HasValue))
                {
                    return;
                }
            }

            writer.BeginSection("REQUESTPAGE");
            requestPage.Properties.Write(PropertiesStyle.Object, writer);

#if NAV2017
            requestPage.Controls.Write(writer, 18);
#else
            requestPage.Controls.Write(writer, 16);
#endif
            writer.EndSection();
        }
Exemplo n.º 21
0
        public void Refresh()
        {
            int pageIndex = 0;
            int pageSize  = this.m_modPageContainer.itemLimit;

            if (pageSize < 0)
            {
                pageSize = APIPaginationParameters.LIMIT_MAX;
            }
            int  pageOffset        = pageIndex * pageSize;
            bool wasDisplayUpdated = false;

            RequestPage <ModProfile> filteredPage = new RequestPage <ModProfile>()
            {
                size         = pageSize,
                items        = new ModProfile[pageSize],
                resultOffset = pageOffset,
                resultTotal  = 0,
            };

            this.m_modPage = filteredPage;

            ModProfileRequestManager.instance.FetchModProfilePage(this.m_requestFilter, pageOffset, pageSize,
                                                                  (page) =>
            {
                if (this != null &&
                    this.m_modPage == filteredPage)
                {
                    this.DisplayModPage(page);
                    wasDisplayUpdated = true;
                }
            },
                                                                  WebRequestError.LogAsWarning);

            if (!wasDisplayUpdated)
            {
                // force updates
                this.m_modPage = null;
                this.DisplayModPage(filteredPage);
            }
        }
Exemplo n.º 22
0
        private async void RenderRequestDetailsPage(ViewOptions options, HttpContext context)
        {
            var parts = context.Request.Path.Value.Split('/');
            var id    = Guid.Empty;

            if (!Guid.TryParse(parts[parts.Length - 1], out id))
            {
                context.Response.StatusCode = 400;
                await context.Response.WriteAsync("Invalid Request Id");

                return;
            }
            var model = new RequestPageModel()
            {
                RequestID = id,
                Activity  = _store.GetActivities().Where(a => a.HttpInfo?.RequestID == id).FirstOrDefault(),
                Options   = options
            };
            var requestPage = new RequestPage(model);
            await requestPage.ExecuteAsync(context);
        }
Exemplo n.º 23
0
        /// <summary>Append the response page to the cached data.</summary>
        public virtual void CacheRequestPage(RequestFilter filter, RequestPage <ModProfile> page)
        {
            // early out if shouldn't cache
            if (!this.isCachingPermitted)
            {
                return;
            }

            // asserts
            Debug.Assert(filter != null);
            Debug.Assert(page != null);

            // cache request
            string          filterString = filter.GenerateFilterString();
            RequestPageData cachedData;

            if (this.requestCache.TryGetValue(filterString, out cachedData))
            {
                cachedData.resultTotal = page.resultTotal;

                this.requestCache[filterString] = RequestPageData.Append(cachedData,
                                                                         page.resultOffset,
                                                                         Utility.MapProfileIds(page.items));
            }
            else
            {
                cachedData = new RequestPageData()
                {
                    resultOffset = page.resultOffset,
                    resultTotal  = page.resultTotal,
                    modIds       = Utility.MapProfileIds(page.items),
                };

                this.requestCache.Add(filterString, cachedData);
            }

            // cache profiles
            this.CacheModProfiles(page.items);
        }
        public async Task <IActionResult> RequestCollegeSubjectsPage(int page)
        {
            page = page * 24;
            var result = from Subject in _ctx.RequestSubjects.AsNoTracking().OrderBy(x => x.RequestDate).Skip(page).Take(24)
                         join scName in _ctx.Schools on Subject.Subject.SchoolID equals scName.SchoolID into RequestPage
                         from m in RequestPage.DefaultIfEmpty()
                         select new
            {
                RequestID = Subject.RequestID,
                //ProfileUrlImage = Subject.Owner.ProfileImageUrl,
                //Firstname = Subject.Owner.FirstName,
                //Lastname = Subject.Owner.LastName,
                Price           = Subject.Price,
                Sub             = Subject.Subject.Name,
                Date            = Subject.RequestDate,
                SchoolName      = m.SchoolName,
                SchoolLogoUrl   = m.SchoolLogo,
                PaymentTimeType = Subject.PayMentTime
            };

            return(Ok(await result.AsNoTracking().ToListAsync()));
        }
        public void Refresh()
        {
            int pageIndex = 0;

            RequestFilter filter            = this.GenerateRequestFilter();
            int           pageSize          = this.itemsPerPage;
            int           pageOffset        = pageIndex * pageSize;
            bool          wasDisplayUpdated = false;

            RequestPage <ModProfile> filteredPage = new RequestPage <ModProfile>()
            {
                size         = pageSize,
                items        = new ModProfile[pageSize],
                resultOffset = pageOffset,
                resultTotal  = 0,
            };

            this.currentPage = filteredPage;

            ModProfileRequestManager.instance.FetchModProfilePage(filter, pageOffset, pageSize,
                                                                  (page) =>
            {
                if (this != null &&
                    this.currentPage == filteredPage)
                {
                    this.currentPage = page;
                    this.UpdateCurrentPageDisplay();
                    this.UpdatePageButtonInteractibility();

                    wasDisplayUpdated = true;
                }
            },
                                                                  WebRequestError.LogAsWarning);

            if (!wasDisplayUpdated)
            {
                this.UpdateCurrentPageDisplay();
            }
        }
Exemplo n.º 26
0
        internal RequestPageProperties(RequestPage requestPage)
        {
            RequestPage = requestPage;

            innerList.Add(permissions);
            innerList.Add(editable);
            innerList.Add(captionML);
            innerList.Add(description);
            innerList.Add(saveValues);
            innerList.Add(multipleNewLines);
            innerList.Add(insertAllowed);
            innerList.Add(deleteAllowed);
            innerList.Add(modifyAllowed);
            innerList.Add(linksAllowed);
            innerList.Add(sourceTable);
            innerList.Add(dataCaptionExpr);
            innerList.Add(populateAllFields);
            innerList.Add(sourceTableView);
            innerList.Add(dataCaptionFields);
            innerList.Add(sourceTableTemporary);
            innerList.Add(cardPageID);
            innerList.Add(instructionalTextML);
            innerList.Add(autoSplitKey);
            innerList.Add(showFilter);
            innerList.Add(onInit);
            innerList.Add(onOpenPage);
            innerList.Add(onClosePage);
            innerList.Add(onFindRecord);
            innerList.Add(onNextRecord);
            innerList.Add(onAfterGetRecord);
            innerList.Add(onNewRecord);
            innerList.Add(onInsertRecord);
            innerList.Add(onModifyRecord);
            innerList.Add(onDeleteRecord);
            innerList.Add(onQueryClosePage);
            innerList.Add(onAfterGetCurrRecord);
            innerList.Add(actionList);
        }
Exemplo n.º 27
0
        public static AnalogTuple <RequestData, ResponseData> Create()
        {
            var win = new RequestPage();

            return(Make(win));
        }
Exemplo n.º 28
0
        // ---------[ UTILITY ]---------
        /// <summary>Recursively fetches all of the mod profiles in the array.</summary>
        protected System.Collections.IEnumerator FetchAllModProfiles(int[] modIds,
                                                                     Action <List <ModProfile> > onSuccess,
                                                                     Action <WebRequestError> onError)
        {
            List <ModProfile> modProfiles = new List <ModProfile>();

            // pagination
            APIPaginationParameters pagination = new APIPaginationParameters()
            {
                limit  = APIPaginationParameters.LIMIT_MAX,
                offset = 0,
            };

            // filter
            RequestFilter filter = new RequestFilter();

            filter.AddFieldFilter(API.GetAllModsFilterFields.id,
                                  new InArrayFilter <int>()
            {
                filterArray = modIds,
            });

            bool isDone = false;

            while (!isDone)
            {
                RequestPage <ModProfile> page  = null;
                WebRequestError          error = null;

                APIClient.GetAllMods(filter, pagination,
                                     (r) => page  = r,
                                     (e) => error = e);

                while (page == null && error == null)
                {
                    yield return(null);
                }

                if (error != null)
                {
                    if (onError != null)
                    {
                        onError(error);
                    }

                    modProfiles = null;
                    isDone      = true;
                }
                else
                {
                    modProfiles.AddRange(page.items);

                    if (page.resultTotal <= (page.resultOffset + page.size))
                    {
                        isDone = true;
                    }
                    else
                    {
                        pagination.offset = page.resultOffset + page.size;
                    }
                }
            }

            if (isDone && modProfiles != null)
            {
                onSuccess(modProfiles);
            }
        }
Exemplo n.º 29
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Fetches page of ModProfiles grabbing from the cache where possible.</summary>
        public virtual void FetchModProfilePage(RequestFilter filter, int resultOffset, int profileCount,
                                                Action <RequestPage <ModProfile> > onSuccess,
                                                Action <WebRequestError> onError)
        {
            Debug.Assert(onSuccess != null);
            Debug.Assert(this.minimumFetchSize <= APIPaginationParameters.LIMIT_MAX);

            if (profileCount > APIPaginationParameters.LIMIT_MAX)
            {
                Debug.LogWarning("[mod.io] FetchModProfilePage has been called with a profileCount"
                                 + " larger than the APIPaginationParameters.LIMIT_MAX."
                                 + "\nAs such, results may not be as expected.");

                profileCount = APIPaginationParameters.LIMIT_MAX;
            }

            // ensure indicies are positive
            if (resultOffset < 0)
            {
                resultOffset = 0;
            }
            if (profileCount < 0)
            {
                profileCount = 0;
            }

            // check if results already cached
            string          filterString = filter.GenerateFilterString();
            RequestPageData cachedPage;

            if (this.requestCache.TryGetValue(filterString, out cachedPage))
            {
                List <int> requestModIds = new List <int>(profileCount);

                int cachedPageOffset = resultOffset - cachedPage.resultOffset;

                if (cachedPageOffset >= 0)
                {
                    int expectedIdCount = profileCount;
                    if (profileCount + resultOffset > cachedPage.resultTotal)
                    {
                        expectedIdCount = cachedPage.resultTotal - resultOffset;
                    }

                    for (int i = 0;
                         i < profileCount &&
                         i + cachedPageOffset < cachedPage.modIds.Length;
                         ++i)
                    {
                        requestModIds.Add(cachedPage.modIds[i + cachedPageOffset]);
                    }

                    if (expectedIdCount == requestModIds.Count)
                    {
                        RequestPage <ModProfile> requestPage = new RequestPage <ModProfile>()
                        {
                            size         = profileCount,
                            resultOffset = resultOffset,
                            resultTotal  = cachedPage.resultTotal,
                            items        = this.PullProfilesFromCache(requestModIds),
                        };

                        bool isPageComplete = true;
                        for (int i = 0;
                             i < requestPage.items.Length &&
                             isPageComplete;
                             ++i)
                        {
                            isPageComplete = (requestPage.items[i] != null);
                        }


                        if (isPageComplete)
                        {
                            onSuccess(requestPage);
                            return;
                        }
                    }
                }
            }

            // PaginationParameters
            APIPaginationParameters pagination = new APIPaginationParameters();

            pagination.offset = resultOffset;
            pagination.limit  = profileCount;
            if (profileCount < this.minimumFetchSize)
            {
                pagination.limit = this.minimumFetchSize;
            }

            // Send Request
            APIClient.GetAllMods(filter, pagination,
                                 (r) =>
            {
                if (this != null)
                {
                    this.CacheRequestPage(filter, r);
                }

                if (onSuccess != null)
                {
                    if (pagination.limit != profileCount)
                    {
                        var subPage = ModProfileRequestManager.CreatePageSubset(r,
                                                                                resultOffset,
                                                                                profileCount);
                        onSuccess(subPage);
                    }
                    else
                    {
                        onSuccess(r);
                    }
                }
            }, onError);
        }
Exemplo n.º 30
0
        /// <summary>Handle the mods returned by the refresh request.</summary>
        protected virtual void Refresh_OnGetModProfiles(IList <ModProfile> modProfiles,
                                                        string requestedTitleFilter,
                                                        Comparison <ModProfile> requestedSortDelegate)
        {
            // check for early outs
            if (this == null ||
                this.m_nameFieldFilter != requestedTitleFilter ||
                this.m_sortDelegate != requestedSortDelegate)
            {
                return;
            }

            List <ModProfile> filteredList = null;

            // check for null list
            if (modProfiles == null ||
                modProfiles.Count == 0)
            {
                filteredList = new List <ModProfile>(0);
            }
            else
            {
                // filter
                Func <ModProfile, bool> nameFieldFilterDelegate = (p) => true;
                if (!String.IsNullOrEmpty(requestedTitleFilter))
                {
                    // set initial value
                    string filterString = requestedTitleFilter.ToUpper();
                    nameFieldFilterDelegate = (p) =>
                    {
                        return(p.name.ToUpper().Contains(filterString));
                    };
                }

                filteredList = new List <ModProfile>(modProfiles.Count);
                foreach (ModProfile profile in modProfiles)
                {
                    if (nameFieldFilterDelegate(profile))
                    {
                        filteredList.Add(profile);
                    }
                }

                // sort
                if (requestedSortDelegate == null)
                {
                    requestedSortDelegate = this.DefaultSortFunction;
                }

                filteredList.Sort(requestedSortDelegate);
            }

            // update displays
            this.DisplayProfiles(filteredList);

            if (this.noSubscriptionsDisplay != null)
            {
                this.noSubscriptionsDisplay.gameObject.SetActive(filteredList.Count == 0 &&
                                                                 string.IsNullOrEmpty(this.m_nameFieldFilter));
            }
            if (this.noResultsDisplay != null)
            {
                this.noResultsDisplay.gameObject.SetActive(filteredList.Count == 0 &&
                                                           !string.IsNullOrEmpty(this.m_nameFieldFilter));
            }

            // create request page
            this.m_modPage = new RequestPage <ModProfile>()
            {
                size         = filteredList.Count,
                resultOffset = 0,
                resultTotal  = filteredList.Count,
                items        = filteredList.ToArray(),
            };
            if (this.onModPageChanged != null)
            {
                this.onModPageChanged.Invoke(this.m_modPage);
            }
        }