public async Task NotifyObserversAsync(GatewayRequest request) { try { // Validates parameter if (string.IsNullOrWhiteSpace(request?.Topic) || (request.Messages == null) || !request.Messages.Any() || (request.ObservableEntityId?.ServiceUri == null)) { throw new ArgumentException($"Parameter {nameof(request)} is null or invalid.", nameof(request)); } // Gets service proxy IClientObservableService proxy = GetServiceProxy( request.ObservableEntityId.PartitionKey, request.ObservableEntityId.ServiceUri); if (proxy == null) { throw new ApplicationException("The ServiceProxy cannot be null."); } // Invokes actor using proxy foreach (Message message in request.Messages.Where(message => message != null)) { ServiceEventSource.Current.Message( $"Notifying observers...\r\n[Observable]: {request.ObservableEntityId}\r\n[Message]: Topic=[{request.Topic}] Body=[{message.Body ?? "NULL"}]"); await proxy.NotifyObserversAsync(request.Topic, message, request.UseObserverAsProxy); } } catch (AggregateException ex) { if (!(ex.InnerExceptions?.Count > 0)) { throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } foreach (Exception exception in ex.InnerExceptions) { ServiceEventSource.Current.Message(exception.Message); } throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } catch (Exception ex) { ServiceEventSource.Current.Message(ex.Message); throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } }
public async Task RegisterObservableServiceAsync(GatewayRequest request) { try { // Validates parameter if (string.IsNullOrWhiteSpace(request?.Topic) || (request.ObservableEntityId?.ServiceUri == null)) { throw new ArgumentException($"Parameter {nameof(request)} is null or invalid.", nameof(request)); } // Gets service proxy IClientObservableService proxy = GetServiceProxy( request.ObservableEntityId.PartitionKey, request.ObservableEntityId.ServiceUri); if (proxy == null) { throw new ApplicationException("The ServiceProxy cannot be null."); } // Invokes actor using proxy ServiceEventSource.Current.Message( $"Registering observable...\r\n[Observable]: {request.ObservableEntityId}\r\n[Publication]: Topic=[{request.Topic}]"); await proxy.RegisterObservableServiceAsync(request.Topic); } catch (AggregateException ex) { if (!(ex.InnerExceptions?.Count > 0)) { throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } foreach (Exception exception in ex.InnerExceptions) { ServiceEventSource.Current.Message(exception.Message); } throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } catch (Exception ex) { ServiceEventSource.Current.Message(ex.Message); throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } }
public async Task ClearObserversAndPublicationsAsync(GatewayRequest request) { try { // Validates parameter if (request.ObservableEntityId?.ServiceUri == null) { throw new ArgumentException($"Parameter {nameof(request)} is null or invalid.", nameof(request)); } // Gets service proxy IClientObservableService proxy = GetServiceProxy( request.ObservableEntityId.PartitionKey, request.ObservableEntityId.ServiceUri); if (proxy == null) { throw new ApplicationException("The ServiceProxy cannot be null."); } // Invokes actor using proxy ServiceEventSource.Current.Message($"Clearing observers and publications...\r\n[Observable]: {request.ObservableEntityId}"); await proxy.ClearObserversAndPublicationsAsync(request.UseObserverAsProxy); } catch (AggregateException ex) { if (!(ex.InnerExceptions?.Count > 0)) { throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } foreach (Exception exception in ex.InnerExceptions) { ServiceEventSource.Current.Message(exception.Message); } throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } catch (Exception ex) { ServiceEventSource.Current.Message(ex.Message); throw new HttpResponseException(this.Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); } }