C# Класс Funcular.IdGenerators.Base36.Base36IdGenerator

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
Base36IdGenerator ( int numTimestampCharacters = 11, int numServerCharacters = 4, int numRandomCharacters = 5, string reservedValue = "", string delimiter = "-", int delimiterPositions = null ) : System

The layout is Timestamp + Server Hash [+ Reserved] + Random.

ComputeHostHash ( string hostname = null ) : string

Base36 representation of the SHA1 of the hostname. The constructor argument numServerCharacters controls the maximum length of this hash.

Format ( string id ) : string

Given a non-delimited Id, format it with the current instance’s delimiter and delimiter positions. If Id already contains delimiter, or is null or empy, returns Id unmodified.

GetRandomString ( int length ) : string

Gets a random Base36 string of the specified length.

GetTimestamp ( int length, TimestampResolution resolution = TimestampResolution.Microsecond, System.DateTime sinceUtc = null, bool strict = false ) : string

Get a Base36 encoded timestamp string, based on Epoch. Use for disposable strings where global/universal uniqueness is not critical. If using the default resolution of Microseconds, 5 character values are exhausted in 1 minute. 6 characters = ½ hour. 7 characters = 21 hours. 8 characters = 1 month. 9 characters = 3 years. 10 characters = 115 years. 11 characters = 4170 years. 12 characteres = 150 thousand years.

NewId ( ) : string

Generates a unique, sequential, Base36 string. If this instance was instantiated using the default constructor, it will be 20 characters long. The first 11 characters are the microseconds elapsed since the InService DateTime (Epoch by default). The next 4 characters are the SHA1 of the hostname in Base36. The last 5 characters are random Base36 number between 0 and 36 ^ 5.

NewId ( bool delimited ) : string

Generates a unique, sequential, Base36 string; you control the len The first 10 characters are the microseconds elapsed since the InService DateTime (constant field you hardcode in this file). The next 2 characters are a compressed checksum of the MD5 of this host. The next 1 character is a reserved constant of 36 ('Z' in Base36). The last 3 characters are random number less than 46655 additional for additional uniqueness.

Приватные методы

Метод Описание
Base36IdGenerator ( ) : System

Static constructor

GetMicroseconds ( ) : long

Return the elapsed microseconds since the in-service DateTime; will never return the same value twice. Uses a high-resolution Stopwatch (not DateTime.Now) to measure durations.

GetMicrosecondsSafe ( ) : long

Returns value with all non base 36 characters removed. Uses mutex.

Return the elapsed microseconds since the in-service DateTime; will never return the same value twice, even across multiple processes.

GetRandomBase36DigitsSafe ( ) : string

Gets random component of Id, pre trimmed and padded to the correct length.

InitStaticMicroseconds ( ) : void
ValidateConstructorArguments ( int numTimestampCharacters, int numServerCharacters, int numRandomCharacters ) : void

Описание методов

Base36IdGenerator() публичный Метод

The layout is Timestamp + Server Hash [+ Reserved] + Random.
public Base36IdGenerator ( int numTimestampCharacters = 11, int numServerCharacters = 4, int numRandomCharacters = 5, string reservedValue = "", string delimiter = "-", int delimiterPositions = null ) : System
numTimestampCharacters int
numServerCharacters int
numRandomCharacters int
reservedValue string
delimiter string
delimiterPositions int
Результат System

ComputeHostHash() публичный Метод

Base36 representation of the SHA1 of the hostname. The constructor argument numServerCharacters controls the maximum length of this hash.
public ComputeHostHash ( string hostname = null ) : string
hostname string
Результат string

Format() публичный Метод

Given a non-delimited Id, format it with the current instance’s delimiter and delimiter positions. If Id already contains delimiter, or is null or empy, returns Id unmodified.
public Format ( string id ) : string
id string
Результат string

GetRandomString() публичный Метод

Gets a random Base36 string of the specified length.
public GetRandomString ( int length ) : string
length int
Результат string

GetTimestamp() публичный Метод

Get a Base36 encoded timestamp string, based on Epoch. Use for disposable strings where global/universal uniqueness is not critical. If using the default resolution of Microseconds, 5 character values are exhausted in 1 minute. 6 characters = ½ hour. 7 characters = 21 hours. 8 characters = 1 month. 9 characters = 3 years. 10 characters = 115 years. 11 characters = 4170 years. 12 characteres = 150 thousand years.
public GetTimestamp ( int length, TimestampResolution resolution = TimestampResolution.Microsecond, System.DateTime sinceUtc = null, bool strict = false ) : string
length int
resolution TimestampResolution
sinceUtc System.DateTime Defaults to Epoch
strict bool If false (default), overflow values will use the /// value modulus 36. Otherwise it will throw an overflow exception.
Результат string

NewId() публичный Метод

Generates a unique, sequential, Base36 string. If this instance was instantiated using the default constructor, it will be 20 characters long. The first 11 characters are the microseconds elapsed since the InService DateTime (Epoch by default). The next 4 characters are the SHA1 of the hostname in Base36. The last 5 characters are random Base36 number between 0 and 36 ^ 5.
public NewId ( ) : string
Результат string

NewId() публичный Метод

Generates a unique, sequential, Base36 string; you control the len The first 10 characters are the microseconds elapsed since the InService DateTime (constant field you hardcode in this file). The next 2 characters are a compressed checksum of the MD5 of this host. The next 1 character is a reserved constant of 36 ('Z' in Base36). The last 3 characters are random number less than 46655 additional for additional uniqueness.
public NewId ( bool delimited ) : string
delimited bool
Результат string