Skip to content

Commit

Permalink
161 new feature rcc should request state change when any of the param…
Browse files Browse the repository at this point in the history
…eters changes (#166)

* auto polling in now triggered from base ReanderableComponent

---------

Co-authored-by: PTKu <PTKu@users.noreply.github.com>
  • Loading branch information
PTKu and PTKu authored Apr 27, 2023
1 parent af8e653 commit 3fa972c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,11 @@
namespace AXSharp.Presentation.Blazor.Controls.RenderableContent
{
/// <summary>
/// Base class for complex componenets with only code-behind.
/// Base class for complex components with only code-behind.
/// </summary>
public class RenderableComplexComponentBase<T> : RenderableComponentBase,
IRenderableComplexComponentBase,
IDisposable
public class RenderableComplexComponentBase<T> : 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,70 @@
// 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
{
/// <summary>
/// Base class which implements methods to update UI when PLC values are changed.
/// </summary>
public partial class RenderableComponentBase : ComponentBase, IRenderableComponent
public partial class RenderableComponentBase : ComponentBase, IRenderableComponent, IDisposable
{
[Parameter] public int PollingInterval { get; set; }

///<inheritdoc/>
public virtual void Dispose()
{
PolledElements.ForEach(p =>
{
p.StopPolling();
});

PolledElements.Clear();
}

private List<ITwinElement> PolledElements { get; } = new List<ITwinElement>();

public bool HasFocus { get; set; }

/// <summary>
/// Method, which updates are primitive values of ITwinObject instance
/// <param name="element">ITwinObject instance.</param>
/// <param name="pollingInterval">Polling interval</param>
/// </summary>
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;
tag.PropertyChanged += new PropertyChangedEventHandler(HandlePropertyChanged);
}
}
}

/// <summary>
/// Method, which updates primitive value.
/// <param name="tag">IValueTag instance.</param>
/// <param name="pollingInterval">Polling interval</param>
/// </summary>
public void UpdateValuesOnChange(OnlinerBase tag)
public void UpdateValuesOnChange(OnlinerBase tag, int pollingInterval = 250)
{
tag.StartPolling(pollingInterval);
PolledElements.Add(tag);
tag.PropertyChanged += new PropertyChangedEventHandler(HandlePropertyChanged);
}

Expand All @@ -62,6 +87,7 @@ public void UpdateShadowValuesOnChange(ITwinObject element)
}
}
}

/// <summary>
/// Method, which updates shadow primitive value.
/// <param name="tag">IValueTag instance.</param>
Expand All @@ -71,7 +97,6 @@ public void UpdateShadowValuesOnChange(ITwinPrimitive tag)
((dynamic)tag).ShadowValueChangeEvent += new ValueChangedEventHandlerDelegate(HandleShadowPropertyChanged);
}


/// <summary>
/// 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.
Expand All @@ -96,6 +121,5 @@ protected void HandlePropertyChangedOnOutFocus(object sender, PropertyChangedEve
{
if(!HasFocus) InvokeAsync(StateHasChanged);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ public string Presentation
[Parameter]
public string LayoutChildrenClass { get; set; }

/// <summary>
/// Gets or sets polling interval for PLC variables of this controls context in ms.
/// </summary>
[Parameter]
public int PollingInterval { get; set; } = 250;

[Inject]
public ComponentService ComponentService { get; set; }
[Inject]
Expand All @@ -93,7 +87,6 @@ protected override void OnInitialized()
try
{
_context = (ITwinElement)Context;
_context.StartPolling(this.PollingInterval);
}
catch
{
Expand Down Expand Up @@ -375,7 +368,6 @@ private string GetDisplayPresentationIfEmpty()

public virtual void Dispose()
{
this._context?.StopPolling();
_viewModelCache.ResetCounter();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
namespace AXSharp.Presentation.Blazor.Controls.RenderableContent
{
/// <summary>
/// Base class for complex componenets with viewmodel support.
/// Base class for complex components with viewmodel support.
/// </summary>
public class RenderableViewModelComponentBase<T> : RenderableComponentBase, IRenderableViewModelBase where T : RenderableViewModelBase, new()
{

[Inject]
private ViewModelCacheService _viewModelCache { get; set; }

private TwinContainerObject _twinContainer;

[Parameter]
public TwinContainerObject TwinContainer
{
Expand Down Expand Up @@ -66,7 +66,6 @@ private void ViewModelInitialization(TwinContainerObject container)

}


public T ViewModel { get; set; }
}
}

0 comments on commit 3fa972c

Please sign in to comment.