/// <summary> /// Deletes 'this' service. /// </summary> private async void DeleteService() { IsLoading = true; Children.Clear(); UpdateContextMenu(); Caption = String.Format(Resources.CloudExplorerGaeServiceDeleteMessage, Service.Id); GaeDataSource datasource = root.DataSource.Value; try { Task <Operation> operationTask = root.DataSource.Value.DeleteServiceAsync(Service.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(GaeServiceDeletedEvent.Create(CommandStatus.Success)); } catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException) { EventsReporterWrapper.ReportEvent(GaeServiceDeletedEvent.Create(CommandStatus.Failure)); IsError = true; if (ex is DataSourceException) { Caption = Resources.CloudExplorerGaeDeleteServiceErrorMessage; } else if (ex is TimeoutException) { Caption = Resources.CloudExploreOperationTimeoutMessage; } else if (ex is OperationCanceledException) { Caption = Resources.CloudExploreOperationCanceledMessage; } } finally { IsLoading = false; if (!IsError) { // Remove the deleted child. _owner.Children.Remove(this); } } }
/// <summary> /// Deletes 'this' service. /// </summary> private async void DeleteService() { IsLoading = true; Children.Clear(); UpdateContextMenu(); Caption = String.Format(Resources.CloudExplorerGaeServiceDeleteMessage, Service.Id); GaeDataSource datasource = _owner.DataSource; try { var operation = await datasource.DeleteServiceAsync(Service.Id); await datasource.AwaitOperationAsync(operation); EventsReporterWrapper.ReportEvent(GaeServiceDeletedEvent.Create(CommandStatus.Success)); } catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException) { EventsReporterWrapper.ReportEvent(GaeServiceDeletedEvent.Create(CommandStatus.Failure)); IsError = true; if (ex is DataSourceException) { Caption = Resources.CloudExplorerGaeDeleteServiceErrorMessage; } else if (ex is TimeoutException) { Caption = Resources.CloudExploreOperationTimeoutMessage; } else if (ex is OperationCanceledException) { Caption = Resources.CloudExploreOperationCanceledMessage; } } finally { IsLoading = false; if (!IsError) { // Remove the deleted child. _owner.Children.Remove(this); } } }