Skip to content

Instantly share code, notes, and snippets.

@YurePereira
Created December 18, 2023 19:21
Show Gist options
  • Select an option

  • Save YurePereira/441fac80847740d6e1ac358818a463fb to your computer and use it in GitHub Desktop.

Select an option

Save YurePereira/441fac80847740d6e1ac358818a463fb to your computer and use it in GitHub Desktop.
Código para emissão de protocolos
using System;
using System.Security.Cryptography;
using System.Linq;
public class Program
{
public static Protocolo protocolo { get; set; }
public static void Main()
{
protocolo = Protocolo.Novo;
Console.WriteLine("Protocolo:");
Console.WriteLine(protocolo.RetornarNumeroProtocolo());
}
}
public class Protocolo
{
public string Numero { get; set; }
public override string ToString()
{
return Numero;
}
public static Protocolo Novo => new Protocolo
{
Numero = DateTime.Now.Year + GerarNumero()
};
public static string GerarNumero()
{
var bytes = new byte[8];
using (var rng = RandomNumberGenerator.Create())
{
rng.GetNonZeroBytes(bytes);
}
return string.Join(string.Empty, bytes.Select(n => n.ToString("X2")));
}
public string RetornarNumeroProtocolo()
{
var anoCorrente = DateTime.Now.Year;
Numero = anoCorrente + GerarNumero();
return Numero;
}
}
@YurePereira
Copy link
Author

Melhorar forma de criação de instância da classe, analisar utilização do padrão de projeto singleton.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment