private async void DeleteVersion() { IsLoading = true; Children.Clear(); UpdateMenu(); Caption = Resources.CloudExplorerGaeVersionDeleteMessage; GaeDataSource datasource = root.DataSource.Value; try { Task <Operation> operationTask = root.DataSource.Value.DeleteVersionAsync(_owner.Service.Id, version.Id); Func <Operation, Task <Operation> > fetch = (o) => datasource.GetOperationAsync(o.GetOperationId()); Predicate <Operation> stopPolling = (o) => o.Done ?? false; Operation operation = await Polling <Operation> .Poll(await operationTask, fetch, stopPolling); if (operation.Error != null) { throw new DataSourceException(operation.Error.Message); } EventsReporterWrapper.ReportEvent(GaeVersionDeletedEvent.Create(CommandStatus.Success)); } catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException) { EventsReporterWrapper.ReportEvent(GaeVersionDeletedEvent.Create(CommandStatus.Failure)); IsError = true; if (ex is DataSourceException) { Caption = Resources.CloudExplorerGaeDeleteVersionErrorMessage; } else if (ex is TimeoutException) { Caption = Resources.CloudExploreOperationTimeoutMessage; } else if (ex is OperationCanceledException) { Caption = Resources.CloudExploreOperationCanceledMessage; } } finally { IsLoading = false; // Re-initialize the instance as it will have a new version. if (!IsError) { // Remove the deleted child. _owner.Children.Remove(this); } else { Caption = GetCaption(); } } }
private async void DeleteVersion() { IsLoading = true; Children.Clear(); UpdateMenu(); Caption = Resources.CloudExplorerGaeVersionDeleteMessage; GaeDataSource dataSource = _owner.DataSource; try { var operation = await dataSource.DeleteVersionAsync(_service.Id, _version.Id); await dataSource.AwaitOperationAsync(operation); _owner.InvalidateService(_service.Id); EventsReporterWrapper.ReportEvent(GaeVersionDeletedEvent.Create(CommandStatus.Success)); } catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException) { EventsReporterWrapper.ReportEvent(GaeVersionDeletedEvent.Create(CommandStatus.Failure)); IsLoading = false; IsError = true; if (ex is DataSourceException) { Caption = Resources.CloudExplorerGaeDeleteVersionErrorMessage; } else if (ex is TimeoutException) { Caption = Resources.CloudExploreOperationTimeoutMessage; } else if (ex is OperationCanceledException) { Caption = Resources.CloudExploreOperationCanceledMessage; } } }
private async Task DeleteVersionAsync() { IsLoading = true; Children.Clear(); UpdateMenu(); Caption = Resources.CloudExplorerGaeVersionDeleteMessage; IGaeDataSource dataSource = _owner.DataSource; try { await dataSource.DeleteVersionAsync(_service.Id, Version.Id); await _owner.InvalidateServiceAsync(_service.Id); EventsReporterWrapper.ReportEvent(GaeVersionDeletedEvent.Create(CommandStatus.Success)); } catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException) { EventsReporterWrapper.ReportEvent(GaeVersionDeletedEvent.Create(CommandStatus.Failure)); IsLoading = false; IsError = true; switch (ex) { case DataSourceException _: Caption = Resources.CloudExplorerGaeDeleteVersionErrorMessage; break; case TimeoutException _: Caption = Resources.CloudExploreOperationTimeoutMessage; break; case OperationCanceledException _: Caption = Resources.CloudExploreOperationCanceledMessage; break; } } }