Skip to content

Commit

Permalink
Simple /shells with DB
Browse files Browse the repository at this point in the history
  • Loading branch information
aorzelskiGH committed Nov 20, 2024
1 parent 0880069 commit 20c377a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/AasxServerBlazor/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"AasxServerBlazor": {
"commandName": "Project",
"commandLineArgs": "--no-security --save-temp 30 --secret-string-api 1234 --aasx-in-memory 1000 --data-path \"C:\\Development\\aasxs-repository\" --edit --external-blazor http://localhost:5001",
"commandLineArgs": "--with-db --start-index 100 --no-security --save-temp 30 --secret-string-api 1234 --aasx-in-memory 1000 --data-path \"C:\\Development\\aasxs-repository\" --edit --external-blazor http://localhost:5001",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
Expand Down
5 changes: 4 additions & 1 deletion src/AasxServerDB/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ public string ParseTreeToExpression(string jsonText, string typePrefix, ref int

if (errorText == "")
{
Console.WriteLine("JSON is valid.");
if (typePrefix == "")
{
Console.WriteLine("JSON is valid.");
}
var json = JsonNode.Parse(jsonText);

string argumentType = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ zur Foerderung der angewandten Forschung e.V.
*/

using AasxServer;
using AasxServerDB;
using AasxServerStandardBib.Exceptions;
using AasxServerStandardBib.Interfaces;
using AasxServerStandardBib.Logging;
using AdminShellNS;
using Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using TimeStamp;

namespace AasxServerStandardBib.Services
{
Expand Down Expand Up @@ -106,14 +109,79 @@ public List<IAssetAdministrationShell> GetAllAssetAdministrationShells()
{
List<IAssetAdministrationShell> output = new List<IAssetAdministrationShell>();

foreach (var package in _packages)
if (!Program.withDb)
{
if (package != null)
foreach (var package in _packages)
{
var env = package.AasEnv;
if (env != null && env.AssetAdministrationShells != null && env.AssetAdministrationShells.Count != 0)
if (package != null)
{
var env = package.AasEnv;
if (env != null && env.AssetAdministrationShells != null && env.AssetAdministrationShells.Count != 0)
{
output.AddRange(env.AssetAdministrationShells);
}
}
}
}
else
{
/*
var db = new AasContext();
var timeStamp = DateTime.UtcNow;
var aasDBList = db.AASSets.ToList();
foreach (var aasDB in aasDBList)
{
int envId = aasDB.EnvId;
var aas = Converter.GetAssetAdministrationShell(aasDB: aasDB);
if (aas.TimeStamp == DateTime.MinValue)
{
aas.TimeStampCreate = timeStamp;
aas.SetTimeStamp(timeStamp);
}
// sm
var smAASDBList = db.SMSets.Where(sm => sm.EnvId == envId && sm.AASId == aasDB.Id).ToList();
foreach (var sm in smAASDBList)
{
output.AddRange(env.AssetAdministrationShells);
aas.Submodels?.Add(new Reference(type: ReferenceTypes.ModelReference,
keys: new List<IKey>() { new Key(KeyTypes.Submodel, sm.Identifier) }
));
}
output.Add(aas);
}
*/

using (var db = new AasContext())
{
var timeStamp = DateTime.UtcNow;

var aasDBList = db.AASSets
.Include(aas => aas.SMSets) // Include related SMSets
.ToList();

foreach (var aasDB in aasDBList)
{
int envId = aasDB.EnvId;

var aas = Converter.GetAssetAdministrationShell(aasDB: aasDB);
if (aas.TimeStamp == DateTime.MinValue)
{
aas.TimeStampCreate = timeStamp;
aas.SetTimeStamp(timeStamp);
}

// sm
foreach (var sm in aasDB.SMSets.Where(sm => sm.EnvId == envId))
{
aas.Submodels?.Add(new Reference(type: ReferenceTypes.ModelReference,
keys: new List<IKey>() { new Key(KeyTypes.Submodel, sm.Identifier) }
));
}

output.Add(aas);
}
}
}
Expand Down

0 comments on commit 20c377a

Please sign in to comment.