private async Task RefreshProjectData(ProteinUpdateType type) { var result = _messageBoxView.AskYesNoQuestion(_view, "Are you sure? This operation cannot be undone.", Core.Application.NameAndVersion); if (result == DialogResult.No) { return; } long updateArg = 0; if (type == ProteinUpdateType.Project) { updateArg = _model.SelectedHistoryEntry.ProjectID; } else if (type == ProteinUpdateType.Id) { updateArg = _model.SelectedHistoryEntry.ID; } try { bool updated = await _database.UpdateProteinDataAsync(type, updateArg).ConfigureAwait(false); if (updated) { _model.ResetBindings(true); } } catch (Exception ex) { Logger.Error(ex.Message, ex); _messageBoxView.ShowError(_view, ex.Message, Core.Application.NameAndVersion); } }
public async Task <bool> UpdateProteinDataAsync(ProteinUpdateType type, long updateArg) { using (var connection = new SQLiteConnection(ConnectionString)) { connection.Open(); using (var transaction = connection.BeginTransaction()) { try { // update the WuHistory table with protein info var proteinDataUpdater = new ProteinDataUpdaterWithCancellation(connection, _proteinService); proteinDataUpdater.UpdateType = type; proteinDataUpdater.UpdateArg = updateArg; await proteinDataUpdater.ExecuteAsyncWithProgress(true, this).ConfigureAwait(false); if (proteinDataUpdater.IsCanceled) { transaction.Rollback(); return(false); } transaction.Commit(); return(true); } catch (Exception) { transaction.Rollback(); throw; } } } }
public Task UpdateProteinDataAsync(ProteinUpdateType type, long updateArg, CancellationToken cancellationToken, IProgress <ProgressChangedEventArgs> progress) { // update the WuHistory table with protein info var proteinDataUpdater = new ProteinDataUpdater(this, _proteinService); proteinDataUpdater.UpdateType = type; proteinDataUpdater.UpdateArg = updateArg; return(proteinDataUpdater.ExecuteAsync(cancellationToken, progress)); }
public void RefreshProjectDataClick(ProteinUpdateType type) { var result = _messageBoxView.AskYesNoQuestion(_view, "Are you sure? This operation cannot be undone.", Core.Application.NameAndVersion); if (result == DialogResult.No) { return; } var progress = new TaskSchedulerProgress <harlam357.Core.ComponentModel.ProgressChangedEventArgs>(); var cancellationTokenSource = new CancellationTokenSource(); var projectDownloadView = _viewFactory.GetProgressDialogAsync(); projectDownloadView.Icon = Properties.Resources.hfm_48_48; projectDownloadView.Text = "Updating Project Data"; projectDownloadView.CancellationTokenSource = cancellationTokenSource; projectDownloadView.Progress = progress; projectDownloadView.Shown += (s, args) => { var uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); long updateArg = 0; if (type == ProteinUpdateType.Project) { updateArg = _model.SelectedHistoryEntry.ProjectID; } else if (type == ProteinUpdateType.Id) { updateArg = _model.SelectedHistoryEntry.ID; } _database.UpdateProteinDataAsync(type, updateArg, cancellationTokenSource.Token, progress) .ContinueWith(t => { if (t.IsFaulted) { var ex = t.Exception.Flatten().InnerException; Logger.Error(ex.Message, ex); _messageBoxView.ShowError(_view, ex.Message, Core.Application.NameAndVersion); } else { _model.ResetBindings(true); } projectDownloadView.Close(); }, uiTaskScheduler); }; projectDownloadView.ShowDialog(_view); _viewFactory.Release(projectDownloadView); }
public void RefreshProjectDataClick(ProteinUpdateType type) { var result = _messageBoxView.AskYesNoQuestion(_view, "Are you sure? This operation cannot be undone.", Core.Application.NameAndVersion); if (result.Equals(DialogResult.No)) { return; } var processor = ServiceLocator.Resolve<ProteinDataUpdater>(); processor.UpdateType = type; if (type.Equals(ProteinUpdateType.Project)) { processor.UpdateArg = _model.SelectedHistoryEntry.ProjectID; } else if (type.Equals(ProteinUpdateType.Id)) { processor.UpdateArg = _model.SelectedHistoryEntry.ID; } // Execute Asynchronous Operation var view = ServiceLocator.Resolve<IProgressDialogView>("ProgressDialog"); view.ProcessRunner = processor; view.Icon = Properties.Resources.hfm_48_48; view.Text = "Updating Project Data"; view.OwnerWindow = _view; view.Process(); var runner = view.ProcessRunner; if (runner.Exception != null) { _logger.Error(runner.Exception.Message, runner.Exception); _messageBoxView.ShowError(_view, runner.Exception.Message, Core.Application.NameAndVersion); } else { RefreshClicked(); } }
public Task UpdateProteinDataAsync(ProteinUpdateType type, long updateArg, CancellationToken cancellationToken, IProgress<ProgressChangedEventArgs> progress) { // update the WuHistory table with protein info var proteinDataUpdater = new ProteinDataUpdater(this, _proteinService); proteinDataUpdater.UpdateType = type; proteinDataUpdater.UpdateArg = updateArg; return proteinDataUpdater.ExecuteAsync(cancellationToken, progress); }
public void RefreshProjectDataClick(ProteinUpdateType type) { var result = _messageBoxView.AskYesNoQuestion(_view, "Are you sure? This operation cannot be undone.", Core.Application.NameAndVersion); if (result == DialogResult.No) { return; } var progress = new TaskSchedulerProgress<harlam357.Core.ComponentModel.ProgressChangedEventArgs>(); var cancellationTokenSource = new CancellationTokenSource(); var projectDownloadView = _viewFactory.GetProgressDialogAsync(); projectDownloadView.Icon = Properties.Resources.hfm_48_48; projectDownloadView.Text = "Updating Project Data"; projectDownloadView.CancellationTokenSource = cancellationTokenSource; projectDownloadView.Progress = progress; projectDownloadView.Shown += (s, args) => { var uiTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); long updateArg = 0; if (type == ProteinUpdateType.Project) { updateArg = _model.SelectedHistoryEntry.ProjectID; } else if (type == ProteinUpdateType.Id) { updateArg = _model.SelectedHistoryEntry.ID; } _database.UpdateProteinDataAsync(type, updateArg, cancellationTokenSource.Token, progress) .ContinueWith(t => { if (t.IsFaulted) { var ex = t.Exception.Flatten().InnerException; Logger.Error(ex.Message, ex); _messageBoxView.ShowError(_view, ex.Message, Core.Application.NameAndVersion); } else { _model.ResetBindings(true); } projectDownloadView.Close(); }, uiTaskScheduler); }; projectDownloadView.ShowDialog(_view); _viewFactory.Release(projectDownloadView); }