private void OnCommandDeleteMemberGroup(object sender, System.EventArgs e) { IGroupsView view = base._view as IGroupsView; IGroupsModel model = base._model as IGroupsModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); string email = view.UserEmail; if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread deletemembergroup = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { if (email.Contains(",")) { char delimiter = ','; string[] emails = email.Split(delimiter); foreach (string newEmail in emails) { this.DeleteMemberGroup(model, newEmail, presenter); } } if (!email.Contains(",")) { this.DeleteMemberGroup(model, email, presenter); } if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <IGroupsView, IGroupsModel>( ref view, model ); // update result and update view. view.RenderGroupList(); presenter.ActivateSpinner(false); presenter.EnableControl(true); presenter.UpdateProgressInfo("Completed."); }, null); } } }); deletemembergroup.Start(); }
private void OnCommandLoadHealth(object sender, EventArgs e) { ITeamHealthView view = base._view as ITeamHealthView; ITeamHealthModel model = base._model as ITeamHealthModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Pulling health report stats..."); }, null); } Thread healthrefresh = new Thread(() => { if (!string.IsNullOrEmpty(model.AccessToken)) { this.RefreshHealth(model, presenter); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view with model. view.LoadViewHealthItems(model); presenter.UpdateProgressInfo("Health stats refreshed at [" + model.RefreshDateTime.ToString() + "]"); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); healthrefresh.Start(); }
private void OnCommandMemberSearch(object sender, System.EventArgs e) { ITextSearchModel model = base._model as ITextSearchModel; ITextSearchView view = base._view as ITextSearchView; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); // notify view to mark start of process if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } // TODO: to improve stability, we will need to ensure to kill // thread when user exits application while thread is running for REST service call Thread memberSearch = new Thread(() => { if (string.IsNullOrEmpty(model.QueryString)) { SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.MISSING_QUERYSTRING, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } else if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.INVALID_TOKEN, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } else { // perform search this.SearchMembers(model); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. view.RenderMembersSearchResult(); presenter.UpdateProgressInfo("Completed"); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); // start async search memberSearch.Start(); }
private void OnCommandListMembers(object sender, EventArgs e) { IDumpUserContentView view = base._view as IDumpUserContentView; IDumpUserContentModel model = base._model as IDumpUserContentModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); // notify view to mark start of process if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } // TODO: to improve stability, we will need to ensure to kill // thread when user exits application while thread is running for REST service call Thread memberSearch = 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 { // perform search this.SearchMembers(model, presenter); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <IDumpUserContentView, IDumpUserContentModel>( ref view, model ); view.RenderMembersSearchResult(); if (model.MemberList.Count > 0) { view.LazyInitializeContextMenu(); view.EnableContextMenuItems(true); //view.EnableDumpControl(true); } presenter.UpdateProgressInfo("Completed"); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); // start async search memberSearch.Start(); }
private void OnCommandSetFolderSyncSetting(object sender, System.EventArgs e) { ITeamFoldersView view = base._view as ITeamFoldersView; ITeamFoldersModel model = base._model as ITeamFoldersModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); TeamFoldersModel teamModel = view.GetTeamFolderIds(); bool syncSetting = view.SyncSetting; if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread setfoldersyncsetting = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { foreach (TeamFoldersListViewItemModel lvItem in teamModel.TeamFolders) { this.SetDefaultSyncSetting(model, lvItem.TeamFolderId, syncSetting, presenter); } if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <ITeamFoldersView, ITeamFoldersModel>( ref view, model ); // update result and update view. view.RenderTeamFoldersList(); presenter.ActivateSpinner(false); presenter.EnableControl(true); //presenter.UpdateProgressInfo("Completed."); }, null); } } }); setfoldersyncsetting.Start(); }
private void OnCommandDumpFiles(object sender, EventArgs e) { IDumpUserContentView view = base._view as IDumpUserContentView; IDumpUserContentModel model = base._model as IDumpUserContentModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } // TODO: to improve stability, we will need to ensure to kill // thread when user exits application while thread is running for REST service call Thread dumpFiles = 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 if (string.IsNullOrEmpty(model.OutputFolder)) { SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.MISSING_OUTPUT_FOLDER, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } else { this.DumpFiles(model, presenter); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. presenter.UpdateProgressInfo("Completed"); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); dumpFiles.Start(); }
private void OnCommandCreateTeamFolder(object sender, System.EventArgs e) { ITeamFoldersView view = base._view as ITeamFoldersView; ITeamFoldersModel model = base._model as ITeamFoldersModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); string teamFolderName = view.TeamFolderName; bool syncSetting = view.SyncSetting; if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread createteamfolder = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { this.CreateTeamFolder(model, teamFolderName, presenter); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <ITeamFoldersView, ITeamFoldersModel>( ref view, model ); // update result and update view. view.RenderTeamFoldersList(); presenter.ActivateSpinner(false); presenter.EnableControl(true); presenter.UpdateProgressInfo("Completed."); }, null); } } }); createteamfolder.Start(); }
private void OnCommandDownloadPaper(object sender, System.EventArgs e) { IPaperView view = base._view as IPaperView; IPaperModel model = base._model as IPaperModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread downloadpaperdocs = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { this.DownloadPaperDocs(model, view, presenter); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <IPaperView, IPaperModel>( ref view, model ); // update result and update view. view.RenderPaperList(); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); downloadpaperdocs.Start(); }
private void OnCommandCreateGroup(object sender, System.EventArgs e) { IGroupsView view = base._view as IGroupsView; IGroupsModel model = base._model as IGroupsModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); string groupName = view.GroupName; string groupType = view.GroupType; if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread creategroup = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { this.CreateGroup(model, groupName, groupType, presenter); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <IGroupsView, IGroupsModel>( ref view, model ); // update result and update view. view.RenderGroupList(); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); creategroup.Start(); }
private string UnsuspendMember(IProvisioningModel model, IMainPresenter presenter) { string errorMessage = string.Empty; IMemberServices service = service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.UnSuspendMemberUrl = ApplicationResource.ActionUnsuspendMember; service.UserAgentVersion = ApplicationResource.UserAgent; try { foreach (MemberListViewItemModel item in model.Members.Where(m => m.IsChecked).ToList()) { IServiceResponse response = service.UnSuspendMember(new MemberData() { Email = item.Email }, model.AccessToken); if (response.StatusCode == HttpStatusCode.OK) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Unsuspended Member: {0}", item.Email)); }, null); } } else { errorMessage = ErrorMessages.FAILED_TO_UNSUSPEND_MEMBER; } } } catch (Exception) { // error message. SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.FAILED_TO_UNSUSPEND_MEMBER, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } return errorMessage; }
private string ProvisionRoles(IProvisioningModel model, IMainPresenter presenter) { string errorMessage = string.Empty; IMemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.AddMemberUrl = ApplicationResource.ActionAddMember; service.UserAgentVersion = ApplicationResource.UserAgent; try { foreach (MemberListViewItemModel item in model.Members.Where(m => m.IsChecked).ToList()) { IServiceResponse response = service.AddMember(new MemberData() { Email = item.Email, FirstName = item.FirstName, LastName = item.LastName, SendWelcomeEmail = model.SendWelcomeEmail, ProvisionStatus = item.ProvisionStatus, RoleName = model.SelectedRole }, model.AccessToken); if (response.StatusCode == HttpStatusCode.OK) { if (SyncContext != null) { SyncContext.Post(delegate { if (response.Message.Contains("success")) { item.ProvisionStatus = "Provisioned successfully."; presenter.UpdateProgressInfo(string.Format("Added Member: {0}: {1} {2}", item.Email, item.FirstName, item.LastName)); } if (response.Message.Contains("team_license_limit")) { item.ProvisionStatus = "Team is already full.The organization has no available licenses."; presenter.UpdateProgressInfo("Team is already full. The organization has no available licenses."); } if (response.Message.Contains("free_team_member_limit_reached")) { item.ProvisionStatus = "Team is already full. The free team member limit has been reached."; presenter.UpdateProgressInfo("Team is already full. The free team member limit has been reached."); } if (response.Message.Contains("user_already_on_team")) { item.ProvisionStatus = "User is already on this team. The provided email address is associated with a user who is already a member of (including in recoverable state) or invited to the team."; presenter.UpdateProgressInfo("User is already on this team. The provided email address is associated with a user who is already a member of (including in recoverable state) or invited to the team."); } if (response.Message.Contains("user_on_another_team")) { item.ProvisionStatus = "User is already on another team. The provided email address is associated with a user that is already a member or invited to another team."; presenter.UpdateProgressInfo("User is already on another team. The provided email address is associated with a user that is already a member or invited to another team."); } if (response.Message.Contains("user_already_paired")) { item.ProvisionStatus = "User is already paired."; presenter.UpdateProgressInfo("User is already paired."); } if (response.Message.Contains("user_migration_failed")) { item.ProvisionStatus = "User migration has failed."; presenter.UpdateProgressInfo("User migration has failed."); } if (response.Message.Contains("duplicate_external_member_id")) { item.ProvisionStatus = "A user with the given external member ID already exists on the team (including in recoverable state)."; presenter.UpdateProgressInfo("A user with the given external member ID already exists on the team (including in recoverable state)."); } if (response.Message.Contains("user_creation_failed")) { item.ProvisionStatus = "User creation has failed."; presenter.UpdateProgressInfo("User creation has failed."); } }, null); } } else { errorMessage = ErrorMessages.FAILED_TO_ADD_MEMBER; } } } catch (Exception) { // error message. SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.FAILED_TO_ADD_MEMBER, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } return errorMessage; }
private void OnCommandExportPaper(object sender, System.EventArgs e) { IPaperView view = base._view as IPaperView; IPaperModel model = base._model as IPaperModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread exportpapertocsv = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { if (SyncContext != null) { SyncContext.Post(delegate { PresenterBase.SetViewPropertiesFromModel <IPaperView, IPaperModel>( ref view, model ); string sPath = string.Empty; if (model.Paper.Count > 0) { //create CSV file in My Documents folder sPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\PaperDocExport.csv"; CsvConfiguration config = new CsvConfiguration() { HasHeaderRecord = true, Delimiter = ",", Encoding = System.Text.Encoding.UTF8 }; config.RegisterClassMap(new PaperHeaderMap()); int total = model.Paper.Count; using (CsvWriter writer = new CsvWriter(new StreamWriter(sPath), config)) { writer.WriteHeader <PaperHeaderRecord>(); int count = 0; foreach (var item in model.Paper) { writer.WriteField <string>(item.PaperName); writer.WriteField <string>(item.PaperId); writer.WriteField <string>(item.FolderPath); writer.WriteField <string>(item.Status); writer.WriteField <string>(item.Owner); writer.WriteField <string>(item.CreatedDate.ToString()); writer.WriteField <string>(item.LastUpdatedDate.ToString()); writer.WriteField <string>(item.LastEditor); writer.WriteField <string>(item.Revision.ToString()); count++; if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (count), total)); }, null); } writer.NextRecord(); } } if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo("Completed. Exported file located at " + sPath); }, null); } } if (model.Paper.Count == 0) { presenter.UpdateProgressInfo("No Paper docs were chosen to export."); } presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); exportpapertocsv.Start(); }
private void OnCommandGetPaper(object sender, System.EventArgs e) { IPaperView view = base._view as IPaperView; IPaperModel model = base._model as IPaperModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread getpaperdocs = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { // clear existing data first model.Paper.Clear(); //get members first IList <TeamListViewItemModel> members = SearchOwners(model, presenter); //get Paper Ids Parallel.ForEach(members, (member) => { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Retrieving member's Paper docs: {0}", member.Email)); }, null); } IList <PaperListViewItemModel> docIds = new List <PaperListViewItemModel>(); docIds = this.GetPaperDocs(model, presenter, member); //get metadata from ids foreach (PaperListViewItemModel item in docIds) { this.GetPaperMetadata(model, presenter, item.PaperId, item.MemberId); } }); if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Sorting Paper docs...")); }, null); } // sort by email then by folder path model.Paper = model.Paper.OrderBy(s => s.Owner).ThenBy(s => s.LastUpdatedDate).ToList(); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <IPaperView, IPaperModel>( ref view, model ); // update result and update view. view.RenderPaperList(); presenter.ActivateSpinner(false); presenter.EnableControl(true); presenter.UpdateProgressInfo("Paper doc list completed. Total Docs [" + model.Paper.Count.ToString() + "]"); }, null); } } }); getpaperdocs.Start(); }
private string DeletePaperDocs(IPaperModel model, IPaperView view, IMainPresenter presenter) { string errorMessage = string.Empty; string fileAccessToken = ApplicationResource.DefaultAccessToken; IMemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.ArchivePaperDocUrl = ApplicationResource.ActionArchivePaperDocs; service.UserAgentVersion = ApplicationResource.UserAgent; IServiceResponse response = null; IMemberServices servicePerm = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); servicePerm.PermDeletePaperDocUrl = ApplicationResource.ActionPermanentlyDeletePaperDocs; servicePerm.UserAgentVersion = ApplicationResource.UserAgent; IServiceResponse responsePerm = null; try { foreach (PaperListViewItemModel item in model.Paper) { if (view.ArchiveSetting && item.IsChecked) { response = service.ArchivePaperDoc(item.MemberId, fileAccessToken, item.PaperId); if (response.StatusCode == HttpStatusCode.OK) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Archived Paper doc [" + item.PaperName + "]")); }, null); } } else { errorMessage = ErrorMessages.FAILED_TO_DELETE_PAPER; } } if (view.PermanentSetting && item.IsChecked) { responsePerm = servicePerm.PermDeletePaperDoc(item.MemberId, fileAccessToken, item.PaperId); if (responsePerm.StatusCode == HttpStatusCode.OK) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Permanently deleted Paper doc [" + item.PaperName + "]")); }, null); } } else { errorMessage = ErrorMessages.FAILED_TO_DELETE_PAPER; } } } } catch (Exception) { // error message. SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.FAILED_TO_DELETE_PAPER, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } return(errorMessage); }
private void OnCommandExportContentExcel(object sender, EventArgs e) { // Export to Excel IDataMigrationView view = base._view as IDataMigrationView; IDataMigrationModel model = base._model as IDataMigrationModel; PresenterBase.SetModelPropertiesFromView <IDataMigrationModel, IDataMigrationView>( ref model, view ); IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); try { if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Preparing Report..."); }, null); } FileInfo fileInfo = new FileInfo(model.OutputFileName); if (Directory.Exists(fileInfo.DirectoryName)) { Thread writeReportExcel = new Thread(() => { int total = model.Contents.Count; //set max rows per sheet to 1 million. Actual number Excel pukes on is anything over 1,048,576 int maxRowsPerSheet = 1000000; int sheetCount = 1; int modelStartRow = 0; int modelEndRow = 1; int totalRowsLeft = 0; bool complete = false; //get inital rows left totalRowsLeft = model.Contents.Count - maxRowsPerSheet; //round up for number of sheets based on rowcount int totalSheets = Convert.ToInt32(Math.Ceiling((double)total / (double)maxRowsPerSheet)); Excel.Application xlApp = new Excel.Application(); xlApp.DisplayAlerts = false; //Give error if Excel not installed on system if (xlApp == null) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(ErrorMessages.EXCEL_MISSING); }, null); return; } Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet = null; object misValue = Missing.Value; xlWorkBook = xlApp.Workbooks.Add(misValue); //need code to add extra worksheets, based on how many rows we have above Excel.Sheets worksheets = xlWorkBook.Worksheets; while (!complete) { while (sheetCount <= totalSheets) { var xlNewSheet = (Excel.Worksheet)worksheets.Add(worksheets[sheetCount], Type.Missing, Type.Missing, Type.Missing); xlNewSheet.Name = sheetCount.ToString(); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(sheetCount); //write headers xlWorkSheet.Cells[1, 1] = "Owner Name"; xlWorkSheet.Cells[1, 2] = "Owner Login"; xlWorkSheet.Cells[1, 3] = "Path"; xlWorkSheet.Cells[1, 4] = "Path ID"; xlWorkSheet.Cells[1, 5] = "Item Name"; xlWorkSheet.Cells[1, 6] = "Item ID"; xlWorkSheet.Cells[1, 7] = "Item Type"; xlWorkSheet.Cells[1, 8] = "Size"; xlWorkSheet.Cells[1, 9] = "Created"; xlWorkSheet.Cells[1, 10] = "Last Modified"; xlWorkSheet.Cells[1, 11] = "Uploaded"; int endRow = 0; //over 1 million rows, setting values for output to Excel sheets if (totalRowsLeft > 0 && totalRowsLeft > maxRowsPerSheet) { endRow = endRow + maxRowsPerSheet; } if (totalRowsLeft > 0 && totalRowsLeft < maxRowsPerSheet) { endRow = endRow + totalRowsLeft; } modelEndRow = modelEndRow + endRow; if (modelEndRow < model.Contents.Count) { modelEndRow--; } if (modelEndRow > model.Contents.Count) { modelEndRow = model.Contents.Count; } //we only need one sheet if (totalRowsLeft < 0) { modelEndRow = model.Contents.Count; } //start at 1 for each sheet so we can increment past header row int rowCount = 1; for (int i2 = modelStartRow; i2 < modelEndRow; i2++) { ContentDisplayListViewItemModel lvItem = model.Contents[i2]; rowCount++; endRow++; xlWorkSheet.Cells[rowCount, 1] = (!string.IsNullOrEmpty(lvItem.OwnerName) ? lvItem.OwnerName : ""); xlWorkSheet.Cells[rowCount, 2] = (lvItem.Email); xlWorkSheet.Cells[rowCount, 3] = (lvItem.ItemPathDisplay); xlWorkSheet.Cells[rowCount, 4] = (!string.IsNullOrEmpty(lvItem.ItemPathId) ? lvItem.ItemPathId : ""); xlWorkSheet.Cells[rowCount, 5] = (lvItem.ItemName); xlWorkSheet.Cells[rowCount, 6] = (!string.IsNullOrEmpty(lvItem.ItemId) ? lvItem.ItemId : ""); xlWorkSheet.Cells[rowCount, 7] = (lvItem.ItemType); xlWorkSheet.Cells[rowCount, 8] = (!string.IsNullOrEmpty(lvItem.ItemSize) ? lvItem.ItemSize : ""); xlWorkSheet.Cells[rowCount, 9] = (!string.IsNullOrEmpty(lvItem.Created) ? lvItem.Created : ""); xlWorkSheet.Cells[rowCount, 10] = (!string.IsNullOrEmpty(lvItem.LastModified) ? lvItem.LastModified : ""); xlWorkSheet.Cells[rowCount, 11] = (!string.IsNullOrEmpty(lvItem.Uploaded) ? lvItem.Uploaded : ""); if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (i2 + 1), total)); }, null); } } //move one row count to make up for the header row modelEndRow++; modelStartRow = modelEndRow; modelStartRow--; sheetCount++; //are we done? if (modelEndRow >= model.Contents.Count) { complete = true; } } } //delete default sheet and save to output file name specified in UI xlWorkBook.Sheets["Sheet1"].Delete(); xlWorkBook.SaveAs(model.OutputFileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); //release all resources Marshal.ReleaseComObject(xlWorkBook); Marshal.ReleaseComObject(xlApp); Marshal.ReleaseComObject(xlWorkSheet); if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo("Completed"); }, null); } }); writeReportExcel.Start(); } else { throw new InvalidDataException(ErrorMessages.INVALID_EXPORT_FOLDER); } } catch (Exception ex) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo("Completed with exception: " + ex.Message); }, null); } } }
private string UpdateProfile(IProvisioningModel model, IMainPresenter presenter) { string errorMessage = string.Empty; IMemberServices service = service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.SetProfileUrl = ApplicationResource.ActionSetProfile; service.UserAgentVersion = ApplicationResource.UserAgent; try { foreach (MemberListViewItemModel item in model.Members.Where(m => m.IsChecked).ToList()) { IServiceResponse response = service.SetProfile(new MemberData() { Email = item.Email, NewEmail = item.NewEmail, NewExternalId = item.NewExternalId }, model.AccessToken); if (response.StatusCode == HttpStatusCode.OK) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Updated profile for: {0}", item.Email)); }, null); } } else if ((response.Message).Contains("user_not_found")) { errorMessage = ErrorMessages.USER_NOT_FOUND; } else if ((response.Message).Contains("user_not_in_team")) { errorMessage = ErrorMessages.USER_NOT_IN_TEAM; } else { errorMessage = ErrorMessages.FAILED_TO_UPDATE_PROFILE; } } } catch(Exception) { //just catch the exception and return error message SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.FAILED_TO_UPDATE_PROFILE, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } return errorMessage; }
private void OnCommandDisplayContent(object sender, System.EventArgs e) { IDataMigrationView view = base._view as IDataMigrationView; IDataMigrationModel model = base._model as IDataMigrationModel; IList <ContentDisplayListViewItemModel> items = model.Contents; if (items != null) { IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); // lock UI if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Searching..."); }, null); } Thread search = new Thread(() => { TimerUtils util = new TimerUtils(); util.Start(); if (string.IsNullOrEmpty(model.AccessToken)) { presenter.ShowErrorMessage(ErrorMessages.INVALID_TOKEN, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); } else { MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); // search all owners first. IList <TeamListViewItemModel> owners = SearchOwner(model, presenter); model.Contents.Clear(); // clear existing contents Parallel.ForEach(owners, (owner) => { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Retrieving Owner's Content: {0}", owner.Email)); }, null); } SearchItems(service, owner, model, presenter); }); // compute folder size. if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Sorting Data...")); }, null); } // sort by email then by folder path model.Contents = model.Contents.OrderBy(s => s.Email).ThenBy(s => s.ItemPathDisplay).ToList(); ContentDisplayListViewItemModel currentFolderSelected = null; foreach (ContentDisplayListViewItemModel lvItem in model.Contents) { if (lvItem.ItemType.ToLower().Equals("folder")) { if (currentFolderSelected != null) { // had previously selected folder. currentFolderSelected.ItemSize = FileUtil.FormatFileSize(currentFolderSelected.ItemSizeByte); if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Calculating Folder Size: {0}", currentFolderSelected.ItemName)); }, null); } } currentFolderSelected = lvItem; } else if (lvItem.ItemType.ToLower().Equals("file")) { if (currentFolderSelected != null) { currentFolderSelected.ItemSizeByte += lvItem.ItemSizeByte; } } } } if (SyncContext != null) { TimeSpan diff = util.Stop(); SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <IDataMigrationView, IDataMigrationModel>( ref view, model ); view.RenderContentSearchResult(); view.EnableExportControl(true); presenter.UpdateProgressInfo( string.Format("Completed. Total Content Count: {0} Elapsed Time: {1}", model.Contents.Count, TimerUtils.ToTimeStamp(diff)) ); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } }); search.Start(); } }
//need work private void OnCommandExportGroupPerms(object sender, System.EventArgs e) { IGroupsView view = base._view as IGroupsView; IGroupsModel model = base._model as IGroupsModel; IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Processing..."); }, null); } Thread exportgroupperms = new Thread(() => { if (string.IsNullOrEmpty(model.AccessToken)) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo(""); }, null); } else { //need to get groups checked then get shared folders for each this.ExportGroups(model, presenter); this.ExportGroupPerms(model, presenter); if (SyncContext != null) { SyncContext.Post(delegate { // update result and update view. PresenterBase.SetViewPropertiesFromModel <IGroupsView, IGroupsModel>( ref view, model ); string sPath = string.Empty; if (model.GroupPerms.Count > 0) { //create CSV file in My Documents folder sPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GroupPermsExport.csv"; CsvConfiguration config = new CsvConfiguration() { HasHeaderRecord = true, Delimiter = ",", Encoding = System.Text.Encoding.UTF8 }; config.RegisterClassMap(new GroupPermsHeaderMap()); int total = model.GroupPerms.Count; using (CsvWriter writer = new CsvWriter(new StreamWriter(sPath), config)) { writer.WriteHeader <GroupPermsHeaderRecord>(); int count = 0; foreach (var item in model.GroupPerms) { writer.WriteField <string>(item.GroupName); writer.WriteField <string>(item.GroupId); writer.WriteField <string>(item.GroupManagementType); writer.WriteField <string>(item.GroupType); writer.WriteField <string>(item.SharedFolderName); writer.WriteField <string>(item.SharedFolderId); writer.WriteField <string>(item.IsMember); writer.WriteField <string>(item.IsOwner); writer.WriteField <string>(item.AccessType); writer.WriteField <string>(item.IsInherited); writer.WriteField <string>(item.IsTeamFolder); writer.WriteField <string>(item.IsInsideTeamFolder); count++; if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (count), total)); }, null); } writer.NextRecord(); } } if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo("Completed. Exported file located at " + sPath); }, null); } } if (model.GroupPerms.Count == 0) { presenter.UpdateProgressInfo("No groups were selected to export."); } presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } } }); exportgroupperms.Start(); }
public bool LoadInputFile(IProvisioningModel model, IMainPresenter presenter) { bool loaded = true; try { FileInfo fInfo = new FileInfo(model.InputFilePath); if (fInfo.Exists) { // try load. model.Members.Clear(); CsvConfiguration config = new CsvConfiguration() { HasHeaderRecord = false }; using (CsvReader reader = new CsvReader(new StreamReader(fInfo.FullName), config)) { while (reader.Read()) { try { MemberListViewItemModel lvItem = new MemberListViewItemModel() { Email = reader.GetField<string>(0), FirstName = reader.GetField<string>(1), LastName = reader.GetField<string>(2), IsChecked = true }; model.Members.Add(lvItem); } catch { throw new InvalidDataException(ErrorMessages.INVALID_CSV_DATA); } } if (model.Members.Any()) { loaded = true; } } } else { throw new InvalidDataException(ErrorMessages.MISSING_CSV_FILE); } } catch (Exception e) { // error message. SyncContext.Post(delegate { presenter.ShowErrorMessage(e.Message, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } return loaded; }
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); model.MemberList.Clear(); 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 GetPaperMetadata(IPaperModel model, IMainPresenter presenter, string docId, string memberId) { IMemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.GetPaperMetadataUrl = ApplicationResource.ActionGetPaperDocMetadata; service.UserAgentVersion = ApplicationResource.UserAgent; string paperAccessToken = ApplicationResource.DefaultAccessToken; IMemberServices serviceFolderInfo = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); serviceFolderInfo.PaperDocFolderInfoUrl = ApplicationResource.ActionPaperDocFolderInfo; serviceFolderInfo.UserAgentVersion = ApplicationResource.UserAgent; string folderPath = @"/"; try { if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Retrieving Paper doc metadata for id: {0}", docId)); }, null); } //get paper doc folder info to add to listview object IDataResponse responseFolderInfo = serviceFolderInfo.GetPaperDocFolderInfo(docId, paperAccessToken, memberId); if (responseFolderInfo.StatusCode == HttpStatusCode.OK) { if (responseFolderInfo.Data != null) { string data = responseFolderInfo.Data.ToString(); dynamic jsonData = JsonConvert.DeserializeObject <dynamic>(data); int resultCount = 0; if (data != "{}") { resultCount = jsonData["folders"].Count; for (int i = 0; i < resultCount; i++) { dynamic folders = jsonData["folders"][i]; dynamic folderPathobj = folders["name"]; string folderPathNext = folderPathobj.Value as string; folderPath = folderPath + folderPathNext + "/"; } } } } //now get remainder of metadata IDataResponse response = service.GetPaperMetadata(docId, paperAccessToken, memberId); if (response.StatusCode == HttpStatusCode.OK) { if (response.Data != null) { string data = response.Data.ToString(); dynamic jsonData = JsonConvert.DeserializeObject <dynamic>(data); dynamic paperDocIdobj = jsonData["doc_id"]; dynamic ownerobj = jsonData["owner"]; dynamic paperNameobj = jsonData["title"]; dynamic createdDateobj = jsonData["created_date"]; dynamic statusobj = jsonData["status"][".tag"]; dynamic revisionobj = jsonData["revision"]; dynamic lastUpdatedDateobj = jsonData["last_updated_date"]; dynamic lastEditorobj = jsonData["last_editor"]; string paperDocId = paperDocIdobj.Value as string; string owner = ownerobj.Value as string; string paperName = paperNameobj.Value as string; DateTime createdDate = DateTime.MinValue; if (createdDateobj != null) { createdDate = createdDateobj; } string status = statusobj.Value as string; UInt64 revision = 0; if (revisionobj != null) { revision = revisionobj; } DateTime lastUpdatedDate = DateTime.MinValue; if (lastUpdatedDateobj != null) { lastUpdatedDate = lastUpdatedDateobj; } string lastEditor = lastEditorobj.Value as string; // update model PaperListViewItemModel lvItem = new PaperListViewItemModel() { PaperId = paperDocId, Owner = owner, PaperName = paperName, FolderPath = folderPath, CreatedDate = createdDate, Status = status, Revision = revision, LastUpdatedDate = lastUpdatedDate, LastEditor = lastEditor, MemberId = memberId, IsChecked = true }; model.Paper.Add(lvItem); } } } catch (Exception) { // error message. SyncContext.Post(delegate { presenter.ShowErrorMessage(ErrorMessages.FAILED_TO_GET_PAPER_METADATA, ErrorMessages.DLG_DEFAULT_TITLE); presenter.UpdateProgressInfo(""); presenter.ActivateSpinner(false); presenter.EnableControl(true); }, null); } }
private void OnCommandExportContent(object sender, EventArgs e) { // Export to CSV IDataMigrationView view = base._view as IDataMigrationView; IDataMigrationModel model = base._model as IDataMigrationModel; PresenterBase.SetModelPropertiesFromView <IDataMigrationModel, IDataMigrationView>( ref model, view ); IMainPresenter presenter = SimpleResolver.Instance.Get <IMainPresenter>(); try { if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(false); presenter.ActivateSpinner(true); presenter.UpdateProgressInfo("Preparing Report..."); }, null); } FileInfo fileInfo = new FileInfo(model.OutputFileName); if (Directory.Exists(fileInfo.DirectoryName)) { Thread writeReport = new Thread(() => { CsvConfiguration config = new CsvConfiguration() { HasHeaderRecord = true, Delimiter = ",", Encoding = System.Text.Encoding.UTF8 }; config.RegisterClassMap(new DataMigrationHeaderMap()); int total = model.Contents.Count; using (CsvWriter writer = new CsvWriter(new StreamWriter(model.OutputFileName), config)) { writer.WriteHeader <DataMigrationHeaderRecord>(); for (int i = 0; i < model.Contents.Count; i++) { ContentDisplayListViewItemModel lvItem = model.Contents[i]; writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.OwnerName) ? lvItem.OwnerName : ""); writer.WriteField <string>(lvItem.Email); writer.WriteField <string>(lvItem.ItemPathDisplay); writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.ItemPathId) ? lvItem.ItemPathId : ""); writer.WriteField <string>(lvItem.ItemName); writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.ItemId) ? lvItem.ItemId : ""); writer.WriteField <string>(lvItem.ItemType); writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.ItemSize) ? lvItem.ItemSize : ""); writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.Created) ? lvItem.Created : ""); writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.LastModified) ? lvItem.LastModified : ""); writer.WriteField <string>(!string.IsNullOrEmpty(lvItem.Uploaded) ? lvItem.Uploaded : ""); writer.NextRecord(); if (SyncContext != null) { SyncContext.Post(delegate { presenter.UpdateProgressInfo(string.Format("Writing Record: {0}/{1}", (i + 1), total)); }, null); } } } if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo("Completed"); }, null); } }); writeReport.Start(); } else { throw new InvalidDataException(ErrorMessages.INVALID_EXPORT_FOLDER); } } catch (Exception ex) { if (SyncContext != null) { SyncContext.Post(delegate { presenter.EnableControl(true); presenter.ActivateSpinner(false); presenter.UpdateProgressInfo("Completed with exception: " + ex.Message); }, null); } } }