private void ObjectListView_MemberList_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            // first of all, if user tries to check mark item which files were NOT loaded yet,
            // show warning and don't allow user to check mark
            ObjectListView        olv  = sender as ObjectListView;
            TeamListViewItemModel item = olv.GetModelObject(e.Index) as TeamListViewItemModel;

            if (item != null)
            {
                if (string.IsNullOrEmpty(item.FileName))
                {
                    if (!_suppressErrorMessage)
                    {
                        MessageBoxUtil.ShowError(this, ErrorMessages.MISSING_FILES);
                    }
                    e.NewValue = CheckState.Unchecked;
                }
            }
        }
        public void RenderMembersFileSearchResult()
        {
            this.objectListView_MemberList.SetObjects(
                MemberList
                );
            foreach (Object item in this.objectListView_MemberList.Objects)
            {
                TeamListViewItemModel model = item as TeamListViewItemModel;
                if (model != null)
                {
                    if (string.IsNullOrEmpty(model.FileName))
                    {
                        // remove all excpet the files that were located under that users group
                        this.objectListView_MemberList.RemoveObject(item);
                    }
                }
            }

            if (this.objectListView_MemberList.GetItemCount() == this.objectListView_MemberList.CheckedObjects.Count)
            {
                this.objectListView_MemberList.CheckHeaderCheckBox(olvColumnContent_Email);
            }
        }
        public void RenderMembersSearchResult()
        {
            this.objectListView_MemberList.SetObjects(
                MemberList
                );
            // disable row if file doesn't exist
            foreach (Object item in this.objectListView_MemberList.Objects)
            {
                TeamListViewItemModel model = item as TeamListViewItemModel;
                if (model != null)
                {
                    if (string.IsNullOrEmpty(model.FileName))
                    {
                        // force disable row.
                        //this.objectListView_MemberList.DisableObject(item);
                    }
                }
            }

            if (this.objectListView_MemberList.GetItemCount() == this.objectListView_MemberList.CheckedObjects.Count)
            {
                this.objectListView_MemberList.CheckHeaderCheckBox(olvColumnContent_Email);
            }
        }
Example #4
0
        public IList <TeamListViewItemModel> SearchOwners(IPaperModel model, IMainPresenter presenter)
        {
            IList <TeamListViewItemModel> members = new List <TeamListViewItemModel>();

            if (!string.IsNullOrEmpty(model.AccessToken))
            {
                MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion);
                service.ListMembersUrl   = ApplicationResource.ActionListMembers;
                service.UserAgentVersion = ApplicationResource.UserAgent;
                IDataResponse response = service.ListMembers(new MemberData()
                {
                    SearchLimit = ApplicationResource.SearchDefaultLimit
                }, model.AccessToken);

                if (SyncContext != null)
                {
                    SyncContext.Post(delegate {
                        presenter.UpdateProgressInfo("Searching users...");
                    }, null);
                }
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    if (response.Data != null)
                    {
                        string  data        = response.Data.ToString();
                        dynamic jsonData    = JsonConvert.DeserializeObject <dynamic>(data);
                        int     resultCount = jsonData["members"].Count;
                        int     total       = 0;
                        for (int i = 0; i < resultCount; i++)
                        {
                            dynamic profile  = jsonData["members"][i]["profile"];
                            dynamic idObj    = profile["team_member_id"];
                            dynamic emailObj = profile["email"];
                            dynamic status   = profile["status"];
                            if (status != null && (status[".tag"].ToString().Equals("active") || status[".tag"].ToString().Equals("suspended")))
                            {
                                string teamId = idObj.Value as string;
                                string email  = emailObj.Value as string;
                                // update model
                                TeamListViewItemModel lvItem = new TeamListViewItemModel()
                                {
                                    Email  = email,
                                    TeamId = teamId
                                };
                                members.Add(lvItem);
                            }
                            if (SyncContext != null)
                            {
                                SyncContext.Post(delegate {
                                    presenter.UpdateProgressInfo("Scanning Account(s): " + (++total));
                                }, null);
                            }
                            Thread.Sleep(1);
                        }
                        // collect more.
                        bool   hasMore = jsonData["has_more"];
                        string cursor  = jsonData["cursor"];

                        while (hasMore)
                        {
                            service.ListMembersContinuationUrl = ApplicationResource.ActionListMembersContinuation;
                            service.UserAgentVersion           = ApplicationResource.UserAgent;
                            IDataResponse responseCont = service.ListMembersContinuation(new MemberData()
                            {
                                Cursor = cursor
                            }, model.AccessToken);

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

                            int resultContCount = jsonDataCont["members"].Count;
                            for (int i = 0; i < resultContCount; i++)
                            {
                                dynamic profile  = jsonDataCont["members"][i]["profile"];
                                dynamic idObj    = profile["team_member_id"];
                                dynamic emailObj = profile["email"];
                                dynamic status   = profile["status"];

                                string teamId = idObj.Value as string;
                                string email  = emailObj.Value as string;

                                if (status != null && (status[".tag"].ToString().Equals("active") || status[".tag"].ToString().Equals("suspended")))
                                {
                                    // update model
                                    TeamListViewItemModel lvItem = new TeamListViewItemModel()
                                    {
                                        Email  = email,
                                        TeamId = teamId
                                    };
                                    members.Add(lvItem);
                                }
                                if (SyncContext != null)
                                {
                                    SyncContext.Post(delegate {
                                        presenter.UpdateProgressInfo("Scanning Account(s): " + (++total));
                                    }, null);
                                }
                                Thread.Sleep(1);
                            }
                            hasMore = jsonDataCont["has_more"];
                            cursor  = jsonDataCont["cursor"];
                        }
                    }
                }
            }
            return(members);
        }
Example #5
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);
            //}
        }
        private bool SearchFiles(
            IMemberServices service,
            TeamListViewItemModel item,
            IDumpUserContentModel model,
            IMainPresenter presenter)
        {
            bool filesAdded = false;

            try
            {
                service.ListFolderUrl    = ApplicationResource.ActionListFolder;
                service.UserAgentVersion = ApplicationResource.UserAgent;
                IDataResponse response = service.ListFolders(
                    new MemberData()
                {
                    MemberId = item.TeamId
                }, model.UserAccessToken);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    if (response.Data != null)
                    {
                        string  content        = response.Data as string;
                        dynamic jsonDataSearch = JsonConvert.DeserializeObject <dynamic>(content);
                        int     entryCount     = 0;
                        if (jsonDataSearch["entries"] != null)
                        {
                            entryCount = jsonDataSearch["entries"].Count;
                        }
                        //remove existing file entries.
                        for (int i = model.MemberList.Count - 1; i >= 0; i--)
                        {
                            TeamListViewItemModel lvItem = model.MemberList[i];
                            if (lvItem.TeamId.Equals(item.TeamId))
                            {
                                model.MemberList.RemoveAt(i);
                            }
                        }
                        int total = 0;
                        for (int i = 0; i < entryCount; i++)
                        {
                            TeamListViewItemModel lvItem = null;
                            if (jsonDataSearch["entries"][i][".tag"].ToString().Equals("file"))
                            {
                                lvItem = new TeamListViewItemModel()
                                {
                                    Email     = item.Email,
                                    TeamId    = item.TeamId,
                                    FileName  = jsonDataSearch["entries"][i]["name"].ToString(),
                                    FilePath  = jsonDataSearch["entries"][i]["path_lower"].ToString(),
                                    FileSize  = FileUtil.FormatFileSize(Convert.ToInt64(jsonDataSearch["entries"][i]["size"].ToString())),
                                    IsChecked = true
                                };
                                lock (insertLock)
                                {
                                    model.MemberList.Add(lvItem);
                                }
                                SyncContext.Post(delegate
                                {
                                    presenter.UpdateProgressInfo(string.Format("Searching Files For : {0} File Count: {1}", item.Email, (++total)));
                                }, null);
                            }
                        }
                        if (entryCount > 0)
                        {
                            filesAdded = true;
                        }
                        bool   hasMore = jsonDataSearch["has_more"];
                        string cursor  = jsonDataSearch["cursor"];

                        while (hasMore)
                        {
                            service.ListFolderUrl    = ApplicationResource.ActionListFolderContinuation;
                            service.UserAgentVersion = ApplicationResource.UserAgent;
                            IDataResponse responseCont = service.ListFolders(
                                new MemberData()
                            {
                                MemberId = item.TeamId,
                                Cursor   = cursor
                            }, model.UserAccessToken);

                            string  contentCont        = responseCont.Data as string;
                            dynamic jsonDataSearchCont = JsonConvert.DeserializeObject <dynamic>(contentCont);

                            int entryCountCont = 0;
                            if (jsonDataSearchCont["entries"] != null)
                            {
                                entryCountCont = jsonDataSearchCont["entries"].Count;
                            }

                            int totalCont = 0;
                            for (int i = 0; i < entryCountCont; i++)
                            {
                                TeamListViewItemModel lvItem = null;
                                if (jsonDataSearchCont["entries"][i][".tag"].ToString().Equals("file"))
                                {
                                    lvItem = new TeamListViewItemModel()
                                    {
                                        Email     = item.Email,
                                        TeamId    = item.TeamId,
                                        FileName  = jsonDataSearchCont["entries"][i]["name"].ToString(),
                                        FilePath  = jsonDataSearchCont["entries"][i]["path_lower"].ToString(),
                                        FileSize  = FileUtil.FormatFileSize(Convert.ToInt64(jsonDataSearchCont["entries"][i]["size"].ToString())),
                                        IsChecked = true
                                    };
                                    lock (insertLock)
                                    {
                                        model.MemberList.Add(lvItem);
                                    }

                                    SyncContext.Post(delegate
                                    {
                                        presenter.UpdateProgressInfo(string.Format("Searching Files For : {0} File Count: {1}", item.Email, (++totalCont)));
                                    }, null);
                                }
                            }
                            if (entryCountCont > 0)
                            {
                                filesAdded = true;
                            }
                            hasMore = jsonDataSearchCont["has_more"];
                            cursor  = jsonDataSearchCont["cursor"];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(filesAdded);
        }
        private void SearchMembers(IDumpUserContentModel model, IMainPresenter presenter)
        {
            if (!string.IsNullOrEmpty(model.UserAccessToken))
            {
                MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion);
                service.ListMembersUrl   = ApplicationResource.ActionListMembers;
                service.UserAgentVersion = ApplicationResource.UserAgent;
                IDataResponse response = service.ListMembers(new MemberData()
                {
                    SearchLimit = ApplicationResource.SearchDefaultLimit
                }, model.UserAccessToken);

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

                        // clear existing data first
                        model.MemberList.Clear();
                        int total       = 0;
                        int resultCount = jsonData["members"].Count;
                        for (int i = 0; i < resultCount; i++)
                        {
                            dynamic profile  = jsonData["members"][i]["profile"];
                            dynamic idObj    = profile["team_member_id"];
                            dynamic emailObj = profile["email"];
                            dynamic status   = profile["status"];
                            if (status != null && (status[".tag"].ToString().Equals("active") || status[".tag"].ToString().Equals("suspended") || status[".tag"].ToString().Equals("invited")))
                            {
                                string teamId = idObj.Value as string;
                                string email  = emailObj.Value as string;

                                // update model
                                TeamListViewItemModel lvItem = new TeamListViewItemModel()
                                {
                                    Email  = email,
                                    TeamId = teamId
                                };

                                model.MemberList.Add(lvItem);
                            }
                            if (SyncContext != null)
                            {
                                SyncContext.Post(delegate {
                                    presenter.UpdateProgressInfo("Scanning Account(s): " + (++total));
                                }, null);
                            }
                        }
                        //if the memberID count is above limit - default 1000 we need to grab the cursor and call continue
                        bool   hasMore = jsonData["has_more"];
                        string cursor  = jsonData["cursor"];

                        while (hasMore)
                        {
                            service.ListMembersContinuationUrl = ApplicationResource.ActionListMembersContinuation;
                            IDataResponse responseCont = service.ListMembersContinuation(new MemberData()
                            {
                                Cursor = cursor
                            }, model.UserAccessToken);

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

                            int resultContCount = jsonDataCont["members"].Count;
                            for (int i = 0; i < resultContCount; i++)
                            {
                                dynamic profile  = jsonDataCont["members"][i]["profile"];
                                dynamic idObj    = profile["team_member_id"];
                                dynamic emailObj = profile["email"];
                                dynamic status   = profile["status"];
                                if (status != null && (status[".tag"].ToString().Equals("active") || status[".tag"].ToString().Equals("suspended") || status[".tag"].ToString().Equals("invited")))
                                {
                                    string teamId = idObj.Value as string;
                                    string email  = emailObj.Value as string;

                                    // update model
                                    TeamListViewItemModel lvItem = new TeamListViewItemModel()
                                    {
                                        Email  = email,
                                        TeamId = teamId
                                    };

                                    model.MemberList.Add(lvItem);
                                }
                                if (SyncContext != null)
                                {
                                    SyncContext.Post(delegate {
                                        presenter.UpdateProgressInfo("Scanning Account(s): " + (++total));
                                    }, null);
                                }
                            }
                            hasMore = jsonDataCont["has_more"];
                            cursor  = jsonDataCont["cursor"];
                        }
                    }
                }
            }
        }
        private void SearchItems(
            IMemberServices service,
            TeamListViewItemModel owner,
            IDataMigrationModel model,
            IMainPresenter presenter)
        {
            bool SuppressStatus = ApplicationResource.SuppressFilenamesInStatus;
            bool complete       = false;

            //remove when done debugging
            exceptionCount = 0;
            try
            {
                while (!complete)
                {
                    service.ListFolderUrl    = ApplicationResource.ActionListFolder;
                    service.UserAgentVersion = ApplicationResource.UserAgent;
                    IDataResponse response = service.ListFolders(
                        new MemberData()
                    {
                        MemberId = owner.TeamId
                    }, model.AccessToken);
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        if (response.Data != null)
                        {
                            string  content        = response.Data as string;
                            dynamic jsonDataSearch = JsonConvert.DeserializeObject <dynamic>(content);
                            IDictionary <string, long> folderMap = new Dictionary <string, long>();
                            int entryCount = jsonDataSearch["entries"].Count;
                            int foundTotal = 0;
                            for (int i = 0; i < entryCount; i++)
                            {
                                dynamic entry = jsonDataSearch["entries"][i];
                                string  type  = entry[".tag"].ToString();
                                ContentDisplayListViewItemModel lvItem = null;
                                if (type.Equals("folder"))
                                {
                                    lvItem = new ContentDisplayListViewItemModel()
                                    {
                                        ItemType        = type,
                                        Email           = owner.Email,
                                        MemberId        = owner.TeamId,
                                        FirstName       = owner.FirstName,
                                        LastName        = owner.LastName,
                                        ItemName        = entry["name"].ToString(),
                                        ItemPath        = entry["path_lower"].ToString(),
                                        ItemPathDisplay = entry["path_display"].ToString(),
                                        ItemSizeByte    = 0
                                    };
                                }
                                else
                                {
                                    string serverModified     = entry["server_modified"].ToString();
                                    string serverModifiedDate = string.Empty;
                                    if (!string.IsNullOrEmpty(serverModified))
                                    {
                                        DateTime lastModified = DateTime.SpecifyKind(
                                            DateTime.Parse(serverModified),
                                            DateTimeKind.Utc
                                            );
                                        serverModifiedDate = lastModified.ToString("dd MMM yyyy");
                                    }
                                    string fileSizeStr = jsonDataSearch["entries"][i]["size"].ToString();
                                    long   fileSize    = 0;
                                    long.TryParse(fileSizeStr, out fileSize);
                                    lvItem = new ContentDisplayListViewItemModel()
                                    {
                                        ItemType        = type,
                                        Email           = owner.Email,
                                        MemberId        = owner.TeamId,
                                        FirstName       = owner.FirstName,
                                        LastName        = owner.LastName,
                                        ItemName        = entry["name"].ToString(),
                                        ItemPath        = entry["path_lower"].ToString(),
                                        ItemPathDisplay = entry["path_display"].ToString(),
                                        ItemSize        = FileUtil.FormatFileSize(fileSize),
                                        ItemSizeByte    = fileSize,
                                        LastModified    = serverModifiedDate,
                                        Uploaded        = serverModifiedDate,
                                        Created         = serverModifiedDate
                                    };
                                }
                                lock (insertLock)
                                {
                                    model.Contents.Add(lvItem);
                                }
                                if (SyncContext != null)
                                {
                                    SyncContext.Post(delegate
                                    {
                                        if (!SuppressStatus)
                                        {
                                            presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, lvItem.ItemName, (++foundTotal), entryCount));
                                        }
                                        else
                                        {
                                            presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, "Suppressing filename status", (++foundTotal), entryCount));
                                        }
                                    }, null);
                                }
                            }
                            bool   hasMore = jsonDataSearch["has_more"];
                            string cursor  = jsonDataSearch["cursor"];

                            while (hasMore)
                            {
                                service.ListFolderUrl = ApplicationResource.ActionListFolderContinuation;
                                IDataResponse responseCont = service.ListFolders(
                                    new MemberData()
                                {
                                    MemberId = owner.TeamId,
                                    Cursor   = cursor
                                }, model.AccessToken);

                                string  contentCont        = responseCont.Data as string;
                                dynamic jsonDataSearchCont = JsonConvert.DeserializeObject <dynamic>(contentCont);
                                IDictionary <string, long> folderMapCont = new Dictionary <string, long>();
                                int entryCountCont = jsonDataSearchCont["entries"].Count;
                                int foundTotalCont = 0;
                                for (int i = 0; i < entryCountCont; i++)
                                {
                                    dynamic entry = jsonDataSearchCont["entries"][i];
                                    string  type  = entry[".tag"].ToString();
                                    ContentDisplayListViewItemModel lvItem = null;
                                    if (type.Equals("folder"))
                                    {
                                        lvItem = new ContentDisplayListViewItemModel()
                                        {
                                            ItemType        = type,
                                            Email           = owner.Email,
                                            MemberId        = owner.TeamId,
                                            FirstName       = owner.FirstName,
                                            LastName        = owner.LastName,
                                            ItemName        = entry["name"].ToString(),
                                            ItemPath        = entry["path_lower"].ToString(),
                                            ItemPathDisplay = entry["path_display"].ToString(),
                                            ItemSizeByte    = 0
                                        };
                                    }
                                    else
                                    {
                                        string serverModified     = entry["server_modified"].ToString();
                                        string serverModifiedDate = string.Empty;
                                        if (!string.IsNullOrEmpty(serverModified))
                                        {
                                            DateTime lastModified = DateTime.SpecifyKind(
                                                DateTime.Parse(serverModified),
                                                DateTimeKind.Utc
                                                );
                                            serverModifiedDate = lastModified.ToString("dd MMM yyyy");
                                        }
                                        string fileSizeStr = jsonDataSearchCont["entries"][i]["size"].ToString();
                                        long   fileSize    = 0;
                                        long.TryParse(fileSizeStr, out fileSize);
                                        lvItem = new ContentDisplayListViewItemModel()
                                        {
                                            ItemType        = type,
                                            Email           = owner.Email,
                                            MemberId        = owner.TeamId,
                                            FirstName       = owner.FirstName,
                                            LastName        = owner.LastName,
                                            ItemName        = entry["name"].ToString(),
                                            ItemPath        = entry["path_lower"].ToString(),
                                            ItemPathDisplay = entry["path_display"].ToString(),
                                            ItemSize        = FileUtil.FormatFileSize(fileSize),
                                            ItemSizeByte    = fileSize,
                                            LastModified    = serverModifiedDate,
                                            Uploaded        = serverModifiedDate,
                                            Created         = serverModifiedDate
                                        };
                                    }
                                    lock (insertLock)
                                    {
                                        model.Contents.Add(lvItem);
                                    }
                                    if (SyncContext != null)
                                    {
                                        SyncContext.Post(delegate
                                        {
                                            if (!SuppressStatus)
                                            {
                                                presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, lvItem.ItemName, (++foundTotalCont), entryCountCont));
                                            }
                                            else
                                            {
                                                presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, "Suppressing filename status", (++foundTotalCont), entryCountCont));
                                            }
                                        }, null);
                                    }
                                }
                                hasMore = jsonDataSearchCont["has_more"];
                                cursor  = jsonDataSearchCont["cursor"];
                            }
                        }
                        complete = true;
                    }
                    if (response.StatusCode != HttpStatusCode.OK)
                    {
                        //error from API
                        if (response.Data != null)
                        {
                            string  data     = response.Data.ToString();
                            dynamic jsonData = JsonConvert.DeserializeObject <dynamic>(data);
                            if (data == "")
                            {
                                complete = false;
                                retryCount++;
                            }
                        }
                        else
                        {
                            //response.Data is null so let's retry
                            complete = false;
                            retryCount++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                exceptionCount++;
                Console.WriteLine(ex.Message);
            }
        }
        private void SearchItems(
            IMemberServices service,
            TeamListViewItemModel owner,
            IDataMigrationModel model,
            IMainPresenter presenter) {
            bool SuppressStatus = ApplicationResource.SuppressFilenamesInStatus;
            try {
                service.ListFolderUrl = ApplicationResource.ActionListFolder;
                service.UserAgentVersion = ApplicationResource.UserAgent;
                IDataResponse response = service.ListFolders(
                   new MemberData() {
                       MemberId = owner.TeamId
                   }, model.AccessToken);
                if (response.StatusCode == HttpStatusCode.OK) {
                    if (response.Data != null) {
                        string content = response.Data as string;
                        dynamic jsonDataSearch = JsonConvert.DeserializeObject<dynamic>(content);
                        IDictionary<string, long> folderMap = new Dictionary<string, long>();
                        int entryCount = jsonDataSearch["entries"].Count;
                        int foundTotal = 0;
                        for (int i = 0; i < entryCount; i++)
                        {
                            dynamic entry = jsonDataSearch["entries"][i];
                            string type = entry[".tag"].ToString();
                            ContentDisplayListViewItemModel lvItem = null;
                            if (type.Equals("folder"))
                            {
                                lvItem = new ContentDisplayListViewItemModel()
                                {
                                    ItemType = type,
                                    Email = owner.Email,
                                    MemberId = owner.TeamId,
                                    FirstName = owner.FirstName,
                                    LastName = owner.LastName,
                                    ItemName = entry["name"].ToString(),
                                    ItemPath = entry["path_lower"].ToString(),
                                    ItemPathDisplay = entry["path_display"].ToString(),
                                    ItemSizeByte = 0
                                };
                            }
                            else {
                                string serverModified = entry["server_modified"].ToString();
                                string serverModifiedDate = string.Empty;
                                if (!string.IsNullOrEmpty(serverModified))
                                {
                                    DateTime lastModified = DateTime.SpecifyKind(
                                        DateTime.Parse(serverModified),
                                        DateTimeKind.Utc
                                    );
                                    serverModifiedDate = lastModified.ToString("dd MMM yyyy");
                                }
                                string fileSizeStr = jsonDataSearch["entries"][i]["size"].ToString();
                                long fileSize = 0;
                                long.TryParse(fileSizeStr, out fileSize);
                                lvItem = new ContentDisplayListViewItemModel()
                                {
                                    ItemType = type,
                                    Email = owner.Email,
                                    MemberId = owner.TeamId,
                                    FirstName = owner.FirstName,
                                    LastName = owner.LastName,
                                    ItemName = entry["name"].ToString(),
                                    ItemPath = entry["path_lower"].ToString(),
                                    ItemPathDisplay = entry["path_display"].ToString(),
                                    ItemSize = FileUtil.FormatFileSize(fileSize),
                                    ItemSizeByte = fileSize,
                                    LastModified = serverModifiedDate,
                                    Uploaded = serverModifiedDate,
                                    Created = serverModifiedDate
                                };
                            }
                            lock (insertLock)
                            {
                                model.Contents.Add(lvItem);
                            }
                            if (SyncContext != null)
                            {
                                SyncContext.Post(delegate
                                {
                                    if (!SuppressStatus)
                                    {
                                        presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, lvItem.ItemName, (++foundTotal), entryCount));
                                    }
                                    else
                                    {
                                        presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, "Suppressing filename status", (++foundTotal), entryCount));
                                    }
                                    
                                }, null);
                            }
                        }
                        bool hasMore = jsonDataSearch["has_more"];
                        string cursor = jsonDataSearch["cursor"];

                        while (hasMore)
                        {
                            service.ListFolderUrl = ApplicationResource.ActionListFolderContinuation;
                            IDataResponse responseCont = service.ListFolders(
                            new MemberData()
                            {
                                MemberId = owner.TeamId,
                                Cursor = cursor
                            }, model.AccessToken);

                            string contentCont = responseCont.Data as string;
                            dynamic jsonDataSearchCont = JsonConvert.DeserializeObject<dynamic>(contentCont);
                            IDictionary<string, long> folderMapCont = new Dictionary<string, long>();
                            int entryCountCont = jsonDataSearchCont["entries"].Count;
                            int foundTotalCont = 0;
                            for (int i = 0; i < entryCountCont; i++)
                            {
                                dynamic entry = jsonDataSearchCont["entries"][i];
                                string type = entry[".tag"].ToString();
                                ContentDisplayListViewItemModel lvItem = null;
                                if (type.Equals("folder"))
                                {
                                    lvItem = new ContentDisplayListViewItemModel()
                                    {
                                        ItemType = type,
                                        Email = owner.Email,
                                        MemberId = owner.TeamId,
                                        FirstName = owner.FirstName,
                                        LastName = owner.LastName,
                                        ItemName = entry["name"].ToString(),
                                        ItemPath = entry["path_lower"].ToString(),
                                        ItemPathDisplay = entry["path_display"].ToString(),
                                        ItemSizeByte = 0
                                    };
                                }
                                else {
                                    string serverModified = entry["server_modified"].ToString();
                                    string serverModifiedDate = string.Empty;
                                    if (!string.IsNullOrEmpty(serverModified))
                                    {
                                        DateTime lastModified = DateTime.SpecifyKind(
                                            DateTime.Parse(serverModified),
                                            DateTimeKind.Utc
                                        );
                                        serverModifiedDate = lastModified.ToString("dd MMM yyyy");
                                    }
                                    string fileSizeStr = jsonDataSearchCont["entries"][i]["size"].ToString();
                                    long fileSize = 0;
                                    long.TryParse(fileSizeStr, out fileSize);
                                    lvItem = new ContentDisplayListViewItemModel()
                                    {
                                        ItemType = type,
                                        Email = owner.Email,
                                        MemberId = owner.TeamId,
                                        FirstName = owner.FirstName,
                                        LastName = owner.LastName,
                                        ItemName = entry["name"].ToString(),
                                        ItemPath = entry["path_lower"].ToString(),
                                        ItemPathDisplay = entry["path_display"].ToString(),
                                        ItemSize = FileUtil.FormatFileSize(fileSize),
                                        ItemSizeByte = fileSize,
                                        LastModified = serverModifiedDate,
                                        Uploaded = serverModifiedDate,
                                        Created = serverModifiedDate
                                    };
                                }
                                lock (insertLock)
                                {
                                    model.Contents.Add(lvItem);
                                }
                                if (SyncContext != null)
                                {
                                    SyncContext.Post(delegate
                                    {
                                        if (!SuppressStatus)
                                        {
                                            presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, lvItem.ItemName, (++foundTotalCont), entryCountCont));
                                        }
                                        else
                                        {
                                            presenter.UpdateProgressInfo(string.Format("Owner: [{0}] Item: [{1}] {2}/{3}", lvItem.Email, "Suppressing filename status", (++foundTotalCont), entryCountCont));
                                        }
                                        
                                    }, null);
                                }
                            }
                            hasMore = jsonDataSearchCont["has_more"];
                            cursor = jsonDataSearchCont["cursor"];     
                        }
                    }
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
        private IList<TeamListViewItemModel> SearchOwner(
            IDataMigrationModel model,
            IMainPresenter presenter) {
            IList<TeamListViewItemModel> members = new List<TeamListViewItemModel>();
            if (!string.IsNullOrEmpty(model.AccessToken)) {
                MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion);
                service.ListMembersUrl = ApplicationResource.ActionListMembers;
                service.UserAgentVersion = ApplicationResource.UserAgent;
                IDataResponse response = service.ListMembers(new MemberData() {
                    SearchLimit = ApplicationResource.SearchDefaultLimit
                }, model.AccessToken);

                if (SyncContext != null) {
                    SyncContext.Post(delegate {
                        presenter.UpdateProgressInfo("Searching Owners...");
                    }, null);
                }

                if (response.StatusCode == HttpStatusCode.OK) {
                    if (response.Data != null) {
                        string data = response.Data.ToString();
                        dynamic jsonData = JsonConvert.DeserializeObject<dynamic>(data);
                        int resultCount = jsonData["members"].Count;
                        int total = 0;
                        for (int i = 0; i < resultCount; i++) {
                            dynamic profile = jsonData["members"][i]["profile"];
                            dynamic idObj = profile["team_member_id"];
                            dynamic emailObj = profile["email"];
                            dynamic name = profile["name"];
                            dynamic status = profile["status"];
                            if (status != null && (status[".tag"].ToString().Equals("active") || status[".tag"].ToString().Equals("suspended"))) {
                                string teamId = idObj.Value as string;
                                string email = emailObj.Value as string;
                                string firstName = name["given_name"].ToString();
                                string surName = name["surname"].ToString();
                                //string familiarName = name["familiar_name"] as string;
                                //string displayName = name["display_name"] as string;

                                // update model
                                TeamListViewItemModel lvItem = new TeamListViewItemModel() {
                                    Email = email,
                                    TeamId = teamId,
                                    FirstName = firstName,
                                    LastName = surName
                                };
                                members.Add(lvItem);
                            }

                            if (SyncContext != null) {
                                SyncContext.Post(delegate {
                                    presenter.UpdateProgressInfo("Scanning Account(s): " + (++total));
                                }, null);
                            }
                        }

                        // collect more.
                        bool hasMore = jsonData["has_more"];
                        string cursor = jsonData["cursor"];

                        while (hasMore) {
                            service.ListMembersContinuationUrl = ApplicationResource.ActionListMembersContinuation;
                            IDataResponse responseCont = service.ListMembersContinuation(new MemberData() {
                                Cursor = cursor
                            }, model.AccessToken);

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

                            int resultContCount = jsonDataCont["members"].Count;
                            for (int i = 0; i < resultContCount; i++) {
                                dynamic profile = jsonDataCont["members"][i]["profile"];
                                dynamic idObj = profile["team_member_id"];
                                dynamic emailObj = profile["email"];
                                dynamic name = profile["name"];
                                dynamic status = profile["status"];

                                string teamId = idObj.Value as string;
                                string email = emailObj.Value as string;
                                string firstName = name["given_name"].ToString();
                                string surName = name["surname"].ToString();

                                if (status != null && (status[".tag"].ToString().Equals("active") || status[".tag"].ToString().Equals("suspended"))) {
                                    // update model
                                    TeamListViewItemModel lvItem = new TeamListViewItemModel() {
                                        Email = email,
                                        TeamId = teamId,
                                        FirstName = firstName,
                                        LastName = surName
                                    };
                                    members.Add(lvItem);
                                }
                                if (SyncContext != null) {
                                    SyncContext.Post(delegate {
                                        presenter.UpdateProgressInfo("Scanning Account(s): " + (++total));
                                    }, null);
                                }
                            }
                            hasMore = jsonDataCont["has_more"];
                            cursor = jsonDataCont["cursor"];
                        }
                    }
                }
            }
            return members;
        }