diff --git a/src/AasxServer.sln b/src/AasxServer.sln index 4889e184d..09a804b08 100644 --- a/src/AasxServer.sln +++ b/src/AasxServer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.32002.261 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AasxServerCore", "AasxServerCore\AasxServerCore.csproj", "{7C0704A8-85C7-4FC9-B12D-C7B9E63EF7B6}" EndProject diff --git a/src/AasxServerBlazor/Pages/Tree.razor b/src/AasxServerBlazor/Pages/Tree.razor index bed64399f..0a0c11d42 100644 --- a/src/AasxServerBlazor/Pages/Tree.razor +++ b/src/AasxServerBlazor/Pages/Tree.razor @@ -10,99 +10,122 @@ https://github.com/mwinkler/Blazor.Components/blob/master/LICENSE @using static TreePage
- @foreach (var node in Nodes ?? Enumerable.Empty()) - { - var nodeExpanded = ExpandedNodes.Contains(node); - var nodeSelected = node.Equals(SelectedNode); - var hasChilds = HasChildNodes(node); - // @("nodeExpanded " + nodeExpanded + " nodeSelected " + nodeSelected + " hasChilds " + hasChilds) - -
- @if (hasChilds) - { - string iconId = ""; - if (AasxServer.Program.htmlId) - iconId = HtmlId(node as Item) + "._icon"; - - - - } - -
- @{ - string titleId = ""; - if (AasxServer.Program.htmlId) - titleId = HtmlId(node as Item) + "._title"; - - @TitleTemplate(node) @{ /* @(" " + node.GetHashCode() + " ") */ } - - } -
- - @if (hasChilds) - { - if (nodeExpanded) - { - - } - } - -
- } + @foreach (var node in Nodes ?? Enumerable.Empty()) + { + var nodeExpanded = ExpandedNodes.Contains(node); + var nodeSelected = node.Equals(SelectedNode); + var hasChilds = HasChildNodes(node); + var isAas = (node as Item).Tag is AdministrationShell; + var isSubmodel = (node as Item).Tag is Submodel; + var color = ""; + + if (isAas) + { + color = "#88A6D2"; + } + else if (isSubmodel) + { + color = "#CBD8EB"; + } + else + { + color = "#F4F4F5"; + } + // @("nodeExpanded " + nodeExpanded + " nodeSelected " + nodeSelected + " hasChilds " + hasChilds) + @if (hasChilds) + { + + string iconId = ""; + if (AasxServer.Program.htmlId) + iconId = HtmlId(node as Item) + "._icon"; +
+ + + +
+ + } +
+
+ + +
+ @{ + string titleId = ""; + if (AasxServer.Program.htmlId) + titleId = HtmlId(node as Item) + "._title"; + + @TitleTemplate(node) @{ + /* @(" " + node.GetHashCode() + " ") */ + } + + } +
+
+
+ @if (hasChilds) + { + if (nodeExpanded) + { + + } + } + + }
@code { - [Parameter] public IEnumerable Nodes { get; set; } + [Parameter] public IEnumerable Nodes { get; set; } - [Parameter] public RenderFragment TitleTemplate { get; set; } + [Parameter] public RenderFragment TitleTemplate { get; set; } - [Parameter] public TNode SelectedNode { get; set; } - [Parameter] public EventCallback SelectedNodeChanged { get; set; } + [Parameter] public TNode SelectedNode { get; set; } + [Parameter] public EventCallback SelectedNodeChanged { get; set; } - [Parameter] public Func> ChildSelector { get; set; } + [Parameter] public Func> ChildSelector { get; set; } - [Parameter] public IList ExpandedNodes { get; set; } = new List(); - [Parameter] public EventCallback> ExpandedNodesChanged { get; set; } + [Parameter] public IList ExpandedNodes { get; set; } = new List(); + [Parameter] public EventCallback> ExpandedNodesChanged { get; set; } - [Parameter] public TreeStyle Style { get; set; } = TreeStyle.Bootstrap; + [Parameter] public TreeStyle Style { get; set; } = TreeStyle.Bootstrap; - [Parameter] public bool Visible { get; set; } = true; + [Parameter] public bool Visible { get; set; } = true; - [Parameter] public Func HasChildNodes { get; set; } = node => true; + [Parameter] public Func HasChildNodes { get; set; } = node => true; - [Parameter] public Func HtmlId { get; set; } = node => ""; + [Parameter] public Func HtmlId { get; set; } = node => ""; - private void OnToggleNode(TNode node, bool expand) - { - var expanded = ExpandedNodes.Contains(node); + private void OnToggleNode(TNode node, bool expand) + { + var expanded = ExpandedNodes.Contains(node); - if (expanded && !expand) - { - ExpandedNodes.Remove(node); - ExpandedNodesChanged.InvokeAsync(ExpandedNodes); - } - else if (!expanded && expand) - { - ExpandedNodes.Add(node); - ExpandedNodesChanged.InvokeAsync(ExpandedNodes); - } - } + if (expanded && !expand) + { + ExpandedNodes.Remove(node); + ExpandedNodesChanged.InvokeAsync(ExpandedNodes); + } + else if (!expanded && expand) + { + ExpandedNodes.Add(node); + ExpandedNodesChanged.InvokeAsync(ExpandedNodes); + } + } - private void OnSelectNode(TNode node) - { - SelectedNode = node; - SelectedNodeChanged.InvokeAsync(node); - } + private void OnSelectNode(TNode node) + { + SelectedNode = node; + SelectedNodeChanged.InvokeAsync(node); + } } \ No newline at end of file diff --git a/src/AasxServerBlazor/Pages/TreePage.razor b/src/AasxServerBlazor/Pages/TreePage.razor index 9ce8ebd80..f8682e127 100644 --- a/src/AasxServerBlazor/Pages/TreePage.razor +++ b/src/AasxServerBlazor/Pages/TreePage.razor @@ -1,5 +1,6 @@ @page "/" @inject AASService SubmodelService +@inject Microsoft.JSInterop.IJSRuntime JsRuntime; @using Microsoft.IdentityModel.Tokens; @using System @using System.Net; @@ -12,340 +13,400 @@ @implements IDisposable -
-
-
- @updateVisibleTree(Items, selectedNode) - @if (Program.isLoading) - {Loading...} - else - { IO.Swagger.Registry.Controllers.RegistryAndDiscoveryInterfaceApiController.initRegistry(DateTime.UtcNow); } - - - @{ //// SubmodelService.syncSubTree(context); - } - @ViewNodeType(context) - @ViewNodeID(context)@ViewNodeInfo(context) - @getSymbols(context) - @ViewTimeStamp(context) - - -
-
-
- @{ - @ViewNodeType(selectedNode) - @ViewNodeID(selectedNode)
- for (int line = 0; line < 6; line++) - { - string nodeDetails0 = ViewNodeDetails(selectedNode, line, 0); - string nodeDetails1 = ViewNodeDetails(selectedNode, line, 1); - string nodeDetails2 = ViewNodeDetails(selectedNode, line, 2); - if (nodeDetails0 != "" && nodeDetails1 != "") - { - string detailsId="SelectedNodeDetailsLeft_" + line; - @nodeDetails0 - detailsId = "SelectedNodeDetailsRight_" + line; - @nodeDetails1 @nodeDetails2
- } - } - if (selectedNode != null && selectedNode.Tag is Referable r) - { - UPDATE @r.TimeStamp.ToString("yy-MM-dd HH:mm:ss.fff")
-
- CREATE @r.TimeStampCreate.ToString("yy-MM-dd HH:mm:ss.fff")
- @code { - private void setTimeStamp() - { - (selectedNode.Tag as Referable).setTimeStamp(DateTime.UtcNow); - } - } - } - // if (selectedNode != null && hasDownloadFile(selectedNode)) - // { - //
- // Thumbnail - // } - bool externalLink = false; - string link = getLink(selectedNode, out externalLink); - if (selectedNode != null && link != "") - { - // if (externalLink) - if (true) - { - @link
- } - else - { -
- } - if (selectedNode != null && selectedNode.Tag is Submodel && Program.connectServer != "") - { - bool toPublish = Program.submodelsToPublish.Contains(selectedNode.Tag); - bool toSubscribe = Program.submodelsToSubscribe.Contains(selectedNode.Tag); - if (toPublish) - { - - } - else - { - - } - if (toSubscribe) - { - - } - else - { - - } - //
- @code { - private void resetSubmodelToPublish() - { - Program.submodelsToPublish.Remove(selectedNode.Tag); - } - private void setSubmodelToPublish() - { - bool toSubscribe = Program.submodelsToSubscribe.Contains(selectedNode.Tag); - if (!toSubscribe) - Program.submodelsToPublish.Add(selectedNode.Tag); - } - private void resetSubmodelToSubscribe() - { - Program.submodelsToSubscribe.Remove(selectedNode.Tag); - } - private void setSubmodelToSubscribe() - { - bool toPublish = Program.submodelsToPublish.Contains(selectedNode.Tag); - if (!toPublish) - Program.submodelsToSubscribe.Add(selectedNode.Tag); - } - } - } - } - if (selectedNode != null && selectedNode.Tag is Property && Program.edit) - { - // @CurrentValue
- @CurrentValue
- @code { private string CurrentValue { get; set; } } - if (CurrentValue != null && CurrentValue != "") - { - if (selectedNode.Tag is Property) - { - (selectedNode.Tag as Property).value = CurrentValue; - (selectedNode.Tag as Property).setTimeStamp(DateTime.UtcNow); - this.StateHasChanged(); - } - CurrentValue = ""; - } - } - if (selectedNode != null && (selectedNode.Tag is AdministrationShell || selectedNode.Tag is AdminShellNS.AdminShellV20.File)) - { - if (selectedNode.Tag is AdministrationShell) - { -
- string qrcodeLink = getQRCodeLink(selectedNode); - if (Program.generatedQrCodes.ContainsKey(selectedNode.Tag)) - { - string qrcodeImage = getQRCodeImage(selectedNode); - if (qrcodeImage != "") - { - -
- Qrcode Image -
-
- } - } - else - { - @qrcodeLink
- } - @code { - private void runCreateQRCodeImage() - { - createQRCodeImage(selectedNode); - } - } - } - } - - if (selectedNode != null && selectedNode.Tag is SubmodelElementCollection smc) - { - string semanticId = ""; - // bool render = false; - - try - { - semanticId = smc.semanticId.Keys[0].value; - } - catch { } - if (semanticId == "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeries/1/0" || - semanticId == "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeriesSegment/1/0") - { - TimeSpan diff = smc.TimeStamp - timeStampPlot; - - if (smc != collectionPlot || diff.TotalSeconds < 0 || diff.TotalSeconds >= 5) - { - watchTimeToProcessImage = System.Diagnostics.Stopwatch.StartNew(); - - collectionPlot = smc; - timeStampPlot = smc.TimeStamp; - - //ListOfTimeSeriesData _timeSeriesData = new ListOfTimeSeriesData(); - _timeSeriesData.Clear(); - var mm = AdminShell.Key.MatchMode.Relaxed; - - // make initial data for time series - var tsd = new TimeSeriesData() { SourceTimeSeries = smc }; - _timeSeriesData.Add(tsd); - - // plot arguments for time series - tsd.Args = PlotArguments.Parse(smc.HasQualifierOfType("TimeSeries.Args")?.value); - - // TODO: info - ZveiTimeSeriesDataV10 is currently hardcoded as JSON string in code - var pcts = ZveiTimeSeriesDataV10.Static; - - var tssReference = pcts.CD_TimeSeriesSegment.GetReference(); - //var k = new Key("ConceptDescription", false, "IRI", "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeriesSegment/1/0"); - //var tssReference = new Reference(k); - //var smcAllValues = smc.value.FindAllSemanticIdAs(tssReference, mm); - - // is it a segment - try - { - if (semanticId == "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeriesSegment/1/0") - { - TimeSeriesAddSegmentData(pcts, mm, tsd, smc); - } - else - { - // search for segements on current level - var smcAllValues = smc.value.FindAllSemanticIdAs(tssReference, mm); - - if (smcAllValues.Count() != 0) - { - foreach (var smcseg in smcAllValues) - { - TimeSeriesAddSegmentData(pcts, mm, tsd, smcseg); - } - } - } - } - catch - { - }; - - _timeSeriesData?.RenderTimeSeries(defPlotHeight: 200, "en", bi.sessionNumber, plotFilter.combinedFromDate, plotFilter.combinedToDate); - watchTimeToProcessImage.Stop(); - } - - byte[] imageArray; - string timeSeriesImageBase64 = ""; - string scottplotImgPath = "wwwroot/images/scottplot/smc_timeseries_clientid" + bi.sessionNumber + ".png"; - - if (System.IO.File.Exists(scottplotImgPath)) - { - imageArray = System.IO.File.ReadAllBytes(scottplotImgPath); - timeSeriesImageBase64 = Convert.ToBase64String(imageArray); - } - - var elapsedMsToProcessImage = watchTimeToProcessImage.ElapsedMilliseconds; - - if (System.IO.File.Exists(scottplotImgPath)) - { - - - - - - - -
- - - - - - -
-
- -
- Visualization of time series - - Image processing took @elapsedMsToProcessImage ms (Last update: @timeStampPlot.ToString("yy-MM-dd HH:mm:ss.fff")) - -
- - - } - else - { -
Rendering time series...
- } - } - else - { - collectionPlot = null; - } - } - } - - @{ - string detailsImage = createDetailsImage(selectedNode); - if (detailsImage != "") - { -
-
- Details Image -
- } - - if (selectedNode != null && (selectedNode.Tag is AdminShellNS.AdminShellV20.BasicEvent be)) - { - if (be.observed != null) - { - string okey = be.observed.GetAsExactlyOneKey().ToString(); - Observed - @(" " + okey)
- var refsme = Program.env[0].AasEnv.FindReferableByReference(be.observed); - if (refsme != null) - { - UPDATE @refsme.TimeStamp.ToString("yy-MM-dd HH:mm:ss.fff")
- CREATE @refsme.TimeStampCreate.ToString("yy-MM-dd HH:mm:ss.fff")
- } - else - { - Referenced element does not exist!
- } - } - } - } -
-
+@functions { + protected async override Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await JsRuntime.InvokeAsync("resize"); + } + } +} + +
+ +
+ + @updateVisibleTree(Items, selectedNode) + @if (Program.isLoading) + { + Loading... + } + else + { IO.Swagger.Registry.Controllers.RegistryAndDiscoveryInterfaceApiController.initRegistry(DateTime.UtcNow); } + + + @{ + //// SubmodelService.syncSubTree(context); + } + +
@ViewNodeType(context)
+ @ViewNodeID(context)@ViewNodeInfo(context) + @getSymbols(context) +
@ViewTimeStamp(context)
+ +
+
+
+ + +
+
+ @{ + // TODO: REFACTORING! + + // ideas: + // - get rid of spans -> better: use inline divs with tailwind classes instead of style paramters + // - use tailwind grid + // - making private methods and/or components + + // Displaying node type and node name +
+ @ViewNodeType(selectedNode) + @ViewNodeID(selectedNode) +
+ + for (int line = 0; line < 6; line++) + { + string nodeType = ViewNodeDetails(selectedNode, line, 0); + string nodeValue = ViewNodeDetails(selectedNode, line, 1); + string additionalInformationOfNode = ViewNodeDetails(selectedNode, line, 2); + + if (nodeType != string.Empty && nodeValue != string.Empty) + { +
+ @nodeType + @nodeValue @additionalInformationOfNode" +
+ } + } + + + if (selectedNode != null && selectedNode.Tag is Referable r) + { + UPDATE @r.TimeStamp.ToString("yy-MM-dd HH:mm:ss.fff") + +
+ + +
+ CREATE @r.TimeStampCreate.ToString("yy-MM-dd HH:mm:ss.fff") + +
+ @code { + private void setTimeStamp() + { + (selectedNode.Tag as Referable).setTimeStamp(DateTime.UtcNow); + } + } + } + // if (selectedNode != null && hasDownloadFile(selectedNode)) + // { + //
+ // Thumbnail + // } + bool externalLink = false; + string link = getLink(selectedNode, out externalLink); + if (selectedNode != null && link != "") + { + // if (externalLink) + if (true) + { + @link + +
+ } + else + { + + +
+ } + if (selectedNode != null && selectedNode.Tag is Submodel && Program.connectServer != "") + { + bool toPublish = Program.submodelsToPublish.Contains(selectedNode.Tag); + bool toSubscribe = Program.submodelsToSubscribe.Contains(selectedNode.Tag); + if (toPublish) + { + + } + else + { + + } + if (toSubscribe) + { + + } + else + { + + } + //
+ @code { + private void resetSubmodelToPublish() + { + Program.submodelsToPublish.Remove(selectedNode.Tag); + } + private void setSubmodelToPublish() + { + bool toSubscribe = Program.submodelsToSubscribe.Contains(selectedNode.Tag); + if (!toSubscribe) + Program.submodelsToPublish.Add(selectedNode.Tag); + } + private void resetSubmodelToSubscribe() + { + Program.submodelsToSubscribe.Remove(selectedNode.Tag); + } + private void setSubmodelToSubscribe() + { + bool toPublish = Program.submodelsToPublish.Contains(selectedNode.Tag); + if (!toPublish) + Program.submodelsToSubscribe.Add(selectedNode.Tag); + } + } + } + } + if (selectedNode != null && selectedNode.Tag is Property && Program.edit) + { + // @CurrentValue
+ @CurrentValue + +
+ @code { + private string CurrentValue { get; set; } + } + if (CurrentValue != null && CurrentValue != "") + { + if (selectedNode.Tag is Property) + { + (selectedNode.Tag as Property).value = CurrentValue; + (selectedNode.Tag as Property).setTimeStamp(DateTime.UtcNow); + this.StateHasChanged(); + } + CurrentValue = ""; + } + } + if (selectedNode != null && (selectedNode.Tag is AdministrationShell || selectedNode.Tag is AdminShellNS.AdminShellV20.File)) + { + if (selectedNode.Tag is AdministrationShell) + { + + +
+ string qrcodeLink = getQRCodeLink(selectedNode); + if (Program.generatedQrCodes.ContainsKey(selectedNode.Tag)) + { + string qrcodeImage = getQRCodeImage(selectedNode); + if (qrcodeImage != "") + { + +
+ Qrcode Image +
+
+ } + } + else + { + @qrcodeLink + +
+ } + @code { + private void runCreateQRCodeImage() + { + createQRCodeImage(selectedNode); + } + } + } + } + + if (selectedNode != null && selectedNode.Tag is SubmodelElementCollection smc) + { + string semanticId = ""; + // bool render = false; + + try + { + semanticId = smc.semanticId.Keys[0].value; + } + catch { } + if (semanticId == "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeries/1/0" || + semanticId == "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeriesSegment/1/0") + { + TimeSpan diff = smc.TimeStamp - timeStampPlot; + + if (smc != collectionPlot || diff.TotalSeconds < 0 || diff.TotalSeconds >= 5) + { + watchTimeToProcessImage = System.Diagnostics.Stopwatch.StartNew(); + + collectionPlot = smc; + timeStampPlot = smc.TimeStamp; + + //ListOfTimeSeriesData _timeSeriesData = new ListOfTimeSeriesData(); + _timeSeriesData.Clear(); + var mm = AdminShell.Key.MatchMode.Relaxed; + + // make initial data for time series + var tsd = new TimeSeriesData() { SourceTimeSeries = smc }; + _timeSeriesData.Add(tsd); + + // plot arguments for time series + tsd.Args = PlotArguments.Parse(smc.HasQualifierOfType("TimeSeries.Args")?.value); + + // TODO: info - ZveiTimeSeriesDataV10 is currently hardcoded as JSON string in code + var pcts = ZveiTimeSeriesDataV10.Static; + + var tssReference = pcts.CD_TimeSeriesSegment.GetReference(); + //var k = new Key("ConceptDescription", false, "IRI", "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeriesSegment/1/0"); + //var tssReference = new Reference(k); + //var smcAllValues = smc.value.FindAllSemanticIdAs(tssReference, mm); + + // is it a segment + try + { + if (semanticId == "https://admin-shell.io/sandbox/zvei/TimeSeriesData/TimeSeriesSegment/1/0") + { + TimeSeriesAddSegmentData(pcts, mm, tsd, smc); + } + else + { + // search for segements on current level + var smcAllValues = smc.value.FindAllSemanticIdAs(tssReference, mm); + + if (smcAllValues.Count() != 0) + { + foreach (var smcseg in smcAllValues) + { + TimeSeriesAddSegmentData(pcts, mm, tsd, smcseg); + } + } + } + } + catch + { + }; + + _timeSeriesData?.RenderTimeSeries(defPlotHeight: 200, "en", bi.sessionNumber, plotFilter.combinedFromDate, plotFilter.combinedToDate); + watchTimeToProcessImage.Stop(); + } + + byte[] imageArray; + string timeSeriesImageBase64 = ""; + string scottplotImgPath = "wwwroot/images/scottplot/smc_timeseries_clientid" + bi.sessionNumber + ".png"; + + if (System.IO.File.Exists(scottplotImgPath)) + { + imageArray = System.IO.File.ReadAllBytes(scottplotImgPath); + timeSeriesImageBase64 = Convert.ToBase64String(imageArray); + } + + var elapsedMsToProcessImage = watchTimeToProcessImage.ElapsedMilliseconds; + + if (System.IO.File.Exists(scottplotImgPath)) + { + + + + + + + +
+ + + + + + +
+
+ +
+ Visualization of time series + + Image processing took @elapsedMsToProcessImage ms (Last update: @timeStampPlot.ToString("yy-MM-dd HH:mm:ss.fff")) + +
+ + + } + else + { +
Rendering time series...
+ } + } + else + { + collectionPlot = null; + } + } + } + + @{ + string detailsImage = createDetailsImage(selectedNode); + if (detailsImage != "") + { +
+
+ Details Image +
+ } + + if (selectedNode != null && (selectedNode.Tag is AdminShellNS.AdminShellV20.BasicEvent be)) + { + if (be.observed != null) + { + string okey = be.observed.GetAsExactlyOneKey().ToString(); + Observed + @(" " + okey) + +
+ var refsme = Program.env[0].AasEnv.FindReferableByReference(be.observed); + if (refsme != null) + { + UPDATE @refsme.TimeStamp.ToString("yy-MM-dd HH:mm:ss.fff") + +
+ CREATE @refsme.TimeStampCreate.ToString("yy-MM-dd HH:mm:ss.fff") + +
+ } + else + { + Referenced element does not exist! + +
+ } + } + } + } +
+
+ + @inject IJSRuntime js @inject BlazorSessionService bi; @using AasxServer; @@ -357,1738 +418,1750 @@ @using ScottPlot; @code { - System.Diagnostics.Stopwatch watchTimeToProcessImage = new System.Diagnostics.Stopwatch(); - DateTime timeStampPlot = new DateTime(); - PlotFilter plotFilter = new PlotFilter(); - SubmodelElementCollection collectionPlot = null; - bool showImageModal = false; - ListOfTimeSeriesData _timeSeriesData = new ListOfTimeSeriesData(); - int plotFilterTsdOffset = 0; - - private class PlotFilter - { - public DateTime fromDate { get; set; } - public DateTime fromTime { get; set; } - public DateTime toDate { get; set; } - public DateTime toTime { get; set; } - public DateTime combinedFromDate { get; set; } - public DateTime combinedToDate { get; set; } - - public PlotFilter() - { - this.SetInitialFilterState(); - } - - public void SetInitialFilterState() - { - ResetTimeOfDates(); - var initialFromDate = DateTime.Now.AddYears(-3); - var initialToDate = DateTime.Now.AddYears(3); - fromDate = initialFromDate; - toDate = initialToDate; - combinedFromDate = initialFromDate; - combinedToDate = initialToDate; - } - - public void SetFilterStateDay(int offset) - { - ResetTimeOfDates(); - DateTime day = DateTime.Today.AddDays(offset); - TimeSpan midnight = new System.TimeSpan(0, 23, 59, 59); - DateTime endOfDay = day.Add(midnight); - - fromDate = day; - fromTime = day; - toDate = endOfDay; - toTime = endOfDay; - combinedFromDate = day; - combinedToDate = endOfDay; - } - - public void ResetTimeOfDates() - { - // Reset to 0 AM - fromDate = new DateTime(fromDate.Year, fromDate.Month, fromDate.Day, 0, 0, 0); - toDate = new DateTime(toDate.Year, toDate.Month, toDate.Day, 0, 0, 0); - } - - public void UpdateFilter(ListOfTimeSeriesData tsd, int sessionNumber) - { - ResetTimeOfDates(); - TimeSpan fromTimeSpan = fromTime.TimeOfDay; - TimeSpan toTimeSpan = toTime.TimeOfDay; - combinedFromDate = fromDate.Add(fromTimeSpan); - combinedToDate = toDate.Add(toTimeSpan); - tsd?.RenderTimeSeries(defPlotHeight: 200, "en", sessionNumber, combinedFromDate, combinedToDate); - } - } - - async Task DownloadFile() - { - this.StateHasChanged(); - var f = selectedNode.Tag as AdminShellNS.AdminShellV20.File; - var fileName = System.IO.Path.GetFileName(f.value); - if (fileName != "") - { - try - { - byte[] data; - using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) - { - Program.env[selectedNode.envIndex].GetLocalStreamFromPackage(f.value).CopyTo(ms); - data = ms.ToArray(); - } - // - await SaveAs(js, fileName, data); - } - catch - { - } - - } - } - async Task SaveAs(IJSRuntime js, string filename, byte[] data) - // async Task SaveAs(IJSRuntime js, string filename, string data) - { - ; await js.InvokeAsync( - "saveAsFile", - filename, - data - ); - /* - await js.InvokeAsync( - "saveAsFile", - filename, - Convert.ToBase64String(data) - ); - */ - /* - await js.InvokeAsync( - "download", - data, - filename, - "application/pdf" - ); - */ - } - - public class Item - { - public string Text { get; set; } - public IEnumerable Childs { get; set; } - public object parent { get; set; } - // public List Childs { get; set; } - public string Type { get; set; } - public object Tag { get; set; } - public int envIndex { get; set; } - } - - List Items = null; - - IList ExpandedNodes = new List(); - Item selectedNode; - Item SelectedNode - { - get { return selectedNode; } - set - { - selectedNode = value; - // OnSelectNode(selectedNode); - } - } - - static ulong dataVersion = 0; - - public static void checkDataVersion() - { - if (Program.getDataVersion() != dataVersion) - { - dataVersion = Program.getDataVersion(); - // TreePage.StateHasChanged(); - } - } - - static int hack = 0; - - System.Threading.Timer refresh = null; - - protected override void OnInitialized() - { - // OnInitialized() allways called twice - // if (hack++ == 0) - // return; - - // hack = 0; - // SubmodelService.buildTree(); - // Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); - // newDataMode = 1; - // StateHasChanged(); - - //ExpandedNodes.Add(Items.Skip(1).First()); - //ExpandedNodes.Add(Items.Skip(1).Take(1).First().Childs.Skip(1).First()); - - SubmodelService.NewDataAvailable += NewData; - Program.signalNewData(1); - - /* - refresh = new System.Threading.Timer(new System.Threading.TimerCallback(_ => - { - // Note that the following line is necessary because otherwise - // Blazor would not recognize the state change and not refresh the UI - // InvokeAsync(() => this.StateHasChanged()); - }), null, 5000, 5000); - */ - } - - public void Dispose() - { - SubmodelService.NewDataAvailable -= NewData; - } - - int newDataMode = 0; - - void NewData(object source, EventArgs args) - { - if (Program.isLoading) - return; - - // update = true; - if (newDataMode == 0) - { - if (args is Program.NewDataAvailableArgs newArgs) - { - newDataMode = newArgs.signalNewDataMode; - // Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); - InvokeAsync(() => this.StateHasChanged()); - } - } - // newDataMode = Program.getSignalNewDataMode(); - // Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); - - // InvokeAsync(() => this.StateHasChanged()); - // this.StateHasChanged(); - } - - bool update = true; - - string updateVisibleTree(List viewItems, Item selectedNode) - { - if (update) - { - switch (newDataMode) - { - // 0 == same tree, only values changed - case 0: - break; - // 1 == same tree, structure may change - // 2 == build new tree, keep open nodes - case 1: - case 2: - bool isSelected = selectedNode != null; - bool isExpanded = ExpandedNodes.Count != 0; - List[] expandedNodesPath = new List[ExpandedNodes.Count + 1]; - List selectedNodePath = getPath(selectedNode); - if (isExpanded) - { - for (int j = 0; j < ExpandedNodes.Count; j++) - { - expandedNodesPath[j] = getPath(ExpandedNodes[j]); - } - } - SubmodelService.buildTree(); - Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); - ExpandedNodes.Clear(); - selectedNode = null; - if (isSelected) - { - selectedNode = findPath(selectedNodePath); - } - if (isExpanded) - { - foreach (var path in expandedNodesPath) - { - Item p = findPath(path); - if (p != null) - ExpandedNodes.Add(p); - } - } - newDataMode = 0; - break; - // 3 == build new tree, all nodes closed - case 3: - SubmodelService.buildTree(); - Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); - ExpandedNodes.Clear(); - selectedNode = null; - newDataMode = 0; - break; - } - SelectedNode = selectedNode; - // update = false; - // updateNode(viewItems[0]); - } - return ""; - } - - List getPath(Item i) - { - if (i == null) - return null; - - List upPath = new List(); - upPath.Add(i.Text); - while (i.parent != null) - { - i = (Item)i.parent; - upPath.Add(i.Text); - } - List downPath = new List(); - int j = upPath.Count - 1; - while (j >= 0) - { - downPath.Add(upPath[j--]); - } - return downPath; - } - - Item findPath(List path) - { - if (path != null && path.Count > 0) - { - Item found = null; - int k = 0; - while (k < Items.Count) - { - Item i = Items[k]; - if (i.Text != path[0]) - { - k++; - continue; - } - int j = 0; - found = i; - while (++j < path.Count) - { - if (i.Childs != null) - { - found = null; - foreach (var c in i.Childs) - { - if (c.Text == path[j]) - { - found = c; - break; - } - } - } - if (found == null) - { - return null; - } - i = found; - } - if (found != null) - return found; - } - } - return null; - } - - void updateNode(Item i) - { - var clist = i.Childs as List; - List listIdshort = new List(); - bool done = false; - if (!done && i.Tag is Submodel sm) - { - foreach (var smew1 in sm.submodelElements) - { - listIdshort.Add(smew1.submodelElement.idShort); - } - done = true; - } - if (!done && i.Tag is SubmodelElementCollection smec) - { - foreach (var smew2 in smec.value) - { - listIdshort.Add(smew2.submodelElement.idShort); - } - done = true; - } - if (!done && i.Tag is SubmodelElement sme) - { - listIdshort.Add(sme.idShort); - done = true; - } - // check if child name exists in data children idshorts, if not delete - if (done) - { - List toDelete = new List(); - if (clist != null) - { - foreach (var c in clist) - { - if (!listIdshort.Contains(c.Text)) - { - toDelete.Add(c); - } - } - } - else - { - if (!listIdshort.Contains(i.Text)) - { - toDelete.Add(i); - } - } - foreach (var c in toDelete) - { - var parent = c.parent as Item; - if (parent != null) - { - (parent.Childs as List).Remove(c); - } - } - } - // check if data children idshorts exist in child names, if not insert - if (clist != null) - { - foreach (var c in clist) - { - updateNode(c); - } - } - } - - string createDetailsImage(Item item) - { - // System.IO.File.Delete("wwwroot/detailsImage.jpg"); - - if (item == null) - { - return ""; - } - - object o = item.Tag; - - if (o is AdministrationShell) - { - var aas = o as AdministrationShell; - lock (Program.changeAasxFile) - { - try - { - using (System.IO.Stream s = Program.env[item.envIndex].GetLocalThumbnailStream()) - { - if (s != null) - { - using (var m = new System.IO.MemoryStream()) - { - s.CopyTo(m); - return System.Convert.ToBase64String(m.ToArray()); - } - } - - } - } - catch { } - } - } - - if (o is AdminShellNS.AdminShellV20.File) - { - var f = o as AdminShellNS.AdminShellV20.File; - - // Test for /aasx/ - if (f.value != "") - { - string[] split = f.value.Split(new Char[] { '/' }); - if (split.Length == 2 || split.Length > 1 && split[1].ToLower() == "aasx") - { - split = f.value.Split(new Char[] { '.' }); - switch (split.Last().ToLower()) - { - case "jpg": - case "bmp": - case "png": - try - { - using (System.IO.Stream s = Program.env[item.envIndex].GetLocalStreamFromPackage(f.value)) - { - if (s != null) - { - using (var m = new System.IO.MemoryStream()) - { - s.CopyTo(m); - return System.Convert.ToBase64String(m.ToArray()); - } - } - } - } - catch { } - break; - } - } - } - } - - return ""; - } - - string getQRCodeLink(Item item) - { - if (item == null) - { - return ""; - } - - string prefix = "http://"; - string hostPort = Program.hostPort; - - string[] split = Program.hostPort.Split(':'); - if (split[0].ToLower() == "admin-shell-io.com") - { - // prefix = "https://"; - // hostPort = split[0] + ":" + (Convert.ToInt32(split[1]) + 1); - } - - object o = item.Tag; - - if (o is AdministrationShell) - { - var aas = o as AdministrationShell; - var asset = Program.env[item.envIndex].AasEnv.FindAsset(aas.assetRef); - if (asset != null) - { - // string url = WebUtility.UrlEncode(asset.identification.id); - string url = asset.identification.id; - // string link = prefix + hostPort + "/server/getaasxbyassetid/" + url; - // string link = Program.externalRest + "/server/getaasxbyassetid/" + url; - string link = url; - - return link; - } - } - - return ""; - } - - string getQRCodeImage(Item item) - { - if (item == null) - { - return ""; - } - - object o = item.Tag; - - if (o is AdministrationShell) - { - string image = Program.generatedQrCodes[item.Tag]; - - if (image != null) - return image; - } - - return ""; - } - - void createQRCodeImage(Item item) - { - // System.IO.File.Delete("wwwroot/detailsImage.jpg"); - - if (item == null) - { - return; - } - - string prefix = "http://"; - string hostPort = Program.hostPort; - - string[] split = Program.hostPort.Split(':'); - if (split[0].ToLower() == "admin-shell-io.com") - { - // prefix = "https://"; - // hostPort = split[0] + ":" + (Convert.ToInt32(split[1]) + 1); - } - - object o = item.Tag; - - if (o is AdministrationShell) - { - if (Program.generatedQrCodes.ContainsKey(item.Tag)) - { - Program.generatedQrCodes.Remove(item.Tag); - return; - } - - var aas = o as AdministrationShell; - var asset = Program.env[item.envIndex].AasEnv.FindAsset(aas.assetRef); - if (asset != null) - { - // string url = WebUtility.UrlEncode(asset.identification.id); - string url = asset.identification.id; - // string link = prefix + hostPort + "/server/getaasxbyassetid/" + url; - // string link = Program.externalRest + "/server/getaasxbyassetid/" + url; - string link = url; - - QRCodeGenerator qrGenerator = new QRCodeGenerator(); - QRCodeData qrCodeData = qrGenerator.CreateQrCode(link, QRCodeGenerator.ECCLevel.Q); - QRCode qrCode = new QRCode(qrCodeData); - Bitmap qrCodeImage = qrCode.GetGraphic(20); - using (System.IO.MemoryStream memory = new System.IO.MemoryStream()) - { - qrCodeImage.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); - string base64 = Convert.ToBase64String(memory.ToArray()); - - Program.generatedQrCodes.Add(item.Tag, base64); - - } - return; - } - } - - return; - } - - bool hasDownloadFile(Item item) - { - return false; - - if (item == null) - { - return false; - } - - object o = item.Tag; - - if (o is AdminShellNS.AdminShellV20.File) - { - - var f = o as AdminShellNS.AdminShellV20.File; - - // Test for /aasx/ - string[] split = f.value.Split(new Char[] { '/' }); - if (split.Length == 2 || split[1].ToLower() == "aasx") - { - return true; - } - } - - return false; - } - - string getLink(Item item, out bool external) - { - external = false; - - if (item == null) - { - return ""; - } - - string prefix = "http://"; - string hostPort = Program.hostPort; - - string[] split = Program.hostPort.Split(':'); - if (split[0].ToLower() == "admin-shell-io.com") - { - prefix = "https://"; - hostPort = split[0] + ":" + (Convert.ToInt32(split[1]) + 1); - } - - object o = item.Tag; - - if (o == null && Program.envSymbols[item.envIndex] == "L") - { - // return prefix + hostPort + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); - return Program.externalRest + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); - } - - if (o is AdministrationShell) - { - // return prefix + hostPort + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); - return Program.externalRest + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); - } - - if (o is AdminShellNS.AdminShellV20.File || o is Property) - { - string value = ""; - - if (o is AdminShellNS.AdminShellV20.File) - { - value = (o as AdminShellNS.AdminShellV20.File).value; - } - if (o is Property) - { - value = (o as Property).value; - } - - split = value.Split(new Char[] { ':' }); - if (split[0].ToLower() == "http" || split[0].ToLower() == "https") - { - external = true; - return value; - } - - // Test for /aasx/ - split = value.Split(new Char[] { '/' }); - if (split.Length > 1) - { - if (split.Length == 2 || split[1].ToLower() == "aasx") - { - // return prefix + hostPort + "/server/getfile/" + item.envIndex.ToString() + value; - return Program.externalRest + "/server/getfile/" + item.envIndex.ToString() + value; - } - } - } - - return ""; - } - - string getSymbols(Item item) - { - if (item == null) - { - return ""; - } - - string ret = ""; - object o = item.Tag; - - if (o is AdministrationShell) - { - string symbols = Program.envSymbols[item.envIndex]; - - if (symbols != null) - { - string[] s = symbols.Split(';'); - - for (int i = 0; i < s.Length; i++) - { - switch (s[i]) - { - case "L": - ret += "ENCRYPTED "; - break; - case "S": - ret += "SIGNED "; - break; - case "V": - ret += "VALIDATED "; - break; - } - } - } - } - - return ret; - } - - string ViewNodeType(Item item) - { - if (item == null) - { - return ""; - } - - string ret = ""; - - if (item.Type != null) - { - ret = item.Type + " "; - } - - object o = item.Tag; - - /* - if (o is Referable) - { - ret = (o as Referable).GetElementName(); - return (ret); - } - */ - - if (o == null && Program.envSymbols[item.envIndex] == "L") - { - ret += "AASX2"; - } - - if (o is AdministrationShell) - { - ret += "AAS"; - } - if (o is Submodel) - { - ret += "Sub"; - } - if (o is SubmodelElement) - { - if (o is SubmodelElementCollection) - { - ret += "Coll"; - } - if (o is Property) - { - ret += "Prop"; - } - } - if (o is Operation) - { - ret += "Opr"; - } - if (o is AdminShellNS.AdminShellV20.File) - { - ret += "File"; - } - if (o is Blob) - { - ret += "Blob"; - } - if (o is AdminShellNS.AdminShellV20.Range) - { - ret += "Range"; - } - if (o is MultiLanguageProperty) - { - ret += "Lang"; - } - if (o is RelationshipElement) - { - ret += "Rel"; - } - if (o is ReferenceElement) - { - ret += "Ref"; - } - if (o is Entity) - { - ret += "Ent"; - } - if (o is AdminShellNS.AdminShellV20.BasicEvent) - { - ret += "Evt"; - } - - return (ret); - } - - string ViewTimeStamp(Item item) - { - if (item == null) - { - return ""; - } - - string ret = ""; - - object o = item.Tag; - - if (o is Referable r) - // ret += " (" + r.TimeStamp.Ticks + ") "; - ret += " (" + r.TimeStamp.ToString("yy-MM-dd HH:mm:ss.fff") + ") "; - - return ret; - } - - string ViewNodeID(Item item) - { - if (item == null) - { - return ""; - } - - string ret = "NULL"; - - object o = item.Tag; - - if (o == null && Program.envSymbols[item.envIndex] == "L") - { - ret = item.Text; - } - - if (o is AdministrationShell) - { - var aas = o as AdministrationShell; - ret = aas.idShort; - } - if (o is Submodel) - { - var sm = o as Submodel; - ret = ""; - if (sm.kind != null && sm.kind.IsTemplate) - ret += " "; - ret += sm.idShort; - } - if (o is SubmodelElement) - { - var sme = o as SubmodelElement; - ret = ""; - if (sme.kind != null && sme.kind.IsTemplate) - ret += " "; - ret += sme.idShort; - } - if (o is AdminShellNS.AdminShellV20.File) - { - var f = o as AdminShellNS.AdminShellV20.File; - ret = ""; - if (f.kind != null && f.kind.IsTemplate) - ret += " "; - ret += f.idShort; - } - if (o is Blob) - { - var b = o as Blob; - ret = ""; - if (b.kind != null && b.kind.IsTemplate) - ret += " "; - ret += b.idShort; - } - if (o is AdminShellNS.AdminShellV20.Range) - { - var r = o as AdminShellNS.AdminShellV20.Range; - ret = ""; - if (r.kind != null && r.kind.IsTemplate) - ret += " "; - ret += r.idShort; - } - if (o is MultiLanguageProperty) - { - var mlp = o as MultiLanguageProperty; - ret = ""; - if (mlp.kind != null && mlp.kind.IsTemplate) - ret += " "; - ret += mlp.idShort; - } - return (ret); - } - - string GetHtmlId(Item item) - { - string ret = ViewNodeID(item); - if (item.parent != null) - { - ret = GetHtmlId(item.parent as Item) + "." + ret; - } - return (ret); - } - - string ViewNodeInfo(Item item) - { - if (item == null) - { - return ""; - } - - string ret = ""; - - object o = item.Tag; - - if (o is AdministrationShell) - { - var aas = o as AdministrationShell; - // ret = aas.identification.ToString(); - } - if (o is Submodel) - { - var sm = o as Submodel; - // ret = sm.identification.ToString(); - if (sm.qualifiers != null && sm.qualifiers.Count > 0) - { - ret += " @QUALIFIERS"; - } - } - if (o is SubmodelElementCollection) - { - var sme = o as SubmodelElementCollection; - // ret = sm.identification.ToString(); - if (sme.value.Count > 0) - { - ret += " #" + sme.value.Count; - } - if (sme.qualifiers != null && sme.qualifiers.Count > 0) - { - ret += " @QUALIFIERS"; - } - } - if (o is SubmodelElement) - { - if (o is Property) - { - var prop = o as Property; - if (prop.value != "") - { - string v = prop.value; - if (v.Length > 100) - v = v.Substring(0, 100) + " .."; - ret = " = " + v; - } - if (prop.qualifiers != null && prop.qualifiers.Count > 0) - { - ret += " @QUALIFIERS"; - } - } - if (o is AdminShellNS.AdminShellV20.File) - { - var f = o as AdminShellNS.AdminShellV20.File; - ret = " = " + f.value; - if (f.qualifiers != null && f.qualifiers.Count > 0) - { - ret += " @QUALIFIERS"; - } - } - } - if (o is AdminShellNS.AdminShellV20.Range) - { - var r = o as AdminShellNS.AdminShellV20.Range; - ret = " = " + r.min + " .. " + r.max; - if (r.qualifiers != null && r.qualifiers.Count > 0) - { - ret += " @QUALIFIERS"; - } - } - if (o is MultiLanguageProperty) - { - var mlp = o as MultiLanguageProperty; - var ls = mlp.value; - ret = " = "; - for (int i = 0; i < ls.Count; i++) - { - ret += ls.langString[i].lang + " "; - if (i == 0) - ret += ls.langString[i].str + " "; - } - if (mlp.qualifiers != null && mlp.qualifiers.Count > 0) - { - ret += " @QUALIFIERS"; - } - } - return (ret); - } - - string ViewNodeDetails(Item item, int line, int col) - { - if (item == null) - { - return ""; - } - - // string ret = "NULL"; - string ret = ""; - - object o = item.Tag; - - if (o == null) - { - return ""; - } - - if (o is AdministrationShell) - { - string subjectIssuer = null; - - ret = ""; - var aas = o as AdministrationShell; - - var asset = Program.env[item.envIndex].AasEnv.FindAsset(aas.assetRef); - - switch (line) - { - case 0: - if (col == 0) - ret = "ID"; - if (col == 1) - ret = aas.identification + ""; - if (col == 2) - ret = " ==> " + Base64UrlEncoder.Encode(aas.identification.id) + ""; - break; - case 1: - if (asset != null) - { - if (col == 0) - ret = "ASSET"; - if (col == 1) - ret = asset.idShort; - } - break; - case 2: - if (asset != null) - { - if (col == 0) - ret = "ASSETID"; - if (col == 1) - ret = asset.identification + ""; - if (col == 2) - ret = " ==> " + Base64UrlEncoder.Encode(asset.identification.id) + ""; - } - break; - case 3: - if (asset != null) - { - if (col == 0) - ret = "ASSETID URLENCODED"; - if (col == 1) - { - string url = WebUtility.UrlEncode(asset.identification.id); - ret = url; - } - } - break; - /* - case 3: - subjectIssuer = Program.envSubjectIssuer[item.envIndex]; - if (subjectIssuer != null) - { - string[] s = subjectIssuer.Split(';'); - if (s.Length > 0 && s[0] != "") - { - ret = "SUBJECT"; - if (col == 1) - ret = s[0]; - } - } - break; - case 4: - subjectIssuer = Program.envSubjectIssuer[item.envIndex]; - if (subjectIssuer != null) - { - string[] s = subjectIssuer.Split(';'); - if (s.Length > 1 && s[1] != "") - { - ret = "ISSUER"; - if (col == 1) - ret = s[1]; - } - } - break; - */ - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is Submodel) - { - var sm = o as Submodel; - ret = ""; - switch (line) - { - case 0: - if (col == 0) - ret = "ID"; - if (col == 1) - ret = sm.identification + ""; - if (col == 2) - ret = " ==> " + Base64UrlEncoder.Encode(sm.identification.id) + ""; - break; - case 1: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = sm.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 2: - ret = getQualifiers(sm.qualifiers, col); - break; - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is Property) - { - var prop = o as Property; - // ret += ", " + prop.value; - ret = ""; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = prop.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "Value Type"; - if (col == 1) - ret = prop.valueType + ""; - break; - case 2: - if (col == 0) - ret = "Value"; - if (col == 1) - ret = prop.value + ""; - break; - case 3: - ret = getQualifiers(prop.qualifiers, col); - break; - case 4: - if (col == 0) - ret = getUnit(item, prop, col); - break; - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is Entity) - { - var e = o as Entity; - // ret += ", " + e.entityType; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = e.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "Entity Type"; - if (col == 1) - ret = e.entityType + ""; - break; - case 2: - ret = ""; - if (e.GetEntityType() == Entity.EntityTypeEnum.SelfManagedEntity) - { - if (e.assetRef != null) - { - if (col == 0) - ret = "Asset"; - if (col == 1) - { - var k = e.assetRef.Keys; - if (k != null) - { - ret = k.ToString(); - } - } - } - } - break; - case 3: - ret = getQualifiers(e.qualifiers, col); - break; - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is AdminShellNS.AdminShellV20.File) - { - var f = o as AdminShellNS.AdminShellV20.File; - // ret += ", " + f.value; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = f.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "Value"; - if (col == 1) - ret = f.value; - break; - case 2: - ret = getQualifiers(f.qualifiers, col); - break; - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is Blob) - { - var b = o as Blob; - ret = ""; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = b.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "MimeType"; - if (col == 1) - ret = b.mimeType; - break; - case 2: - if (col == 0) - ret = "Value"; - if (col == 1) - ret = b.value; - break; - case 3: - ret = getQualifiers(b.qualifiers, col); - break; - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is AdminShellNS.AdminShellV20.Range) - { - var r = o as AdminShellNS.AdminShellV20.Range; - // ret = r.idShort; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = r.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "Min"; - if (col == 1) - ret = r.min + ""; - break; - case 2: - if (col == 0) - ret = "Max"; - if (col == 1) - ret = r.max + ""; - break; - case 3: - ret = getQualifiers(r.qualifiers, col); - break; - case 4: - if (col == 0) - ret = getUnit(item, r, col); - break; - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is Operation) - { - var op = o as Operation; - // ret = op.idShort; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = op.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "CountInputs"; - if (col == 1) - { - ret = "0"; - if (op.inputVariable != null) - { - ret = op.inputVariable.Count + ""; - } - } - break; - case 2: - if (col == 0) - ret = "CountOutputs"; - if (col == 1) - { - ret = "0"; - if (op.outputVariable != null) - { - ret = op.outputVariable.Count + ""; - } - } - break; - case 3: - ret = getQualifiers(op.qualifiers, col); - break; - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is RelationshipElement) - { - var r = o as RelationshipElement; - // ret = r.idShort; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = r.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "First"; - if (col == 1) - { - ret = "NULL"; - var k = r.first; - if (k != null) - { - ret = k.Keys.ToString(); - } - } - break; - case 2: - if (col == 0) - ret = "Second"; - if (col == 1) - { - ret = "NULL"; - var k = r.second; - if (k != null) - { - ret = k.Keys.ToString(); - } - } - break; - case 3: - ret = getQualifiers(r.qualifiers, col); - break; - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is ReferenceElement) - { - var r = o as ReferenceElement; - // ret = r.idShort; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = r.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - if (col == 0) - ret = "Value"; - if (col == 1) - { - ret = "NULL"; - if (!(r.value == null || r.value.IsEmpty)) - { - var k = r.value.Keys; - if (k != null) - { - ret = k.ToString(); - } - } - } - break; - case 2: - ret = getQualifiers(r.qualifiers, col); - break; - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is MultiLanguageProperty) - { - var mlp = o as MultiLanguageProperty; - var ls = mlp.value; - for (int i = 0; i < ls.Count; i++) - { - ret += ls.langString[i].lang + " "; - } - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = mlp.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - case 2: - case 3: - case 4: - ret = ""; - if (ls.Count > line - 1) - { - if (col == 0) - ret = ls.langString[line - 1].lang; - if (col == 1) - ret = ls.langString[line - 1].str + ""; - } - break; - case 5: - ret = getQualifiers(mlp.qualifiers, col); - break; - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - if (o is SubmodelElement) - { - var sme = o as SubmodelElement; - // ret = sme.idShort + ", " + sme.semanticId; - switch (line) - { - case 0: - if (col == 0) - ret = "Semantic ID"; - if (col == 1) - { - ret = "NULL"; - var k = sme.semanticId?.GetAsExactlyOneKey(); - if (k != null) - { - ret = k.ToString(); - } - } - break; - case 1: - ret = getQualifiers(sme.qualifiers, col); - break; - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = ""; - break; - } - return ret; - } - - return (ret); - } - - static string getQualifiers(QualifierCollection q, int col) - { - string ret = ""; - - if (q != null && q.Count > 0) - { - if (col == 0) - ret = "Qualifiers"; - if (col == 1) - { - ret = ""; - for (int i = 0; i < q.Count; i++) - { - if (i != 0) - ret += ", "; - if (q[i].type != null && q[i].type != "") - { - ret += q[i].type + " "; - } - if (q[i].value != null && q[i].value != "") - { - ret += "= " + q[i].value; - } - } - } - } - return ret; - } - - public string getUnit(Item item, SubmodelElement se, int col) - { - string ret = ""; - if (se.semanticId == null || se.semanticId.Keys == null) - { - return ret; - } - var cd = Program.env[item.envIndex].AasEnv.FindConceptDescription(se.semanticId.Keys); - if (cd != null) - { - var iec = cd.GetIEC61360(); - if (iec != null) - { - ret = "Unit"; - if (col == 1) - { - ret = iec.unit; - if (iec.unitId != null && iec.unitId.keys != null && iec.unitId.keys.Count > 0) - ret += " (UnitId = " + iec.unitId.keys[0].ToString() + ")"; - } - } - } - return ret; - } + System.Diagnostics.Stopwatch watchTimeToProcessImage = new System.Diagnostics.Stopwatch(); + DateTime timeStampPlot = new DateTime(); + PlotFilter plotFilter = new PlotFilter(); + SubmodelElementCollection collectionPlot = null; + bool showImageModal = false; + ListOfTimeSeriesData _timeSeriesData = new ListOfTimeSeriesData(); + int plotFilterTsdOffset = 0; + + string informationType = "text-white bg-[blue]"; + + private class PlotFilter + { + public DateTime fromDate { get; set; } + public DateTime fromTime { get; set; } + public DateTime toDate { get; set; } + public DateTime toTime { get; set; } + public DateTime combinedFromDate { get; set; } + public DateTime combinedToDate { get; set; } + + public PlotFilter() + { + this.SetInitialFilterState(); + } + + public void SetInitialFilterState() + { + ResetTimeOfDates(); + var initialFromDate = DateTime.Now.AddYears(-3); + var initialToDate = DateTime.Now.AddYears(3); + fromDate = initialFromDate; + toDate = initialToDate; + combinedFromDate = initialFromDate; + combinedToDate = initialToDate; + } + + public void SetFilterStateDay(int offset) + { + ResetTimeOfDates(); + DateTime day = DateTime.Today.AddDays(offset); + TimeSpan midnight = new System.TimeSpan(0, 23, 59, 59); + DateTime endOfDay = day.Add(midnight); + + fromDate = day; + fromTime = day; + toDate = endOfDay; + toTime = endOfDay; + combinedFromDate = day; + combinedToDate = endOfDay; + } + + public void ResetTimeOfDates() + { + // Reset to 0 AM + fromDate = new DateTime(fromDate.Year, fromDate.Month, fromDate.Day, 0, 0, 0); + toDate = new DateTime(toDate.Year, toDate.Month, toDate.Day, 0, 0, 0); + } + + public void UpdateFilter(ListOfTimeSeriesData tsd, int sessionNumber) + { + ResetTimeOfDates(); + TimeSpan fromTimeSpan = fromTime.TimeOfDay; + TimeSpan toTimeSpan = toTime.TimeOfDay; + combinedFromDate = fromDate.Add(fromTimeSpan); + combinedToDate = toDate.Add(toTimeSpan); + tsd?.RenderTimeSeries(defPlotHeight: 200, "en", sessionNumber, combinedFromDate, combinedToDate); + } + } + + async Task DownloadFile() + { + this.StateHasChanged(); + var f = selectedNode.Tag as AdminShellNS.AdminShellV20.File; + var fileName = System.IO.Path.GetFileName(f.value); + if (fileName != "") + { + try + { + byte[] data; + using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) + { + Program.env[selectedNode.envIndex].GetLocalStreamFromPackage(f.value).CopyTo(ms); + data = ms.ToArray(); + } + // + await SaveAs(js, fileName, data); + } + catch + { + } + + } + } + async Task SaveAs(IJSRuntime js, string filename, byte[] data) + // async Task SaveAs(IJSRuntime js, string filename, string data) + { + ; await js.InvokeAsync( + "saveAsFile", + filename, + data + ); + /* + await js.InvokeAsync( + "saveAsFile", + filename, + Convert.ToBase64String(data) + ); + */ + /* + await js.InvokeAsync( + "download", + data, + filename, + "application/pdf" + ); + */ + } + + public class Item + { + public string Text { get; set; } + public IEnumerable Childs { get; set; } + public object parent { get; set; } + // public List Childs { get; set; } + public string Type { get; set; } + public object Tag { get; set; } + public int envIndex { get; set; } + } + + List Items = null; + + IList ExpandedNodes = new List(); + Item selectedNode; + Item SelectedNode + { + get { return selectedNode; } + set + { + selectedNode = value; + // OnSelectNode(selectedNode); + } + } + + static ulong dataVersion = 0; + + public static void checkDataVersion() + { + if (Program.getDataVersion() != dataVersion) + { + dataVersion = Program.getDataVersion(); + // TreePage.StateHasChanged(); + } + } + + static int hack = 0; + + System.Threading.Timer refresh = null; + + protected override void OnInitialized() + { + // OnInitialized() allways called twice + // if (hack++ == 0) + // return; + + // hack = 0; + // SubmodelService.buildTree(); + // Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); + // newDataMode = 1; + // StateHasChanged(); + + //ExpandedNodes.Add(Items.Skip(1).First()); + //ExpandedNodes.Add(Items.Skip(1).Take(1).First().Childs.Skip(1).First()); + + SubmodelService.NewDataAvailable += NewData; + Program.signalNewData(1); + + /* + refresh = new System.Threading.Timer(new System.Threading.TimerCallback(_ => + { + // Note that the following line is necessary because otherwise + // Blazor would not recognize the state change and not refresh the UI + // InvokeAsync(() => this.StateHasChanged()); + }), null, 5000, 5000); + */ + } + + public void Dispose() + { + SubmodelService.NewDataAvailable -= NewData; + } + + int newDataMode = 0; + + void NewData(object source, EventArgs args) + { + if (Program.isLoading) + return; + + // update = true; + if (newDataMode == 0) + { + if (args is Program.NewDataAvailableArgs newArgs) + { + newDataMode = newArgs.signalNewDataMode; + // Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); + InvokeAsync(() => this.StateHasChanged()); + } + } + // newDataMode = Program.getSignalNewDataMode(); + // Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); + + // InvokeAsync(() => this.StateHasChanged()); + // this.StateHasChanged(); + } + + bool update = true; + + string updateVisibleTree(List viewItems, Item selectedNode) + { + if (update) + { + switch (newDataMode) + { + // 0 == same tree, only values changed + case 0: + break; + // 1 == same tree, structure may change + // 2 == build new tree, keep open nodes + case 1: + case 2: + bool isSelected = selectedNode != null; + bool isExpanded = ExpandedNodes.Count != 0; + List[] expandedNodesPath = new List[ExpandedNodes.Count + 1]; + List selectedNodePath = getPath(selectedNode); + if (isExpanded) + { + for (int j = 0; j < ExpandedNodes.Count; j++) + { + expandedNodesPath[j] = getPath(ExpandedNodes[j]); + } + } + SubmodelService.buildTree(); + Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); + ExpandedNodes.Clear(); + selectedNode = null; + if (isSelected) + { + selectedNode = findPath(selectedNodePath); + } + if (isExpanded) + { + foreach (var path in expandedNodesPath) + { + Item p = findPath(path); + if (p != null) + ExpandedNodes.Add(p); + } + } + newDataMode = 0; + break; + // 3 == build new tree, all nodes closed + case 3: + SubmodelService.buildTree(); + Items = SubmodelService.GetTree(selectedNode, ExpandedNodes); + ExpandedNodes.Clear(); + selectedNode = null; + newDataMode = 0; + break; + } + SelectedNode = selectedNode; + // update = false; + // updateNode(viewItems[0]); + } + return ""; + } + + List getPath(Item i) + { + if (i == null) + return null; + + List upPath = new List(); + upPath.Add(i.Text); + while (i.parent != null) + { + i = (Item)i.parent; + upPath.Add(i.Text); + } + List downPath = new List(); + int j = upPath.Count - 1; + while (j >= 0) + { + downPath.Add(upPath[j--]); + } + return downPath; + } + + Item findPath(List path) + { + if (path != null && path.Count > 0) + { + Item found = null; + int k = 0; + while (k < Items.Count) + { + Item i = Items[k]; + if (i.Text != path[0]) + { + k++; + continue; + } + int j = 0; + found = i; + while (++j < path.Count) + { + if (i.Childs != null) + { + found = null; + foreach (var c in i.Childs) + { + if (c.Text == path[j]) + { + found = c; + break; + } + } + } + if (found == null) + { + return null; + } + i = found; + } + if (found != null) + return found; + } + } + return null; + } + + void updateNode(Item i) + { + var clist = i.Childs as List; + List listIdshort = new List(); + bool done = false; + if (!done && i.Tag is Submodel sm) + { + foreach (var smew1 in sm.submodelElements) + { + listIdshort.Add(smew1.submodelElement.idShort); + } + done = true; + } + if (!done && i.Tag is SubmodelElementCollection smec) + { + foreach (var smew2 in smec.value) + { + listIdshort.Add(smew2.submodelElement.idShort); + } + done = true; + } + if (!done && i.Tag is SubmodelElement sme) + { + listIdshort.Add(sme.idShort); + done = true; + } + // check if child name exists in data children idshorts, if not delete + if (done) + { + List toDelete = new List(); + if (clist != null) + { + foreach (var c in clist) + { + if (!listIdshort.Contains(c.Text)) + { + toDelete.Add(c); + } + } + } + else + { + if (!listIdshort.Contains(i.Text)) + { + toDelete.Add(i); + } + } + foreach (var c in toDelete) + { + var parent = c.parent as Item; + if (parent != null) + { + (parent.Childs as List).Remove(c); + } + } + } + // check if data children idshorts exist in child names, if not insert + if (clist != null) + { + foreach (var c in clist) + { + updateNode(c); + } + } + } + + string createDetailsImage(Item item) + { + // System.IO.File.Delete("wwwroot/detailsImage.jpg"); + + if (item == null) + { + return ""; + } + + object o = item.Tag; + + if (o is AdministrationShell) + { + var aas = o as AdministrationShell; + lock (Program.changeAasxFile) + { + try + { + using (System.IO.Stream s = Program.env[item.envIndex].GetLocalThumbnailStream()) + { + if (s != null) + { + using (var m = new System.IO.MemoryStream()) + { + s.CopyTo(m); + return System.Convert.ToBase64String(m.ToArray()); + } + } + + } + } + catch { } + } + } + + if (o is AdminShellNS.AdminShellV20.File) + { + var f = o as AdminShellNS.AdminShellV20.File; + + // Test for /aasx/ + if (f.value != "") + { + string[] split = f.value.Split(new Char[] { '/' }); + if (split.Length == 2 || split.Length > 1 && split[1].ToLower() == "aasx") + { + split = f.value.Split(new Char[] { '.' }); + switch (split.Last().ToLower()) + { + case "jpg": + case "bmp": + case "png": + try + { + using (System.IO.Stream s = Program.env[item.envIndex].GetLocalStreamFromPackage(f.value)) + { + if (s != null) + { + using (var m = new System.IO.MemoryStream()) + { + s.CopyTo(m); + return System.Convert.ToBase64String(m.ToArray()); + } + } + } + } + catch { } + break; + } + } + } + } + + return ""; + } + + string getQRCodeLink(Item item) + { + if (item == null) + { + return ""; + } + + string prefix = "http://"; + string hostPort = Program.hostPort; + + string[] split = Program.hostPort.Split(':'); + if (split[0].ToLower() == "admin-shell-io.com") + { + // prefix = "https://"; + // hostPort = split[0] + ":" + (Convert.ToInt32(split[1]) + 1); + } + + object o = item.Tag; + + if (o is AdministrationShell) + { + var aas = o as AdministrationShell; + var asset = Program.env[item.envIndex].AasEnv.FindAsset(aas.assetRef); + if (asset != null) + { + // string url = WebUtility.UrlEncode(asset.identification.id); + string url = asset.identification.id; + // string link = prefix + hostPort + "/server/getaasxbyassetid/" + url; + // string link = Program.externalRest + "/server/getaasxbyassetid/" + url; + string link = url; + + return link; + } + } + + return ""; + } + + string getQRCodeImage(Item item) + { + if (item == null) + { + return ""; + } + + object o = item.Tag; + + if (o is AdministrationShell) + { + string image = Program.generatedQrCodes[item.Tag]; + + if (image != null) + return image; + } + + return ""; + } + + void createQRCodeImage(Item item) + { + // System.IO.File.Delete("wwwroot/detailsImage.jpg"); + + if (item == null) + { + return; + } + + string prefix = "http://"; + string hostPort = Program.hostPort; + + string[] split = Program.hostPort.Split(':'); + if (split[0].ToLower() == "admin-shell-io.com") + { + // prefix = "https://"; + // hostPort = split[0] + ":" + (Convert.ToInt32(split[1]) + 1); + } + + object o = item.Tag; + + if (o is AdministrationShell) + { + if (Program.generatedQrCodes.ContainsKey(item.Tag)) + { + Program.generatedQrCodes.Remove(item.Tag); + return; + } + + var aas = o as AdministrationShell; + var asset = Program.env[item.envIndex].AasEnv.FindAsset(aas.assetRef); + if (asset != null) + { + // string url = WebUtility.UrlEncode(asset.identification.id); + string url = asset.identification.id; + // string link = prefix + hostPort + "/server/getaasxbyassetid/" + url; + // string link = Program.externalRest + "/server/getaasxbyassetid/" + url; + string link = url; + + QRCodeGenerator qrGenerator = new QRCodeGenerator(); + QRCodeData qrCodeData = qrGenerator.CreateQrCode(link, QRCodeGenerator.ECCLevel.Q); + QRCode qrCode = new QRCode(qrCodeData); + Bitmap qrCodeImage = qrCode.GetGraphic(20); + using (System.IO.MemoryStream memory = new System.IO.MemoryStream()) + { + qrCodeImage.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); + string base64 = Convert.ToBase64String(memory.ToArray()); + + Program.generatedQrCodes.Add(item.Tag, base64); + + } + return; + } + } + + return; + } + + bool hasDownloadFile(Item item) + { + return false; + + if (item == null) + { + return false; + } + + object o = item.Tag; + + if (o is AdminShellNS.AdminShellV20.File) + { + + var f = o as AdminShellNS.AdminShellV20.File; + + // Test for /aasx/ + string[] split = f.value.Split(new Char[] { '/' }); + if (split.Length == 2 || split[1].ToLower() == "aasx") + { + return true; + } + } + + return false; + } + + string getLink(Item item, out bool external) + { + external = false; + + if (item == null) + { + return ""; + } + + string prefix = "http://"; + string hostPort = Program.hostPort; + + string[] split = Program.hostPort.Split(':'); + if (split[0].ToLower() == "admin-shell-io.com") + { + prefix = "https://"; + hostPort = split[0] + ":" + (Convert.ToInt32(split[1]) + 1); + } + + object o = item.Tag; + + if (o == null && Program.envSymbols[item.envIndex] == "L") + { + // return prefix + hostPort + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); + return Program.externalRest + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); + } + + if (o is AdministrationShell) + { + // return prefix + hostPort + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); + return Program.externalRest + "/server/getaasx/" + Convert.ToString(selectedNode.envIndex); + } + + if (o is AdminShellNS.AdminShellV20.File || o is Property) + { + string value = ""; + + if (o is AdminShellNS.AdminShellV20.File) + { + value = (o as AdminShellNS.AdminShellV20.File).value; + } + if (o is Property) + { + value = (o as Property).value; + } + + split = value.Split(new Char[] { ':' }); + if (split[0].ToLower() == "http" || split[0].ToLower() == "https") + { + external = true; + return value; + } + + // Test for /aasx/ + split = value.Split(new Char[] { '/' }); + if (split.Length > 1) + { + if (split.Length == 2 || split[1].ToLower() == "aasx") + { + // return prefix + hostPort + "/server/getfile/" + item.envIndex.ToString() + value; + return Program.externalRest + "/server/getfile/" + item.envIndex.ToString() + value; + } + } + } + + return ""; + } + + string getSymbols(Item item) + { + if (item == null) + { + return ""; + } + + string ret = ""; + object o = item.Tag; + + if (o is AdministrationShell) + { + string symbols = Program.envSymbols[item.envIndex]; + + if (symbols != null) + { + string[] s = symbols.Split(';'); + + for (int i = 0; i < s.Length; i++) + { + switch (s[i]) + { + case "L": + ret += "ENCRYPTED "; + break; + case "S": + ret += "SIGNED "; + break; + case "V": + ret += "VALIDATED "; + break; + } + } + } + } + + return ret; + } + + string ViewNodeType(Item item) + { + if (item == null) + { + return ""; + } + + string ret = ""; + + if (item.Type != null) + { + ret = item.Type + " "; + } + + object o = item.Tag; + + /* + if (o is Referable) + { + ret = (o as Referable).GetElementName(); + return (ret); + } + */ + + if (o == null && Program.envSymbols[item.envIndex] == "L") + { + ret += "AASX2"; + } + + if (o is AdministrationShell) + { + ret += "AAS"; + } + if (o is Submodel) + { + ret += "Sub"; + } + if (o is SubmodelElement) + { + if (o is SubmodelElementCollection) + { + ret += "Coll"; + } + if (o is Property) + { + ret += "Prop"; + } + } + if (o is Operation) + { + ret += "Opr"; + } + if (o is AdminShellNS.AdminShellV20.File) + { + ret += "File"; + } + if (o is Blob) + { + ret += "Blob"; + } + if (o is AdminShellNS.AdminShellV20.Range) + { + ret += "Range"; + } + if (o is MultiLanguageProperty) + { + ret += "Lang"; + } + if (o is RelationshipElement) + { + ret += "Rel"; + } + if (o is ReferenceElement) + { + ret += "Ref"; + } + if (o is Entity) + { + ret += "Ent"; + } + if (o is AdminShellNS.AdminShellV20.BasicEvent) + { + ret += "Evt"; + } + + return (ret); + } + + string ViewTimeStamp(Item item) + { + if (item == null) + { + return ""; + } + + string ret = ""; + + object o = item.Tag; + + if (o is Referable r) + // ret += " (" + r.TimeStamp.Ticks + ") "; + ret += " (" + r.TimeStamp.ToString("yy-MM-dd HH:mm:ss.fff") + ") "; + + return ret; + } + + string ViewNodeID(Item item) + { + if (item == null) + { + return ""; + } + + string ret = "NULL"; + + object o = item.Tag; + + if (o == null && Program.envSymbols[item.envIndex] == "L") + { + ret = item.Text; + } + + if (o is AdministrationShell) + { + var aas = o as AdministrationShell; + ret = aas.idShort; + } + if (o is Submodel) + { + var sm = o as Submodel; + ret = ""; + if (sm.kind != null && sm.kind.IsTemplate) + ret += " "; + ret += sm.idShort; + } + if (o is SubmodelElement) + { + var sme = o as SubmodelElement; + ret = ""; + if (sme.kind != null && sme.kind.IsTemplate) + ret += " "; + ret += sme.idShort; + } + if (o is AdminShellNS.AdminShellV20.File) + { + var f = o as AdminShellNS.AdminShellV20.File; + ret = ""; + if (f.kind != null && f.kind.IsTemplate) + ret += " "; + ret += f.idShort; + } + if (o is Blob) + { + var b = o as Blob; + ret = ""; + if (b.kind != null && b.kind.IsTemplate) + ret += " "; + ret += b.idShort; + } + if (o is AdminShellNS.AdminShellV20.Range) + { + var r = o as AdminShellNS.AdminShellV20.Range; + ret = ""; + if (r.kind != null && r.kind.IsTemplate) + ret += " "; + ret += r.idShort; + } + if (o is MultiLanguageProperty) + { + var mlp = o as MultiLanguageProperty; + ret = ""; + if (mlp.kind != null && mlp.kind.IsTemplate) + ret += " "; + ret += mlp.idShort; + } + return (ret); + } + + string GetHtmlId(Item item) + { + string ret = ViewNodeID(item); + if (item.parent != null) + { + ret = GetHtmlId(item.parent as Item) + "." + ret; + } + return (ret); + } + + string ViewNodeInfo(Item item) + { + if (item == null) + { + return ""; + } + + string ret = ""; + + object o = item.Tag; + + if (o is AdministrationShell) + { + var aas = o as AdministrationShell; + // ret = aas.identification.ToString(); + } + if (o is Submodel) + { + var sm = o as Submodel; + // ret = sm.identification.ToString(); + if (sm.qualifiers != null && sm.qualifiers.Count > 0) + { + ret += " @QUALIFIERS"; + } + } + if (o is SubmodelElementCollection) + { + var sme = o as SubmodelElementCollection; + // ret = sm.identification.ToString(); + if (sme.value.Count > 0) + { + ret += " #" + sme.value.Count; + } + if (sme.qualifiers != null && sme.qualifiers.Count > 0) + { + ret += " @QUALIFIERS"; + } + } + if (o is SubmodelElement) + { + if (o is Property) + { + var prop = o as Property; + if (prop.value != "") + { + string v = prop.value; + if (v.Length > 100) + v = v.Substring(0, 100) + " .."; + ret = " = " + v; + } + if (prop.qualifiers != null && prop.qualifiers.Count > 0) + { + ret += " @QUALIFIERS"; + } + } + if (o is AdminShellNS.AdminShellV20.File) + { + var f = o as AdminShellNS.AdminShellV20.File; + ret = " = " + f.value; + if (f.qualifiers != null && f.qualifiers.Count > 0) + { + ret += " @QUALIFIERS"; + } + } + } + if (o is AdminShellNS.AdminShellV20.Range) + { + var r = o as AdminShellNS.AdminShellV20.Range; + ret = " = " + r.min + " .. " + r.max; + if (r.qualifiers != null && r.qualifiers.Count > 0) + { + ret += " @QUALIFIERS"; + } + } + if (o is MultiLanguageProperty) + { + var mlp = o as MultiLanguageProperty; + var ls = mlp.value; + ret = " = "; + for (int i = 0; i < ls.Count; i++) + { + ret += ls.langString[i].lang + " "; + if (i == 0) + ret += ls.langString[i].str + " "; + } + if (mlp.qualifiers != null && mlp.qualifiers.Count > 0) + { + ret += " @QUALIFIERS"; + } + } + return (ret); + } + + string ViewNodeDetails(Item item, int line, int col) + { + if (item == null) + { + return ""; + } + + // string ret = "NULL"; + string ret = ""; + + object o = item.Tag; + + if (o == null) + { + return ""; + } + + if (o is AdministrationShell) + { + string subjectIssuer = null; + + ret = ""; + var aas = o as AdministrationShell; + + var asset = Program.env[item.envIndex].AasEnv.FindAsset(aas.assetRef); + + switch (line) + { + case 0: + if (col == 0) + ret = "ID"; + if (col == 1) + ret = aas.identification + ""; + if (col == 2) + ret = " ==> " + Base64UrlEncoder.Encode(aas.identification.id) + ""; + break; + case 1: + if (asset != null) + { + if (col == 0) + ret = "ASSET"; + if (col == 1) + ret = asset.idShort; + } + break; + case 2: + if (asset != null) + { + if (col == 0) + ret = "ASSETID"; + if (col == 1) + ret = asset.identification + ""; + if (col == 2) + ret = " ==> " + Base64UrlEncoder.Encode(asset.identification.id) + ""; + } + break; + case 3: + if (asset != null) + { + if (col == 0) + ret = "ASSETID URLENCODED"; + if (col == 1) + { + string url = WebUtility.UrlEncode(asset.identification.id); + ret = url; + } + } + break; + /* + case 3: + subjectIssuer = Program.envSubjectIssuer[item.envIndex]; + if (subjectIssuer != null) + { + string[] s = subjectIssuer.Split(';'); + if (s.Length > 0 && s[0] != "") + { + ret = "SUBJECT"; + if (col == 1) + ret = s[0]; + } + } + break; + case 4: + subjectIssuer = Program.envSubjectIssuer[item.envIndex]; + if (subjectIssuer != null) + { + string[] s = subjectIssuer.Split(';'); + if (s.Length > 1 && s[1] != "") + { + ret = "ISSUER"; + if (col == 1) + ret = s[1]; + } + } + break; + */ + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is Submodel) + { + var sm = o as Submodel; + ret = ""; + switch (line) + { + case 0: + if (col == 0) + ret = "ID"; + if (col == 1) + ret = sm.identification + ""; + if (col == 2) + ret = " ==> " + Base64UrlEncoder.Encode(sm.identification.id) + ""; + break; + case 1: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = sm.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 2: + ret = getQualifiers(sm.qualifiers, col); + break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is Property) + { + var prop = o as Property; + // ret += ", " + prop.value; + ret = ""; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = prop.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "Value Type"; + if (col == 1) + ret = prop.valueType + ""; + break; + case 2: + if (col == 0) + ret = "Value"; + if (col == 1) + ret = prop.value + ""; + break; + case 3: + ret = getQualifiers(prop.qualifiers, col); + break; + case 4: + if (col == 0) + ret = getUnit(item, prop, col); + break; + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is Entity) + { + var e = o as Entity; + // ret += ", " + e.entityType; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = e.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "Entity Type"; + if (col == 1) + ret = e.entityType + ""; + break; + case 2: + ret = ""; + if (e.GetEntityType() == Entity.EntityTypeEnum.SelfManagedEntity) + { + if (e.assetRef != null) + { + if (col == 0) + ret = "Asset"; + if (col == 1) + { + var k = e.assetRef.Keys; + if (k != null) + { + ret = k.ToString(); + } + } + } + } + break; + case 3: + ret = getQualifiers(e.qualifiers, col); + break; + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is AdminShellNS.AdminShellV20.File) + { + var f = o as AdminShellNS.AdminShellV20.File; + // ret += ", " + f.value; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = f.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "Value"; + if (col == 1) + ret = f.value; + break; + case 2: + ret = getQualifiers(f.qualifiers, col); + break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is Blob) + { + var b = o as Blob; + ret = ""; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = b.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "MimeType"; + if (col == 1) + ret = b.mimeType; + break; + case 2: + if (col == 0) + ret = "Value"; + if (col == 1) + ret = b.value; + break; + case 3: + ret = getQualifiers(b.qualifiers, col); + break; + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is AdminShellNS.AdminShellV20.Range) + { + var r = o as AdminShellNS.AdminShellV20.Range; + // ret = r.idShort; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = r.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "Min"; + if (col == 1) + ret = r.min + ""; + break; + case 2: + if (col == 0) + ret = "Max"; + if (col == 1) + ret = r.max + ""; + break; + case 3: + ret = getQualifiers(r.qualifiers, col); + break; + case 4: + if (col == 0) + ret = getUnit(item, r, col); + break; + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is Operation) + { + var op = o as Operation; + // ret = op.idShort; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = op.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "CountInputs"; + if (col == 1) + { + ret = "0"; + if (op.inputVariable != null) + { + ret = op.inputVariable.Count + ""; + } + } + break; + case 2: + if (col == 0) + ret = "CountOutputs"; + if (col == 1) + { + ret = "0"; + if (op.outputVariable != null) + { + ret = op.outputVariable.Count + ""; + } + } + break; + case 3: + ret = getQualifiers(op.qualifiers, col); + break; + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is RelationshipElement) + { + var r = o as RelationshipElement; + // ret = r.idShort; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = r.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "First"; + if (col == 1) + { + ret = "NULL"; + var k = r.first; + if (k != null) + { + ret = k.Keys.ToString(); + } + } + break; + case 2: + if (col == 0) + ret = "Second"; + if (col == 1) + { + ret = "NULL"; + var k = r.second; + if (k != null) + { + ret = k.Keys.ToString(); + } + } + break; + case 3: + ret = getQualifiers(r.qualifiers, col); + break; + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is ReferenceElement) + { + var r = o as ReferenceElement; + // ret = r.idShort; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = r.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + if (col == 0) + ret = "Value"; + if (col == 1) + { + ret = "NULL"; + if (!(r.value == null || r.value.IsEmpty)) + { + var k = r.value.Keys; + if (k != null) + { + ret = k.ToString(); + } + } + } + break; + case 2: + ret = getQualifiers(r.qualifiers, col); + break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is MultiLanguageProperty) + { + var mlp = o as MultiLanguageProperty; + var ls = mlp.value; + for (int i = 0; i < ls.Count; i++) + { + ret += ls.langString[i].lang + " "; + } + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = mlp.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + case 2: + case 3: + case 4: + ret = ""; + if (ls.Count > line - 1) + { + if (col == 0) + ret = ls.langString[line - 1].lang; + if (col == 1) + ret = ls.langString[line - 1].str + ""; + } + break; + case 5: + ret = getQualifiers(mlp.qualifiers, col); + break; + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + if (o is SubmodelElement) + { + var sme = o as SubmodelElement; + // ret = sme.idShort + ", " + sme.semanticId; + switch (line) + { + case 0: + if (col == 0) + ret = "Semantic ID"; + if (col == 1) + { + ret = "NULL"; + var k = sme.semanticId?.GetAsExactlyOneKey(); + if (k != null) + { + ret = k.ToString(); + } + } + break; + case 1: + ret = getQualifiers(sme.qualifiers, col); + break; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + ret = ""; + break; + } + return ret; + } + + return (ret); + } + + static string getQualifiers(QualifierCollection q, int col) + { + string ret = ""; + + if (q != null && q.Count > 0) + { + if (col == 0) + ret = "Qualifiers"; + if (col == 1) + { + ret = ""; + for (int i = 0; i < q.Count; i++) + { + if (i != 0) + ret += ", "; + if (q[i].type != null && q[i].type != "") + { + ret += q[i].type + " "; + } + if (q[i].value != null && q[i].value != "") + { + ret += "= " + q[i].value; + } + } + } + } + return ret; + } + + public string getUnit(Item item, SubmodelElement se, int col) + { + string ret = ""; + if (se.semanticId == null || se.semanticId.Keys == null) + { + return ret; + } + var cd = Program.env[item.envIndex].AasEnv.FindConceptDescription(se.semanticId.Keys); + if (cd != null) + { + var iec = cd.GetIEC61360(); + if (iec != null) + { + ret = "Unit"; + if (col == 1) + { + ret = iec.unit; + if (iec.unitId != null && iec.unitId.keys != null && iec.unitId.keys.Count > 0) + ret += " (UnitId = " + iec.unitId.keys[0].ToString() + ")"; + } + } + } + return ret; + } } diff --git a/src/AasxServerBlazor/Pages/TreePage.razor.css b/src/AasxServerBlazor/Pages/TreePage.razor.css new file mode 100644 index 000000000..2b3329bd5 --- /dev/null +++ b/src/AasxServerBlazor/Pages/TreePage.razor.css @@ -0,0 +1,9 @@ +.test { + color: red; + background-color: yellow; +} + +h1 { + color: purple; + background-color: yellow; +} \ No newline at end of file diff --git a/src/AasxServerBlazor/Pages/TreePage.razor.js b/src/AasxServerBlazor/Pages/TreePage.razor.js new file mode 100644 index 000000000..a625f901b --- /dev/null +++ b/src/AasxServerBlazor/Pages/TreePage.razor.js @@ -0,0 +1,3 @@ +$('.left_inner').resizable(); +$('.right_top_inner').resizable(); +$('.right_bottom_inner').resizable(); \ No newline at end of file diff --git a/src/AasxServerBlazor/Pages/_Host.cshtml b/src/AasxServerBlazor/Pages/_Host.cshtml index 59ec042d7..6cbfec1d6 100644 --- a/src/AasxServerBlazor/Pages/_Host.cshtml +++ b/src/AasxServerBlazor/Pages/_Host.cshtml @@ -5,214 +5,230 @@ - - - AasxServerBlazor - - - - - - - @{ - if (System.IO.File.Exists("TAILWIND.DAT")) - { - - } - } - - - + + + AasxServerBlazor + + + + + + + + + + + + + + + + + + + - - @(await Html.RenderComponentAsync(RenderMode.ServerPrerendered)) - + + @(await Html.RenderComponentAsync(RenderMode.ServerPrerendered)) + + + - diff --git a/src/AasxServerBlazor/Properties/launchSettings.json b/src/AasxServerBlazor/Properties/launchSettings.json index b6b92bb23..b150775b3 100644 --- a/src/AasxServerBlazor/Properties/launchSettings.json +++ b/src/AasxServerBlazor/Properties/launchSettings.json @@ -1,12 +1,4 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:56189", - "sslPort": 0 - } - }, "profiles": { "IIS Express": { "commandName": "IISExpress", @@ -18,13 +10,21 @@ }, "AasxServerBlazor": { "commandName": "Project", - "commandLineArgs": "--rest --data-path \"C:\\Development\\AASX\" --edit --external-blazor http://localhost:5001 --no-security", + "commandLineArgs": "--rest --data-path \"C:\\Benutzer\\Mateusz\\Desktop\\aasx_files\" --edit --no-security", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:5001", - "jsWebView2Debugging": true + "jsWebView2Debugging": true, + "applicationUrl": "http://localhost:5001" + } + }, + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:56189", + "sslPort": 0 } } } \ No newline at end of file diff --git a/src/AasxServerStandardBib/Properties/launchSettings.json b/src/AasxServerStandardBib/Properties/launchSettings.json new file mode 100644 index 000000000..37baff7c3 --- /dev/null +++ b/src/AasxServerStandardBib/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "AasxServerStandardBib": { + "commandName": "Project" + } + } +} \ No newline at end of file