-
Notifications
You must be signed in to change notification settings - Fork 21
Add new properties, types, and validation rules to C# ThingValidator #1340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jrdouceur
wants to merge
3
commits into
main
Choose a base branch
from
johndo/new-properties-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
340 changes: 318 additions & 22 deletions
340
wot-codegen/src/Azure.Iot.Operations.CodeGeneration/ThingValidator.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
wot-codegen/src/Azure.Iot.Operations.TDParser/Model/TDAffordanceGroup.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License | ||
|
|
||
| namespace Azure.Iot.Operations.TDParser.Model | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
|
|
||
| public class TDAffordanceGroup : IEquatable<TDAffordanceGroup>, IDeserializable<TDAffordanceGroup> | ||
| { | ||
| public const string TitleName = TDCommon.TitleName; | ||
|
|
||
| public static readonly HashSet<string> SupportedProperties = new() | ||
| { | ||
| TitleName | ||
| }; | ||
|
|
||
| public ValueTracker<StringHolder>? Title { get; set; } | ||
|
|
||
| public Dictionary<string, long> PropertyNames { get; set; } = new(); | ||
|
|
||
| public virtual bool Equals(TDAffordanceGroup? other) | ||
| { | ||
| if (other == null) | ||
| { | ||
| return false; | ||
| } | ||
| else | ||
| { | ||
| return Title == other.Title; | ||
| } | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return Title?.GetHashCode() ?? 0; | ||
| } | ||
|
|
||
| public static bool operator ==(TDAffordanceGroup? left, TDAffordanceGroup? right) | ||
| { | ||
| if (left is null) | ||
| { | ||
| return right is null; | ||
| } | ||
| else | ||
| { | ||
| return left.Equals(right); | ||
| } | ||
| } | ||
|
|
||
| public static bool operator !=(TDAffordanceGroup? left, TDAffordanceGroup? right) | ||
| { | ||
| return !(left == right); | ||
| } | ||
|
|
||
| public override bool Equals(object? obj) | ||
| { | ||
| if (ReferenceEquals(this, obj)) | ||
| { | ||
| return true; | ||
| } | ||
| else if (ReferenceEquals(obj, null)) | ||
| { | ||
| return false; | ||
| } | ||
| else if (obj is not TDAffordanceGroup other) | ||
| { | ||
| return false; | ||
| } | ||
| else | ||
| { | ||
| return Equals(other); | ||
| } | ||
| } | ||
|
|
||
| public IEnumerable<ITraversable> Traverse() | ||
| { | ||
| if (Title != null) | ||
| { | ||
| foreach (ITraversable item in Title.Traverse()) | ||
| { | ||
| yield return item; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static TDAffordanceGroup Deserialize(ref Utf8JsonReader reader) | ||
| { | ||
| if (reader.TokenType != JsonTokenType.StartObject) | ||
| { | ||
| throw new InvalidOperationException($"expected JSON object but found {reader.TokenType}"); | ||
| } | ||
|
|
||
| TDAffordanceGroup group = new(); | ||
|
|
||
| reader.Read(); | ||
| while (reader.TokenType == JsonTokenType.PropertyName) | ||
| { | ||
| string propertyName = reader.GetString()!; | ||
| ParsingSupport.CheckForDuplicatePropertyName(ref reader, propertyName, group.PropertyNames, "affordance group"); | ||
| group.PropertyNames[propertyName] = reader.TokenStartIndex; | ||
| reader.Read(); | ||
|
|
||
| switch (propertyName) | ||
| { | ||
| case TitleName: | ||
| group.Title = ValueTracker<StringHolder>.Deserialize(ref reader, TitleName); | ||
| break; | ||
| default: | ||
| reader.Skip(); | ||
| break; | ||
| } | ||
|
|
||
| reader.Read(); | ||
| } | ||
|
|
||
| return group; | ||
| } | ||
| } | ||
| } |
89 changes: 89 additions & 0 deletions
89
wot-codegen/src/Azure.Iot.Operations.TDParser/Model/TDAnything.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License | ||
|
|
||
| namespace Azure.Iot.Operations.TDParser.Model | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
|
|
||
| public class TDAnything : IEquatable<TDAnything>, IDeserializable<TDAnything> | ||
| { | ||
| public Dictionary<string, long> PropertyNames { get; set; } = new(); | ||
|
|
||
| public virtual bool Equals(TDAnything? other) | ||
| { | ||
| return other != null; | ||
| } | ||
|
|
||
| public override int GetHashCode() | ||
| { | ||
| return 0; | ||
| } | ||
|
jrdouceur marked this conversation as resolved.
|
||
|
|
||
| public static bool operator ==(TDAnything? left, TDAnything? right) | ||
| { | ||
| if (left is null) | ||
| { | ||
| return right is null; | ||
| } | ||
| else | ||
| { | ||
| return left.Equals(right); | ||
| } | ||
| } | ||
|
|
||
| public static bool operator !=(TDAnything? left, TDAnything? right) | ||
| { | ||
| return !(left == right); | ||
| } | ||
|
|
||
| public override bool Equals(object? obj) | ||
| { | ||
| if (ReferenceEquals(this, obj)) | ||
| { | ||
| return true; | ||
| } | ||
| else if (ReferenceEquals(obj, null)) | ||
| { | ||
| return false; | ||
| } | ||
| else if (obj is not TDAnything other) | ||
| { | ||
| return false; | ||
| } | ||
| else | ||
| { | ||
| return Equals(other); | ||
| } | ||
| } | ||
|
|
||
| public IEnumerable<ITraversable> Traverse() | ||
| { | ||
| yield break; | ||
| } | ||
|
|
||
| public static TDAnything Deserialize(ref Utf8JsonReader reader) | ||
| { | ||
| if (reader.TokenType != JsonTokenType.StartObject) | ||
| { | ||
| throw new InvalidOperationException($"expected JSON object but found {reader.TokenType}"); | ||
| } | ||
|
|
||
| TDAnything anything = new(); | ||
|
|
||
| reader.Read(); | ||
| while (reader.TokenType == JsonTokenType.PropertyName) | ||
| { | ||
| string propertyName = reader.GetString()!; | ||
| ParsingSupport.CheckForDuplicatePropertyName(ref reader, propertyName, anything.PropertyNames, "object"); | ||
| anything.PropertyNames[propertyName] = reader.TokenStartIndex; | ||
| reader.Read(); | ||
| reader.Skip(); | ||
| reader.Read(); | ||
| } | ||
|
|
||
| return anything; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.