5
5
// https://github.com/ix-ax/axsharp/blob/dev/LICENSE
6
6
// Third party licenses: https://github.com/ix-ax/axsharp/blob/master/notices.md
7
7
8
+ using System ;
9
+ using System . Collections . Generic ;
8
10
using System . ComponentModel ;
11
+ using System . Linq ;
9
12
using System . Threading . Tasks ;
10
13
using Microsoft . AspNetCore . Components ;
11
14
using AXSharp . Connector ;
12
15
using AXSharp . Connector . ValueTypes ;
13
16
using AXSharp . Presentation . Blazor . Interfaces ;
14
17
using AXSharp . Connector . ValueTypes . Online ;
18
+ using System . Xml . Linq ;
15
19
16
20
namespace AXSharp . Presentation . Blazor . Controls . RenderableContent
17
21
{
18
22
/// <summary>
19
23
/// Base class which implements methods to update UI when PLC values are changed.
20
24
/// </summary>
21
- public partial class RenderableComponentBase : ComponentBase , IRenderableComponent
25
+ public partial class RenderableComponentBase : ComponentBase , IRenderableComponent , IDisposable
22
26
{
27
+ [ Parameter ] public int PollingInterval { get ; set ; }
28
+
29
+ ///<inheritdoc/>
30
+ public virtual void Dispose ( )
31
+ {
32
+ PolledElements . ForEach ( p =>
33
+ {
34
+ p . StopPolling ( ) ;
35
+ } ) ;
36
+
37
+ PolledElements . Clear ( ) ;
38
+ }
39
+
40
+ private List < ITwinElement > PolledElements { get ; } = new List < ITwinElement > ( ) ;
23
41
24
42
public bool HasFocus { get ; set ; }
25
43
26
44
/// <summary>
27
45
/// Method, which updates are primitive values of ITwinObject instance
28
46
/// <param name="element">ITwinObject instance.</param>
47
+ /// <param name="pollingInterval">Polling interval</param>
29
48
/// </summary>
30
- public void UpdateValuesOnChange ( ITwinObject element )
49
+ public void UpdateValuesOnChange ( ITwinObject element , int pollingInterval = 250 )
31
50
{
32
51
if ( element != null )
33
52
{
53
+ element . StartPolling ( pollingInterval ) ;
54
+ PolledElements . Add ( element ) ;
34
55
foreach ( var twinPrimitive in element . RetrievePrimitives ( ) )
35
56
{
36
57
var tag = ( OnlinerBase ) twinPrimitive ;
37
58
tag . PropertyChanged += new PropertyChangedEventHandler ( HandlePropertyChanged ) ;
38
59
}
39
60
}
40
61
}
62
+
41
63
/// <summary>
42
64
/// Method, which updates primitive value.
43
65
/// <param name="tag">IValueTag instance.</param>
66
+ /// <param name="pollingInterval">Polling interval</param>
44
67
/// </summary>
45
- public void UpdateValuesOnChange ( OnlinerBase tag )
68
+ public void UpdateValuesOnChange ( OnlinerBase tag , int pollingInterval = 250 )
46
69
{
70
+ tag . StartPolling ( pollingInterval ) ;
71
+ PolledElements . Add ( tag ) ;
47
72
tag . PropertyChanged += new PropertyChangedEventHandler ( HandlePropertyChanged ) ;
48
73
}
49
74
@@ -62,6 +87,7 @@ public void UpdateShadowValuesOnChange(ITwinObject element)
62
87
}
63
88
}
64
89
}
90
+
65
91
/// <summary>
66
92
/// Method, which updates shadow primitive value.
67
93
/// <param name="tag">IValueTag instance.</param>
@@ -71,7 +97,6 @@ public void UpdateShadowValuesOnChange(ITwinPrimitive tag)
71
97
( ( dynamic ) tag ) . ShadowValueChangeEvent += new ValueChangedEventHandlerDelegate ( HandleShadowPropertyChanged ) ;
72
98
}
73
99
74
-
75
100
/// <summary>
76
101
/// Method, which updates primitive value only, when element is out of focus.
77
102
/// Public property IsFocus can be set. If is true, element won't be updated.
@@ -96,6 +121,5 @@ protected void HandlePropertyChangedOnOutFocus(object sender, PropertyChangedEve
96
121
{
97
122
if ( ! HasFocus ) InvokeAsync ( StateHasChanged ) ;
98
123
}
99
-
100
124
}
101
125
}
0 commit comments