Skip to content

Commit

Permalink
* update
Browse files Browse the repository at this point in the history
  • Loading branch information
festo-i40 committed Oct 14, 2024
1 parent e3aaa4d commit 49eab51
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/AasxPackageExplorer/options-debug.MIHO.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"EclassTwoPass": true,
"BackupDir": ".\\backup",
"BackupFiles": 10,
"MaxParallelOps": 20,
"MaxParallelOps": 1,
"AllowFakeResponses": true,
"RestServerHost": "localhost",
"RestServerPort": "1111",
Expand Down
10 changes: 8 additions & 2 deletions src/AasxPackageLogic/DispEditHelperEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,8 @@ public void DisplayOrEditAasEntityAas(
if (lrs != null)
{
var ids = lrs.Select((lr) => (lr?.Reference?.IsValid() == true) ? lr.Reference.Keys[0].Value : null).ToList();
var fetched = await dynPack.TryFetchSpecificIds(ids);
var fetched = await dynPack.TryFetchSpecificIds(ids,
useParallel: Options.Curr.MaxParallelOps > 1);
if (fetched)
return new AnyUiLambdaActionRedrawAllElements(nextFocus: aas);
}
Expand Down Expand Up @@ -2798,7 +2799,8 @@ public void DisplayOrEditAasEntitySubmodelOrRef(
//

public void DisplayOrEditAasEntitySubmodelStub(
PackageCentral.PackageCentral packages, AdminShellPackageEnvBase packEnv,
PackageCentral.PackageCentral packages,
AdminShellPackageEnvBase packEnv,
Aas.IAssetAdministrationShell aas,
Aas.IReference smref,
Action setSmRefNull,
Expand All @@ -2823,6 +2825,10 @@ public void DisplayOrEditAasEntitySubmodelStub(
}
else
{
// infos
DisplayOrEditEntitySideInfo(packEnv?.AasEnv, stack, aas, sideInfo, "Submodel", superMenu);

// actions
AddActionPanel(stack, "Action:",
repo: repo,
superMenu: superMenu,
Expand Down
21 changes: 14 additions & 7 deletions src/AasxPackageLogic/DispEditHelperModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,22 +346,29 @@ public void DisplayOrEditEntitySideInfo(
AasxMenu superMenu = null)
{
// access
if (stack == null || referable == null || si == null)
if (stack == null || si == null)
return;

this.AddGroup(stack, $"{key} was provided by Endpoint of dynamic fetch environment",
this.AddGroup(stack, $"{key} is provided by Endpoint of dynamic fetch environment",
this.levelColors.SubSection);

AddKeyValue(stack, "StubLevel", "" + si.StubLevel.ToString(), repo: null);
AddKeyValue(stack, "IdShort", "" + si.IdShort, repo: null);
AddKeyValue(stack, "Id", "" + si.Id, repo: null);
AddKeyValue(stack, "Endpoint", "" + si.Endpoint.ToString(), repo: null,
AddKeyValue(stack, "Endpoint", "" + si.Endpoint?.ToString(), repo: null,
auxButtonTitle: "Copy",
auxButtonLambda: (i) => {
this.context?.ClipboardSet(new AnyUiClipboardData(
text: si.Endpoint.ToString())
{ });
Log.Singleton.Info(StoredPrint.Color.Blue, "Endpoint copied to clipboard.");
if (si.Endpoint == null)
{
Log.Singleton.Error("No endpoint data available");
}
else
{
this.context?.ClipboardSet(new AnyUiClipboardData(
text: si.Endpoint.ToString())
{ });
Log.Singleton.Info(StoredPrint.Color.Blue, "Endpoint copied to clipboard.");
}
return new AnyUiLambdaActionNone();
},
auxButtonOverride: true);
Expand Down
8 changes: 8 additions & 0 deletions src/AasxPackageLogic/PackageCentral/AasOnDemandEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public int FindSideInfoIndexFromId(string id)
return -1;
}

public AasIdentifiableSideInfo FindSideInfoFromId(string id)
{
var ndx = FindSideInfoIndexFromId(id);
if (ndx >= 0)
return GetSideInfo(ndx);
return null;
}

public static AasIdentifiableSideInfo FindSideInfoInListOfIdentifiables(
object listIdf,
Aas.IReference rf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,30 +125,49 @@ await PackageHttpDownloadUtil.HttpGetToMemoryStreamOLD(
var smndx = sms?.FindSideInfoIndexFromId(id);
if (smndx.HasValue && smndx.Value >= 0)
{
// side info
var si = sms.GetSideInfo(smndx.Value);

// directly use id to fetch Identifiable
Aas.IIdentifiable res = null;

// build the location
var loc = PackageContainerHttpRepoSubset.BuildUriForRepoSingleSubmodel(_defaultRepoBaseUri, id);
var loc = (si.StubLevel >= AasIdentifiableSideInfoLevel.IdWithEndpoint && si.Endpoint != null)
? si.Endpoint
: PackageContainerHttpRepoSubset.BuildUriForRepoSingleSubmodel(_defaultRepoBaseUri, id);
if (loc == null)
return null;

await PackageHttpDownloadUtil.HttpGetToMemoryStreamOLD(
await PackageHttpDownloadUtil.HttpGetToMemoryStream(
sourceUri: loc,
allowFakeResponses: _runtimeOptions?.AllowFakeResponses ?? false,
runtimeOptions: _runtimeOptions,
lambdaDownloadDone: (ms, contentFn) =>
lambdaDownloadDoneOrFail: (code, ms, contentFn) =>
{
// fail!!
if (code != HttpStatusCode.OK)
{
_runtimeOptions?.Log?.Error($"Error while downloading on-demand loaded Submodel. " +
$"Endpoint was expected to be available! Status: {(int)code} {code}. " +
$"Location: {loc.ToString()}");
return;
}

try
{
// load?
var node = System.Text.Json.Nodes.JsonNode.Parse(ms);
var sm = Jsonization.Deserialize.SubmodelFrom(node);

// replace, side info will go null
// replace, side info need to be preserved!
lock (_aasEnv.Submodels)
{
// data
sms[smndx.Value] = sm;

// side info
si.IsStub = false;
sms.SetSideInfo(smndx.Value, si);
}

// ok
Expand All @@ -171,10 +190,12 @@ await PackageHttpDownloadUtil.HttpGetToMemoryStreamOLD(
return null;
}

public async Task<bool> TryFetchSpecificIds(IEnumerable<string> ids)
public async Task<bool> TryFetchSpecificIds(
IEnumerable<string> ids,
bool useParallel = true)
{
var someFetched = false;
if (true)
if (useParallel)
{
// parallel
await Parallel.ForEachAsync(
Expand Down Expand Up @@ -233,7 +254,7 @@ public async Task<bool> TryFetchAllMissingIdentifiables(

protected async Task<int> TrySaveAllTaintedIdentifiablesOf<T>(
object listOfIdf,
Func<Uri, string, Uri> lambdaBuildRessource,
Func<Uri, string, Uri> lambdaBuildRessourceForNoEndpoint,
bool clearTaintedFlags = true) where T : Aas.IIdentifiable
{
var list = listOfIdf as OnDemandListIdentifiable<T>;
Expand All @@ -260,8 +281,11 @@ protected async Task<int> TrySaveAllTaintedIdentifiablesOf<T>(
if (tidf?.TaintedData != null && tidf.TaintedData.Tainted == null)
continue;

// try save, need a REST ressource
var uri = lambdaBuildRessource(_defaultRepoBaseUri, idf.Id);
// try save, need a REST ressource. Either use the existing endpoint
// or build the uri.
var uri = (si.StubLevel >= AasIdentifiableSideInfoLevel.IdWithEndpoint && si.Endpoint != null)
? si.Endpoint
: lambdaBuildRessourceForNoEndpoint(_defaultRepoBaseUri, idf.Id);
if (uri == null)
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,30 +707,52 @@ await PackageHttpDownloadUtil.HttpGetToMemoryStream(
prepAas.Add(aas, aasSi);

// check if to add the Submodels
// be prepared to download them
var numRes = await DownloadListOfIdentifiables<Aas.ISubmodel, AasIdentifiableSideInfo>(
smRegged,
lambdaGetLocation: (si) => si.Endpoint,
runtimeOptions: runtimeOptions,
allowFakeResponses: allowFakeResponses,
lambdaDownloadDoneOrFail: (code, sm, contentFn, si) =>
{
// error ?
if (code != HttpStatusCode.OK)
if (!record.AutoLoadOnDemand)
{
// be prepared to download them
var numRes = await DownloadListOfIdentifiables<Aas.ISubmodel, AasIdentifiableSideInfo>(
smRegged,
lambdaGetLocation: (si) => si.Endpoint,
runtimeOptions: runtimeOptions,
allowFakeResponses: allowFakeResponses,
lambdaDownloadDoneOrFail: (code, sm, contentFn, si) =>
{
Log.Singleton.Error(
"Could not download Submodel from endpoint given by registry: {0}",
si.Endpoint.ToString());
// error ?
if (code != HttpStatusCode.OK)
{
Log.Singleton.Error(
"Could not download Submodel from endpoint given by registry: {0}",
si.Endpoint.ToString());

// add as pure side info
si.IsStub = true;
prepSM.Add(null, si);
}
// add as pure side info
si.IsStub = true;
prepSM.Add(null, si);
}

// no, add with data
si.IsStub = false;
prepSM.Add(sm, si);
});
// no, add with data
si.IsStub = false;
prepSM.Add(sm, si);
});
}
else
{
foreach (var si in smRegged)
{
// valid Id is required
if (si?.Id?.HasContent() != true)
continue;

// for the Submodels add Identifiables with null content, but side infos
var siEx = prepSM.FindSideInfoFromId(si.Id);
if (siEx != null)
// already existing!
continue;

// need to do
si.IsStub = true;
prepSM.Add(null, si);
}
}

// a little debug
runtimeOptions?.Log?.Info(StoredPrint.Color.Blue,
Expand All @@ -745,7 +767,7 @@ await PackageHttpDownloadUtil.HttpGetToMemoryStream(
// REPO
//

if (record.BaseType == ConnectExtendedRecord.BaseTypeEnum.Registry)
if (record.BaseType == ConnectExtendedRecord.BaseTypeEnum.Repository)
{
// start with a list of AAS or Submodels (very similar)
var isAllAAS = IsValidUriForRepoAllAAS(fullItemLocation);
Expand Down

0 comments on commit 49eab51

Please sign in to comment.