Skip to content

Commit

Permalink
Removed 2 methods no longer in the spec. AssetIds can be browsed. Als…
Browse files Browse the repository at this point in the history
…o updated nugets.
  • Loading branch information
barnstee committed Apr 15, 2024
1 parent ee8e116 commit 59b1e72
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 68 deletions.
29 changes: 16 additions & 13 deletions UACloudLibraryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,22 @@ public void Login(string uaCloudLibraryUrl, string clientId, string secret)
string address = uaCloudLibraryUrl + "infomodel/namespaces";
HttpResponseMessage response = _client.Send(new HttpRequestMessage(HttpMethod.Get, address));
string[] identifiers = JsonConvert.DeserializeObject<string[]>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult());

foreach (string nodeset in identifiers)
{
string[] tuple = nodeset.Split(",");

if (NamespacesInCloudLibrary.ContainsKey(tuple[0]))
{
NamespacesInCloudLibrary[tuple[0]] = tuple[1];
}
else
{
NamespacesInCloudLibrary.Add(tuple[0], tuple[1]);
}

if (identifiers != null)
{
foreach (string nodeset in identifiers)
{
string[] tuple = nodeset.Split(",");

if (NamespacesInCloudLibrary.ContainsKey(tuple[0]))
{
NamespacesInCloudLibrary[tuple[0]] = tuple[1];
}
else
{
NamespacesInCloudLibrary.Add(tuple[0], tuple[1]);
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions UAEdgeTranslator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua" Version="1.4.372.107" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua" Version="1.5.374.36" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
Expand Down
57 changes: 4 additions & 53 deletions UANodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -544,14 +544,6 @@ private void AddAssetManagementNodes(IList<IReference> references)
deleteAssetMethod.OnCallMethod = new GenericMethodCalledEventHandler(DeleteAsset);
deleteAssetMethod.InputArguments = CreateInputArguments(deleteAssetMethod, "AssetId", "The ID of the asset to be deleted", DataTypeIds.String, (ushort)Server.NamespaceUris.GetIndex("http://opcfoundation.org/UA/EdgeTranslator/"));

MethodState getAssetsMethod = CreateMethod(assetManagementFolder, "GetAssetsIds", (ushort)Server.NamespaceUris.GetIndex("http://opcfoundation.org/UA/EdgeTranslator/"));
getAssetsMethod.OnCallMethod = new GenericMethodCalledEventHandler(GetAssetIds);
getAssetsMethod.OutputArguments = CreateOutputArguments(getAssetsMethod, "AssetIds", "The IDs of the assets currently defined", DataTypeIds.String, (ushort)Server.NamespaceUris.GetIndex("http://opcfoundation.org/UA/EdgeTranslator/"), true);

MethodState getAssetMethod = CreateMethod(assetManagementFolder, "GetAsset", (ushort)Server.NamespaceUris.GetIndex("http://opcfoundation.org/UA/EdgeTranslator/"));
getAssetMethod.OnCallMethod = new GenericMethodCalledEventHandler(GetAsset);
getAssetMethod.InputArguments = CreateInputArguments(getAssetMethod, "AssetId", "The ID of the asset for which to retrieve the WoT Thing Description", DataTypeIds.String, (ushort)Server.NamespaceUris.GetIndex("http://opcfoundation.org/UA/EdgeTranslator/"));

// add everything to our server namespace
AddPredefinedNode(SystemContext, assetManagementFolder);
}
Expand Down Expand Up @@ -680,8 +672,10 @@ private ServiceResult CreateAsset(ISystemContext context, MethodState method, IL
// parse WoT TD file contents
ThingDescription td = JsonConvert.DeserializeObject<ThingDescription>(contents);

List<string> namespaceUris = new(NamespaceUris);
namespaceUris.Add("http://opcfoundation.org/UA/" + td.Name + "/");
List<string> namespaceUris = new(NamespaceUris)
{
"http://opcfoundation.org/UA/" + td.Name + "/"
};

foreach (object ns in td.Context)
{
Expand Down Expand Up @@ -768,49 +762,6 @@ private ServiceResult DeleteAsset(ISystemContext context, MethodState method, IL
return new ServiceResult(StatusCodes.BadNotFound);
}

private ServiceResult GetAssetIds(ISystemContext context, MethodState method, IList<object> inputArguments, IList<object> outputArguments)
{
if (outputArguments.Count == 0)
{
return new ServiceResult(StatusCodes.BadInvalidArgument);
}

outputArguments[0] = _assets.Keys.ToArray();

return ServiceResult.Good;
}

private ServiceResult GetAsset(ISystemContext context, MethodState method, IList<object> inputArguments, IList<object> outputArguments)
{
if (inputArguments.Count == 0)
{
return new ServiceResult(StatusCodes.BadInvalidArgument);
}

IEnumerable<string> WoTFiles = Directory.EnumerateFiles(Path.Combine(Directory.GetCurrentDirectory(), "settings"), "*.jsonld");
foreach (string file in WoTFiles)
{
try
{
string assetId = Path.GetFileNameWithoutExtension(file);

if (inputArguments[0].ToString() == assetId)
{
outputArguments[0] = File.ReadAllText(file);

return ServiceResult.Good;
}
}
catch (Exception ex)
{
Log.Logger.Error(ex.Message, ex);
return new ServiceResult(ex);
}
}

return new ServiceResult(StatusCodes.BadNotFound);
}

private void HandleServerRestart()
{
_shutdown = true;
Expand Down

0 comments on commit 59b1e72

Please sign in to comment.