From 59b1e722e4b2012cf035ff6a845b1a8de877af24 Mon Sep 17 00:00:00 2001 From: Erich Barnstedt Date: Mon, 15 Apr 2024 13:37:50 +0200 Subject: [PATCH] Removed 2 methods no longer in the spec. AssetIds can be browsed. Also updated nugets. --- UACloudLibraryClient.cs | 29 +++++++++++---------- UAEdgeTranslator.csproj | 4 +-- UANodeManager.cs | 57 +++-------------------------------------- 3 files changed, 22 insertions(+), 68 deletions(-) diff --git a/UACloudLibraryClient.cs b/UACloudLibraryClient.cs index 0ae978a..8d378f3 100644 --- a/UACloudLibraryClient.cs +++ b/UACloudLibraryClient.cs @@ -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(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]); + } + } } } } diff --git a/UAEdgeTranslator.csproj b/UAEdgeTranslator.csproj index 6fa26a8..1d3e375 100644 --- a/UAEdgeTranslator.csproj +++ b/UAEdgeTranslator.csproj @@ -19,8 +19,8 @@ - - + + diff --git a/UANodeManager.cs b/UANodeManager.cs index 099106c..4cdc67d 100644 --- a/UANodeManager.cs +++ b/UANodeManager.cs @@ -544,14 +544,6 @@ private void AddAssetManagementNodes(IList 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); } @@ -680,8 +672,10 @@ private ServiceResult CreateAsset(ISystemContext context, MethodState method, IL // parse WoT TD file contents ThingDescription td = JsonConvert.DeserializeObject(contents); - List namespaceUris = new(NamespaceUris); - namespaceUris.Add("http://opcfoundation.org/UA/" + td.Name + "/"); + List namespaceUris = new(NamespaceUris) + { + "http://opcfoundation.org/UA/" + td.Name + "/" + }; foreach (object ns in td.Context) { @@ -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 inputArguments, IList 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 inputArguments, IList outputArguments) - { - if (inputArguments.Count == 0) - { - return new ServiceResult(StatusCodes.BadInvalidArgument); - } - - IEnumerable 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;