Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1.       private sealed class GereEstadoComunicacao
  2.         {
  3.             private int contadorConexoes = 0;
  4.             private bool ultimoEstadoLigacao = false;
  5.             private int tempoWatchDog = 0;
  6.             private DateTime ultimoTempoMedido = DateTime.MinValue;
  7.  
  8.             /// <summary>
  9.             /// Estado da Ligação com o leitor DM
  10.             /// </summary>
  11.             public bool EstadoLigacao
  12.             {
  13.                 get
  14.                 {
  15.                     bool estado = TempoPassadoDesdeUltimoHeartBeat < tempoWatchDog;
  16.  
  17.                     if (estado && !ultimoEstadoLigacao)
  18.                     {
  19.                         contadorConexoes++;
  20.                         Debug.WriteLine("Contador de conexões: " + contadorConexoes);
  21.                     }
  22.  
  23.                     ultimoEstadoLigacao = estado;
  24.  
  25.                     return estado;
  26.                 }
  27.             }
  28.  
  29.             /// <summary>
  30.             /// Retorna o tempo passado desde o último heartbeat recebido
  31.             /// </summary>
  32.             public double TempoPassadoDesdeUltimoHeartBeat
  33.             {
  34.                 get
  35.                 {
  36.                     return (DateTime.Now - ultimoTempoMedido).TotalMilliseconds;
  37.                 }
  38.             }
  39.  
  40.             /// <summary>
  41.             /// Retorna o total de conexões efetuadas
  42.             /// </summary>
  43.             public int TotalConexoes
  44.             {
  45.                 get { return contadorConexoes; }
  46.             }
  47.  
  48.             /// <summary>
  49.             /// Retorna o total de conexões perdidas
  50.             /// </summary>
  51.             public int TotalConexoesPerdidas
  52.             {
  53.                 get { return (contadorConexoes > 0) ? contadorConexoes - 1 : 0; }
  54.             }
  55.  
  56.             public GereEstadoComunicacao(int _tempoWatchDog)
  57.             {
  58.                 tempoWatchDog = _tempoWatchDog;
  59.             }
  60.  
  61.             public void HeartBeat()
  62.             {
  63.                 ultimoTempoMedido = DateTime.Now;
  64.             }
  65.  
  66.             private void LimpaValores()
  67.             {
  68.                 contadorConexoes = 0;
  69.                 ultimoEstadoLigacao = false;
  70.                 ultimoTempoMedido = DateTime.MinValue;
  71.             }
  72.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement