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 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(); }