Пример #1
0
        private void SearchMembers(ITextSearchModel model)
        {
            if (!string.IsNullOrEmpty(model.QueryString) &&
                !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 = model.SearchResultsLimit
                }, model.AccessToken);
                IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>();

                if (response.StatusCode == System.Net.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 resultCount = jsonData["members"].Count;
                        for (int i = 0; i < resultCount; i++)
                        {
                            dynamic idObj    = jsonData["members"][i]["profile"]["team_member_id"];
                            dynamic emailObj = jsonData["members"][i]["profile"]["email"];
                            string  memberId = idObj.Value as string;
                            string  email    = emailObj.Value as string;

                            // update model
                            MemberListViewItemModel lvItem = new MemberListViewItemModel()
                            {
                                Email    = email,
                                MemberId = memberId
                            };

                            // perform file search
                            if (!SearchFiles(service, memberId, model, email, presenter))
                            {
                                model.MemberList.Add(lvItem);
                            }
                            SyncContext.Post(delegate {
                                presenter.UpdateProgressInfo(string.Format("Searching Content(s) From : {0}", email));
                            }, null);
                        }
                    }
                }
                else
                {
                    // TODO: Report error
                }
            }
        }
        private void SearchMembersGetUsage(IProvisioningModel model)
        {
            string UserAccessToken = ApplicationResource.DefaultAccessToken;
            if (!string.IsNullOrEmpty(UserAccessToken))
            {
                MemberServices serviceUsage = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion);
                serviceUsage.GetUsageUrl = ApplicationResource.ActionGetUsage;
                List<string[]> members = new List<string[]>();

                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
                }, 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.Members.Clear();

                        int resultCount = jsonData["members"].Count;
                        for (int i = 0; i < resultCount; i++)
                        {
                            dynamic emailObj = jsonData["members"][i]["profile"]["email"];
                            dynamic firstNameObj = jsonData["members"][i]["profile"]["name"]["given_name"];
                            dynamic lastNameObj = jsonData["members"][i]["profile"]["name"]["surname"];
                            dynamic idObj = jsonData["members"][i]["profile"]["team_member_id"];
                            string teamId = idObj.Value as string;
                            string email = emailObj.Value as string;
                            string firstName = firstNameObj.Value as string;
                            string lastName = lastNameObj.Value as string;

                            IDataResponse responseUsage = serviceUsage.GetUsage(new MemberData()
                            {
                                MemberId = teamId
                            }, UserAccessToken);

                            UInt64 used = 0;

                            if (responseUsage.StatusCode == HttpStatusCode.OK)
                            {
                                if (responseUsage.Data != null)
                                {
                                    string dataUsage = responseUsage.Data.ToString();
                                    dynamic jsonDataUsage = JsonConvert.DeserializeObject<dynamic>(dataUsage);

                                    used = jsonDataUsage["used"];
                                }
                            }

                            // update model
                            MemberListViewItemModel lvItem = new MemberListViewItemModel()
                            {
                                Email = email,
                                MemberId = teamId,
                                FirstName = firstName,
                                LastName = lastName,
                                Usage = FileUtil.FormatFileSizeMB(used)
                            };

                            model.Members.Add(lvItem);
                        }
                        //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
                            }, 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 emailObj = jsonDataCont["members"][i]["profile"]["email"];
                                dynamic firstNameObj = jsonDataCont["members"][i]["profile"]["name"]["given_name"];
                                dynamic lastNameObj = jsonDataCont["members"][i]["profile"]["name"]["surname"];
                                dynamic idObj = jsonData["members"][i]["profile"]["team_member_id"];
                                string teamId = idObj.Value as string;
                                string email = emailObj.Value as string;
                                string firstName = firstNameObj.Value as string;
                                string lastName = lastNameObj.Value as string;

                                IDataResponse responseUsage = serviceUsage.GetUsage(new MemberData()
                                {
                                    MemberId = teamId
                                }, UserAccessToken);

                                decimal used = 0;

                                if (responseUsage.StatusCode == HttpStatusCode.OK)
                                {
                                    if (responseUsage.Data != null)
                                    {
                                        string dataUsage = responseUsage.Data.ToString();
                                        dynamic jsonDataUsage = JsonConvert.DeserializeObject<dynamic>(dataUsage);

                                        used = jsonDataUsage["used"];
                                    }
                                }
                                // update model
                                MemberListViewItemModel lvItem = new MemberListViewItemModel()
                                {
                                    Email = email,
                                    MemberId = teamId,
                                    FirstName = firstName,
                                    LastName = lastName,
                                    Usage = FileUtil.FormatFileSizeMB(used)
                                };
                                model.Members.Add(lvItem);
                            }
                            hasMore = jsonDataCont["has_more"];
                            cursor = jsonDataCont["cursor"];
                        }
                    }
                }
            }
        }
Пример #3
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);
        }
        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 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;
        }