Skip to content

Commit

Permalink
Patch with write to DB
Browse files Browse the repository at this point in the history
  • Loading branch information
aorzelskiGH committed Apr 17, 2024
1 parent 194310e commit 1533202
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -29,6 +32,7 @@ public interface IAdminShellPackageEnvironmentService
void ReplaceSubmodelById(string submodelIdentifier, ISubmodel newSubmodel);
List<ISubmodel> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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;
}
Expand Down
35 changes: 22 additions & 13 deletions src/AasxServerStandardBib/Services/SubmodelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1533202

Please sign in to comment.