Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
340 changes: 318 additions & 22 deletions wot-codegen/src/Azure.Iot.Operations.CodeGeneration/ThingValidator.cs

Large diffs are not rendered by default.

40 changes: 35 additions & 5 deletions wot-codegen/src/Azure.Iot.Operations.TDParser/Model/TDAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public class TDAction : IEquatable<TDAction>, IDeserializable<TDAction>
public const string FormsName = TDCommon.FormsName;
public const string NamespaceName = TDCommon.NamespaceName;
public const string NamespaceLegacyName = TDCommon.NamespaceLegacyName;
public const string MemberOfName = "dov:memberOf";
public const string MemberOfLegacyName = "aov:memberOf";
public const string MemberOfName = TDCommon.MemberOfName;
public const string MemberOfLegacyName = TDCommon.MemberOfLegacyName;
public const string PropertyIriName = TDCommon.PropertyIriName;
public const string ActionConfigurationName = "dov:actionConfiguration";

public static readonly HashSet<string> SupportedProperties = new()
{
Expand All @@ -31,7 +33,9 @@ public class TDAction : IEquatable<TDAction>, IDeserializable<TDAction>
NamespaceName,
NamespaceLegacyName,
MemberOfName,
MemberOfLegacyName
MemberOfLegacyName,
PropertyIriName,
ActionConfigurationName
};

public ValueTracker<StringHolder>? Description { get; set; }
Expand All @@ -50,6 +54,10 @@ public class TDAction : IEquatable<TDAction>, IDeserializable<TDAction>

public ValueTracker<StringHolder>? MemberOf { get; set; }

public ValueTracker<StringHolder>? PropertyIri { get; set; }

public ValueTracker<TDAnything>? ActionConfiguration { get; set; }

public Dictionary<string, long> PropertyNames { get; set; } = new();

public PrefixType NamespacePrefixType { get; set; } = PrefixType.Indeterminate;
Expand All @@ -71,13 +79,15 @@ public virtual bool Equals(TDAction? other)
Safe == other.Safe &&
Forms == other.Forms &&
Namespace == other.Namespace &&
MemberOf == other.MemberOf;
MemberOf == other.MemberOf &&
PropertyIri == other.PropertyIri &&
ActionConfiguration == other.ActionConfiguration;
}
}

public override int GetHashCode()
{
return (Description, Input, Output, Idempotent, Safe, Forms, Namespace, MemberOf).GetHashCode();
return (Description, Input, Output, Idempotent, Safe, Forms, Namespace, MemberOf, PropertyIri, ActionConfiguration).GetHashCode();
}

public static bool operator ==(TDAction? left, TDAction? right)
Expand Down Expand Up @@ -175,6 +185,20 @@ public IEnumerable<ITraversable> Traverse()
yield return item;
}
}
if (PropertyIri != null)
{
foreach (ITraversable item in PropertyIri.Traverse())
{
yield return item;
}
}
if (ActionConfiguration != null)
{
foreach (ITraversable item in ActionConfiguration.Traverse())
{
yield return item;
}
}
}

public static TDAction Deserialize(ref Utf8JsonReader reader)
Expand Down Expand Up @@ -230,6 +254,12 @@ public static TDAction Deserialize(ref Utf8JsonReader reader)
action.MemberOf = ValueTracker<StringHolder>.Deserialize(ref reader, MemberOfName);
action.MemberOfPrefixType = PrefixType.AioPlatform;
break;
case PropertyIriName:
action.PropertyIri = ValueTracker<StringHolder>.Deserialize(ref reader, PropertyIriName);
break;
case ActionConfigurationName:
action.ActionConfiguration = ValueTracker<TDAnything>.Deserialize(ref reader, ActionConfigurationName);
break;
default:
reader.Skip();
break;
Expand Down
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;
}
}
}
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;
Comment thread
jrdouceur marked this conversation as resolved.
}
Comment thread
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static class TDCommon
public const string WithUnitName = "dov:withUnit";
public const string WithUnitLegacyName = "aov:withUnit";
public const string HasQuantityKindName = "qudt:hasQuantityKind";
public const string MemberOfName = "dov:memberOf";
public const string MemberOfLegacyName = "aov:memberOf";
public const string PropertyIriName = "dov:propertyIRI";

public const string WithUnitPrefix = "properties/";
}
Expand Down
Loading
Loading