Skip to content

Commit

Permalink
- Fixed issue related to the method 'GetObjects()' (the parameter 'le…
Browse files Browse the repository at this point in the history
…vels' was not properly handled)

- Enhanced methods 'ReadProperty()' and 'ReadPropertyMultiple()'
- Enhanced the TestClient app in order to support the latest changes.
  • Loading branch information
Federico-Artioli committed Apr 11, 2024
1 parent e0212cb commit be6f762
Show file tree
Hide file tree
Showing 17 changed files with 488 additions and 459 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [6.0.3] - 2024-04-11
### Changed
- Fixed issue related to the method 'GetObjects()' (the parameter 'levels' was not properly handled)
- Enhanced methods 'ReadProperty()' and 'ReadPropertyMultiple()'
- Enhanced the TestClient app in order to support the latest changes.
## [6.0.2] - 2024-03-20
### Changed
- Fixed issue related to the method that is retrieving the list of Activities when API v4 was selected.
Expand Down Expand Up @@ -268,7 +273,8 @@ First Release.
- LegacyMetasysClient for compatibility with COM services.
- Automatic enumeration translations for supported languages.

[Unreleased]: https://github.com/metasys-server/basic-services-dotnet/compare/v6.0.1...HEAD
[Unreleased]: https://github.com/metasys-server/basic-services-dotnet/compare/v6.0.3...HEAD
[6.0.3]: https://github.com/metasys-server/basic-services-dotnet/compare/v6.0.2...v6.0.3
[6.0.2]: https://github.com/metasys-server/basic-services-dotnet/compare/v6.0.1...v6.0.2
[6.0.1]: https://github.com/metasys-server/basic-services-dotnet/compare/v6.0.0...v6.0.1
[6.0.0]: https://github.com/metasys-server/basic-services-dotnet/compare/v5.0.3...v6.0.0
Expand Down
2 changes: 1 addition & 1 deletion MetasysServices.Tests/MetasysServices.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<IsPackable>false</IsPackable>

<Version>6.0.2</Version>
<Version>6.0.3</Version>

<Copyright>© 2020-2024 Johnson Controls</Copyright>
</PropertyGroup>
Expand Down
15 changes: 8 additions & 7 deletions MetasysServices/Interfaces/IMetasysClient.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using System;
using JohnsonControls.Metasys.BasicServices;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using JohnsonControls.Metasys.BasicServices;

namespace JohnsonControls.Metasys.BasicServices
{
/// <summary>
/// An HTTP client for consuming the most commonly used endpoints of the Metasys API.
/// </summary>
public interface IMetasysClient :IBasicService
public interface IMetasysClient : IBasicService
{
/// <summary>
/// The hostname of Metasys API server.
Expand Down Expand Up @@ -239,7 +239,7 @@ public interface IMetasysClient :IBasicService
/// </summary>
Task WritePropertyMultipleAsync(IEnumerable<Guid> ids, IEnumerable<(string Attribute, object Value)> attributeValues);
/// <inheritdoc cref="IMetasysClient.WritePropertyMultiple(IEnumerable{Guid}, Dictionary{string, object})"/>
Task WritePropertyMultipleAsync(IEnumerable<Guid> ids, Dictionary<string, object> attributeValues);
Task WritePropertyMultipleAsync(IEnumerable<Guid> ids, Dictionary<string, object> attributeValues);


/// <summary>
Expand Down Expand Up @@ -306,15 +306,16 @@ public interface IMetasysClient :IBasicService
/// <remarks>
/// A level of 1 only retrieves immediate children of the parent object.
/// </remarks>
/// <param name="id"></param>
/// <param name="id">The ID of the parent object.</param>
/// <param name="levels">The depth of the children to retrieve.</param>
/// <param name="includeInternalObjects">Set it to true to see also internal objects that are not displayed in the Metasys tree. </param>
/// <param name="includeExtensions">Set it to true to get also the extensions of the object.</param>
/// <remarks> The flag includeInternalObjects applies since Metasys API v3. </remarks>
/// <exception cref="MetasysHttpException"></exception>
/// <exception cref="MetasysHttpParsingException"></exception>
IEnumerable<MetasysObject> GetObjects(Guid id, int levels = 1, bool includeInternalObjects = false);
IEnumerable<MetasysObject> GetObjects(Guid id, int levels = 1, bool includeInternalObjects = false, bool includeExtensions = false);
/// <inheritdoc cref="IMetasysClient.GetObjects(Guid, int, bool)"/>
Task<IEnumerable<MetasysObject>> GetObjectsAsync(Guid id, int levels = 1, bool includeInternalObjects = false);
Task<IEnumerable<MetasysObject>> GetObjectsAsync(Guid id, int levels = 1, bool includeInternalObjects = false, bool includeExtensions = false);

/// <summary>
/// Gets all child objects given a parent Guid and object type.
Expand Down
44 changes: 22 additions & 22 deletions MetasysServices/MetasysClient.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Flurl;
using Flurl.Http;
using JohnsonControls.Metasys.BasicServices.Utils;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net;
using Flurl;
using Flurl.Http;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using JohnsonControls.Metasys.BasicServices.Utils;
using System.IdentityModel.Tokens.Jwt;
using System.Timers;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;


namespace JohnsonControls.Metasys.BasicServices
Expand Down Expand Up @@ -69,7 +69,7 @@ public string Hostname
{
// No need to init base url on first call (already done on Version set)
if (hostname != null && hostname != value) // it's the same hostname: no changes
{
{
// reset the base client according to settings
InitFlurlClient(value);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ public MetasysClient(string hostname, bool ignoreCertificateErrors = false, ApiV
Spaces = new SpaceServiceProvider(Client, version, logClientErrors);
Trends = new TrendServiceProvider(Client, version, logClientErrors);
if (Version > ApiVersion.v3) Streams = new StreamServiceProvider(Client, version, logClientErrors);


base.Version = version;
}
Expand Down Expand Up @@ -342,12 +342,12 @@ public async Task<AccessToken> RefreshAsync()
}

// Refresh2 ------------------------------------------------------------------------------------------------------------------

private AccessToken Refresh2()
{
return Refresh2Async().GetAwaiter().GetResult();
}

private async Task<AccessToken> Refresh2Async()
{
try
Expand Down Expand Up @@ -490,12 +490,12 @@ public async Task<IEnumerable<MetasysObjectType>> GetNetworkDeviceTypesAsync()
#region "OBJECTS" // ========================================================================================================
// GetObjects ---------------------------------------------------------------------------------------------------------------
/// <inheritdoc/>
public IEnumerable<MetasysObject> GetObjects(Guid id, int levels = 1, bool includeInternalObjects = false)
public IEnumerable<MetasysObject> GetObjects(Guid id, int levels = 1, bool includeInternalObjects = false, bool includeExtensions = false)
{
return GetObjectsAsync(id, levels, includeInternalObjects).GetAwaiter().GetResult();
return GetObjectsAsync(id, levels, includeInternalObjects, includeExtensions).GetAwaiter().GetResult();
}
/// <inheritdoc/>
public async Task<IEnumerable<MetasysObject>> GetObjectsAsync(Guid id, int levels, bool includeInternalObjects = false)
public async Task<IEnumerable<MetasysObject>> GetObjectsAsync(Guid id, int levels, bool includeInternalObjects = false, bool includeExtensions = false)
{
Dictionary<string, string> parameters = null;
if (Version == ApiVersion.v3)
Expand All @@ -511,10 +511,10 @@ public async Task<IEnumerable<MetasysObject>> GetObjectsAsync(Guid id, int level
// Since API v3 we could use the includeInternalObjects parameter
parameters = new Dictionary<string, string>
{
{ "includeInternal", includeInternalObjects.ToString() }, //This param has different name when version > v3
{ "depth", levels.ToString() },
{ "flatten", "true".ToString() }, //This parameter is needed to get the data in a 'flat' way and keep consistency in the logic to retrieve the objects
{ "includeExtensions", "true".ToString() },
{ "depth", "2".ToString() }
{ "includeExtensions", includeExtensions.ToString() },
{ "includeInternal", includeInternalObjects.ToString() } //This param has different name when version > v3
};
}

Expand Down Expand Up @@ -549,7 +549,7 @@ public async Task<IEnumerable<MetasysObject>> GetObjectsAsync(Guid objectId, str
}

var objects = await GetObjectChildrenAsync(objectId, parameters).ConfigureAwait(false);

return ToMetasysObject(objects, Version);
}

Expand Down Expand Up @@ -827,7 +827,7 @@ public IEnumerable<MetasysObject> GetSpaces(SpaceTypeEnum? type = null)
}
/// <inheritdoc/>
public async Task<IEnumerable<MetasysObject>> GetSpacesAsync(SpaceTypeEnum? type = null)
{
{
return await Spaces.GetAsync(type);
}

Expand Down Expand Up @@ -940,7 +940,7 @@ private void ScheduleRefresh()
Enabled = true
};

_timer.Elapsed += (object sender, ElapsedEventArgs e) =>
_timer.Elapsed += (object sender, ElapsedEventArgs e) =>
{
DateTime now = DateTime.UtcNow;
if (now > this.RefreshDateTime)
Expand Down Expand Up @@ -1231,7 +1231,7 @@ private Url GetUrlFromHttpRequest(HttpRequestMessage requestMessage)
throw new UriFormatException("HTTP request can not be made. Scheme or Host is invalid.");
}
return new Url(requestUri);
}
}
else
{
return new Url(Url.Combine(baseUri.GetLeftPart(UriPartial.Authority), "/api/", requestUri));
Expand Down
6 changes: 3 additions & 3 deletions MetasysServices/MetasysServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<PackageId>JohnsonControls.Metasys.BasicServices</PackageId>
<PackageProjectUrl>https://github.com/metasys-server/basic-services-dotnet</PackageProjectUrl>
<PackageTags>Johnson Controls, Metasys, API, .NET, Services</PackageTags>
<PackageReleaseNotes>- Fixed issue related to the method 'Activities.Get()'
- Enhanced method 'Alarms.Get()' to support params for v4+</PackageReleaseNotes>
<PackageReleaseNotes>- Fixed issue related to the method 'GetObjects()'
- Enhanced methods 'ReadProperty()' and 'ReadPropertyMultiple()'</PackageReleaseNotes>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Version>6.0.2</Version>
<Version>6.0.3</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down
46 changes: 35 additions & 11 deletions MetasysServices/Models/Variant.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Globalization;
using JohnsonControls.Metasys.BasicServices.Utils;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using JohnsonControls.Metasys.BasicServices.Utils;
using System;
using System.Globalization;

namespace JohnsonControls.Metasys.BasicServices
{
Expand All @@ -22,6 +22,12 @@ public class Variant

private const string Array = "dataTypeEnumSet.arrayDataType";

/// <summary>The string representation of the item type.</summary>
/// <value>
/// Type of the item (e.g. 'string', 'numeric', 'boolean', 'object').
/// </value>
public string ItemType { private set; get; }

/// <summary>The string representation of the value.</summary>
/// <value>
/// String value as specified in the MSSDA Bulletin stringValue or a translated string if
Expand Down Expand Up @@ -50,6 +56,12 @@ public class Variant
/// </value>
public bool BooleanValue { private set; get; }

/// <summary>The object representation of the value.</summary>
/// <value>
/// Object value specified as Json.
/// </value>
public object ObjectValue { private set; get; }

/// <summary>An array of Variant values.</summary>
/// <value>Null unless value is an array.</value>
public Variant[] ArrayValue { private set; get; }
Expand Down Expand Up @@ -99,7 +111,8 @@ public class Variant

private CultureInfo _CultureInfo;

internal Variant() {
internal Variant()
{
}

internal Variant(Guid id, JToken token, string attribute, CultureInfo cultureInfo, ApiVersion apiVersion)
Expand All @@ -114,7 +127,7 @@ internal Variant(Guid id, JToken token, string attribute, CultureInfo cultureInf
PriorityEnumerationKey = null;
StringValueEnumerationKey = null;
StringValue = null;
NumericValue = 1;
NumericValue = 0;
ArrayValue = null;
BooleanValue = false;
ProcessToken(token);
Expand All @@ -130,30 +143,34 @@ internal Variant(Guid id, JToken token, string attribute, CultureInfo cultureInf
/// </summary>
private void ProcessToken(JToken token)
{
if (token == null || token["item"]== null || token ["item"][Attribute] == null)
if (token == null || token["item"] == null || token["item"][Attribute] == null)
{
// return unsupported attribute result
NumericValue = 1;
ItemType = "unsupported";
NumericValue = 0;
StringValueEnumerationKey = Unsupported;
StringValue = ResourceManager.Localize(StringValueEnumerationKey, _CultureInfo);
return;
}
JToken attributeToken=token["item"][Attribute];
JToken attributeToken = token["item"][Attribute];
// switch on attributeToken type and set the fields appropriately
switch (attributeToken.Type)
{
case JTokenType.Integer:
ItemType = "numeric";
NumericValue = attributeToken.Value<double>();
StringValue = NumericValue.ToString(_CultureInfo);
BooleanValue = Convert.ToBoolean(NumericValue);
ArrayValue = null;
break;
case JTokenType.Float:
ItemType = "numeric";
NumericValue = attributeToken.Value<double>();
StringValue = NumericValue.ToString(_CultureInfo);
BooleanValue = Convert.ToBoolean(NumericValue);
break;
case JTokenType.String:
ItemType = "string";
NumericValue = 0;
StringValueEnumerationKey = attributeToken.Value<string>();
StringValue = ResourceManager.Localize(StringValueEnumerationKey, _CultureInfo);
Expand All @@ -162,6 +179,7 @@ private void ProcessToken(JToken token)
ProcessArray(attributeToken);
break;
case JTokenType.Boolean:
ItemType = "boolean";
if ((bool)(attributeToken) == true)
{
NumericValue = 1;
Expand All @@ -182,13 +200,19 @@ private void ProcessToken(JToken token)
// From v3 onwards presentValue is threated like other attributes and additional information are moved in Condition property.
ProcessPresentValue(attributeToken);
}
else
{
ItemType = "object";
ObjectValue = attributeToken;
}
break;
default:
NumericValue = 1;
NumericValue = 0;
StringValueEnumerationKey = Unsupported;
StringValue = ResourceManager.Localize(StringValueEnumerationKey, _CultureInfo);
ObjectValue = null;
break;
}
}
}

/// <summary>Parses a JArray and adds each item as a Variant.</summary>
Expand Down Expand Up @@ -265,7 +289,7 @@ internal void ProcessCondition(JToken token)
{
PriorityEnumerationKey = priorityToken.ToString();
Priority = ResourceManager.Localize(PriorityEnumerationKey, _CultureInfo);
}
}
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions MetasysServicesCom.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
[assembly: Guid("c6ad9c27-b7dd-4520-9c03-a0efca68fb51")]

// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("6.0.2.0")]
[assembly: AssemblyFileVersion("6.0.2.0")]
[assembly: AssemblyVersion("6.0.3.0")]
[assembly: AssemblyFileVersion("6.0.3.0")]
Loading

0 comments on commit be6f762

Please sign in to comment.