-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ControlledUnits in Units.razor returns all items that are derived fro…
…m UnitContainerBase (#18) * ControlledUnits in Units.razor returns all items that are derived from UnitContainerBase * simplification of getting all CUs in Units.razor * create unit services automatically * Added generation of the view of all cotrolled unit * Default view generation call added * Global modes button added
- Loading branch information
Showing
5 changed files
with
189 additions
and
12 deletions.
There are no files selected for viewing
94 changes: 91 additions & 3 deletions
94
axopen.template.simple/axpansion/server/Pages/Context/Context.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,99 @@ | ||
@page "/Context/" | ||
@using AXOpen.VisualComposer; | ||
@using AXSharp.Connector | ||
@using AXOpen.Core; | ||
@using AXOpen.Core.Blazor.AxoAlertDialog; | ||
@using AXOpen.Base.Dialogs | ||
@using axosimple.BaseUnit | ||
@inject IAlertService _alerts | ||
|
||
<div class="text-center p-2 fixed-top" style="z-index: 0;"> | ||
<button type="button" class="btn btn-primary" @onclick="Automat">@Localizer["AUTOMAT"]</button> | ||
<button type="button" class="btn btn-primary" @onclick="Ground">@Localizer["GROUND"]</button> | ||
<button type="button" class="btn btn-primary" @onclick="Service">@Localizer["SERVICE"]</button> | ||
</div> | ||
|
||
<VisualComposerContainer | ||
Objects="new ITwinObject []{ Entry.Plc.Context, Entry.Plc.Inputs, Entry.Plc.Outputs }" | ||
Id="ContextView"/> | ||
|
||
@code { | ||
|
||
} | ||
@code | ||
{ | ||
private async Task Automat() | ||
{ | ||
_alerts.AddAlertDialog(eAlertType.Info, Localizer["Mode change"], $"{Localizer[$"Requesting automatic mode of selected units"]}.", 1); | ||
|
||
var notGroundedStations = ControlledUnits.Where(p => p.GroundStatus != eAxoTaskState.Done); | ||
var ungroundedStationsList = string.Join(",", notGroundedStations.Select(p => p.AttributeName)); | ||
|
||
if (notGroundedStations.Count() > 0) | ||
{ | ||
_alerts.AddAlertDialog(eAlertType.Warning, Localizer["Mode change"], | ||
$"{Localizer[$"Cannot start automatic mode on unit(s)"]} `{ungroundedStationsList}`. Ground must be executed successfully first.", 5); | ||
return; | ||
} | ||
|
||
foreach (var a in ControlledUnits) | ||
{ | ||
await a.AutomatTask.ExecuteAsync(); | ||
} | ||
|
||
_alerts.AddAlertDialog(eAlertType.Success, Localizer["Mode change"], $"{Localizer[$"Automatic mode of selected units"]} has been started.", 3); | ||
} | ||
|
||
private async Task Ground() | ||
{ | ||
_alerts.AddAlertDialog(eAlertType.Info, Localizer["Mode change"], $"{Localizer[$"Requesting ground mode of selected units"]}.", 1); | ||
int expectedTimeToExecute = 20000; | ||
ControlledUnits.ToList().ForEach(async a => await a.GroundTask.ExecuteAsync()); | ||
|
||
var sw = new System.Diagnostics.Stopwatch(); | ||
sw.Start(); | ||
await Task.Run(async () => | ||
{ | ||
foreach (var a in ControlledUnits) | ||
{ | ||
while (a.GroundStatus != eAxoTaskState.Done | ||
&& sw.ElapsedMilliseconds <= expectedTimeToExecute) | ||
{ | ||
await Task.Delay(25); | ||
} | ||
} | ||
|
||
}); | ||
|
||
if (sw.ElapsedMilliseconds > expectedTimeToExecute) | ||
{ | ||
var pp = string.Join(",\n", ControlledUnits | ||
.Where(p => p.GroundStatus != eAxoTaskState.Done) | ||
.Select(p => p.AttributeName)); | ||
|
||
_alerts.AddAlertDialog(eAlertType.Danger, | ||
Localizer["Mode change"], | ||
$"{Localizer[$"Ground mode did not succeed on unit"]} " + | ||
$"{pp}", 5); | ||
|
||
return; | ||
} | ||
|
||
_alerts.AddAlertDialog(eAlertType.Success, | ||
Localizer["Mode change"], | ||
$"{Localizer[$"Ground mode of selected unit(s)"]} was successfully executed.", 3); | ||
|
||
this.StateHasChanged(); | ||
} | ||
|
||
private void Service() | ||
{ | ||
ControlledUnits.ToList().ForEach(async a => await a.ServiceTask.ExecuteAsync()); | ||
this.StateHasChanged(); | ||
} | ||
|
||
private UnitContainerBase[] ControlledUnits | ||
{ | ||
get | ||
{ | ||
return (Entry.Plc.Context.GetChildren().Where(o => o is UnitContainerBase)).Cast<UnitContainerBase>().ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
axopen.template.simple/axpansion/server/VisualComposerSerialize/ContextView.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"Views": [ | ||
"A" | ||
"A", | ||
"_generated" | ||
], | ||
"DefaultView": "A" | ||
"DefaultView": "_generated" | ||
} |
29 changes: 29 additions & 0 deletions
29
axopen.template.simple/axpansion/server/VisualComposerSerialize/ContextView/_generated.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"BackgroundWidth": 100, | ||
"BackgroundHeight": 200, | ||
"ImgSrc": null, | ||
"BackgroundColor": "#027dfb", | ||
"BackgroundSVGInput": "", | ||
"Items": [ | ||
{ | ||
"Id": "f122746ffacbbf3a0633a9695c646677467d58ed708ea07d46a16dea4f178979", | ||
"Left": 42.71396103914338, | ||
"Top": 6.913580246913581, | ||
"Transform": "TopCenter", | ||
"Presentation": "Spot", | ||
"Width": -1, | ||
"Height": -1, | ||
"ZIndex": 10, | ||
"Scale": 1, | ||
"Roles": "", | ||
"PresentationTemplate": null, | ||
"Background": false, | ||
"BackgroundColor": "#FFFFFF" | ||
} | ||
], | ||
"Theme": "text-dark", | ||
"Scale": 1, | ||
"TranslateX": 0, | ||
"TranslateY": 0, | ||
"AllowZoomingAndPanning": false | ||
} |