public static IIdentityGenerator Generator(this IdentityGeneratorType type) { switch (type) { case IdentityGeneratorType.NameBased: return(new NameBasedIdentityGenerator()); case IdentityGeneratorType.Random: return(new RandomIdentityGenerator()); case IdentityGeneratorType.TimeBased: return(new TimeBasedIdentityGenerator()); default: throw new ArgumentException($"Cannot find a UUID generatator for type {Enum.GetName(typeof(IdentityGeneratorType), type)}"); } }
public static Guid NewSequentialGuid(IdentityGeneratorType guidType) { var randomBytes = new byte[10]; Rng.GetBytes(randomBytes); var timestamp = DateTime.UtcNow.Ticks / 10000L; var timestampBytes = BitConverter.GetBytes(timestamp); if (BitConverter.IsLittleEndian) { Array.Reverse(timestampBytes); } var guidBytes = new byte[16]; switch (guidType) { case IdentityGeneratorType.SequentialAsString: case IdentityGeneratorType.SequentialAsBinary: Buffer.BlockCopy(timestampBytes, 2, guidBytes, 0, 6); Buffer.BlockCopy(randomBytes, 0, guidBytes, 6, 10); if (guidType == IdentityGeneratorType.SequentialAsString && BitConverter.IsLittleEndian) { Array.Reverse(guidBytes, 0, 4); Array.Reverse(guidBytes, 4, 2); } break; case IdentityGeneratorType.SequentialAtEnd: Buffer.BlockCopy(randomBytes, 0, guidBytes, 0, 10); Buffer.BlockCopy(timestampBytes, 2, guidBytes, 10, 6); break; } return(new Guid(guidBytes)); }
public GuidAddressFactory(IdentityGeneratorType type) { _type = type; _generator = type.Generator(); _highId = new AtomicLong(World.HighRootId); }
public GridAddressFactory(IdentityGeneratorType type) : base(type) { }