public void Awake()
        {
            m_Dispatcher = DispatcherFactory.GetDispatcher();

            m_ApplicationContextTarget = ApplicationContext.BindTarget(m_UIApplicationState);
            m_DebugContextTarget       = DebugOptionContext.BindTarget(m_UIDebugState);

            DispatchToken = m_Dispatcher.Register <Payload <IViewerAction> >(InvokeOnDispatch);
        }
Ejemplo n.º 2
0
        private async Task SaveAndSendNotifications(
            Func <string, NotificationMessage> messageFactory,
            IEnumerable <string> targets,
            CancellationToken ct,
            bool force,
            bool save)
        {
            using (var scope = _serviceProvider.CreateScope())
            {
                try
                {
                    var ctx = scope.ServiceProvider.GetRequiredService <AppDbContext>();
                    foreach (var target in targets)
                    {
                        _logger.LogInformation("Sending notifications to {0}", target);

                        var message = messageFactory(target);
                        if (save)
                        {
                            ctx.NotificationMessages.Add(message);
                            await ctx.SaveChangesAsync(ct);
                        }

                        var mediums = await ctx.NotificationConfigurations
                                      .AsNoTracking()
                                      .Where(x => x.UserInformationId == target && (x.Active || force))
                                      .ToListAsync(ct);

                        _logger.LogInformation("Found {0} mediums: {1}", mediums.Count, mediums);
                        foreach (var medium in mediums)
                        {
                            var dispatcher = _dispatcherFactory.GetDispatcher(medium.ConfigurationType);
                            _logger.LogInformation("Dispatching to {0}, destination: {1}",
                                                   medium.ConfigurationType.ToString(),
                                                   medium.NotificationId);
                            try
                            {
                                await dispatcher.SendNotification(message, medium.NotificationId, ct);
                            }
                            catch (Exception e)
                            {
                                _logger.LogError(e, "Failed to dispatch {0} notification.",
                                                 medium.ConfigurationType.ToString());
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Notification process failed.");
                }
            }
        }
Ejemplo n.º 3
0
        public async Task InvokeAsync(HttpContext httpContext, IanvsContext ianvsContext, DispatcherFactory dispatcherFactory, Tracer tracer)
        {
            var egressSpan = tracer.StartSpan("ianvs-egress");

            // TODO: Implement Protocol Translation - e.g. REST to gRPC
            // https://github.com/onyx-ws/ianvs/issues/11

            // Get the dispatcher matching for the backend
            ianvsContext.Dispatcher = dispatcherFactory.GetDispatcher(ianvsContext.MatchedEndpoint.Protocol);
            egressSpan.AddEvent("Preparing Request");
            // Prepare backend request message
            ianvsContext.BackendMessage.Message = ianvsContext.Dispatcher.PrepareRequest(ianvsContext, egressSpan);
            egressSpan.AddEvent("Request prepared");

            Stopwatch backendTimer = new Stopwatch();

            backendTimer.Start();

            egressSpan.AddEvent("Sending backend request");

            _logger.LogInformation($"{Environment.MachineName} {ianvsContext.RequestId} Sending request to backend service {ianvsContext.MatchedOperation.OperationId} {ianvsContext.MatchedOperation.Method} {ianvsContext.MatchedEndpoint.Url} {ianvsContext.TargetServer.Url}");
            Task <object> backendResponse = ianvsContext.Dispatcher.Dispatch(ianvsContext);

            _logger.LogInformation($"{Environment.MachineName} {ianvsContext.RequestId} Waiting for backend service response");
            backendResponse.Wait();
            backendTimer.Stop();
            egressSpan.AddEvent("Backend service response received");

            ianvsContext.BackendResponse = new BackendMessage()
            {
                Message = backendResponse.Result
            };

            ianvsContext.Dispatcher.ProcessResponse(ianvsContext);
            _logger.LogInformation($"{Environment.MachineName} {ianvsContext.RequestId} Backend service response received in {backendTimer.ElapsedMilliseconds}ms {ianvsContext.StatusCode}");

            egressSpan.End();
            // Egress middleware is the last in the Ianvs processing chain
            // No further calls made to _next
        }
Ejemplo n.º 4
0
 protected virtual void Awake()
 {
     Setup(DispatcherFactory.GetDispatcher());
 }