Exemplo n.º 1
0
        private IList <PaperListViewItemModel> GetPaperDocs(IPaperModel model, IMainPresenter presenter, TeamListViewItemModel memberitem)
        {
            IMemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion);

            service.ListPaperDocsUrl = ApplicationResource.ActionListPaperDocs;
            service.UserAgentVersion = ApplicationResource.UserAgent;
            string paperAccessToken = ApplicationResource.DefaultAccessToken;
            string memberId         = string.Empty;
            IList <PaperListViewItemModel> docIds = new List <PaperListViewItemModel>();

            //foreach (var memberitem in members)
            //{
            if (!string.IsNullOrEmpty(memberitem.TeamId))
            {
                memberId = memberitem.TeamId;
            }
            IDataResponse response = service.ListPaperDocs(new MemberData()
            {
                MemberId = memberId
            }, paperAccessToken);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                if (response.Data != null)
                {
                    string  data     = response.Data.ToString();
                    dynamic jsonData = JsonConvert.DeserializeObject <dynamic>(data);

                    int resultCount = jsonData["doc_ids"].Count;
                    for (int i = 0; i < resultCount; i++)
                    {
                        dynamic paperDocId = jsonData["doc_ids"][i];

                        // update model
                        PaperListViewItemModel lvItem = new PaperListViewItemModel()
                        {
                            PaperId   = paperDocId,
                            MemberId  = memberId,
                            IsChecked = true
                        };
                        docIds.Add(lvItem);
                    }
                    //if the group count is above limit - default 1000 we need to grab the cursor and call continue
                    string cursor  = jsonData["cursor"]["value"];
                    bool   hasMore = jsonData["has_more"];
                    while (hasMore)
                    {
                        service.ListPaperDocsUrl = ApplicationResource.ActionListContinuationPaperDocs;
                        IDataResponse responseCont = service.ListPaperDocs(new MemberData()
                        {
                            Cursor = cursor
                        }, paperAccessToken);

                        string  dataCont     = responseCont.Data.ToString();
                        dynamic jsonDataCont = JsonConvert.DeserializeObject <dynamic>(dataCont);

                        int resultContCount = jsonDataCont["doc_ids"].Count;
                        for (int i = 0; i < resultContCount; i++)
                        {
                            dynamic paperDocId = jsonDataCont["doc_ids"][i];
                            // update model
                            PaperListViewItemModel lvItem = new PaperListViewItemModel()
                            {
                                PaperId   = paperDocId,
                                MemberId  = memberId,
                                IsChecked = true
                            };
                            docIds.Add(lvItem);
                        }
                        hasMore = jsonDataCont["has_more"];
                        cursor  = jsonDataCont["cursor"]["value"];
                    }
                }
            }
            return(docIds);
            //}
        }