private void DumpDevices(IDevicesModel model, IMainPresenter presenter) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo("Preparing Device Removal..."); }, null); } int counter = 0; int total = model.DeviceList.Where(d => d.IsChecked && !string.IsNullOrEmpty(d.SessionId)).ToList().Count; IMemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.DumpDevicesUrl = ApplicationResource.ActionDumpDevices; service.UserAgentVersion = ApplicationResource.UserAgent; foreach (DeviceListViewItemModel lvItem in model.DeviceList) { if (lvItem.IsChecked && !string.IsNullOrEmpty(lvItem.SessionId)) { // notify progress if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Removing device: {0}/{1}", ++counter, total)); }, null); } service.DumpDevices( new MemberData() { SessionId = lvItem.SessionId, MemberId = lvItem.TeamId, ClientType = lvItem.ClientType }, model.UserAccessToken ); } } }
private void GetDevices(IDevicesModel model, IMainPresenter presenter) { if (!string.IsNullOrEmpty(model.UserAccessToken)) { IMemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.GetDevicesUrl = ApplicationResource.ActionListTeamDevices; service.UserAgentVersion = ApplicationResource.UserAgent; List<string[]> members = new List<string[]>(); //BEGIN GET MEMBERS MemberServices serviceMembers = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); serviceMembers.ListMembersUrl = ApplicationResource.ActionListMembers; IDataResponse responseMembers = serviceMembers.ListMembers(new MemberData() { SearchLimit = ApplicationResource.SearchDefaultLimit }, ApplicationResource.DefaultAccessToken); if (responseMembers.StatusCode == HttpStatusCode.OK) { if (responseMembers.Data != null) { string data = responseMembers.Data.ToString(); dynamic jsonData = JsonConvert.DeserializeObject<dynamic>(data); 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 teamId = idObj.Value as string; string email = emailObj.Value as string; string[] str = new string[2]; str[0] = teamId; str[1] = email; members.Add(str); } //if the memberID count is above limit - grab the cursor and call continue bool hasMore = jsonData["has_more"]; string cursor = jsonData["cursor"]; while (hasMore) { serviceMembers.ListMembersContinuationUrl = ApplicationResource.ActionListMembersContinuation; IDataResponse responseMembersCont = serviceMembers.ListMembersContinuation(new MemberData() { Cursor = cursor }, ApplicationResource.DefaultAccessToken); string dataCont = responseMembersCont.Data.ToString(); dynamic jsonDataCont = JsonConvert.DeserializeObject<dynamic>(dataCont); int resultContCount = jsonDataCont["members"].Count; for (int i = 0; i < resultContCount; i++) { dynamic idObj = jsonDataCont["members"][i]["profile"]["team_member_id"]; dynamic emailObj = jsonDataCont["members"][i]["profile"]["email"]; string teamId = idObj.Value as string; string email = emailObj.Value as string; string[] str = new string[2]; str[0] = teamId; str[1] = email; members.Add(str); } hasMore = jsonDataCont["has_more"]; cursor = jsonDataCont["cursor"]; } } } //END GET MEMBERS bool FilterCriteriaContains = false; bool FilterCriteriaNotContains = false; bool FilterCriteriaBeginsWith = false; bool FilterCriteriaEndsWith = false; if (model.FilterCriteria == "CONTAINS") { FilterCriteriaContains = true; } if (model.FilterCriteria == "NOT CONTAINS") { FilterCriteriaNotContains = true; } if (model.FilterCriteria == "BEGINS WITH") { FilterCriteriaBeginsWith = true; } if (model.FilterCriteria == "ENDS WITH") { FilterCriteriaEndsWith = true; } IDataResponse response = service.FindDevices(new MemberData() { //no cursor needed on first hit }, model.UserAccessToken); if (response.StatusCode == HttpStatusCode.OK) { if (response.Data != null) { string data = response.Data.ToString(); dynamic jsonDevicesData = JsonConvert.DeserializeObject<dynamic>(data); // clear existing data first model.DeviceList.Clear(); int resultCount = jsonDevicesData["devices"].Count; if (resultCount > 0) { for (int i = 0; i < resultCount; i++) { DateTime created = new DateTime(); string teamId = string.Empty; string deviceName = string.Empty; string ipAddress = string.Empty; string sessionId = string.Empty; string clientType = string.Empty; string email = string.Empty; dynamic idObj = jsonDevicesData["devices"][i]["team_member_id"]; int resultWebCount = jsonDevicesData["devices"][i]["web_sessions"].Count; int resultDesktopCount = jsonDevicesData["devices"][i]["desktop_clients"].Count; int resultMobileCount = jsonDevicesData["devices"][i]["mobile_clients"].Count; if (resultWebCount > 0) { for (int i2 = 0; i2 < resultWebCount; i2++) { dynamic deviceNameObj = jsonDevicesData["devices"][i]["web_sessions"][i2]["user_agent"]; dynamic ipAddressObj = jsonDevicesData["devices"][i]["web_sessions"][i2]["ip_address"]; dynamic sessionIdObj = jsonDevicesData["devices"][i]["web_sessions"][i2]["session_id"]; clientType = "Web"; dynamic createdObj = jsonDevicesData["devices"][i]["web_sessions"][i2]["created"]; if (idObj != null) { teamId = idObj.Value as string; } if (deviceNameObj != null) { deviceName = deviceNameObj.Value as string; } if (ipAddressObj != null) { ipAddress = ipAddressObj.Value as string; } if (sessionIdObj != null) { sessionId = sessionIdObj.Value as string; } if (createdObj != null) { created = jsonDevicesData["devices"][i]["web_sessions"][i2]["created"]; } foreach (string[] lvitem in members) { if (teamId == lvitem[0]) { email = lvitem[1]; } } // update model DeviceListViewItemModel lvItem = new DeviceListViewItemModel() { Created = created, TeamId = teamId, DeviceName = deviceName, IpAddress = ipAddress, SessionId = sessionId, ClientType = clientType, Email = email }; if (string.IsNullOrEmpty(model.Filter)) { model.DeviceList.Add(lvItem); } if (FilterCriteriaContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaNotContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { //do nothing, don't add to list } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { //do nothing, don't add to list } if ((model.FilterType == "IpAddress" && (!ipAddress.Contains(model.Filter))) || (model.FilterType == "DeviceName" && (!deviceName.Contains(model.Filter)))) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaBeginsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaEndsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } } if (resultDesktopCount > 0) { for (int i3 = 0; i3 < resultDesktopCount; i3++) { dynamic deviceNameObj = jsonDevicesData["devices"][i]["desktop_clients"][i3]["host_name"]; dynamic ipAddressObj = jsonDevicesData["devices"][i]["desktop_clients"][i3]["ip_address"]; dynamic sessionIdObj = jsonDevicesData["devices"][i]["desktop_clients"][i3]["session_id"]; clientType = "Desktop"; dynamic createdObj = jsonDevicesData["devices"][i]["desktop_clients"][i3]["created"]; if (idObj != null) { teamId = idObj.Value as string; } if (deviceNameObj != null) { deviceName = deviceNameObj.Value as string; } if (ipAddressObj != null) { ipAddress = ipAddressObj.Value as string; } if (sessionIdObj != null) { sessionId = sessionIdObj.Value as string; } if (createdObj != null) { created = jsonDevicesData["devices"][i]["desktop_clients"][i3]["created"]; } foreach (string[] lvitem in members) { if (teamId == lvitem[0]) { email = lvitem[1]; } } // update model DeviceListViewItemModel lvItem = new DeviceListViewItemModel() { Created = created, TeamId = teamId, DeviceName = deviceName, IpAddress = ipAddress, SessionId = sessionId, ClientType = clientType, Email = email }; if (string.IsNullOrEmpty(model.Filter)) { model.DeviceList.Add(lvItem); } if (FilterCriteriaContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaNotContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { //do nothing, don't add to list } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { //do nothing, don't add to list } if ((model.FilterType == "IpAddress" && (!ipAddress.Contains(model.Filter))) || (model.FilterType == "DeviceName" && (!deviceName.Contains(model.Filter)))) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaBeginsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaEndsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } } } if (resultMobileCount > 0) { for (int i4 = 0; i4 < resultMobileCount; i4++) { dynamic deviceNameObj = jsonDevicesData["devices"][i]["mobile_clients"][i4]["device_name"]; dynamic ipAddressObj = jsonDevicesData["devices"][i]["mobile_clients"][i4]["ip_address"]; dynamic sessionIdObj = jsonDevicesData["devices"][i]["mobile_clients"][i4]["session_id"]; clientType = "Mobile"; dynamic createdObj = jsonDevicesData["devices"][i]["mobile_clients"][i4]["created"]; if (idObj != null) { teamId = idObj.Value as string; } if (deviceNameObj != null) { deviceName = deviceNameObj.Value as string; } if (ipAddressObj != null) { ipAddress = ipAddressObj.Value as string; } if (sessionIdObj != null) { sessionId = sessionIdObj.Value as string; } if (createdObj != null) { created = jsonDevicesData["devices"][i]["mobile_clients"][i4]["created"]; } foreach (string[] lvitem in members) { if (teamId == lvitem[0]) { email = lvitem[1]; } } // update model DeviceListViewItemModel lvItem = new DeviceListViewItemModel() { Created = created, TeamId = teamId, DeviceName = deviceName, IpAddress = ipAddress, SessionId = sessionId, ClientType = clientType, Email = email }; if (string.IsNullOrEmpty(model.Filter)) { model.DeviceList.Add(lvItem); } if (FilterCriteriaContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaNotContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { //do nothing, don't add to list } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { //do nothing, don't add to list } if ((model.FilterType == "IpAddress" && (!ipAddress.Contains(model.Filter))) || (model.FilterType == "DeviceName" && (!deviceName.Contains(model.Filter)))) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaBeginsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaEndsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } } } } } //if the device count has more, we need to pull next batch from cursor value bool hasMore = jsonDevicesData["has_more"]; string cursor = jsonDevicesData["cursor"]; while (hasMore) { service.GetDevicesUrl = ApplicationResource.ActionListTeamDevices; IDataResponse responseCont = service.FindDevices(new MemberData() { Cursor = cursor }, model.UserAccessToken); string dataCont = responseCont.Data.ToString(); dynamic jsonDevicesDataCont = JsonConvert.DeserializeObject<dynamic>(dataCont); int resultCountCont = jsonDevicesDataCont["devices"].Count; if (resultCountCont > 0) { for (int i = 0; i < resultCountCont; i++) { DateTime created = new DateTime(); string teamId = string.Empty; string deviceName = string.Empty; string ipAddress = string.Empty; string sessionId = string.Empty; string clientType = string.Empty; string email = string.Empty; dynamic idObj = jsonDevicesDataCont["devices"][i]["team_member_id"]; int resultWebCount = jsonDevicesDataCont["devices"][i]["web_sessions"].Count; int resultDesktopCount = jsonDevicesDataCont["devices"][i]["desktop_clients"].Count; int resultMobileCount = jsonDevicesDataCont["devices"][i]["mobile_clients"].Count; if (resultWebCount > 0) { for (int i2 = 0; i2 < resultWebCount; i2++) { dynamic deviceNameObj = jsonDevicesDataCont["devices"][i]["web_sessions"][i2]["user_agent"]; dynamic ipAddressObj = jsonDevicesDataCont["devices"][i]["web_sessions"][i2]["ip_address"]; dynamic sessionIdObj = jsonDevicesDataCont["devices"][i]["web_sessions"][i2]["session_id"]; clientType = "Web"; dynamic createdObj = jsonDevicesDataCont["devices"][i]["web_sessions"][i2]["created"]; if (idObj != null) { teamId = idObj.Value as string; } if (deviceNameObj != null) { deviceName = deviceNameObj.Value as string; } if (ipAddressObj != null) { ipAddress = ipAddressObj.Value as string; } if (sessionIdObj != null) { sessionId = sessionIdObj.Value as string; } if (createdObj != null) { created = jsonDevicesDataCont["devices"][i]["web_sessions"][i2]["created"]; } foreach (string[] lvitem in members) { if (teamId == lvitem[0]) { email = lvitem[1]; } } // update model DeviceListViewItemModel lvItem = new DeviceListViewItemModel() { Created = created, TeamId = teamId, DeviceName = deviceName, IpAddress = ipAddress, SessionId = sessionId, ClientType = clientType, Email = email }; if (string.IsNullOrEmpty(model.Filter)) { model.DeviceList.Add(lvItem); } if (FilterCriteriaContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaNotContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { //do nothing, don't add to list } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { //do nothing, don't add to list } if ((model.FilterType == "IpAddress" && (!ipAddress.Contains(model.Filter))) || (model.FilterType == "DeviceName" && (!deviceName.Contains(model.Filter)))) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaBeginsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaEndsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } } } if (resultDesktopCount > 0) { for (int i3 = 0; i3 < resultDesktopCount; i3++) { dynamic deviceNameObj = jsonDevicesDataCont["devices"][i]["desktop_clients"][i3]["host_name"]; dynamic ipAddressObj = jsonDevicesDataCont["devices"][i]["desktop_clients"][i3]["ip_address"]; dynamic sessionIdObj = jsonDevicesDataCont["devices"][i]["desktop_clients"][i3]["session_id"]; clientType = "Desktop"; dynamic createdObj = jsonDevicesDataCont["devices"][i]["desktop_clients"][i3]["created"]; if (idObj != null) { teamId = idObj.Value as string; } if (deviceNameObj != null) { deviceName = deviceNameObj.Value as string; } if (ipAddressObj != null) { ipAddress = ipAddressObj.Value as string; } if (sessionIdObj != null) { sessionId = sessionIdObj.Value as string; } if (createdObj != null) { created = jsonDevicesDataCont["devices"][i]["desktop_clients"][i3]["created"]; } foreach (string[] lvitem in members) { if (teamId == lvitem[0]) { email = lvitem[1]; } } // update model DeviceListViewItemModel lvItem = new DeviceListViewItemModel() { Created = created, TeamId = teamId, DeviceName = deviceName, IpAddress = ipAddress, SessionId = sessionId, ClientType = clientType, Email = email }; if (string.IsNullOrEmpty(model.Filter)) { model.DeviceList.Add(lvItem); } if (FilterCriteriaContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaNotContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { //do nothing, don't add to list } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { //do nothing, don't add to list } if ((model.FilterType == "IpAddress" && (!ipAddress.Contains(model.Filter))) || (model.FilterType == "DeviceName" && (!deviceName.Contains(model.Filter)))) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaBeginsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaEndsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } } } if (resultMobileCount > 0) { for (int i4 = 0; i4 < resultMobileCount; i4++) { dynamic deviceNameObj = jsonDevicesDataCont["devices"][i]["mobile_clients"][i4]["device_name"]; dynamic ipAddressObj = jsonDevicesDataCont["devices"][i]["mobile_clients"][i4]["ip_address"]; dynamic sessionIdObj = jsonDevicesDataCont["devices"][i]["mobile_clients"][i4]["session_id"]; clientType = "Mobile"; dynamic createdObj = jsonDevicesDataCont["devices"][i]["mobile_clients"][i4]["created"]; if (idObj != null) { teamId = idObj.Value as string; } if (deviceNameObj != null) { deviceName = deviceNameObj.Value as string; } if (ipAddressObj != null) { ipAddress = ipAddressObj.Value as string; } if (sessionIdObj != null) { sessionId = sessionIdObj.Value as string; } if (createdObj != null) { created = jsonDevicesDataCont["devices"][i]["mobile_clients"][i4]["created"]; } foreach (string[] lvitem in members) { if (teamId == lvitem[0]) { email = lvitem[1]; } } // update model DeviceListViewItemModel lvItem = new DeviceListViewItemModel() { Created = created, TeamId = teamId, DeviceName = deviceName, IpAddress = ipAddress, SessionId = sessionId, ClientType = clientType, Email = email }; if (string.IsNullOrEmpty(model.Filter)) { model.DeviceList.Add(lvItem); } if (FilterCriteriaContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaNotContains && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.Contains(model.Filter)) { //do nothing, don't add to list } if (model.FilterType == "DeviceName" && deviceName.Contains(model.Filter)) { //do nothing, don't add to list } if ((model.FilterType == "IpAddress" && (!ipAddress.Contains(model.Filter))) || (model.FilterType == "DeviceName" && (!deviceName.Contains(model.Filter)))) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaBeginsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.StartsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } if (FilterCriteriaEndsWith && !string.IsNullOrEmpty(model.Filter)) { if (model.FilterType == "IpAddress" && ipAddress.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } if (model.FilterType == "DeviceName" && deviceName.EndsWith(model.Filter)) { model.DeviceList.Add(lvItem); } } } } } } hasMore = jsonDevicesDataCont["has_more"]; cursor = jsonDevicesDataCont["cursor"]; } } } } } }
private void OnCommandContextMenuClicked(object sender, Common.DataExchange.DataUpdatedEventArgs e) { MenuItem selectedContextMenuItem = sender as MenuItem; if (selectedContextMenuItem != null) { if (selectedContextMenuItem.Text.ToLower().Equals(LIST_FILES, StringComparison.CurrentCultureIgnoreCase)) { if (e.Data != null) { IDumpUserContentView view = base._view as IDumpUserContentView; IDumpUserContentModel model = base._model as IDumpUserContentModel; IMainPresenter presenter = SimpleResolver.Instance.Get<IMainPresenter>(); ArrayList list = (ArrayList)e.Data; IList<TeamListViewItemModel> selectedLvItems = list.Cast<TeamListViewItemModel>().ToList(); if (selectedLvItems != null && selectedLvItems.Count > 0) { // lock UI if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Preparing Search..."); }, null); } Thread search = new Thread(() => { if (string.IsNullOrEmpty(model.UserAccessToken)) { SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.INVALID_TOKEN, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } else { MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); foreach (TeamListViewItemModel item in selectedLvItems) { SearchFiles(service, item, model, presenter); } // complete. if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel<IDumpUserContentView, IDumpUserContentModel>( ref view, model ); //view.ShowGroups(true); view.RenderMembersFileSearchResult(); view.EnableDumpControl(true); presenter.UpdateProgressInfo("Completed"); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); search.Start(); } } } } }
private void DumpFiles(IDumpUserContentModel model, IMainPresenter presenter) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo("Preparing Download..."); }, null); } string ProvisionToken = ApplicationResource.DefaultProvisionToken; int counter = 0; int total = model.MemberList.Where(d => d.IsChecked && !string.IsNullOrEmpty(d.FileName)).ToList().Count; IMemberServices service = new MemberServices(ApplicationResource.ContentUrl, ApplicationResource.ApiVersion); service.FileDumpUrl = ApplicationResource.ActionFilesDownload; service.UserAgentVersion = ApplicationResource.UserAgent; foreach (TeamListViewItemModel lvItem in model.MemberList) { if (lvItem.IsChecked && !string.IsNullOrEmpty(lvItem.FileName)) { // notify progress if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Downloading File: {0}/{1}", ++counter, total)); }, null); } service.DumpFile( new MemberData() { Email = lvItem.Email, Path = lvItem.FilePath, FileName = lvItem.FileName, MemberId = lvItem.TeamId, ZipFiles = model.ZipFiles }, model.OutputFolder, model.UserAccessToken ); if (model.SuspendUser) { IMemberServices serviceSus = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); serviceSus.SuspendMemberUrl = ApplicationResource.ActionSuspendMember; serviceSus.UserAgentVersion = ApplicationResource.UserAgent; IServiceResponse response = serviceSus.SuspendMember(new MemberData() { Email = lvItem.Email }, ProvisionToken); if (response.StatusCode == HttpStatusCode.OK) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Suspended Member: {0}", lvItem.Email)); }, null); } } else { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format(ErrorMessages.FAILED_TO_SUSPEND_MEMBER)); }, null); } } } if (model.DeleteUser) { IMemberServices serviceDel = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); serviceDel.RemoveMemberUrl = ApplicationResource.ActionRemoveMember; serviceDel.UserAgentVersion = ApplicationResource.UserAgent; IServiceResponse response = serviceDel.RemoveMember(new MemberData() { Email = lvItem.Email, KeepAccount = model.KeepAccount }, ProvisionToken); if (response.StatusCode == HttpStatusCode.OK) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Removed Member: {0}", lvItem.Email)); }, null); } } else { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format(ErrorMessages.FAILED_TO_REMOVE_MEMBER)); }, null); } } } } } }
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 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 } } }