private Task Handle(GenericJsonMeasurement measurement, CancellationToken cancellationToken)
        {
            if (!HistorianConfiguration.Npgsql.GenericJson.Enable)
            {
                return(Task.CompletedTask);
            }

            return(Insert(command =>
            {
                command.WithCommandText(measurement.QueryString)
                .AddParameter(nameof(measurement.Topic), measurement.Topic)
                .AddParameter(nameof(measurement.Payload), measurement.Payload);
            }, cancellationToken));
        }
        public Task Handle(PublishReceived notification, CancellationToken cancellationToken)
        {
            if (!HistorianConfiguration.Npgsql.Enable)
            {
                return(Task.CompletedTask);
            }

            var settings = new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented,
                Converters =
                {
                    new Newtonsoft.Json.Converters.StringEnumConverter()
                },
            };

            if ($"{Prefix}/cpu-temperature".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("cpu-temperature", JsonConvert.DeserializeObject <CpuTemperatureMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/hdd-temperature".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("hdd-temperature", JsonConvert.DeserializeObject <HddTemperatureMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/hdd-usage".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("hdd-usage", JsonConvert.DeserializeObject <HddUsageMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/heartbeat".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("heartbeat", JsonConvert.DeserializeObject <HeartbeatMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/load".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("load", JsonConvert.DeserializeObject <LoadMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/ping".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("ping", JsonConvert.DeserializeObject <PingMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/tcp-port-state".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("tcp-port-state", JsonConvert.DeserializeObject <TcpPortStateMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/uptime".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("uptime", JsonConvert.DeserializeObject <UptimeMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/ns-resolve".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("ns-resolve", JsonConvert.DeserializeObject <NsResolveMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/dht22".Equals(notification.Topic))
            {
                // parse ping payload
                OnMeasurementReceived("dht22", JsonConvert.DeserializeObject <Dht22Measurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/state".Equals(notification.Topic))
            {
                // parse payload
                OnMeasurementReceived("state", JsonConvert.DeserializeObject <StateMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/rational-number".Equals(notification.Topic))
            {
                // parse payload
                OnMeasurementReceived("rational-number", JsonConvert.DeserializeObject <RationalNumberMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            if ($"{Prefix}/ups-battery".Equals(notification.Topic))
            {
                // parse payload
                OnMeasurementReceived("ups-battery", JsonConvert.DeserializeObject <UpsBatteryMeasurement>(Encoding.UTF8.GetString(notification.Payload), settings), cancellationToken);
            }

            foreach (var genericJsonEventConfigurationItem in HistorianConfiguration.Npgsql.GenericJson.Items)
            {
                bool isTopicMatch = genericJsonEventConfigurationItem.Topics.Any(topicPattern => topicPattern.IsTopicMatch(notification.Topic));
                if (isTopicMatch)
                {
                    var measurement = new GenericJsonMeasurement()
                    {
                        QueryString = genericJsonEventConfigurationItem.QueryString,
                        Topic       = notification.Topic,
                        Payload     = Encoding.UTF8.GetString(notification.Payload),
                    };
                    OnMeasurementReceived("generic-json", measurement, cancellationToken);
                }
            }

            return(Task.CompletedTask);
        }