Example #1
0
 // ReSharper disable NotResolvedInText
 /// <summary>
 ///     Validates that the topic does not exceed the maximum length.
 /// </summary>
 /// <param name="topicInstance">The instance to check.</param>
 protected static void ValidateMaxLength(Topic topicInstance) {
     if (topicInstance.RawTopic.Length > MaxTopicLength) {
         throw new ArgumentException(
             String.Format("The length of the supplied rawTopic ({0}) is longer than the maximum allowable ({1})",
                           topicInstance.RawTopic.Length, MaxTopicLength),
             "topic");
     }
 }
Example #2
0
 /// <summary>
 ///     Validates the placement of the multi-wildcard character in subscription topics.
 /// </summary>
 /// <param name="topicInstance">The instance to check.</param>
 private static void ValidateMultiWildcard(Topic topicInstance) {
     if (topicInstance.RawTopic.Contains(MultiWildcard) && !topicInstance.RawTopic.EndsWith(MultiWildcard)) {
         throw new ArgumentException("The rawTopic wildcard # can only be present at the end of a topic", "topic");
     }
     if (topicInstance.RawTopic.Length > 1 && topicInstance.RawTopic.EndsWith(MultiWildcard) && 
         !topicInstance.RawTopic.EndsWith(MultiWildcardValidEnd)) {
         throw new ArgumentException(
             "Topics using the # wildcard longer than 1 character must be immediately preceeded by a the rawTopic separator /.", "topic");
     }
 }
Example #3
0
 /// <summary>
 ///     Validates all unqiue fragments in the topic match the MQTT spec requirements.
 /// </summary>
 // ReSharper disable NotResolvedInText
 private static void ValidateFragments(Topic topicInstance) {
     // if any fragment contains a wildcard or a multi wildcard but is greater than 
     // 1 character long, then it's an error - wildcards must appear by themselves.
     var invalidFragment = topicInstance.TopicFragments.FirstOrDefault(
         fragment => (fragment.Contains(MultiWildcard) || fragment.Contains(Wildcard)) && fragment.Length > 1);
     if (invalidFragment != null) {
         throw new ArgumentException(
             String.Format("rawTopic Fragment '{0}' contains a wildcard but is more than one character long.",  invalidFragment),
             "topic");
     }
 }
Example #4
0
 /// <summary>
 ///     Validates that the topic does not fall below the minimum length.
 /// </summary>
 /// <param name="topicInstance">The instance to check.</param>
 protected static void ValidateMinLength(Topic topicInstance) {
     if (String.IsNullOrWhiteSpace(topicInstance.RawTopic)) {
         throw new ArgumentException("rawTopic must contain at least one character.", "topic");
     }
 }
Example #5
0
 /// <summary>
 ///     Validates that the topic has no wildcards which are not allowed in publication topics.
 /// </summary>
 /// <param name="topicInstance">The instance to check.</param>
 private static void ValidateWildcards(Topic topicInstance) {
     if (topicInstance.HasWildcards) {
         throw new ArgumentException("Cannot publish to a topic that contains MQTT topic wildcards (# or +)");
     }
 }