private void OnRecvWorker() { var polling = new Polling(PollingEvents.RecvReady, this._socket); polling.RecvReady += socket => { var topic = _socket.RecvString(); var messageInBytes = _socket.Recv(); var message = _deserializer(messageInBytes); this.OnReceived(topic, message); }; try { while (_started) { polling.Poll(1000); } } catch (ZmqException e) { if (LogAdapter.LogEnabled) { LogAdapter.LogDebug(this.GetType().FullName, "BaseSubscriber exception. Disposing. Details: " + e.ToString()); } this.Dispose(); } }
/// <summary> /// Update the serving status of the version. /// </summary> /// <param name="status">The serving status to update the version to.</param> /// <param name="statusMessage">The message to display while updating the status</param> private async void UpdateServingStatus(string status, string statusMessage) { IsLoading = true; Children.Clear(); UpdateMenu(); Caption = statusMessage; GaeDataSource datasource = root.DataSource.Value; try { Task <Operation> operationTask = datasource.UpdateVersionServingStatus(status, _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); } version = await datasource.GetVersionAsync(_owner.Service.Id, version.Id); EventsReporterWrapper.ReportEvent( GaeVersionServingStatusUpdatedEvent.Create(CommandStatus.Success, statusMessage)); } catch (Exception ex) when(ex is DataSourceException || ex is TimeoutException || ex is OperationCanceledException) { EventsReporterWrapper.ReportEvent( GaeVersionServingStatusUpdatedEvent.Create(CommandStatus.Failure, statusMessage)); IsError = true; if (ex is DataSourceException) { Caption = Resources.CloudExplorerGaeUpdateServingStatusErrorMessage; } 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) { Initialize(); } else { Caption = GetCaption(); } } }
/// <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(); } }
/// <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); } } }
private Tuple <T, bool> SendReqAndWaitReply(IZmqSocket socket) { SendRequest(socket); var polling = new Polling(PollingEvents.RecvReady, socket); if (polling.Poll(this.Timeout)) { var data = socket.Recv(); var ret = GetReply(data, socket, false); return(Tuple.Create(ret, false)); } else { // timeout var ret = GetReply(null, socket, true); return(Tuple.Create(ret, true)); } }
/// <summary> /// Opens the a dialog to manage authorized networks for the instance. This will allow /// the user to add and remove authorized networks and then save the changes they have made. /// </summary> private async void OnManageAuthorizedNetworks() { // Get the changes to the networks and check if any changes have occured (or the results is // null if the user canceled the dialog). AuthorizedNetworkChange networkChange = AuthorizedNetworksWindow.PromptUser(Instance); if (networkChange == null || !networkChange.HasChanges) { return; } IList <AclEntry> updatedNetworks = networkChange.AuthorizedNetworks; DatabaseInstanceExtensions.UpdateAuthorizedNetworks(Instance, updatedNetworks); // Update the user display and menu. IsLoading = true; UpdateMenu(); Caption = Resources.CloudExplorerSqlUpdatedAthorizedNetworksCaption; CloudSqlDataSource dataSource = _owner.DataSource.Value; try { // Poll until the update to completes. Task <Operation> operation = _owner.DataSource.Value.UpdateInstanceAsync(Instance); Func <Operation, Task <Operation> > fetch = (o) => dataSource.GetOperationAsync(o.Name); Predicate <Operation> stopPolling = (o) => CloudSqlDataSource.OperationStateDone.Equals(o.Status); await Polling <Operation> .Poll(await operation, fetch, stopPolling); EventsReporterWrapper.ReportEvent(ManageCloudSqlAuthorizedNetworkEvent.Create(CommandStatus.Success)); } catch (DataSourceException ex) { IsError = true; UserPromptUtils.ErrorPrompt(ex.Message, Resources.CloudExplorerSqlUpdateAthorizedNetworksErrorMessage); EventsReporterWrapper.ReportEvent(ManageCloudSqlAuthorizedNetworkEvent.Create(CommandStatus.Failure)); } catch (TimeoutException ex) { IsError = true; UserPromptUtils.ErrorPrompt( Resources.CloudExploreOperationTimeoutMessage, Resources.CloudExplorerSqlUpdateAthorizedNetworksErrorMessage); EventsReporterWrapper.ReportEvent(ManageCloudSqlAuthorizedNetworkEvent.Create(CommandStatus.Failure)); } catch (OperationCanceledException ex) { IsError = true; UserPromptUtils.ErrorPrompt( Resources.CloudExploreOperationCanceledMessage, Resources.CloudExplorerSqlUpdateAthorizedNetworksErrorMessage); EventsReporterWrapper.ReportEvent(ManageCloudSqlAuthorizedNetworkEvent.Create(CommandStatus.Failure)); } finally { // Update the user display and menu. IsLoading = false; UpdateMenu(); Caption = Instance.Name; } // Be sure to update the instance when finished to ensure we have // the most up to date version. Instance = await dataSource.GetInstanceAsync(Instance.Name); }