/// <summary>
        /// Update a service's traffic split.
        /// </summary>
        private async void UpdateTrafficSplit(TrafficSplit split)
        {
            IsLoading = true;
            Children.Clear();
            UpdateContextMenu();
            Caption = Resources.CloudExplorerGaeUpdateTrafficSplitMessage;
            GaeDataSource datasource = root.DataSource.Value;

            try
            {
                Task <Operation> operationTask            = root.DataSource.Value.UpdateServiceTrafficSplit(split, 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);
                }
                Service = await datasource.GetServiceAsync(Service.Id);

                Caption = Service.Id;

                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Success));
            }
            catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException)
            {
                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Failure));
                IsError = true;

                if (ex is DataSourceException)
                {
                    Caption = Resources.CloudExplorerGaeUpdateTrafficSplitErrorMessage;
                }
                else if (ex is TimeoutException)
                {
                    Caption = Resources.CloudExploreOperationTimeoutMessage;
                }
                else if (ex is OperationCanceledException)
                {
                    Caption = Resources.CloudExploreOperationCanceledMessage;
                }
            }
            finally
            {
                IsLoading = false;
                PresentViewModels();
                Icon = s_serviceIcon.Value;
                UpdateContextMenu();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Update a service's traffic split.
        /// </summary>
        private async void UpdateTrafficSplit(TrafficSplit split)
        {
            IsLoading = true;
            Children.Clear();
            UpdateContextMenu();
            Caption = Resources.CloudExplorerGaeUpdateTrafficSplitMessage;
            GaeDataSource datasource = _owner.DataSource;

            try
            {
                var operation = await _owner.DataSource.UpdateServiceTrafficSplitAsync(split, Service.Id);

                await _owner.DataSource.AwaitOperationAsync(operation);

                _owner.InvalidateService(_service.Id);

                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Success));
            }
            catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException)
            {
                EventsReporterWrapper.ReportEvent(GaeTrafficSplitUpdatedEvent.Create(CommandStatus.Failure));
                IsError = true;

                if (ex is DataSourceException)
                {
                    Caption = Resources.CloudExplorerGaeUpdateTrafficSplitErrorMessage;
                }
                else if (ex is TimeoutException)
                {
                    Caption = Resources.CloudExploreOperationTimeoutMessage;
                }
                else if (ex is OperationCanceledException)
                {
                    Caption = Resources.CloudExploreOperationCanceledMessage;
                }
            }
            finally
            {
                IsLoading = false;
                PresentViewModels();
                Icon = s_serviceIcon.Value;
                UpdateContextMenu();
            }
        }