public void ProcessMessage(IHandlerContext <RegisterMetricsCommand> context)
        {
            var message = context.Message;

            using (_databaseContextFactory.Create())
            {
                var id = _endpointQuery.FindId(message.EndpointName, message.MachineName, message.BaseDirectory);

                if (!id.HasValue)
                {
                    return;
                }

                var endpointId = id.Value;

                foreach (var metric in message.MessageTypeMetrics)
                {
                    _endpointQuery.AddMessageTypeMetric(
                        endpointId,
                        metric.MessageType,
                        metric.Count,
                        metric.FastestExecutionDuration,
                        metric.SlowestExecutionDuration,
                        metric.TotalExecutionDuration);
                }

                foreach (var association in message.MessageTypeAssociations)
                {
                    _endpointQuery.AddMessageTypeAssociation(
                        endpointId,
                        association.MessageTypeHandled,
                        association.MessageTypeDispatched);
                }

                foreach (var dispatched in message.MessageTypesDispatched)
                {
                    _endpointQuery.AddMessageTypeDispatched(
                        endpointId,
                        dispatched.MessageType,
                        dispatched.RecipientInboxWorkQueueUri);
                }

                foreach (var messageType in message.MessageTypesHandled)
                {
                    _endpointQuery.AddMessageTypeHandled(
                        endpointId,
                        messageType);
                }

                //foreach (var systemMetric in message.SystemMetrics)
                //{
                //    _endpointQuery.AddSystemMetric()
                //}
            }
        }
Ejemplo n.º 2
0
        public void ProcessMessage(IHandlerContext <RegisterEndpointCommand> context)
        {
            var message = context.Message;

            if (string.IsNullOrEmpty(message.MachineName)
                ||
                string.IsNullOrEmpty(message.BaseDirectory)
                ||
                context.TransportMessage.SendDate < DateTime.Now.Subtract(_configuration.HeartbeatIntervalDuration))
            {
                return;
            }

            string heartbeatIntervalDuration;

            try
            {
                var span = TimeSpan.Parse(message.HeartbeatIntervalDuration);

                heartbeatIntervalDuration = span.ToString();
            }
            catch
            {
                heartbeatIntervalDuration = SentinelConfiguration.DefaultHeartbeatIntervalDuration.ToString();
            }

            using (_databaseContextFactory.Create())
            {
                _endpointQuery.Save(
                    message.MachineName,
                    message.BaseDirectory,
                    message.EntryAssemblyQualifiedName,
                    message.IPv4Address,
                    message.InboxWorkQueueUri,
                    message.InboxDeferredQueueUri,
                    message.InboxErrorQueueUri,
                    message.OutboxWorkQueueUri,
                    message.OutboxErrorQueueUri,
                    message.ControlInboxWorkQueueUri,
                    message.ControlInboxErrorQueueUri,
                    heartbeatIntervalDuration);

                var id = _endpointQuery.FindId(message.MachineName, message.BaseDirectory);

                if (!id.HasValue)
                {
                    return;
                }

                var endpointId = id.Value;

                foreach (var metric in message.MessageTypeMetrics)
                {
                    _endpointQuery.AddMessageTypeMetric(
                        context.TransportMessage.MessageId,
                        metric.MessageType,
                        context.TransportMessage.SendDate,
                        endpointId,
                        metric.Count,
                        metric.FastestExecutionDuration,
                        metric.SlowestExecutionDuration,
                        metric.TotalExecutionDuration);
                }

                foreach (var association in message.MessageTypeAssociations)
                {
                    _endpointQuery.AddMessageTypeAssociation(
                        endpointId,
                        association.MessageTypeHandled,
                        association.MessageTypeDispatched);
                }

                foreach (var dispatched in message.MessageTypesDispatched)
                {
                    _endpointQuery.AddMessageTypeDispatched(
                        endpointId,
                        dispatched.MessageType,
                        dispatched.RecipientInboxWorkQueueUri);
                }

                foreach (var messageType in message.MessageTypesHandled)
                {
                    _endpointQuery.AddMessageTypeHandled(
                        endpointId,
                        messageType);
                }
            }

            SaveQueue(context, message.InboxWorkQueueUri, "inbox", "work");
            SaveQueue(context, message.InboxDeferredQueueUri, "inbox", "deferred");
            SaveQueue(context, message.InboxErrorQueueUri, "inbox", "error");
            SaveQueue(context, message.OutboxWorkQueueUri, "outbox", "work");
            SaveQueue(context, message.OutboxErrorQueueUri, "outbox", "error");
            SaveQueue(context, message.ControlInboxWorkQueueUri, "control-inbox", "work");
            SaveQueue(context, message.ControlInboxErrorQueueUri, "control-inbox", "error");
        }