diff --git a/src/AasxServerStandardBib/Interfaces/IAdminShellPackageEnvironmentService.cs b/src/AasxServerStandardBib/Interfaces/IAdminShellPackageEnvironmentService.cs index f1ea08a04..5d47ae74f 100644 --- a/src/AasxServerStandardBib/Interfaces/IAdminShellPackageEnvironmentService.cs +++ b/src/AasxServerStandardBib/Interfaces/IAdminShellPackageEnvironmentService.cs @@ -6,6 +6,9 @@ namespace AasxServerStandardBib.Interfaces { public interface IAdminShellPackageEnvironmentService { + #region Other + public void setWrite(int packageIndex, bool status); + #endregion #region AssetAdministrationShell IAssetAdministrationShell CreateAssetAdministrationShell(IAssetAdministrationShell body); void DeleteAssetAdministrationShell(int packageIndex, IAssetAdministrationShell aas); @@ -29,6 +32,7 @@ public interface IAdminShellPackageEnvironmentService void ReplaceSubmodelById(string submodelIdentifier, ISubmodel newSubmodel); List GetAllSubmodels(IReference reqSemanticId = null, string idShort = null); bool IsSubmodelPresent(string submodelIdentifier); + bool IsSubmodelPresent(string submodelIdentifier, out ISubmodel output, out int packageIndex); ISubmodel CreateSubmodel(ISubmodel newSubmodel, string aasIdentifier = null); #endregion diff --git a/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs b/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs index 17d2928c2..8e3eb5d7a 100644 --- a/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs +++ b/src/AasxServerStandardBib/Services/AdminShellPackageEnvironmentService.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Packaging; using System.Linq; using System.Threading.Tasks; @@ -48,6 +49,12 @@ private bool EmptyPackageAvailable(out int emptyPackageIndex) return false; } + + public void setWrite(int packageIndex, bool status) + { + _packages[packageIndex].setWrite(status); + } + #endregion #region AssetAdministrationShell @@ -238,7 +245,7 @@ public bool IsSubmodelPresent(string submodelIdentifier) return IsSubmodelPresent(submodelIdentifier, out _, out _); } - private bool IsSubmodelPresent(string submodelIdentifier, out ISubmodel output, out int packageIndex) + public bool IsSubmodelPresent(string submodelIdentifier, out ISubmodel output, out int packageIndex) { output = null; packageIndex = -1; @@ -255,6 +262,7 @@ private bool IsSubmodelPresent(string submodelIdentifier, out ISubmodel output, var submodels = env.Submodels.Where(a => a.Id.Equals(submodelIdentifier)); if (submodels.Any()) { + /* if (!Program.withDb) { output = submodels.First(); @@ -263,6 +271,8 @@ private bool IsSubmodelPresent(string submodelIdentifier, out ISubmodel output, { output = DBRead.getSubmodel(submodelIdentifier); } + */ + output = submodels.First(); packageIndex = Array.IndexOf(_packages, package); return true; } diff --git a/src/AasxServerStandardBib/Services/SubmodelService.cs b/src/AasxServerStandardBib/Services/SubmodelService.cs index 98387f696..0cabee998 100644 --- a/src/AasxServerStandardBib/Services/SubmodelService.cs +++ b/src/AasxServerStandardBib/Services/SubmodelService.cs @@ -500,30 +500,39 @@ public ISubmodel CreateSubmodel(ISubmodel newSubmodel, string aasIdentifier) public void UpdateSubmodelById(string submodelIdentifier, ISubmodel newSubmodel) { - var submodel = _packageEnvService.GetSubmodelById(submodelIdentifier, out _); - - //Verify the body first - _verificationService.VerifyRequestBody(newSubmodel); + int packageIndex = -1; + ISubmodel submodel = null; + if (_packageEnvService.IsSubmodelPresent(submodelIdentifier, out submodel, out packageIndex)) + { + //Verify the body first + _verificationService.VerifyRequestBody(newSubmodel); - Update.ToUpdateObject(submodel, newSubmodel); + Update.ToUpdateObject(submodel, newSubmodel); - submodel.SetTimeStamp(DateTime.UtcNow); + submodel.SetTimeStamp(DateTime.UtcNow); - Program.signalNewData(0); + _packageEnvService.setWrite(packageIndex, true); + Program.signalNewData(1); + } } public void UpdateSubmodelElementByPath(string submodelIdentifier, string idShortPath, ISubmodelElement newSme) { - var submodelElement = GetSubmodelElementByPath(submodelIdentifier, idShortPath); + int packageIndex = -1; + if (_packageEnvService.IsSubmodelPresent(submodelIdentifier, out ISubmodel _, out packageIndex)) + { + var submodelElement = GetSubmodelElementByPath(submodelIdentifier, idShortPath); - //Verify the body first - _verificationService.VerifyRequestBody(newSme); + //Verify the body first + _verificationService.VerifyRequestBody(newSme); - Update.ToUpdateObject(submodelElement, newSme); + Update.ToUpdateObject(submodelElement, newSme); - newSme.SetTimeStamp(DateTime.UtcNow); + submodelElement.SetTimeStamp(DateTime.UtcNow); - Program.signalNewData(0); + _packageEnvService.setWrite(packageIndex, true); + Program.signalNewData(1); + } } public void ReplaceFileByPath(string submodelIdentifier, string idShortPath, string fileName, string contentType, MemoryStream fileContent)