diff --git a/IdGen.Configuration/IdGen.Configuration.csproj b/IdGen.Configuration/IdGen.Configuration.csproj index 593944d..c17d295 100644 --- a/IdGen.Configuration/IdGen.Configuration.csproj +++ b/IdGen.Configuration/IdGen.Configuration.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netstandard2.0 RobIII Devcorner.nl IdGen.Configuration @@ -21,17 +21,13 @@ git true latest - Debug;Release;ReleaseWithDocumentation + Debug;Release bin\Release\IdGen.Configuration.xml - - bin\Release\IdGen.Configuration.xml - - diff --git a/IdGen.Configuration/IdGeneratorElement.cs b/IdGen.Configuration/IdGeneratorElement.cs index 71f2fdd..379c706 100644 --- a/IdGen.Configuration/IdGeneratorElement.cs +++ b/IdGen.Configuration/IdGeneratorElement.cs @@ -9,7 +9,7 @@ namespace IdGen.Configuration; /// public sealed class IdGeneratorElement : ConfigurationElement { - private readonly string[] DATETIMEFORMATS = { "yyyy-MM-dd\\THH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd" }; + private readonly string[] DATETIMEFORMATS = ["yyyy-MM-dd\\THH:mm:ss", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"]; /// /// Gets/sets the name of the . diff --git a/IdGen.DependencyInjection/IdGen.DependencyInjection.csproj b/IdGen.DependencyInjection/IdGen.DependencyInjection.csproj index 64f1b8f..2b5cd2d 100644 --- a/IdGen.DependencyInjection/IdGen.DependencyInjection.csproj +++ b/IdGen.DependencyInjection/IdGen.DependencyInjection.csproj @@ -21,23 +21,19 @@ latest true latest - Debug;Release;ReleaseWithDocumentation + Debug;Release bin\Release\IdGen.DependencyInjection.xml - - bin\Release\IdGen.DependencyInjection.xml - - - + diff --git a/IdGen.sln b/IdGen.sln index dce8e1b..a561cad 100644 --- a/IdGen.sln +++ b/IdGen.sln @@ -12,12 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdGen", "IdGen\IdGen.csproj", "{E6856E0A-523F-4451-9C95-621156A1B9F4}" EndProject -Project("{7CF6DF6D-3B04-46F8-A40B-537D21BCA0B4}") = "IdGenDocumentation", "IdGenDocumentation\IdGenDocumentation.shfbproj", "{E2E02CC8-5CA2-4FA9-912F-3174152DE7D3}" - ProjectSection(ProjectDependencies) = postProject - {E6856E0A-523F-4451-9C95-621156A1B9F4} = {E6856E0A-523F-4451-9C95-621156A1B9F4} - {651A0785-A880-4467-A92F-110C26F3FA28} = {651A0785-A880-4467-A92F-110C26F3FA28} - EndProjectSection -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdGenTests", "IdGenTests\IdGenTests.csproj", "{12E4642B-A533-400C-987B-67B21DB80EC7}" ProjectSection(ProjectDependencies) = postProject {651A0785-A880-4467-A92F-110C26F3FA28} = {651A0785-A880-4467-A92F-110C26F3FA28} @@ -31,37 +25,24 @@ Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU - ReleaseWithDocumentation|Any CPU = ReleaseWithDocumentation|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {E6856E0A-523F-4451-9C95-621156A1B9F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E6856E0A-523F-4451-9C95-621156A1B9F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {E6856E0A-523F-4451-9C95-621156A1B9F4}.Release|Any CPU.ActiveCfg = Release|Any CPU {E6856E0A-523F-4451-9C95-621156A1B9F4}.Release|Any CPU.Build.0 = Release|Any CPU - {E6856E0A-523F-4451-9C95-621156A1B9F4}.ReleaseWithDocumentation|Any CPU.ActiveCfg = ReleaseWithDocumentation|Any CPU - {E6856E0A-523F-4451-9C95-621156A1B9F4}.ReleaseWithDocumentation|Any CPU.Build.0 = ReleaseWithDocumentation|Any CPU - {E2E02CC8-5CA2-4FA9-912F-3174152DE7D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E2E02CC8-5CA2-4FA9-912F-3174152DE7D3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E2E02CC8-5CA2-4FA9-912F-3174152DE7D3}.ReleaseWithDocumentation|Any CPU.ActiveCfg = ReleaseWithDocumentation|Any CPU - {E2E02CC8-5CA2-4FA9-912F-3174152DE7D3}.ReleaseWithDocumentation|Any CPU.Build.0 = ReleaseWithDocumentation|Any CPU {12E4642B-A533-400C-987B-67B21DB80EC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {12E4642B-A533-400C-987B-67B21DB80EC7}.Debug|Any CPU.Build.0 = Debug|Any CPU {12E4642B-A533-400C-987B-67B21DB80EC7}.Release|Any CPU.ActiveCfg = Release|Any CPU {12E4642B-A533-400C-987B-67B21DB80EC7}.Release|Any CPU.Build.0 = Release|Any CPU - {12E4642B-A533-400C-987B-67B21DB80EC7}.ReleaseWithDocumentation|Any CPU.ActiveCfg = ReleaseWithDocumentation|Any CPU - {12E4642B-A533-400C-987B-67B21DB80EC7}.ReleaseWithDocumentation|Any CPU.Build.0 = ReleaseWithDocumentation|Any CPU {651A0785-A880-4467-A92F-110C26F3FA28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {651A0785-A880-4467-A92F-110C26F3FA28}.Debug|Any CPU.Build.0 = Debug|Any CPU {651A0785-A880-4467-A92F-110C26F3FA28}.Release|Any CPU.ActiveCfg = Release|Any CPU {651A0785-A880-4467-A92F-110C26F3FA28}.Release|Any CPU.Build.0 = Release|Any CPU - {651A0785-A880-4467-A92F-110C26F3FA28}.ReleaseWithDocumentation|Any CPU.ActiveCfg = ReleaseWithDocumentation|Any CPU - {651A0785-A880-4467-A92F-110C26F3FA28}.ReleaseWithDocumentation|Any CPU.Build.0 = ReleaseWithDocumentation|Any CPU {ED1E5B28-18FA-475D-A0FC-6CB08CD05185}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ED1E5B28-18FA-475D-A0FC-6CB08CD05185}.Debug|Any CPU.Build.0 = Debug|Any CPU {ED1E5B28-18FA-475D-A0FC-6CB08CD05185}.Release|Any CPU.ActiveCfg = Release|Any CPU {ED1E5B28-18FA-475D-A0FC-6CB08CD05185}.Release|Any CPU.Build.0 = Release|Any CPU - {ED1E5B28-18FA-475D-A0FC-6CB08CD05185}.ReleaseWithDocumentation|Any CPU.ActiveCfg = ReleaseWithDocumentation|Any CPU - {ED1E5B28-18FA-475D-A0FC-6CB08CD05185}.ReleaseWithDocumentation|Any CPU.Build.0 = ReleaseWithDocumentation|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/IdGen/DefaultTimeSource.cs b/IdGen/DefaultTimeSource.cs index 57ddd24..b945d5b 100644 --- a/IdGen/DefaultTimeSource.cs +++ b/IdGen/DefaultTimeSource.cs @@ -8,7 +8,12 @@ namespace IdGen; /// /// Unless specified the default duration of a tick for a is 1 millisecond. /// -public class DefaultTimeSource : StopwatchTimeSource +/// +/// Initializes a new object. +/// +/// The epoch to use as an offset from now, +/// The duration of a tick for this timesource. +public class DefaultTimeSource(DateTimeOffset epoch, TimeSpan tickDuration) : StopwatchTimeSource(epoch, tickDuration) { /// /// Initializes a new object. @@ -18,14 +23,6 @@ public class DefaultTimeSource : StopwatchTimeSource public DefaultTimeSource(DateTimeOffset epoch) : this(epoch, TimeSpan.FromMilliseconds(1)) { } - /// - /// Initializes a new object. - /// - /// The epoch to use as an offset from now, - /// The duration of a tick for this timesource. - public DefaultTimeSource(DateTimeOffset epoch, TimeSpan tickDuration) - : base(epoch, tickDuration) { } - /// /// Returns the current number of ticks for the . /// @@ -35,4 +32,4 @@ public DefaultTimeSource(DateTimeOffset epoch, TimeSpan tickDuration) /// it a millisecond, an hour, 2.5 seconds or any other value. /// public override long GetTicks() => (Offset.Ticks + Elapsed.Ticks) / TickDuration.Ticks; -} +} \ No newline at end of file diff --git a/IdGen/IdGen.csproj b/IdGen/IdGen.csproj index e9015a9..95b97d4 100644 --- a/IdGen/IdGen.csproj +++ b/IdGen/IdGen.csproj @@ -10,26 +10,21 @@ MIT https://github.com/RobThree/IdGen scalable unique id generator distributed - Added NetStandard 2.0 + Twitter Snowflake-alike ID generator for .Net IdGen logo.png - https://github.com/RobThree/IdGen git enable true latest latest - Debug;Release;ReleaseWithDocumentation + Debug;Release README.md - - bin\Release\IdGen.xml - - - + bin\Release\IdGen.xml diff --git a/IdGen/IdGeneratorOptions.cs b/IdGen/IdGeneratorOptions.cs index 6c1390e..8fc4470 100644 --- a/IdGen/IdGeneratorOptions.cs +++ b/IdGen/IdGeneratorOptions.cs @@ -5,7 +5,16 @@ namespace IdGen; /// /// Represents the options an can be configured with. /// -public class IdGeneratorOptions +/// +/// Initializes a new instance of the class. +/// +/// The for ID's to be generated. +/// The to use when generating ID's. +/// The to use when generating ID's. +public class IdGeneratorOptions( + IdStructure? idStructure = null, + ITimeSource? timeSource = null, + SequenceOverflowStrategy sequenceOverflowStrategy = SequenceOverflowStrategy.Throw) { /// /// Returns the default epoch. @@ -29,31 +38,15 @@ public class IdGeneratorOptions /// /// Gets the of the generated ID's /// - public IdStructure IdStructure { get; init; } = _defaultidstructure; + public IdStructure IdStructure { get; init; } = idStructure ?? _defaultidstructure; /// /// Gets the to use when generating ID's. /// - public ITimeSource TimeSource { get; init; } = _defaulttimesource; + public ITimeSource TimeSource { get; init; } = timeSource ?? _defaulttimesource; /// /// Gets the to use when generating ID's. /// - public SequenceOverflowStrategy SequenceOverflowStrategy { get; init; } = _defaultsequenceoverflowstrategy; - - /// - /// Initializes a new instance of the class. - /// - /// The for ID's to be generated. - /// The to use when generating ID's. - /// The to use when generating ID's. - public IdGeneratorOptions( - IdStructure? idStructure = null, - ITimeSource? timeSource = null, - SequenceOverflowStrategy sequenceOverflowStrategy = SequenceOverflowStrategy.Throw) - { - IdStructure = idStructure ?? _defaultidstructure; - TimeSource = timeSource ?? _defaulttimesource; - SequenceOverflowStrategy = sequenceOverflowStrategy; - } + public SequenceOverflowStrategy SequenceOverflowStrategy { get; init; } = sequenceOverflowStrategy; } \ No newline at end of file diff --git a/IdGen/InvalidSystemClockException.cs b/IdGen/InvalidSystemClockException.cs index fec5a26..032d853 100644 --- a/IdGen/InvalidSystemClockException.cs +++ b/IdGen/InvalidSystemClockException.cs @@ -5,7 +5,20 @@ namespace IdGen; /// /// The exception that is thrown when a clock going backwards is detected. /// -public class InvalidSystemClockException : Exception +/// +/// Initializes a new instance of the class with a message that describes +/// the error and underlying exception. +/// +/// +/// The message that describes the exception. The caller of this constructor is required to ensure that this +/// string has been localized for the current system culture. +/// +/// +/// The exception that is the cause of the current . If the +/// innerException parameter is not null, the current exception is raised in a catch block that handles the +/// inner exception. +/// +public class InvalidSystemClockException(string message, Exception? innerException) : Exception(message, innerException) { /// /// Initializes a new instance of the class. @@ -21,19 +34,4 @@ public InvalidSystemClockException() : this("Invalid system clock") { } /// public InvalidSystemClockException(string message) : this(message, null) { } - - /// - /// Initializes a new instance of the class with a message that describes - /// the error and underlying exception. - /// - /// - /// The message that describes the exception. The caller of this constructor is required to ensure that this - /// string has been localized for the current system culture. - /// - /// - /// The exception that is the cause of the current . If the - /// innerException parameter is not null, the current exception is raised in a catch block that handles the - /// inner exception. - /// - public InvalidSystemClockException(string message, Exception? innerException) : base(message, innerException) { } } diff --git a/IdGen/SequenceOverflowException.cs b/IdGen/SequenceOverflowException.cs index 71015b0..4ca8706 100644 --- a/IdGen/SequenceOverflowException.cs +++ b/IdGen/SequenceOverflowException.cs @@ -5,7 +5,20 @@ namespace IdGen; /// /// The exception that is thrown when a sequence overflows (e.g. too many Id's generated within the same timespan (ms)). /// -public class SequenceOverflowException : Exception +/// +/// Initializes a new instance of the class with a message that describes +/// the error and underlying exception. +/// +/// +/// The message that describes the exception. The caller of this constructor is required to ensure that this +/// string has been localized for the current system culture. +/// +/// +/// The exception that is the cause of the current . If the +/// innerException parameter is not null, the current exception is raised in a catch block that handles the +/// inner exception. +/// +public class SequenceOverflowException(string message, Exception? innerException) : Exception(message, innerException) { /// /// Initializes a new instance of the class. @@ -21,19 +34,4 @@ public SequenceOverflowException() : this("Sequence overflow") { } /// public SequenceOverflowException(string message) : this(message, null) { } - - /// - /// Initializes a new instance of the class with a message that describes - /// the error and underlying exception. - /// - /// - /// The message that describes the exception. The caller of this constructor is required to ensure that this - /// string has been localized for the current system culture. - /// - /// - /// The exception that is the cause of the current . If the - /// innerException parameter is not null, the current exception is raised in a catch block that handles the - /// inner exception. - /// - public SequenceOverflowException(string message, Exception? innerException) : base(message, innerException) { } } \ No newline at end of file diff --git a/IdGen/SequenceOverflowStrategy.cs b/IdGen/SequenceOverflowStrategy.cs index 986dc56..05624d6 100644 --- a/IdGen/SequenceOverflowStrategy.cs +++ b/IdGen/SequenceOverflowStrategy.cs @@ -10,7 +10,7 @@ public enum SequenceOverflowStrategy /// Throw = 0, /// - /// Wait, using a , for the tick te pass before generating a new ID. + /// Wait, using a , for the tick te pass before generating a new ID. /// SpinWait = 1 } diff --git a/IdGenDocumentation/Content/VersionHistory/VersionHistory.aml b/IdGenDocumentation/Content/VersionHistory/VersionHistory.aml deleted file mode 100644 index 4dc6c8d..0000000 --- a/IdGenDocumentation/Content/VersionHistory/VersionHistory.aml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - The topics in this section describe the various changes made to the IdGen library over the life of the project. - - -
- Version History - - Select a version below to see a description of its changes. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
-
diff --git a/IdGenDocumentation/Content/VersionHistory/v1.0.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v1.0.0.0.aml deleted file mode 100644 index 42077a0..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v1.0.0.0.aml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - Version 1.0.0.0 was released on 2015-04-09. - - - -
- Changes in This Release - - - - - Initial release. - - - - - -
- - - - - -
-
diff --git a/IdGenDocumentation/Content/VersionHistory/v1.1.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v1.1.0.0.aml deleted file mode 100644 index f84397f..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v1.1.0.0.aml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - Version 1.1.0.0 was released on 2015-06-29. - - - -
- Changes in This Release - - - - - Moved away from DateTime.UtcNow and implemented a better, millisecond resolution, DefaultTimeSource using QueryPerformanceCounter. - - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v1.2.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v1.2.0.0.aml deleted file mode 100644 index bbdb9a5..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v1.2.0.0.aml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - Version 1.2.0.0 was released on 2016-03-07. - - - -
- Changes in This Release - - - - - Added support for config section. - - - GetMachineSpecificGenerator & GetThreadSpecificGenerator renamed to CreateMachineSpecificGenerator & CreateThreadSpecificGenerator respectively to better convey that each invocation creates a new instance. - - - Explicitly check for negative generator-id's. - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.0.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.0.0.0.aml deleted file mode 100644 index 2534d45..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.0.0.0.aml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - Version 2.0.0.0 was released on 2016-07-21. - - - -
- Changes in This Release - - - - - Timesource(s) is (are) no longer fixed to milliseconds; we now have the concept of a 'tick'. Each timesource can define it's own definition of what a 'tick' is, be it a millisecond or a minute or any other timespan. - - This means breaking changes in the T:IdGen.ITimeSource interface and the way timesources are implemented and breaking changes in some of the MaskConfig's method signatures. - - - - - The T:IdGen.IIdGenerator`1 interface now explicitly exposes an IdGenerator's T:IdGen.ITimeSource, MaskConfig and Epoch as (read-only) properties. - - - - - CreateMachineSpecificGenerator & CreateThreadSpecificGenerator methods have been removed; these are way to 'dangerous' to use anyway since they are very prone to 'collisions' in 'auto-generated' values for the IdGenerators. - - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.0.1.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.0.1.0.aml deleted file mode 100644 index 97ad6a4..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.0.1.0.aml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - Version 2.0.1.0 was released on 2016-11-23. - - - -
- Changes in This Release - - - - - Minor bugfixes - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.0.2.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.0.2.0.aml deleted file mode 100644 index 72e66f9..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.0.2.0.aml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - Version 2.0.2.0 was released on 2018-02-09. - - - -
- Changes in This Release - - - - - Minor bugfixes - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.0.3.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.0.3.0.aml deleted file mode 100644 index f734ff3..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.0.3.0.aml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - Version 2.0.3.0 was released on 2018-07-31. - - - -
- Changes in This Release - - - - - Added FromId method - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.1.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.1.0.0.aml deleted file mode 100644 index efc3626..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.1.0.0.aml +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - Version 2.1.0.0 was released on 2020-02-19. - - - -
- Changes in This Release - - - - - Support for NetStandard 1.1+ - - - - Moved AppConfig stuff to separate IDGen.Configuration package - - - - - ID now implements IEquatable - - - - - Fixed some ArgumentOutOfRangeExceptions from the IdGenerator's ctor messages - - - - - Fixed bug (see - #18 - https://github.com/RobThree/IdGen/issues/18 - ) where internal timer was started only on first use instead of on instantiation - - - - Minor internal cleanup / refactoring - - - - -
- -
- Breaking changes - - - If you're using the IdGenerator.GetFromConfig(...) method make sure you check the README. The changes aren't big, but breaking nonetheless. How to fix: - - - - - Install IdGen.Configuration package - - - - - Change the configsection type from: - - - IdGen.Configuration.IdGeneratorsSection, IdGen - - - to: - - - IdGen.Configuration.IdGeneratorsSection, IdGen.Configuration - - - - - Add a using IdGen.Configuration - - - - - Change IdGenerator.GetFromConfig(...) to AppConfigFactory.GetFromConfig(...) - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.2.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.2.0.0.aml deleted file mode 100644 index e1a8e93..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.2.0.0.aml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - Version 2.2.0.0 was released on 2020-03-04. - - - -
- Changes in This Release - - - - - - Fixed a bug where the StopwatchTimeSource didn't share it's internal offset between instances causing unexpected behavior in the DefaultTimeSource which relies on the StopwatchTimeSource (see - #20 - https://github.com/RobThree/IdGen/issues/20 - ). - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.3.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.3.0.0.aml deleted file mode 100644 index 9a9006c..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.3.0.0.aml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - Version 2.3.0.0 was released on 2020-04-18. - - - -
- Changes in This Release - - - - - - Added a TryCreateId method that doesn't throw any exceptions but rather indicates succes by return value (see - #21 - https://github.com/RobThree/IdGen/issues/21 - ). - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.4.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.4.0.0.aml deleted file mode 100644 index 9e88a7c..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.4.0.0.aml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - Version 2.4.0.0 was released on 2020-04-18. - - - -
- Changes in This Release - - - - - - Fixed concurrency issue (see - #23 - https://github.com/RobThree/IdGen/pull/23 - ). - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v2.4.1.0.aml b/IdGenDocumentation/Content/VersionHistory/v2.4.1.0.aml deleted file mode 100644 index c1eb599..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v2.4.1.0.aml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - Version 2.4.1.0 was released on 2020-07-02. - - - -
- Changes in This Release - - - - - - Implemented spinwait (see - #24 - https://github.com/RobThree/IdGen/pull/24 - ). - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v3.0.0.0.aml b/IdGenDocumentation/Content/VersionHistory/v3.0.0.0.aml deleted file mode 100644 index 78e1415..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v3.0.0.0.aml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - Version 3.0.0.0 was released on 2020-07-06. - - - -
- Changes in This Release - - - - - - This release contains a few (minor) breaking changes. Generated 2.x ID's are still compatible with 3.x ID's. This release is mostly better and more consistent naming of objects. - - - - - - Most of the constructor overloads for the T:IdGen.IdGenerator have been replaced with a single constructor which accepts T:IdGen.IdGeneratorOptions that contains the T:IdGen.ITimeSource, T:IdGen.IdStructure and T:IdGen.SequenceOverflowStrategy. - - - - - The MaskConfig class is now more appropriately named T:IdGen.IdStructure since it describes the structure of the generated ID's. - - - - - The UseSpinWait property has moved to the T:IdGen.IdGeneratorOptions and is now an enum of type T:IdGen.SequenceOverflowStrategy instead of a boolean value. Note that this property has also been renamed in the config file (from useSpinWait to sequenceOverflowStrategy) and is no longer a boolean but requires one of the values from T:IdGen.SequenceOverflowStrategy. - - - - - ID is now Id (only used as return value by the M:IdGen.IdGenerator.FromId(System.Int64) method) - - - - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v3.0.1.0.aml b/IdGenDocumentation/Content/VersionHistory/v3.0.1.0.aml deleted file mode 100644 index a0419a6..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v3.0.1.0.aml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - Version 3.0.1.0 was released on 2022-05-28. - - - -
- Changes in This Release - - - - - Internal changes and refactoring - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v3.0.2.0.aml b/IdGenDocumentation/Content/VersionHistory/v3.0.2.0.aml deleted file mode 100644 index 4dc4246..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v3.0.2.0.aml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - Version 3.0.2.0 was released on 2022-09-14. - - - -
- Changes in This Release - - - - - Internal changes and refactoring - - - - T:IdGen.Id is now a record. - - - - Fixed bounds check where when the GeneratorId was 31 bits the constructor would throw on any generator id. - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/VersionHistory/v3.0.3.0.aml b/IdGenDocumentation/Content/VersionHistory/v3.0.3.0.aml deleted file mode 100644 index 316fdff..0000000 --- a/IdGenDocumentation/Content/VersionHistory/v3.0.3.0.aml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - Version 3.0.3.0 was released on 2022-12-28. - - - -
- Changes in This Release - - - - - Added NetStandard 2.0 - - - - -
- - - - - -
-
\ No newline at end of file diff --git a/IdGenDocumentation/Content/Welcome.aml b/IdGenDocumentation/Content/Welcome.aml deleted file mode 100644 index 9ab6e0c..0000000 --- a/IdGenDocumentation/Content/Welcome.aml +++ /dev/null @@ -1,293 +0,0 @@ - - - - - - Twitter Snowflake-alike ID generator for .Net. Available as - - Nuget package - https://www.nuget.org/packages/IdGen - . - - - -
- Why - - - In certain situations you need a low-latency uncoordinated, (roughly) time ordered, compact and highly available Id generation system. This project was inspired by - - Twitter's Snowflake - https://github.com/twitter/snowflake - - project which has been retired. Note that this project was inspired by Snowflake but is not an exact implementation. This library provides a basis for Id generation; it does not provide a service for handing out these Id's nor does it provide generator-id ('worker-id') coordination. - - -
- -
- How it works - - - IdGen generates, like Snowflake, 64 bit Id's. The - - Sign Bit - https://en.wikipedia.org/wiki/Sign_bit - - is unused since this can cause incorrect ordering on some systems that cannot use unsigned types and/or make it hard to get correct ordering. So, in effect, IdGen generates 63 bit Id's. An Id consists of 3 parts: - - - - Timestamp - - - Generator-id - - - Sequence - - - - An Id generated with a P:IdGen.IdStructure.Default is structured as follows: - - - - - - - However, using the T:IdGen.IdStructure class you can tune the structure of the created Id's to your own needs; you can use 45 bits for the timestamp, 2 bits for the generator-id and 16 bits for the sequence if you prefer. As long as all 3 parts (timestamp, generator and sequence) add up to 63 bits you're good to go! - - - The timestamp-part of the Id should speak for itself; by default this is incremented every millisecond and represents the number of milliseconds since a certain epoch. However, IdGen relies on an T:IdGen.ITimeSource which uses a 'tick' that can be defined to be anything; be it a millisecond (default), a second or even a day or nanosecond (hardware support etc. permitting). By default IdGen uses 2015-01-01 0:00:00Z as epoch, but you can specify a custom epoch too. - - - The generator-id-part of the Id is the part that you 'configure'; it could correspond to a host, thread, datacenter or continent: it's up to you. However, the generator-id should be unique in the system: if you have several hosts or threads generating Id's, each host or thread should have it's own generator-id. This could be based on the hostname, a config-file value or even be retrieved from an coordinating service. Remember: a generator-id should be unique within the entire system to avoid collisions! - - - The sequence-part is simply a value that is incremented each time a new Id is generated within the same tick (again, by default, a millisecond but can be anything); it is reset every time the tick changes. - - -
- -
- System Clock Dependency - - - We recommend you use NTP to keep your system clock accurate. IdGen protects from non-monotonic clocks, i.e. clocks that run backwards. The T:IdGen.DefaultTimeSource relies on a 64bit monotonic, increasing only, system counter. However, we still recommend you use NTP to keep your system clock accurate; this will prevent duplicate Id's between system restarts for example. - - - The T:IdGen.DefaultTimeSource relies on a T:System.Diagnostics.Stopwatch for calculating the 'ticks' but you can implement your own time source by simply implementing the T:IdGen.ITimeSource interface. - - -
- -
- Getting started - - - Install the - - Nuget package - https://www.nuget.org/packages/IdGen - - and write the following code: - - - - - Voila. You have created your first Id! Want to create 100 Id's? Instead of: - - - - write: - - - - - This is because the T:IdGen.IdGenerator implements T:System.Collections.IEnumerable providing you with a never-ending stream of Id's (so you might want to be careful doing a .Select(...) or .Count() on it!). - - - The above example creates a default T:IdGen.IdGenerator with the P:IdGen.IdGenerator.Id (or: 'Worker Id') set to 0 and using a T:IdGen.DefaultTimeSource. If you're using multiple generators (across machines or in separate threads or...) you'll want to make sure each generator is assigned it's own unique Id (and same timesource/epoch configuration). One way of doing this is by simply storing a value in your configuration file for example, another way may involve a service handing out GeneratorId's to machines/threads. IdGen does not provide a solution for this since each project or setup may have different requirements or infrastructure to provide these generator-id's. - - - The below sample is a bit more complicated; we set a custom epoch, define our own structure for generated Id's and then display some information about the setup: - - - - - Output: - - - - - The T:IdGen.ITimeSource interface can be handy for - - unittesting - https://github.com/RobThree/IdGen/blob/master/IdGenTests/IdGenTests.cs - - purposes or if you want to provide a time-source for the timestamp part of your Id's that is not based on milliseconds (or even (system)time at all). For unittesting we use our own - - MockTimeSource - https://github.com/RobThree/IdGen/blob/master/IdGenTests/MockTimeSource.cs - . - - - The AppConfigFactory class in the IdGen.Configuration package provides a 'factory method' to quickly create an IdGenerator based on a configuration file. To use this, add the following to your configuration: - - - - -
- - - - - - - - - - - - ]]> - - - The attributes (name, id, epoch, timestampBits, generatorIdBits and sequenceBits) are required. The tickDuration is optional and defaults to the default tickduration from a T:IdGen.DefaultTimeSource. The sequenceOverflowStrategy is optional too and defaults to Throw. Valid DateTime notations for the epoch are: - - - - - yyyy-MM-ddTHH:mm:ss - - - - - yyyy-MM-dd HH:mm:ss - - - - - yyyy-MM-dd - - - - You can get the IdGenerator from the config using the following code: - - - - -
- -
- Dependency Injection - - - There is an - IdGen.DependencyInjection NuGet package - https://www.nuget.org/packages/IdGen.DependencyInjection - available that allows for easy integration with the commonly used - Microsoft.Extensions.DependencyInjection - https://docs.microsoft.com/en-us/dotnet/core/extensions/dependency-injection - . - - Usage is straightforward: - - - - Or, when you want to use non-default options: - - new IdGeneratorOptions(...)); // Where 123 is the generator-id - ]]> - - - This registers both an IdGenerator as well as an IIdGenerator<long>, both pointing to the same singleton generator. - - -
- -
- Upgrading from 2.x to 3.x - - - Upgrading from 2.x to 3.x should be pretty straightforward. See for the changes. - - -
- - - - - - \ No newline at end of file diff --git a/IdGenDocumentation/ContentLayout.content b/IdGenDocumentation/ContentLayout.content deleted file mode 100644 index da0a0e1..0000000 --- a/IdGenDocumentation/ContentLayout.content +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/IdGenDocumentation/IdGenDocumentation.shfbproj b/IdGenDocumentation/IdGenDocumentation.shfbproj deleted file mode 100644 index c774d89..0000000 --- a/IdGenDocumentation/IdGenDocumentation.shfbproj +++ /dev/null @@ -1,134 +0,0 @@ - - - - - Debug - AnyCPU - 2.0 - e2e02cc8-5ca2-4fa9-912f-3174152de7d3 - 2017.9.26.0 - - IdGenDocumentation - IdGenDocumentation - IdGenDocumentation - - .NET Core/.NET Standard/.NET 5.0+ - .\Help\ - IdGenHelp - en-US - - - - - - - - - - 2 - False - Standard - Blank - False - VS2013 - False - Guid - IdGen documentation - Rob Janssen - rob%40robiii.me - %28c%29 2015 - 2023 Devcorner.nl - https://github.com/RobThree/IdGen - AboveNamespaces - VisualStudio11 - -1 - 100 - 100 - -1 - Rob Janssen - Msdn - 100 - VS - - - - OnlyWarningsAndErrors - HtmlHelp1 - False - True - False - False - True - - <para>The IdGen namespace contains classes that allow generating unique (distributed) ID's.</para> - <para>The IdGen.Configuration namespace contains the types that provide the programming model for handling configuration data.</para> - - 3.0.0 - ms.vsipcc+, ms.vsexpresscc+ - Hierarchical - Msdn - True - 100 - v4.8 - - - - - - - - - - - - - - - - - - - - bin\ReleaseWithDocumentation\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - structure - structure - - - - - \ No newline at end of file diff --git a/IdGenDocumentation/Media/structure.png b/IdGenDocumentation/Media/structure.png deleted file mode 100644 index da3e585..0000000 Binary files a/IdGenDocumentation/Media/structure.png and /dev/null differ diff --git a/IdGenDocumentation/icons/Help.png b/IdGenDocumentation/icons/Help.png deleted file mode 100644 index 901e120..0000000 Binary files a/IdGenDocumentation/icons/Help.png and /dev/null differ diff --git a/IdGenTests/IdGenTests.csproj b/IdGenTests/IdGenTests.csproj index 12a1b28..393adca 100644 --- a/IdGenTests/IdGenTests.csproj +++ b/IdGenTests/IdGenTests.csproj @@ -1,19 +1,19 @@  - net48;net7 + net48;net8 enable latest false - Debug;Release;ReleaseWithDocumentation + Debug;Release - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/IdGenTests/IdGeneratorTests.cs b/IdGenTests/IdGeneratorTests.cs index d676a10..5c46595 100644 --- a/IdGenTests/IdGeneratorTests.cs +++ b/IdGenTests/IdGeneratorTests.cs @@ -84,14 +84,12 @@ public void Constructor_DoesNotThrow_OnMaxGeneratorId() var structure = new IdStructure(41, 10, 12); // 1023 is the max generator id for 10 bits. var maxgeneratorid = 1023; - new IdGenerator(maxgeneratorid, new IdGeneratorOptions(structure)); + _ = new IdGenerator(maxgeneratorid, new IdGeneratorOptions(structure)); } [TestMethod] public void Constructor_DoesNotThrow_OnGeneratorId_0() - { - new IdGenerator(0, new IdGeneratorOptions(new IdStructure(41, 10, 12))); - } + => _ = new IdGenerator(0, new IdGeneratorOptions(new IdStructure(41, 10, 12))); [TestMethod] [ExpectedException(typeof(ArgumentNullException))] @@ -105,8 +103,8 @@ public void Constructor_Throws_OnInvalidGeneratorId_Positive_MaxPlusOne() var structure = new IdStructure(41, 10, 12); // 1023 is the max generator id for 10 bits. var maxgeneratorid = 1023; - int maxPlusOne = maxgeneratorid + 1; - new IdGenerator(maxPlusOne, new IdGeneratorOptions(structure)); + var maxPlusOne = maxgeneratorid + 1; + _ = new IdGenerator(maxPlusOne, new IdGeneratorOptions(structure)); } [TestMethod] @@ -116,7 +114,7 @@ public void Constructor_Throws_OnInvalidGeneratorId_Negative() [TestMethod] public void Constructor_DoesNotThrow_OnMaxValidatorId() - => new IdGenerator(int.MaxValue, new IdGeneratorOptions { IdStructure = new IdStructure(16, 31, 16) }); + => _ = new IdGenerator(int.MaxValue, new IdGeneratorOptions { IdStructure = new IdStructure(16, 31, 16) }); [TestMethod] public void Constructor_UsesCorrectId() diff --git a/IdGenTests/Mocks/MockAutoIncrementingIntervalTimeSource.cs b/IdGenTests/Mocks/MockAutoIncrementingIntervalTimeSource.cs index af0b7da..a9c9257 100644 --- a/IdGenTests/Mocks/MockAutoIncrementingIntervalTimeSource.cs +++ b/IdGenTests/Mocks/MockAutoIncrementingIntervalTimeSource.cs @@ -3,21 +3,14 @@ namespace IdGenTests.Mocks; -public class MockAutoIncrementingIntervalTimeSource : MockTimeSource +public class MockAutoIncrementingIntervalTimeSource(int incrementEvery, long? current = null, TimeSpan? tickDuration = null, DateTimeOffset? epoch = null) + : MockTimeSource(current ?? 0, tickDuration ?? TimeSpan.FromMilliseconds(1), epoch ?? DateTimeOffset.MinValue) { - private readonly int _incrementevery; - private int _count; - - public MockAutoIncrementingIntervalTimeSource(int incrementEvery, long? current = null, TimeSpan? tickDuration = null, DateTimeOffset? epoch = null) - : base(current ?? 0, tickDuration ?? TimeSpan.FromMilliseconds(1), epoch ?? DateTimeOffset.MinValue) - { - _incrementevery = incrementEvery; - _count = 0; - } + private int _count = 0; public override long GetTicks() { - if (_count == _incrementevery) + if (_count == incrementEvery) { NextTick(); _count = 0; diff --git a/IdGenTests/Mocks/MockTimeSource.cs b/IdGenTests/Mocks/MockTimeSource.cs index 7e26749..bc945f4 100644 --- a/IdGenTests/Mocks/MockTimeSource.cs +++ b/IdGenTests/Mocks/MockTimeSource.cs @@ -4,16 +4,14 @@ namespace IdGenTests.Mocks; -public class MockTimeSource : ITimeSource +public class MockTimeSource(long current, TimeSpan tickDuration, DateTimeOffset epoch) : ITimeSource { - private long _current; - public MockTimeSource() : this(0) { } - public DateTimeOffset Epoch { get; private set; } + public DateTimeOffset Epoch { get; private set; } = epoch; - public TimeSpan TickDuration { get; } + public TimeSpan TickDuration { get; } = tickDuration; public MockTimeSource(long current) : this(current, TimeSpan.FromMilliseconds(1), DateTimeOffset.MinValue) { } @@ -21,16 +19,9 @@ public MockTimeSource(long current) public MockTimeSource(TimeSpan tickDuration) : this(0, tickDuration, DateTimeOffset.MinValue) { } - public MockTimeSource(long current, TimeSpan tickDuration, DateTimeOffset epoch) - { - _current = current; - TickDuration = tickDuration; - Epoch = epoch; - } - - public virtual long GetTicks() => _current; + public virtual long GetTicks() => current; - public void NextTick() => Interlocked.Increment(ref _current); + public void NextTick() => Interlocked.Increment(ref current); - public void PreviousTick() => Interlocked.Decrement(ref _current); + public void PreviousTick() => Interlocked.Decrement(ref current); }