Skip to content

Commit

Permalink
* 1st overall progress
Browse files Browse the repository at this point in the history
   working for repo load
  • Loading branch information
festo-i40 committed Dec 23, 2024
1 parent e6d6bcb commit bb20c1b
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 66 deletions.
62 changes: 55 additions & 7 deletions src/AasxPackageExplorer/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,31 @@
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>

<!-- use central ressources shared by all projects -->
<ResourceDictionary Source="pack://application:,,,/AasxIntegrationBaseWpf;component/Themes/Generic.xaml"/>

<!-- define some own ressources -->
<ResourceDictionary>

<Style x:Key="TranspBackground" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" BorderBrush="Transparent" BorderThickness="0">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Transparent"/>
</Trigger>
</Style.Triggers>
</Style>

</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Expand Down Expand Up @@ -71,7 +94,9 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Menu x:Name="MenuMain" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0" VerticalAlignment="Center" FontSize="14" Background="Transparent">
<Menu Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0"
x:Name="MenuMain"
VerticalAlignment="Center" FontSize="14" Background="Transparent">
</Menu>

<Grid Grid.Column="2">
Expand Down Expand Up @@ -215,7 +240,7 @@
</Viewbox>
</Border>

<Border Grid.Row="2" Grid.Column="0"
<Border Grid.Row="2" Grid.Column="0" x:Name="BorderContainerList"
BorderThickness="1.0" BorderBrush="{DynamicResource DarkestAccentColor}" CornerRadius="6"
Margin="2,0,0,0" Padding="2">
<repo:PackageContainerListOfListControl x:Name="RepoListControl" >
Expand All @@ -226,14 +251,14 @@


<!-- MIHO1 -->
<Border Grid.Row="0" Grid.Column="2"
<Border Grid.Row="0" Grid.Column="2" x:Name="BorderDisplayElements"
BorderThickness="1.0" BorderBrush="{DynamicResource DarkestAccentColor}" CornerRadius="6"
Margin="0,2,0,0" Padding="2">
<local:DiplayVisualAasxElements x:Name="DisplayElements" SelectedItemChanged="DisplayElements_SelectedItemChanged" MouseDoubleClick="DisplayElements_MouseDoubleClick">
</local:DiplayVisualAasxElements>
</Border>

<Border Grid.Row="0" Grid.Column="4"
<Border Grid.Row="0" Grid.Column="4" x:Name="BorderEditElements"
BorderThickness="1.0" BorderBrush="{DynamicResource DarkestAccentColor}" CornerRadius="6"
Margin="0,2,2,0" Padding="2">
<TabControl x:Name="ElementTabControl" MinWidth="320" BorderBrush="White">
Expand Down Expand Up @@ -365,17 +390,40 @@
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ProgressBar x:Name="ProgressBarInfo"

<!-- left column: overall progress -->
<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"
Background="White"
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"
Content="&#x2bbe;">
</Button>

<!-- right column: progress bar for single download -->
<ProgressBar Grid.Row="0" Grid.Column="2" x:Name="ProgressBarDownload"
BorderBrush="LightGray"
Background="Transparent" Foreground="{DynamicResource DarkAccentColor}"
MinWidth="120" Margin="2,3,6,2"/>
<Label Grid.Row="0" Grid.Column="0" x:Name="LabelProgressBarInfo"
<Label Grid.Row="0" Grid.Column="2" x:Name="LabelProgressBarDownload"
Content="0 bytes" Foreground="LightGray"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</Grid>

<Label x:Name="Message" VerticalContentAlignment="Center"></Label>
<Label x:Name="Message"
Margin="2,3,2,2" Padding="0, 0, 0, 2"
Content="Ready"
VerticalContentAlignment="Center"/>
</DockPanel>

</Grid>
Expand Down
83 changes: 64 additions & 19 deletions src/AasxPackageExplorer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This source code may use other Open Source software components (see LICENSE.txt)
using Extensions;
using Microsoft.Win32;
using Newtonsoft.Json;
using NPOI.POIFS.Properties;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -312,18 +313,34 @@ private PackCntRuntimeOptions UiBuildRuntimeOptionsForMainAppLoad()
var ro = new PackCntRuntimeOptions()
{
Log = Log.Singleton,
ProgressChanged = (state, tfs, tbd) =>
ProgressChanged = (state, tfs, tbd, msg) =>
{
if (state == PackCntRuntimeOptions.Progress.Starting
|| state == PackCntRuntimeOptions.Progress.Ongoing)
SetProgressBar(
Math.Min(100.0, 100.0 * tbd / (tfs.HasValue ? tfs.Value : 5 * 1024 * 1024)),
AdminShellUtil.ByteSizeHumanReadable(tbd));
if (state == PackCntRuntimeOptions.Progress.StartOverall)
{
SetProgressOverall(true, msg);
}

if (state == PackCntRuntimeOptions.Progress.OverallMessage)
{
SetProgressOverall(true, msg);
}

if (state == PackCntRuntimeOptions.Progress.Final)
if (state == PackCntRuntimeOptions.Progress.EndOverall)
{
SetProgressOverall(false, msg);
}

if ((state == PackCntRuntimeOptions.Progress.StartDownload
|| state == PackCntRuntimeOptions.Progress.PerformDownload)
&& tfs.HasValue && tbd.HasValue)
SetProgressDownload(
Math.Min(100.0, 100.0 * tbd.Value / (tfs.HasValue ? tfs.Value : 5 * 1024 * 1024)),
AdminShellUtil.ByteSizeHumanReadable(tbd.Value));

if (state == PackCntRuntimeOptions.Progress.EndDownload)
{
// clear
SetProgressBar();
SetProgressDownload();

// close message boxes
if (currentFlyoutControl is IntegratedConnectFlyout)
Expand Down Expand Up @@ -957,7 +974,7 @@ private async void Window_Loaded(object sender, RoutedEventArgs e)
// attach result search
ToolFindReplace.Flyout = this;
ToolFindReplace.ResultSelected += ToolFindReplace_ResultSelected;
ToolFindReplace.SetProgressBar += SetProgressBar;
ToolFindReplace.SetProgressBar += SetProgressDownload;

// Package Central starting ..
PackageCentral.CentralRuntimeOptions = UiBuildRuntimeOptionsForMainAppLoad();
Expand Down Expand Up @@ -1860,7 +1877,8 @@ private void UiHandleReRenderAnyUiInEntityPanel(

var newIdfs = new List<Aas.IIdentifiable>();
var loadedIdfs = new List<Aas.IIdentifiable>();
var loadRes = await PackageContainerHttpRepoSubset.LoadFromSourceInternalAsync(

var loadRes = await PackageContainerHttpRepoSubset.LoadFromSourceToTargetAsync(
fullItemLocation: fullItemLocation,
targetEnv: packEnv,
loadNew: false,
Expand Down Expand Up @@ -2875,22 +2893,48 @@ public void TriggerPendingReIndexElements()
_mainTimer_PendingReIndexElements = true;
}

private void SetProgressBar()
private void SetProgressOverallIsEnabled(bool active)
{
BorderDisplayElements.IsEnabled = active;
BorderEditElements.IsEnabled = active;
BorderContainerList.IsEnabled = active;
MenuMain.IsEnabled = active;
}

private void SetProgressOverall(bool active, string message)
{
ProgressBarDownload.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(() => {
TextBlockProgressOverall.Background = (active) ? Brushes.DarkGreen : Brushes.White;
TextBlockProgressOverall.Text = "" + message;
ButtonProgressOverallClear.Visibility = (active) ? Visibility.Visible : Visibility.Collapsed;
// an active == true will set all controls to isEnabled == false!! and vice versa
SetProgressOverallIsEnabled(!active);
} ));
}

private void ButtonProgressOverallClear_Click(object sender, RoutedEventArgs e)
{
SetProgressOverall(false, "");
}

private void SetProgressDownload()
{
SetProgressBar(0.0, "");
SetProgressDownload(0.0, "");
}

private void SetProgressBar(double? percent, string message = null)
private void SetProgressDownload(double? percent, string message = null)
{
if (percent.HasValue)
ProgressBarInfo.Dispatcher.BeginInvoke(
ProgressBarDownload.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(() => ProgressBarInfo.Value = percent.Value));
new Action(() => ProgressBarDownload.Value = percent.Value));

if (message != null)
LabelProgressBarInfo.Dispatcher.BeginInvoke(
LabelProgressBarDownload.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(() => LabelProgressBarInfo.Content = message));
new Action(() => LabelProgressBarDownload.Content = message));
}

private async Task ButtonHistory_ObjectRequested(object sender, VisualElementHistoryItem hi)
Expand Down Expand Up @@ -3011,7 +3055,7 @@ public void StatusLineClear()
Message.Background = Brushes.White;
Message.Foreground = Brushes.Black;
Message.FontWeight = FontWeights.Normal;
SetProgressBar();
SetProgressDownload();
}

/// <summary>
Expand Down Expand Up @@ -3081,7 +3125,7 @@ public void SaveScreenshot(string filename = "noname")
filename += ".png";

// needs to be the main thread
ProgressBarInfo.Dispatcher.BeginInvoke(
ProgressBarDownload.Dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Background,
new Action(() =>
{
Expand Down Expand Up @@ -4278,5 +4322,6 @@ private async void Button_Click(object sender, RoutedEventArgs e)
}
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ internal async Task<string> LoadAasxPackageAsync(string packageId, PackCntRuntim

if (fileSize > totalBytes)
{
runtimeOptions?.ProgressChanged?.Invoke(PackCntRuntimeOptions.Progress.Ongoing,
runtimeOptions?.ProgressChanged?.Invoke(PackCntRuntimeOptions.Progress.PerformDownload,
fileSize, totalBytes);
}
else
{
runtimeOptions?.ProgressChanged?.Invoke(PackCntRuntimeOptions.Progress.Final, fileSize, totalBytes);
runtimeOptions?.ProgressChanged?.Invoke(PackCntRuntimeOptions.Progress.EndDownload, fileSize, totalBytes);
runtimeOptions?.Log?.Info($".. download done with {totalBytes} bytes read!");
}

Expand Down
11 changes: 8 additions & 3 deletions src/AasxPackageLogic/PackageCentral/PackageContainerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ public class PackageContainerCredentials
/// </summary>
public class PackCntRuntimeOptions
{
public enum Progress { Idle, Starting, Ongoing, Final }

public delegate void ProgressChangedHandler(Progress state, long? totalFileSize, long totalBytesDownloaded);
public enum Progress {
Idle,
StartOverall, EndOverall,
StartDownload, PerformDownload, EndDownload,
OverallMessage }

public delegate void ProgressChangedHandler(
Progress state, long? totalFileSize = null, long? totalBytesDownloaded = null, string message = "");

public delegate void AskForSelectFromListHandler(
string caption, List<AnyUiDialogueListItem> list,
Expand Down
Loading

0 comments on commit bb20c1b

Please sign in to comment.