Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/AXOpen-L3-tests.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXOpen.Security", "Security
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "inxton_axopen_simatic1500", "simatic1500\ctrl\ix\inxton_axopen_simatic1500.csproj", "{153256A2-1F20-4652-9577-EA3F21C58604}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXOpen.Operon.Blazor", "styling\src\AXOpen.Operon.Blazor.csproj", "{AB74CFA4-4E4A-4142-A491-8059359297B8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "inxton_axopen_timers", "timers\src\AXOpen.Timers\inxton_axopen_timers.csproj", "{64E1326E-63C4-4623-B3E9-AE6C33D3D4A4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AXOpen.ToolBox", "toolbox\src\AXOpen.ToolBox\AXOpen.ToolBox.csproj", "{4FFE9FDF-E6FB-4B5F-A4C8-9623F6358A7B}"
Expand Down Expand Up @@ -173,6 +175,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ctrl", "simatic1500\ctrl",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "simatic1500", "simatic1500", "{09E8FEB5-793C-47E0-90A2-3B30199FB321}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "styling\src", "{9B9A3CC5-663F-4767-B17B-5EB7F2C001DE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "styling", "styling", "{91077ADC-5D83-4331-977B-BAC82A86A64D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AXOpen.Timers", "timers\src\AXOpen.Timers", "{93475E41-C4BC-48D7-96F5-E488C3ADFCFD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "timers\src", "{D33BF467-F818-440E-AC41-00B02A851D8B}"
Expand Down Expand Up @@ -309,6 +315,10 @@ Global
{153256A2-1F20-4652-9577-EA3F21C58604}.Debug|Any CPU.Build.0 = Debug|Any CPU
{153256A2-1F20-4652-9577-EA3F21C58604}.Release|Any CPU.ActiveCfg = Release|Any CPU
{153256A2-1F20-4652-9577-EA3F21C58604}.Release|Any CPU.Build.0 = Release|Any CPU
{AB74CFA4-4E4A-4142-A491-8059359297B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB74CFA4-4E4A-4142-A491-8059359297B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB74CFA4-4E4A-4142-A491-8059359297B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB74CFA4-4E4A-4142-A491-8059359297B8}.Release|Any CPU.Build.0 = Release|Any CPU
{64E1326E-63C4-4623-B3E9-AE6C33D3D4A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64E1326E-63C4-4623-B3E9-AE6C33D3D4A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64E1326E-63C4-4623-B3E9-AE6C33D3D4A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -397,6 +407,8 @@ Global
{153256A2-1F20-4652-9577-EA3F21C58604} = {5D7F1861-9390-47C6-ABB5-D0371D58292E}
{5D7F1861-9390-47C6-ABB5-D0371D58292E} = {EBE4D729-DBF6-440F-9C1E-93A7D09668CC}
{EBE4D729-DBF6-440F-9C1E-93A7D09668CC} = {09E8FEB5-793C-47E0-90A2-3B30199FB321}
{AB74CFA4-4E4A-4142-A491-8059359297B8} = {9B9A3CC5-663F-4767-B17B-5EB7F2C001DE}
{9B9A3CC5-663F-4767-B17B-5EB7F2C001DE} = {91077ADC-5D83-4331-977B-BAC82A86A64D}
{64E1326E-63C4-4623-B3E9-AE6C33D3D4A4} = {93475E41-C4BC-48D7-96F5-E488C3ADFCFD}
{93475E41-C4BC-48D7-96F5-E488C3ADFCFD} = {D33BF467-F818-440E-AC41-00B02A851D8B}
{D33BF467-F818-440E-AC41-00B02A851D8B} = {89504C16-C7D9-4274-A430-850E3DC30C37}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ public interface IBrowsableDataObject
{
dynamic RecordId { get; set; }

string _EntityId { get; set; }
string _EntityId { get; set; }

DateTime? ModifiedAt { get; set; }
DateTime? CreatedAt { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ public void AddPredicates<T>(Expression<Func<T, bool>> predicate)
this._predicates[typeof(T)].Add(predicate);
}

public void AddPredicates(Type type, Expression<Func<IBrowsableDataObject, bool>> expression)
{
if (!this._predicates.ContainsKey(type))
{
this._predicates[type] = new List<LambdaExpression>();
}

this._predicates[type].Add(expression);
}

public void AddPredicates(Type type, LambdaExpression predicate)
{
if (!this._predicates.ContainsKey(type))
Expand Down
5 changes: 4 additions & 1 deletion src/base/src/AXOpen.Base.Abstractions/Data/RepositoryBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ public void Create(string identifier, T data)
}
try
{
data?.CreatedAt = DateTime.UtcNow;
data?.ModifiedAt = DateTime.UtcNow;
CreateNvi(identifier, data);
}
catch (Exception e)
Expand Down Expand Up @@ -409,12 +411,13 @@ public void Update(string identifier, T data)
}
try
{
data?.ModifiedAt = DateTime.UtcNow;
UpdateNvi(identifier, data);
}
catch (Exception e)
{
OnUpdateFailed?.Invoke(identifier, data, e);
throw e;
throw;
}
OnUpdateDone?.Invoke(identifier, data);
}
Expand Down
24 changes: 12 additions & 12 deletions src/base/src/AXOpen.Logging/SerilogLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,83 +30,83 @@ public SerilogLogger(Serilog.ILogger logger)

public void Debug(string message, IIdentity identity)
{
Log.Debug("{message} {identity}",message, new { UserName = identity.Name });
Log.Debug("{message} {identity}",message, new { UserName = identity?.Name });
}

public void Debug(string message, ITwinElement sender, IIdentity identity, object details)
{
Log.Debug<object, object, object>($"{message} {{sender}} {{identity}} {{details}}",
new { Symbol = sender?.Symbol, Label = sender?.HumanReadable },
new { UserName = identity.Name, Type = identity.AuthenticationType },
new { UserName = identity.Name, Type = identity?.AuthenticationType },
details
);
}

public void Verbose(string message, IIdentity identity)
{
Log.Verbose("{message} {identity}", message, new { UserName = identity.Name });
Log.Verbose("{message} {identity}", message, new { UserName = identity?.Name });
}

public void Verbose(string message, ITwinElement sender, IIdentity identity, object details)
{
Log.Verbose<object, object, object>($"{message} {{sender}} {{identity}} {{details}}",
new { Symbol = sender?.Symbol, Label = sender?.HumanReadable },
new { UserName = identity.Name, Type = identity.AuthenticationType },
new { UserName = identity.Name, Type = identity?.AuthenticationType },
details
);
}

public void Information(string message, IIdentity identity)
{
Log.Information("{message} {identity}", message,new { UserName = identity.Name });
Log.Information("{message} {identity}", message,new { UserName = identity?.Name });
}

public void Information(string message, ITwinElement sender, IIdentity identity, object details)
{
Log.Information<object, object, object>($"{message} {{sender}} {{identity}} {{details}}",
new { Symbol = sender?.Symbol, Label = sender?.HumanReadable },
new { UserName = identity.Name, Type = identity.AuthenticationType },
new { UserName = identity.Name, Type = identity?.AuthenticationType },
details);
}

public void Warning(string message, IIdentity identity)
{
Log.Warning("{message} {identity}", message, new { UserName = identity.Name });
Log.Warning("{message} {identity}", message, new { UserName = identity?.Name });
}

public void Warning(string message, ITwinElement sender, IIdentity identity, object details)
{
Log.Warning<object, object, object>($"{message} {{sender}} {{identity}} {{details}}",
new { Symbol = sender?.Symbol, Label = sender?.HumanReadable },
new { UserName = identity.Name, Type = identity.AuthenticationType },
new { UserName = identity.Name, Type = identity?.AuthenticationType },
details
);
}

public void Error(string message, IIdentity identity)
{
Log.Error("{message} {identity}", message, new { UserName = identity.Name });
Log.Error("{message} {identity}", message, new { UserName = identity?.Name });
}

public void Error(string message, ITwinElement sender, IIdentity identity, object details)
{
Log.Error<object, object, object>($"{message} {{sender}} {{identity}} {{details}}",
new { Symbol = sender?.Symbol, Label = sender?.HumanReadable },
new { UserName = identity.Name, Type = identity.AuthenticationType },
new { UserName = identity.Name, Type = identity?.AuthenticationType },
details
);
}

public void Fatal(string message, IIdentity identity)
{
Log.Fatal("{message} {identity}", message, new { UserName = identity.Name });
Log.Fatal("{message} {identity}", message, new { UserName = identity?.Name });
}

public void Fatal(string message, ITwinElement sender, IIdentity identity, object details)
{
Log.Fatal<object, object, object>($"{message} {{sender}} {{identity}} {{details}}",
new { Symbol = sender?.Symbol, Label = sender?.HumanReadable },
new { UserName = identity.Name, Type = identity.AuthenticationType },
new { UserName = identity.Name, Type = identity?.AuthenticationType },
details
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/core/ctrl/src/AxoObject/AxoObject.st
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ NAMESPACE AXOpen.Core
NULL_CONTEXT_OBJ : IAxoObject;
END_VAR

// We always reset message count upon initialization.
THIS.MsgCnt := LINT#0;

IF _isInitialized THEN
RETURN;
END_IF;
Expand All @@ -117,7 +120,7 @@ NAMESPACE AXOpen.Core
_errorState := UINT#40;
RETURN;
END_IF;

_context := inParent.GetContext();
_parent := inParent;
_isInitialized := TRUE;
Expand All @@ -141,6 +144,9 @@ NAMESPACE AXOpen.Core
inContext : IAxoContext;
END_VAR


// We always reset message count upon initialization.
THIS.MsgCnt := LINT#0;
IF _isInitialized THEN
RETURN;
END_IF;
Expand All @@ -151,6 +157,8 @@ NAMESPACE AXOpen.Core
RETURN;
END_IF;



_context := inContext;
_isInitialized := TRUE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
///<inheritdoc/>
protected override async Task OnInitializedAsync()
{
if (observer != null) await observer.InitializeLightUpdate(this.StartPolling);
if (observer != null) await observer.InitializeUpdate(this.StartPolling);
await base.OnInitializedAsync();
}
}
106 changes: 84 additions & 22 deletions src/core/src/AXOpen.Core/AxoMessenger/Static/AxoMessageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,102 @@ private AxoMessageProvider(IEnumerable<ITwinObject> observedObjects)

public IEnumerable<ITwinObject> ObservedObjects { get; }

private int? _cachedActiveMessagesCount;
private DateTime _lastActiveMessagesCountUpdate = DateTime.MinValue;
private readonly TimeSpan _activeMessagesCountCacheDuration = TimeSpan.FromMilliseconds(500);
private readonly object _activeMessagesCountLock = new object();

/// <summary>
/// Gets the number of active messages.
/// </summary>
/// <remarks>
/// This property counts the number of messages that are currently active.
/// An active message is defined as a message belonging to a Messenger that has a state other than Idle or NotActiveWatingAckn.
/// The value is cached for a short period to prevent flickering due to asynchronous PLC communication.
/// </remarks>
public int? ActiveMessagesCount
{
get
{
try
{
return ObservedObjects
.OfType<AXOpen.Core.AxoObject>()
.Select(p => Convert.ToInt32(p.MsgCnt.LastValue)) // Convert to appropriate numeric type
.Sum();
}
catch (Exception e)
lock (_activeMessagesCountLock)
{
Console.WriteLine(e);
var now = DateTime.UtcNow;

// Return cached value if still valid
if (_cachedActiveMessagesCount.HasValue &&
(now - _lastActiveMessagesCountUpdate) < _activeMessagesCountCacheDuration)
{
return _cachedActiveMessagesCount;
}

try
{
var count = ObservedObjects
.OfType<AxoObject>()
.Select(p => Convert.ToInt32(p.MsgCnt.LastValue))
.Sum();

_cachedActiveMessagesCount = count;
_lastActiveMessagesCountUpdate = now;

return count;
}
catch (Exception e)
{
return -1;
}
}

return 0;
}
}


private int? _cachedRelevantMessagesCount;
private DateTime _lastRelevantMessagesCountUpdate = DateTime.MinValue;
private readonly TimeSpan _relevantMessagesCountCacheDuration = TimeSpan.FromMilliseconds(500);
private readonly object _relevantMessagesCountLock = new object();

/// <summary>
/// Gets the count of relevant messages based on the state of Messengers.
/// </summary>
/// <remarks>
/// The RelevantMessagesCount property will return the number of messengers that have a state greater than eAxoMessengerState.Idle.
/// Messengers is a collection of objects that represents messengers.
/// The value is cached for a short period to prevent flickering due to asynchronous PLC communication.
/// </remarks>
/// <returns>An integer that represents the count of relevant messages.</returns>
public int? RelevantMessagesCount
{
get
{
try
{
return ObservedObjects
.OfType<AXOpen.Core.AxoObject>()
.Select(p => Convert.ToInt32(p.MsgCnt.LastValue)) // Convert to appropriate numeric type
.Sum();
}
catch (Exception e)
lock (_relevantMessagesCountLock)
{
Console.WriteLine(e);
}
var now = DateTime.UtcNow;

// Return cached value if still valid
if (_cachedRelevantMessagesCount.HasValue &&
(now - _lastRelevantMessagesCountUpdate) < _relevantMessagesCountCacheDuration)
{
return _cachedRelevantMessagesCount;
}

return 0;
try
{
var count = ObservedObjects
.OfType<AXOpen.Core.AxoObject>()
.Select(p => Convert.ToInt32(p.MsgCnt.LastValue))
.Sum();

_cachedRelevantMessagesCount = count;
_lastRelevantMessagesCountUpdate = now;

return count;
}
catch (Exception e)
{
Console.WriteLine(e);
return 0;
}
}
}
}

Expand Down Expand Up @@ -190,5 +233,24 @@ public async Task ReadMessageStateAsync()
await con.ReadBatchAsync(r)!;
}
}

/// <summary>
/// Invalidates the cached message counts, forcing them to be recalculated on next access.
/// Use this method if you need to ensure fresh values after a batch read operation.
/// </summary>
public void InvalidateMessageCountCache()
{
lock (_activeMessagesCountLock)
{
_cachedActiveMessagesCount = null;
_lastActiveMessagesCountUpdate = DateTime.MinValue;
}

lock (_relevantMessagesCountLock)
{
_cachedRelevantMessagesCount = null;
_lastRelevantMessagesCountUpdate = DateTime.MinValue;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public IEnumerable<IBrowsableDataObject> GetRecords(string identifier, int limit
{
return ((dynamic)Repository)?.GetRecords(identifier, limit, skip, searchMode, sortExpression, sortAscending);
}

public IEnumerable<IBrowsableDataObject> GetRecords(PredicateContainer predicates,
int limit, int skip)
{
Expand Down
Loading
Loading