using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Fuel.Infrastructure.Payment { public class SequenceNumber { private const int INIT_VALUE = 1; private static readonly object obj = new object(); private static int counter = INIT_VALUE; public static string Next() { lock (obj) { var now = DateTime.Now.ToString("yyyyMMddHHmmssfff"); var cnt = counter.ToString().PadLeft(11, '0'); if (counter >= int.MaxValue) counter = INIT_VALUE; else counter++; return now + cnt; // length of 28 } } } public class SequenceNumber20 { private const int INIT_VALUE = 1; private const int MAX_VALUE = 999; private static readonly object obj = new object(); private static int counter = INIT_VALUE; public static string Next() { lock (obj) { var now = DateTime.Now.ToString("yyyyMMddHHmmssfff"); // length of 17 var cnt = counter.ToString().PadLeft(3, '0'); if (counter > MAX_VALUE) counter = INIT_VALUE; else counter++; return now + cnt; // length of 20 } } } }