From 3fa972cf699897ec194499eaaf50359afd7bf6af Mon Sep 17 00:00:00 2001 From: Peter Kurhajec <61538034+PTKu@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:40:45 +0200 Subject: [PATCH] 161 new feature rcc should request state change when any of the parameters changes (#166) * auto polling in now triggered from base ReanderableComponent --------- Co-authored-by: PTKu --- .../RenderableComplexComponentBase.cs | 19 ++--------- .../RenderableComponentBase.cs | 34 ++++++++++++++++--- .../RenderableContentControl.cs | 8 ----- .../RenderableViewModelComponentBase.cs | 5 ++- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComplexComponentBase.cs b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComplexComponentBase.cs index 35257cc8..594adef3 100644 --- a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComplexComponentBase.cs +++ b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComplexComponentBase.cs @@ -17,26 +17,11 @@ namespace AXSharp.Presentation.Blazor.Controls.RenderableContent { /// - /// Base class for complex componenets with only code-behind. + /// Base class for complex components with only code-behind. /// - public class RenderableComplexComponentBase : RenderableComponentBase, - IRenderableComplexComponentBase, - IDisposable + public class RenderableComplexComponentBase : RenderableComponentBase, IRenderableComplexComponentBase { [Parameter] public T Component { get; set; } - - [Parameter] public int PollingInterval { get; set; } = 250; - - protected override void OnInitialized() - { - base.OnInitialized(); - (Component as ITwinElement)?.StartPolling(PollingInterval); - } - - public virtual void Dispose() - { - (Component as ITwinElement)?.StopPolling(); - } } } diff --git a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComponentBase.cs b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComponentBase.cs index 61aa6aca..fb3f2423 100644 --- a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComponentBase.cs +++ b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableComponentBase.cs @@ -5,32 +5,53 @@ // https://github.com/ix-ax/axsharp/blob/dev/LICENSE // Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md +using System; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; using AXSharp.Connector; using AXSharp.Connector.ValueTypes; using AXSharp.Presentation.Blazor.Interfaces; using AXSharp.Connector.ValueTypes.Online; +using System.Xml.Linq; namespace AXSharp.Presentation.Blazor.Controls.RenderableContent { /// /// Base class which implements methods to update UI when PLC values are changed. /// - public partial class RenderableComponentBase : ComponentBase, IRenderableComponent + public partial class RenderableComponentBase : ComponentBase, IRenderableComponent, IDisposable { + [Parameter] public int PollingInterval { get; set; } + + /// + public virtual void Dispose() + { + PolledElements.ForEach(p => + { + p.StopPolling(); + }); + + PolledElements.Clear(); + } + + private List PolledElements { get; } = new List(); public bool HasFocus { get; set; } /// /// Method, which updates are primitive values of ITwinObject instance /// ITwinObject instance. + /// Polling interval /// - public void UpdateValuesOnChange(ITwinObject element) + public void UpdateValuesOnChange(ITwinObject element, int pollingInterval = 250) { if (element != null) { + element.StartPolling(pollingInterval); + PolledElements.Add(element); foreach (var twinPrimitive in element.RetrievePrimitives()) { var tag = (OnlinerBase)twinPrimitive; @@ -38,12 +59,16 @@ public void UpdateValuesOnChange(ITwinObject element) } } } + /// /// Method, which updates primitive value. /// IValueTag instance. + /// Polling interval /// - public void UpdateValuesOnChange(OnlinerBase tag) + public void UpdateValuesOnChange(OnlinerBase tag, int pollingInterval = 250) { + tag.StartPolling(pollingInterval); + PolledElements.Add(tag); tag.PropertyChanged += new PropertyChangedEventHandler(HandlePropertyChanged); } @@ -62,6 +87,7 @@ public void UpdateShadowValuesOnChange(ITwinObject element) } } } + /// /// Method, which updates shadow primitive value. /// IValueTag instance. @@ -71,7 +97,6 @@ public void UpdateShadowValuesOnChange(ITwinPrimitive tag) ((dynamic)tag).ShadowValueChangeEvent += new ValueChangedEventHandlerDelegate(HandleShadowPropertyChanged); } - /// /// Method, which updates primitive value only, when element is out of focus. /// Public property IsFocus can be set. If is true, element won't be updated. @@ -96,6 +121,5 @@ protected void HandlePropertyChangedOnOutFocus(object sender, PropertyChangedEve { if(!HasFocus) InvokeAsync(StateHasChanged); } - } } diff --git a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableContentControl.cs b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableContentControl.cs index da7da631..87b29af2 100644 --- a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableContentControl.cs +++ b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableContentControl.cs @@ -68,12 +68,6 @@ public string Presentation [Parameter] public string LayoutChildrenClass { get; set; } - /// - /// Gets or sets polling interval for PLC variables of this controls context in ms. - /// - [Parameter] - public int PollingInterval { get; set; } = 250; - [Inject] public ComponentService ComponentService { get; set; } [Inject] @@ -93,7 +87,6 @@ protected override void OnInitialized() try { _context = (ITwinElement)Context; - _context.StartPolling(this.PollingInterval); } catch { @@ -375,7 +368,6 @@ private string GetDisplayPresentationIfEmpty() public virtual void Dispose() { - this._context?.StopPolling(); _viewModelCache.ResetCounter(); } } diff --git a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableViewModelComponentBase.cs b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableViewModelComponentBase.cs index b63df347..bdb257db 100644 --- a/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableViewModelComponentBase.cs +++ b/src/AXSharp.blazor/src/AXSharp.Presentation.Blazor.Controls/RenderableContent/RenderableViewModelComponentBase.cs @@ -21,15 +21,15 @@ namespace AXSharp.Presentation.Blazor.Controls.RenderableContent { /// - /// Base class for complex componenets with viewmodel support. + /// Base class for complex components with viewmodel support. /// public class RenderableViewModelComponentBase : RenderableComponentBase, IRenderableViewModelBase where T : RenderableViewModelBase, new() { - [Inject] private ViewModelCacheService _viewModelCache { get; set; } private TwinContainerObject _twinContainer; + [Parameter] public TwinContainerObject TwinContainer { @@ -66,7 +66,6 @@ private void ViewModelInitialization(TwinContainerObject container) } - public T ViewModel { get; set; } } }