Example #1
0
        public void GetShotCommentById(int shotId, int pageIndex = 0, int prePage = 0)
        {
            if (shotId == 0)
            {
                return;
            }
            string            requestUrl        = GetRequestUrl("shots/" + shotId.ToString() + "/comments", pageIndex, prePage);
            DataRequestHelper dataRequestHelper = new DataRequestHelper();

            dataRequestHelper.ExcuteAsyncRequest(requestUrl, Method.GET, base._postArgumentList);
            dataRequestHelper.AsyncResponseComplated += (responseData, ex) =>
            {
                if (!string.IsNullOrEmpty(responseData.ToString()))
                {
                    if (!base.IsRateLimitedRequest(responseData.ToString()))
                    {
                        try
                        {
                            ShotComment commentDetailCol = JsonConvert.DeserializeObject <ShotComment>(responseData.ToString());
                            if (AsyncRequestComplated != null)
                            {
                                AsyncRequestComplated(commentDetailCol, null);
                            }
                        }
                        catch (Exception se)
                        {
                            if (AsyncRequestComplated != null)
                            {
                                AsyncRequestComplated("Json format error.try later", se);
                            }
                        }
                    }
                    else
                    {
                        if (AsyncRequestComplated != null)
                        {
                            AsyncRequestComplated("Rate limited for a minute.", new Exception());
                        }
                    }
                }
            };
        }
        public void GetPlayerRecentShots(string username, int pageIndex, int prePage, bool isDynamicLoad = false)
        {
            //start processbar
            _processBarHelper.StartProcessBar();

            //register pagncation
            RegisterPaginationInfo(PagintaionType.ProfileShots, pageIndex, prePage);

            UserRequestHelper userProfileHelper = new UserRequestHelper();

            userProfileHelper.GetUserMostRecentShots(username, pageIndex, prePage);
            userProfileHelper.AsyncUserProfileComplated += (responseData, ex) =>
            {
                //end processbar
                _processBarHelper.EndProcessBar();

                if (ex == null)
                {
                    #region get use most recent shot
                    UserRecentShot recentShots = null;
                    if (responseData != null)
                    {
                        recentShots = responseData as UserRecentShot;
                    }

                    if (recentShots != null)
                    {
                        if (!isDynamicLoad)
                        {
                            _userRecentShotsCol.Clear();
                        }

                        //update total pages
                        UpdateTotalPage(PagintaionType.ProfileShots, recentShots.Pages);

                        if (recentShots.Shots.Count > 0)
                        {
                            recentShots.Shots.ForEach(queryEntity =>
                            {
                                #region get shot first author comment detail body
                                ShotRequestHelper shotHelper = new ShotRequestHelper();
                                shotHelper.GetShotCommentById(queryEntity.Id, 1, 1);
                                shotHelper.AsyncRequestComplated += (commentData, comEx) =>
                                {
                                    if (comEx == null)
                                    {
                                        #region get comment by shot id
                                        ShotComment firstComment = null;
                                        if (commentData != null)
                                        {
                                            firstComment = commentData as ShotComment;
                                        }

                                        if (firstComment.Comments.Count > 0)
                                        {
                                            string commentContent = firstComment.Comments[0].Body;
                                            commentContent        = commentContent.Replace('\r', ' ').Replace('\n', ' ');

                                            if (commentContent.Length > 150)
                                            {
                                                queryEntity.Comment = commentContent.Substring(0, 150) + "...";
                                            }
                                            else
                                            {
                                                queryEntity.Comment = commentContent;
                                            }
                                        }

                                        //format datetime
                                        BasicRequestHelper requestHelper = new BasicRequestHelper();
                                        queryEntity.FormatDate           = requestHelper.SpiltDateTimeStr(queryEntity.Created_at);
                                        #endregion
                                    }
                                    else
                                    {
                                        string errorMessage = commentData.ToString();
                                        if (!string.IsNullOrEmpty(errorMessage))
                                        {
                                            new ToastNotifyHelper().ShowCoding4FunToastNotify(errorMessage, "Tip");
                                        }
                                    }
                                };
                                #endregion
                                this._userRecentShotsCol.Add(queryEntity);
                            });
                        }
                    }
                    #endregion
                }
                else
                {
                    string errorMessage = responseData.ToString();
                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        new ToastNotifyHelper().ShowCoding4FunToastNotify(errorMessage, "Tip");
                    }
                }
            };
        }
Example #3
0
        public void GetShotDetailComments(int shotId, int pageIndex = 0, int prePage = 0, bool isDynamicLoad = false)
        {
            if (shotId == 0)
            {
                return;
            }

            //start processbar
            LoadProcessBarHelper processBarHelper = new LoadProcessBarHelper();

            processBarHelper.StartProcessBar();

            //register pagintion
            RegisterPaginationInfo(pageIndex, prePage);

            ShotRequestHelper shotHelper = new ShotRequestHelper();

            shotHelper.GetShotCommentById(shotId, pageIndex, prePage);
            shotHelper.AsyncRequestComplated += (responseData, Ex) =>
            {
                //end processbar
                processBarHelper.EndProcessBar();

                if (Ex == null)
                {
                    #region get shot comment by id
                    ShotComment shotComments = null;
                    if (responseData != null)
                    {
                        shotComments = responseData as ShotComment;
                    }

                    //update total pagecount
                    UpateTotalPage(shotComments.Pages);

                    if (shotComments.Comments != null)
                    {
                        if (!isDynamicLoad)
                        {
                            _shotCommentsCol.Clear();
                        }

                        if (shotComments.Comments.Count > 0)
                        {
                            shotComments.Comments.ForEach(queryEntity =>
                            {
                                BasicRequestHelper requestHelper = new BasicRequestHelper();
                                queryEntity.FormatDate           = requestHelper.SpiltDateTimeWithPM(queryEntity.Created_at);
                                _shotCommentsCol.Add(queryEntity);
                            });
                        }
                    }
                    #endregion
                }
                else
                {
                    string errorMessage = responseData.ToString();
                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        new ToastNotifyHelper().ShowCoding4FunToastNotify(errorMessage, "Tip");
                    }
                }
            };
        }
Example #4
0
        public void GetCatalogShot(Common.ShotCatalog catalogType, int pageIndex, int prePage, bool isDynamicLoad = false)
        {
            //start process bar
            LoadProcessBarHelper processBarHelper = new LoadProcessBarHelper();

            processBarHelper.StartProcessBar();

            //pagination control
            ControlPivotPage(catalogType, pageIndex, prePage);

            CatalogShotHelper catalogShotHelper = new CatalogShotHelper();

            catalogShotHelper.GetCatalogShots(catalogType, pageIndex, prePage);
            catalogShotHelper.AsyncCatalogShotsComplated += (responseData, ex) =>
            {
                //end process bar
                processBarHelper.EndProcessBar();

                if (ex == null)
                {
                    #region format catalog shot
                    CatalogShots catalogShots = null;
                    if (responseData != null)
                    {
                        catalogShots = responseData as CatalogShots;
                    }

                    //update total page count
                    UpateTotalPage(catalogType, catalogShots.Pages);

                    if (catalogShots.Shots.Count > 0)
                    {
                        switch (catalogType)
                        {
                        case ShotCatalog.Popular:
                            if (!isDynamicLoad)
                            {
                                _popularShotCol.Clear();
                            }
                            catalogShots.Shots.ForEach(queryEntity => { _popularShotCol.Add(queryEntity); });
                            break;

                        case ShotCatalog.Everyone:
                            if (!isDynamicLoad)
                            {
                                _everyoneShotCol.Clear();
                            }
                            catalogShots.Shots.ForEach(queryEntity => { _everyoneShotCol.Add(queryEntity); });
                            break;

                        case ShotCatalog.Debuts:
                            if (!isDynamicLoad)
                            {
                                _debutsShotCol.Clear();
                            }
                            catalogShots.Shots.ForEach(queryEntity =>
                            {
                                #region get shot first author comment detail body
                                ShotRequestHelper shotHelper = new ShotRequestHelper();
                                shotHelper.GetShotCommentById(queryEntity.Id, 1, 1);
                                shotHelper.AsyncRequestComplated += (commentData, comEx) =>
                                {
                                    if (comEx == null)
                                    {
                                        #region get comment by id
                                        ShotComment firstComment = null;
                                        if (commentData != null)
                                        {
                                            firstComment = commentData as ShotComment;
                                        }

                                        if (firstComment.Comments.Count > 0)
                                        {
                                            string commentContent = firstComment.Comments[0].Body;
                                            commentContent        = commentContent.Replace('\r', ' ').Replace('\n', ' ');

                                            if (commentContent.Length > 150)
                                            {
                                                queryEntity.Comment = commentContent.Substring(0, 150) + "...";
                                            }
                                            else
                                            {
                                                queryEntity.Comment = commentContent;
                                            }
                                        }

                                        //format datetime
                                        BasicRequestHelper requestHelper = new BasicRequestHelper();
                                        queryEntity.FormatDate           = requestHelper.SpiltDateTimeStr(queryEntity.Created_at);
                                        #endregion
                                    }
                                    else
                                    {
                                        string errorMessage = commentData.ToString();
                                        if (!string.IsNullOrEmpty(errorMessage))
                                        {
                                            new ToastNotifyHelper().ShowCoding4FunToastNotify(errorMessage, "Tip");
                                        }
                                    }
                                };
                                #endregion
                                _debutsShotCol.Add(queryEntity);
                            });
                            break;
                        }
                    }

                    #endregion
                }
                else
                {
                    string errorMessage = responseData.ToString();
                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        new ToastNotifyHelper().ShowCoding4FunToastNotify(errorMessage, "Tip");
                    }
                }
            };
        }