Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/AasxCsharpLibrary/AdminShellUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1458,11 +1458,21 @@ public static bool CheckIfUriIsAttachment(string uri)
if (uri?.HasContent() != true || uri.Length < 2)
return false;

// first char needs to be a slash, second must not be a slash!!
// Note: URIs starting with double slashes are called protocol-relative URLs or scheme-relative URIs
// can extract scheme and path -> no attachment
var p = uri.IndexOf("://");
if (p >= 0 && p <= 5)
return false;

// old style supplemental files: first char needs to be a slash, second must not be a slash!!
// Note: URIs starting with double slashes are called protocol-relative URLs or scheme-relative URIs
if (uri[0] == '/' && uri[2] != '/')
return true;

// Basyx style for attachment: starting with a 'normal' char
if (char.IsAsciiLetterOrDigit(uri[0]))
return true;

// rest of the cases: assume is external
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/AasxCsharpLibrary/Extensions/ExtendEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,7 @@ public static List<IReferable> RenameIdentifiable<T>(this AasCore.Aas3_0.IEnviro
{
// directly replace
r.Keys[i].Value = newId;
if (res.Contains(lr.Identifiable))
if (!res.Contains(lr.Identifiable))
res.Add(lr.Identifiable);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendILangStringNameType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,15 @@ public static bool IsValid(this List<ILangStringNameType> elems)
return false;
return true;
}

public static bool Contains(this List<ILangStringNameType> elems, String value, StringComparison comparisonType)
{
if (elems == null || elems.Count < 1)
return false;
var res = false;
foreach (var ls in elems)
res = res || ls?.Text?.Contains(value, comparisonType) == true;
return res;
}
}
}
10 changes: 10 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendILangStringTextType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,15 @@ public static bool IsValid(this List<ILangStringTextType> elems)
return false;
return true;
}

public static bool Contains(this List<ILangStringTextType> elems, String value, StringComparison comparisonType)
{
if (elems == null || elems.Count < 1)
return false;
var res = false;
foreach (var ls in elems)
res = res || ls?.Text?.Contains(value, comparisonType) == true;
return res;
}
}
}
4 changes: 2 additions & 2 deletions src/AasxCsharpLibrary/Extensions/ExtendIReferable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public static Submodel GetParentSubmodel(this IReferable referable)
return parent as Submodel;
}

public static string CollectIdShortByParent(
public static string CollectIdShortPathByParent(
this IReferable referable,
char separatorChar = '/',
bool excludeIdentifiable = false)
Expand All @@ -476,7 +476,7 @@ public static string CollectIdShortByParent(
&& referable.Parent is IReferable parentReferable
&& (!excludeIdentifiable || parentReferable is not IIdentifiable))
// can go up
head = parentReferable.CollectIdShortByParent(separatorChar, excludeIdentifiable)
head = parentReferable.CollectIdShortPathByParent(separatorChar, excludeIdentifiable)
+ separatorChar;
// add own
var myid = "<no id-Short!>";
Expand Down
28 changes: 28 additions & 0 deletions src/AasxCsharpLibrary/Extensions/ExtendISubmodelElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,34 @@ public static IEnumerable<ISubmodelElement> Join(params IEnumerable<ISubmodelEle
yield return sme;
}

public static string CollectIdShortPathBySmeAndParents(
IReferable sme,
IEnumerable<IReferable> parents,
char separatorChar = '/',
bool excludeIdentifiable = false)
{
// access
if (sme == null)
return null;
var path = "" + sme.IdShort?.Trim();

// now put the parents in front
if (parents != null)
foreach (var parent in parents.Reverse())
{
// exclude
if (parent == null || string.IsNullOrEmpty(parent.IdShort))
continue;
if (excludeIdentifiable && parent is IIdentifiable)
continue;
// prepend
path = parent.IdShort.Trim() + separatorChar + path;
}

// ok
return path;
}

public static void RecurseOnReferables(
this List<ISubmodelElement> submodelElements, object state, List<IReferable> parents,
Func<object, List<IReferable>, IReferable, bool> lambda)
Expand Down
5 changes: 3 additions & 2 deletions src/AasxCsharpLibrary/PackageEnv/AdminShellPackageEnvBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,8 @@ public virtual async Task<string> MakePackageFileAvailableAsTempFileAsync(
string aasId = null,
string smId = null,
string idShortPath = null,
bool keepFilename = false)
bool keepFilename = false,
ISecurityAccessHandler secureAccess = null)
{
// this uses the virtual implementation and should therefore work ok in the base class

Expand All @@ -686,7 +687,7 @@ public virtual async Task<string> MakePackageFileAvailableAsTempFileAsync(

// get input stream
var inputBytes = await GetBytesFromPackageOrExternalAsync(packageUri, aasId, smId,
idShortPath: idShortPath);
idShortPath: idShortPath, secureAccess: secureAccess);
if (inputBytes == null)
return null;

Expand Down
2 changes: 1 addition & 1 deletion src/AasxIntegrationBaseGdi/AnyUI/AnyUiMagickHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public void Add(
if (package == null || aas == null || submodel == null || fileElem == null)
return;

var idShortPath = "" + fileElem.CollectIdShortByParent(
var idShortPath = "" + fileElem.CollectIdShortPathByParent(
separatorChar: '.', excludeIdentifiable: true);


Expand Down
155 changes: 11 additions & 144 deletions src/AasxPackageExplorer/MainWindow.CommandBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ public string DetermineInitialDirectory(string existingFn = null)
/// <summary>
/// Redraw tree elements (middle), AAS entitty (right side)
/// </summary>
public void CommandExecution_RedrawAll()
public async Task CommandExecution_RedrawAllAsync()
{
// redraw everything
RedrawAllAasxElements();
RedrawElementView();
await RedrawAllAasxElementsAsync();
await RedrawElementViewAsync();
}

/// <summary>
Expand Down Expand Up @@ -307,9 +307,9 @@ private async Task CommandBinding_GeneralDispatch(
currMdo = DisplayElements.SelectedItem.GetMainDataObject();

// edit mode affects the total element view
RedrawAllAasxElements();
await RedrawAllAasxElementsAsync();
// fake selection
RedrawElementView();
await RedrawElementViewAsync();
// select last object
if (currMdo != null)
{
Expand Down Expand Up @@ -468,7 +468,7 @@ public void PanelConcurrentSetVisibleIfRequired(
}
}

public void CommandBinding_CheckAndFix()
public async Task CommandBinding_CheckAndFix()
{
// work on package
var msgBoxHeadline = "Check, validate and fix ..";
Expand Down Expand Up @@ -561,7 +561,7 @@ public void CommandBinding_CheckAndFix()
AnyUiMessageBoxButton.OK, AnyUiMessageBoxImage.Information);

// redraw
CommandExecution_RedrawAll();
await CommandExecution_RedrawAllAsync();
}
}

Expand Down Expand Up @@ -1274,7 +1274,7 @@ public bool MenuSelectOpenFilename(
return true;
}

public void CommandBinding_ImportDictToSubmodel(
public async Task CommandBinding_ImportDictToSubmodel(
string cmd,
AasxMenuActionTicket ticket = null)
{
Expand Down Expand Up @@ -1326,7 +1326,7 @@ public void CommandBinding_ImportDictToSubmodel(
if (dataChanged)
{
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
RestartUIafterNewPackage();
await RestartUIafterNewPackage();
Mouse.OverrideCursor = null;
}
#endif
Expand Down Expand Up @@ -1362,7 +1362,7 @@ public void CommandBinding_ImportDictToSubmodel(
if (dataChanged)
{
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
RestartUIafterNewPackage();
await RestartUIafterNewPackage();
Mouse.OverrideCursor = null;
}
#endif
Expand Down Expand Up @@ -1398,141 +1398,8 @@ public async Task CommandBinding_ExportImportTableUml(
$"Import/Export: While displaying html-based help.");
}
};
// dead-csharp off
//if (cmd == "exporttable" || cmd == "importtable")
//{
// if (ticket?.ScriptMode != true)
// {
// // interactive
// // handle the export dialogue
// var uc = new ExportTableFlyout((cmd == "exporttable")
// ? "Export SubmodelElements as Table"
// : "Import SubmodelElements from Table");
// uc.Presets = Logic?.GetImportExportTablePreset().Item1;

// StartFlyoverModal(uc);

// if (uc.CloseForHelp)
// {
// callHelp?.Invoke();
// return;
// }

// if (uc.Result == null)
// return;

// // have a result
// var record = uc.Result;

// // be a little bit specific
// var dlgTitle = "Select text file to be exported";
// var dlgFileName = "";
// var dlgFilter = "";

// if (record.Format == (int)ImportExportTableRecord.FormatEnum.TSF)
// {
// dlgFileName = "new.txt";
// dlgFilter =
// "Tab separated file (*.txt)|*.txt|Tab separated file (*.tsf)|*.tsf|All files (*.*)|*.*";
// }
// if (record.Format == (int)ImportExportTableRecord.FormatEnum.LaTex)
// {
// dlgFileName = "new.tex";
// dlgFilter = "LaTex file (*.tex)|*.tex|All files (*.*)|*.*";
// }
// if (record.Format == (int)ImportExportTableRecord.FormatEnum.Excel)
// {
// dlgFileName = "new.xlsx";
// dlgFilter = "Microsoft Excel (*.xlsx)|*.xlsx|All files (*.*)|*.*";
// }
// if (record.Format == (int)ImportExportTableRecord.FormatEnum.Word)
// {
// dlgFileName = "new.docx";
// dlgFilter = "Microsoft Word (*.docx)|*.docx|All files (*.*)|*.*";
// }
// if (record.Format == (int)ImportExportTableRecord.FormatEnum.NarkdownGH)
// {
// dlgFileName = "new.md";
// dlgFilter = "Markdown (*.md)|*.md|All files (*.*)|*.*";
// }

// // store
// ticket["Record"] = record;

// // ask now for a filename
// if (!(await DisplayContext.MenuSelectSaveFilenameToTicketAsync(
// ticket, "File",
// dlgTitle,
// dlgFileName,
// dlgFilter,
// "Import/ export table: No valid filename.")))
// return;
// }

// // pass on
// try
// {
// Logic?.CommandBinding_GeneralDispatchHeadless(cmd, null, ticket);
// }
// catch (Exception ex)
// {
// Logic?.LogErrorToTicket(ticket, ex, "Import/export table: passing on.");
// }
//}

//if (cmd == "importtimeseries")
//{
// if (ticket?.ScriptMode != true)
// {
// // interactive
// // handle the export dialogue
// var uc = new ImportTimeSeriesFlyout();
// uc.Result = Logic?.GetImportExportTablePreset().Item3 ?? new ImportTimeSeriesRecord();

// StartFlyoverModal(uc);

// if (uc.Result == null)
// return;

// // have a result
// var result = uc.Result;

// // store
// ticket["Record"] = result;

// // be a little bit specific
// var dlgTitle = "Select file for time series import ..";
// var dlgFilter = "All files (*.*)|*.*";

// if (result.Format == (int)ImportTimeSeriesRecord.FormatEnum.Excel)
// {
// dlgFilter =
// "Tab separated file (*.txt)|*.txt|Tab separated file (*.tsf)|*.tsf|All files (*.*)|*.*";
// }

// // ask now for a filename
// if (!(await DisplayContext.MenuSelectOpenFilenameToTicketAsync(
// ticket, "File",
// dlgTitle,
// null,
// dlgFilter,
// "Import time series: No valid filename.")))
// return;
// }

// // pass on
// try
// {
// Logic?.CommandBinding_GeneralDispatchHeadless(cmd, null, ticket);
// }
// catch (Exception ex)
// {
// Logic?.LogErrorToTicket(ticket, ex, "Import time series: passing on.");
// }
//}
// dead-csharp on
// redraw
CommandExecution_RedrawAll();
await CommandExecution_RedrawAllAsync();
}

public async Task CommandBinding_ToolsFind(
Expand Down
Loading
Loading