Skip to content

Commit

Permalink
* update
Browse files Browse the repository at this point in the history
* better monitoring of
   fetch
  • Loading branch information
festo-i40 committed Dec 25, 2024
1 parent bb20c1b commit 962bf0b
Show file tree
Hide file tree
Showing 16 changed files with 359 additions and 79 deletions.
6 changes: 6 additions & 0 deletions src/AasxCsharpLibrary/AdminShellCollections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public class MultiValueDictionary<K, V>

public void Add(K key, V value)
{
if (key == null)
return;

if (dict.TryGetValue(key, out var list))
list.Add(value);
else
Expand All @@ -41,6 +44,9 @@ public void Add(K key, V value)

public void AddIfValueIsNew(K key, V value)
{
if (key == null)
return;

if (dict.TryGetValue(key, out var list))
{
if (!list.Contains(value))
Expand Down
9 changes: 6 additions & 3 deletions src/AasxPackageExplorer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,18 @@
<TextBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
x:Name="TextBlockProgressOverall"
BorderBrush="LightGray" Padding="2, 2, 2, 2" Margin="0,3,0,2"
Text="inactive" Foreground="LightGray"
Text="" Foreground="LightGray"
Background="White"
IsReadOnly="true"
IsReadOnlyCaretVisible="False"
MinWidth="120"/>

<Button Grid.Row="0" Grid.Column="1" x:Name="ButtonProgressOverallClear"
Style="{DynamicResource TranspBackground}"
FontSize="16" Foreground="LightGray"
BorderThickness="0" Background="Transparent"
Click="ButtonProgressOverallClear_Click"
Visibility="Collapsed"
Content="&#x2bbe;">
</Button>

Expand All @@ -416,12 +419,12 @@
Background="Transparent" Foreground="{DynamicResource DarkAccentColor}"
MinWidth="120" Margin="2,3,6,2"/>
<Label Grid.Row="0" Grid.Column="2" x:Name="LabelProgressBarDownload"
Content="0 bytes" Foreground="LightGray"
Content="" Foreground="LightGray"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</Grid>

<Label x:Name="Message"
Margin="2,3,2,2" Padding="0, 0, 0, 2"
Margin="2,3,2,2" Padding="0, 2, 0, 0"
Content="Ready"
VerticalContentAlignment="Center"/>
</DockPanel>
Expand Down
120 changes: 81 additions & 39 deletions src/AasxPackageExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ private PackCntRuntimeOptions UiBuildRuntimeOptionsForMainAppLoad()
SetProgressOverall(true, msg);
}

if (state == PackCntRuntimeOptions.Progress.OverallMessage)
if (state == PackCntRuntimeOptions.Progress.OverallMessage
&& _progressOverallActive)
{
SetProgressOverall(true, msg);
}
Expand Down Expand Up @@ -405,7 +406,8 @@ public void UiLoadPackageWithNew(
string storeFnToLRU = null,
bool indexItems = false,
bool preserveEditMode = false,
bool? nextEditMode = null)
bool? nextEditMode = null,
bool autoFocusFirstRelevant = false)
{
// access
if (packItem == null)
Expand Down Expand Up @@ -459,6 +461,44 @@ public void UiLoadPackageWithNew(
try
{
RestartUIafterNewPackage(onlyAuxiliary, nextEditMode);

if (autoFocusFirstRelevant && PackageCentral.Main?.AasEnv is Aas.IEnvironment menv)
{
VisualElementEnvironmentItem.ItemType? eit = null;
var nextLevelExpand = false;

if (menv.AssetAdministrationShellCount() < 1 && menv.SubmodelCount() >= 1)
{
// focus on All Submodels
eit = VisualElementEnvironmentItem.ItemType.AllSubmodels;
}
else
if (menv.AssetAdministrationShellCount() < 1 && menv.SubmodelCount() < 1
&& menv.ConceptDescriptionCount() >= 1)
{
// focus on All CD
eit = VisualElementEnvironmentItem.ItemType.AllConceptDescriptions;
nextLevelExpand = true;
}

// now?
if (eit.HasValue)
{
DisplayElements.ExpandAllItems();
var ve = DisplayElements.FindAllVisualElementTop()
.Where((ve) => ve is VisualElementEnvironmentItem veei && veei.theItemType == eit.Value)
.FirstOrDefault();

// one level deeper expanded
if (nextLevelExpand && ve?.Members != null)
foreach (var child in ve.Members)
if (child != null)
child.IsExpanded = true;

// show this
DisplayElements.TrySelectVisualElement(ve, wishExpanded: true);
}
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -501,25 +541,6 @@ public void UiLoadPackageWithNew(
return;
}

/* TODO (MIHO, 2021-12-27): consider extending for better testing or
* script running */
#if __leave_in_for_accelerated_tet
if (false)
{
var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(4) };
timer.Tick += (sender, args) =>
{
timer.Stop();
var pluginName = "AasxPluginExportTable";
var actionName = "export-uml";
var pi = Plugins.FindPluginInstance(pluginName);
pi?.InvokeAction(actionName, this, _packageCentral?.Main?.AasEnv,
_packageCentral?.Main?.AasEnv?.Submodels[0], "test.uml");

};
timer.Start();
}
#endif

// done
Log.Singleton.Info("AASX {0} loaded.", info);
Expand Down Expand Up @@ -1076,16 +1097,27 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
};

// refer to (static) function
var res = await DispEditHelperEntities.ExecuteUiForFetchOfElements(
PackageCentral, DisplayContext,
ticket: null,
mainWindow: this,
fetchContext: fetchContext,
preserveEditMode: true,
doEditNewRecord: true,
doCheckTainted: true,
doFetchGoNext: false,
doFetchExec: true);
try
{
var res = await DispEditHelperEntities.ExecuteUiForFetchOfElements(
PackageCentral, DisplayContext,
ticket: null,
mainWindow: this,
fetchContext: fetchContext,
preserveEditMode: true,
doEditNewRecord: true,
doCheckTainted: true,
doFetchGoNext: false,
doFetchExec: true);
}
catch (OperationCanceledException)
{
Log.Singleton.Info("User cancellation: Repository/ Registry fetch.");
}
catch (Exception ex)
{
Log.Singleton.Error(ex, "when performing Repository/ Registry fetch");
}
}
}

Expand Down Expand Up @@ -2901,8 +2933,12 @@ private void SetProgressOverallIsEnabled(bool active)
MenuMain.IsEnabled = active;
}

protected bool _progressOverallActive = false;

private void SetProgressOverall(bool active, string message)
{
_progressOverallActive = active;

ProgressBarDownload.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(() => {
Expand All @@ -2917,6 +2953,8 @@ private void SetProgressOverall(bool active, string message)
private void ButtonProgressOverallClear_Click(object sender, RoutedEventArgs e)
{
SetProgressOverall(false, "");
if (PackageCentral.CentralRuntimeOptions?.CancellationTokenSource != null)
PackageCentral.CentralRuntimeOptions.CancellationTokenSource.Cancel();
}

private void SetProgressDownload()
Expand Down Expand Up @@ -3197,13 +3235,16 @@ private async void DisplayElements_MouseDoubleClick(object sender, MouseButtonEv
return;
}

// at the end?
if (siei.theItemType == VisualElementEnvironmentItem.ItemType.FetchNext
&& fetchContext.Cursor?.HasContent() != true)
// at the start or end?
var goPrev = siei.theItemType == VisualElementEnvironmentItem.ItemType.FetchPrev;
var goNext = siei.theItemType == VisualElementEnvironmentItem.ItemType.FetchNext;
var goNextFake = false;
if (goNext && fetchContext.Cursor?.HasContent() != true)
{
Log.Singleton.Error("No further fetch operation available " +
"(at the end of the selected subset of elements?).");
return;
Log.Singleton.Info(StoredPrint.Color.Blue, "No cursor for fetch operation available " +
"(at the end of the selected subset of elements or no server support).");
goNext = false;
goNextFake = true;
}

// refer to (static) function
Expand All @@ -3212,8 +3253,9 @@ private async void DisplayElements_MouseDoubleClick(object sender, MouseButtonEv
preserveEditMode: true,
doEditNewRecord: false,
doCheckTainted: true,
doFetchGoPrev: siei.theItemType == VisualElementEnvironmentItem.ItemType.FetchPrev,
doFetchGoNext: siei.theItemType == VisualElementEnvironmentItem.ItemType.FetchNext,
doFetchGoPrev: goPrev,
doFetchGoNext: goNext,
doFakeGoNext: goNextFake,
doFetchExec: true);

// success will trigger redraw independently, therefore always do nothing
Expand Down
3 changes: 2 additions & 1 deletion src/AasxPackageExplorer/debug.MIHO.script
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
// Tool("exportsmtasciidoc", "File", "C:\\HOMI\\Develop\\Aasx\\repo\\new.zip", "AntoraStyle", "true");
Tool("editkey");
// Tool("createrepofromapi", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository");
Tool("connectextended", "BaseAddress", "http://smt-repo.admin-shell-io.com/api/v3.0", "BaseType", "Repository", "AasId", "https://admin-shell.io/idta/aas/DigitalNameplate/3/0", "AutoLoadOnDemand", "false", "AutoLoadCds", "true");
Tool("connectextended", "BaseAddress", "http://smt-repo.admin-shell-io.com/api/v3.0", "BaseType", "Repository", "GetAllAas", "false", "GetSingleAas", "true", "AasId", "https://admin-shell.io/idta/aas/DigitalNameplate/3/0", "AutoLoadOnDemand", "false", "AutoLoadCds", "true", "ParallelReads", "10");
// Tool("connectextended", "BaseAddress", "http://smt-repo.admin-shell-io.com/api/v3.0", "BaseType", "Repository", "GetSingleAas", "false", "GetAllAas", "true", "PageLimit", "4", "AutoLoadOnDemand", "false", "AutoLoadCds", "true");
// Tool("connectextended", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository", "GetSingleAas", "false", "GetAllAas", "true", "PageLimit", "99", "AutoLoadOnDemand", "false");
// Tool("connectextended", "BaseAddress", "http://localhost:5001/api/v3.0/", "BaseType", "Repository", "GetSingleAas", "true", "AasId", "http://smart.festo.com/id/demo-box/aas/instance/99920202206560529000071817", "AutoLoadOnDemand", "false");
// Tool("connectextended", "BaseAddress", "https://eis-data.aas-voyager.com/", "BaseType", "Repository", "GetSingleAas", "true", "PageLimit", "2", "AutoLoadOnDemand", "false", "AasId", "https://new.abb.com/products/de/2CSF204101R1400/aas");
Expand Down
17 changes: 15 additions & 2 deletions src/AasxPackageLogic/DispEditHelperEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ public static async Task<bool> ExecuteUiForFetchOfElements(
bool doEditNewRecord = false,
bool doFetchGoPrev = false,
bool doFetchGoNext = false,
bool doFakeGoNext = false,
bool doFetchExec = false)
{
await Task.Yield();
Expand Down Expand Up @@ -1545,6 +1546,15 @@ public static async Task<bool> ExecuteUiForFetchOfElements(
fetchContext.Record.PageSkip = 0;
}

if (doFakeGoNext)
{
// provide no cursor, therefore fetch from very beginning, skip elements
fetchContext.Cursor = null;
fetchContext.Record.PageSkip = Math.Max(0, fetchContext.Record.PageOffset + fetchContext.Record.PageLimit);
fetchContext.Record.PageOffset += fetchContext.Record.PageLimit;
fetchContext.Record.PageOffset = Math.Max(0, fetchContext.Record.PageOffset);
}

if (doFetchExec)
{
// build location
Expand All @@ -1568,6 +1578,8 @@ public static async Task<bool> ExecuteUiForFetchOfElements(
Log.Singleton.Info($"For refining extended connect, loading " +
$"from {location} into container");

packages.CentralRuntimeOptions.CancellationTokenSource = new System.Threading.CancellationTokenSource();

var container = await PackageContainerFactory.GuessAndCreateForAsync(
packages,
location,
Expand All @@ -1578,15 +1590,16 @@ public static async Task<bool> ExecuteUiForFetchOfElements(

if (container == null)
{
Log.Singleton.Error($"Failed to load from {location}");
Log.Singleton.Error($"Failed to load from {location}.");
return false;
}

// display
mainWindow.UiLoadPackageWithNew(packages.MainItem,
takeOverContainer: container, onlyAuxiliary: false, indexItems: true,
storeFnToLRU: location,
preserveEditMode: preserveEditMode);
preserveEditMode: preserveEditMode,
autoFocusFirstRelevant: true);

Log.Singleton.Info($"Successfully loaded {location}");

Expand Down
3 changes: 2 additions & 1 deletion src/AasxPackageLogic/IMainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void UiLoadPackageWithNew(
string storeFnToLRU = null,
bool indexItems = false,
bool preserveEditMode = false,
bool? nextEditMode = null);
bool? nextEditMode = null,
bool autoFocusFirstRelevant = false);

public Task<Aas.IIdentifiable> UiSearchRepoAndExtendEnvironmentAsync(
AdminShellPackageEnvBase packEnv,
Expand Down
14 changes: 13 additions & 1 deletion src/AasxPackageLogic/MainWindowAnyUiDialogs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography.Pkcs;
Expand Down Expand Up @@ -218,20 +219,27 @@ public async Task CommandBinding_GeneralDispatchAnyUiDialogs(
}

// shall be a local/ user file?!
var proposeFn = PackageCentral.MainItem.Filename;
var isLocalFile = PackageCentral.MainItem.Container is PackageContainerLocalFile;
var isUserFile = PackageCentral.MainItem.Container is PackageContainerUserFile;
if (!isLocalFile && !isUserFile)
{
// warn
if (!ticket.ScriptMode
&& AnyUiMessageBoxResult.Yes != await DisplayContext.MessageBoxFlyoutShowAsync(
"Current AASX file is not a local or user file. Proceed and convert to such file?",
"Save", AnyUiMessageBoxButton.YesNo, AnyUiMessageBoxImage.Hand))
return;

// point to local directory
proposeFn = System.IO.Path.GetFileName(proposeFn);
}

// filename
var ucsf = await DisplayContextPlus.MenuSelectSaveFilenameAsync(
ticket, "File",
"Save AASX package",
PackageCentral.MainItem.Filename,
proposeFn,
"AASX package files (*.aasx)|*.aasx|AASX package files w/ JSON (*.aasx)|*.aasx|" +
(!isLocalFile ? "" : "AAS XML file (*.xml)|*.xml|AAS JSON file (*.json)|*.json|") +
"All files (*.*)|*.*",
Expand Down Expand Up @@ -524,6 +532,10 @@ await val.PerformDialogue(ticket, DisplayContext,
doFetchGoNext: false,
doFetchExec: true);
}
catch (OperationCanceledException)
{
Log.Singleton.Info("User cancellation: extended connect");
}
catch (Exception ex)
{
LogErrorToTicket(ticket, ex, "when performing extended connect");
Expand Down
11 changes: 10 additions & 1 deletion src/AasxPackageLogic/PackageCentral/PackageContainerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Aas = AasCore.Aas3_0;

Expand Down Expand Up @@ -80,6 +81,13 @@ public delegate AnyUiMessageBoxResult ShowMessageDelegate(
/// Log more
/// </summary>
public bool ExtendedConnectionDebug = false;

/// <summary>
/// Set by the main application in order to be able to cancel an operation
/// Note: Normally, only CancellationTokenSource().Token shall be passed, however this
/// is used as source of truth.
/// </summary>
public CancellationTokenSource CancellationTokenSource = null;
}

/// <summary>
Expand Down Expand Up @@ -370,12 +378,13 @@ public virtual void BackupInDir(string backupDir, int maxFiles, BackupType backu
{
}

public virtual async Task LoadFromSourceAsync(
public virtual async Task<bool> LoadFromSourceAsync(
string fullItemLocation,
PackageContainerOptionsBase containerOptions = null,
PackCntRuntimeOptions runtimeOptions = null)
{
await Task.Yield();
return true;
}

public virtual async Task<bool> SaveLocalCopyAsync(
Expand Down
Loading

0 comments on commit 962bf0b

Please sign in to comment.