Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private sealed class GereEstadoComunicacao
- {
- private int contadorConexoes = 0;
- private bool ultimoEstadoLigacao = false;
- private int tempoWatchDog = 0;
- private DateTime ultimoTempoMedido = DateTime.MinValue;
- /// <summary>
- /// Estado da Ligação com o leitor DM
- /// </summary>
- public bool EstadoLigacao
- {
- get
- {
- bool estado = TempoPassadoDesdeUltimoHeartBeat < tempoWatchDog;
- if (estado && !ultimoEstadoLigacao)
- {
- contadorConexoes++;
- Debug.WriteLine("Contador de conexões: " + contadorConexoes);
- }
- ultimoEstadoLigacao = estado;
- return estado;
- }
- }
- /// <summary>
- /// Retorna o tempo passado desde o último heartbeat recebido
- /// </summary>
- public double TempoPassadoDesdeUltimoHeartBeat
- {
- get
- {
- return (DateTime.Now - ultimoTempoMedido).TotalMilliseconds;
- }
- }
- /// <summary>
- /// Retorna o total de conexões efetuadas
- /// </summary>
- public int TotalConexoes
- {
- get { return contadorConexoes; }
- }
- /// <summary>
- /// Retorna o total de conexões perdidas
- /// </summary>
- public int TotalConexoesPerdidas
- {
- get { return (contadorConexoes > 0) ? contadorConexoes - 1 : 0; }
- }
- public GereEstadoComunicacao(int _tempoWatchDog)
- {
- tempoWatchDog = _tempoWatchDog;
- }
- public void HeartBeat()
- {
- ultimoTempoMedido = DateTime.Now;
- }
- private void LimpaValores()
- {
- contadorConexoes = 0;
- ultimoEstadoLigacao = false;
- ultimoTempoMedido = DateTime.MinValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement