You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.9 KiB
73 lines
1.9 KiB
namespace Mirle.Component.API.AutomatedGuideVehicleController.Entities
|
|
{
|
|
/// <summary>
|
|
/// Class for message sequnce number
|
|
/// </summary>
|
|
public class MessageSequnce
|
|
{
|
|
/// <summary>
|
|
/// Constructure
|
|
/// </summary>
|
|
protected MessageSequnce()
|
|
{
|
|
_sequence = 0;
|
|
}
|
|
|
|
#region === [Private Properties] ===
|
|
|
|
/// <summary>
|
|
/// Message sequnce number
|
|
/// </summary>
|
|
private static volatile MessageSequnce _messageSequnce;
|
|
/// <summary>
|
|
/// Lock of message sequnce number
|
|
/// </summary>
|
|
private static readonly object _syncRoot = new object();
|
|
/// <summary>
|
|
/// Sequnce number
|
|
/// </summary>
|
|
private int _sequence;
|
|
/// <summary>
|
|
/// Lock of get sequnce number
|
|
/// </summary>
|
|
private static readonly object _messageLock = new object();
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// Message Sequnce instance
|
|
/// </summary>
|
|
public static MessageSequnce Instance
|
|
{
|
|
get
|
|
{
|
|
lock (_syncRoot)
|
|
{
|
|
_messageSequnce ??= new MessageSequnce();
|
|
return _messageSequnce;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Message sequnce number
|
|
/// </summary>
|
|
public string Sequence
|
|
{
|
|
get
|
|
{
|
|
lock (_messageLock)
|
|
{
|
|
if (_sequence == 0 || _sequence == 999999)
|
|
{
|
|
_sequence = 1;
|
|
}
|
|
else
|
|
{
|
|
_sequence++;
|
|
}
|
|
return _sequence.ToString().PadLeft(6, '0');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|