Is a custom sequence generator. Supports InMemory , Text File and MSSQL storage. Developers can also create their own storage providers.
It can be used to generate a custom ID using a pre-defined and configurable format.
Properties :
- Fomat - The generated string format. ( see Format Examples )
- ApplicationName - Optional setting storing the name of the application using it.
- SequenceLenght - The lenght of the generated sequence number.
- FillerCharacter - The characer used to pad the generated sequence
- Date - If needed, the date to be used by the Generator. The default is current system date.
Sample Usage in Code :
SequenceConfiguration conf = new SequenceConfiguration()
{
Format = "N",
ApplicationName = "Test App",
SequenceLenght = 5,
Date = DateTime.Now
};
Generator gen = new Generator(conf);
Storage providers provides the persistence object for the sequence. The library provides 3 simple storage providers :
- InMemoryStorage - the sequence is only stored in memory.
InMemoryStorage storage1 = new InMemoryStorage(); // Sequence starts at 1
InMemoryStorage storage2 = new InMemoryStorage(100); // Sequence starts at 100
Generator gen = new Generator(storage1, conf);
- TextFileStorage - the sequence will be written on a text file in clear text.
TextFileStorage fileStorage1 = new TextFileStorage("C:\\Data\\Example.id"); // Starts at 1 , storage at filename provided
TextFileStorage fileStorage1 = new TextFileStorage("C:\\Data\\Example.id",10); // Starts at 10
- MSSQLStorage - the sequence is stored in MSSQL database. The table SIMPLEIDSEQUENCE with 1 field [id] must be created else the sequence returned will alwys be 1 or the starting count set at constructor.
MSSQLStorage _msSqlStorage = new MSSQLStorage(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TestDB;Integrated Security=True");
MSSQLStorage _msSqlStorage = new MSSQLStorage(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=TestDB;Integrated Security=True",50);
Format Notations :
- N - the sequence number
- Y - System Year ( 4 digits)
- M - System Month (2 Digits )
- D - System Day ( 2 Digits )
- 0...9 - Custom Values to be passed on the GenerateID call
- {....} - Any value in between brackets will be included as is.
Example: (Assume sequence = 00003 and custom values = {"AAA","BBB","CCC"}
- N - "00001"
- 0N1 - "AAA00001BBB"
- Y-N{TEST} - "2017-00005TEST"
Sample Code See Example project.
- .NET Framework 4.5