Exemplo n.º 1
0
        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 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 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();
        }
 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 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 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;
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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 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 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();
            }
        }