private static void ValidateTopic(MqttChannelConfig mqttChannelConfig) { if (string.IsNullOrWhiteSpace(mqttChannelConfig.Topic)) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.Topic), mqttChannelConfig.Topic, "Topic should not be empty or whitespace"); } if (mqttChannelConfig.Topic.Any(char.IsWhiteSpace)) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.Topic), mqttChannelConfig.Topic, "Topic should not contain whitespace"); } if (mqttChannelConfig.Topic.StartsWith('/')) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.Topic), mqttChannelConfig.Topic, "Topic should not start with /"); } if (mqttChannelConfig.Topic.Contains('#') && !mqttChannelConfig.Topic.EndsWith('#')) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.Topic), mqttChannelConfig.Topic, "Topic should contain # at the end only"); } if (mqttChannelConfig.Topic.Contains("//")) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.Topic), mqttChannelConfig.Topic, "Topic should not define empty groups"); } }
private static void ValidateChannel(MqttChannelConfig mqttChannelConfig) { if (!EnumIsDefined(typeof(MqttChannelConfig.Actions), mqttChannelConfig.Action)) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.Action), mqttChannelConfig.Action, $"Allowed values are {string.Join(", ", Enum.GetNames(typeof(MqttChannelConfig.Actions)))}"); } if (!EnumIsDefined(typeof(MqttChannelConfig.Types), mqttChannelConfig.Type)) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.Type), mqttChannelConfig.Type, $"Allowed values are {string.Join(", ", Enum.GetNames(typeof(MqttChannelConfig.Types)))}"); } if (!EnumIsDefined(typeof(MqttChannelConfig.QoS), mqttChannelConfig.QualityOfService)) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.QualityOfService), mqttChannelConfig.QualityOfService, $"Allowed values are {string.Join(", ", Enum.GetNames(typeof(MqttChannelConfig.QoS)))}"); } if (mqttChannelConfig.LogoAddress is < MemoryRangeMinimum or > MemoryRangeMaximum) { throw new ArgumentOutOfRangeException( nameof(mqttChannelConfig.LogoAddress), mqttChannelConfig.LogoAddress, $"The range should be {MemoryRangeMinimum}..{MemoryRangeMaximum}"); } ValidateTopic(mqttChannelConfig); }