public void TestAllGenerators() { Int32[] Versions = UUIDFactory.GetAvailableVersion(); Int32 CurVersion; Int32 CurVariant; for (Int32 VersionIndex = 0; VersionIndex < Versions.Length; VersionIndex++) { CurVersion = Versions[VersionIndex]; Int32[] Variants = UUIDFactory.GetAvailableVariants(Versions[VersionIndex]); for (Int32 VariantIndex = 0; VariantIndex < Variants.Length; VariantIndex++) { CurVariant = Variants[VariantIndex]; IUUIDGenerator Generator = UUIDFactory.CreateGenerator(CurVersion, CurVariant); if (Generator.NeedContext) { Assert.IsFalse(Generator.ContextType == null, $"{CurVersion}:{CurVariant} if context text is needed then context type cannot be null"); } Assert.IsTrue(Generator.Version == CurVersion, "Wrong version of generator"); Assert.IsTrue(Generator.Variant == CurVariant, "Wrong variant of generator"); } } }
/// <summary>Creates a new instance of <see cref="GeneratorInfo"/></summary> /// <param name="generator">The generator to copy the info from</param> public GeneratorInfo(IUUIDGenerator generator) { this.ContextType = generator.ContextType; this.NeedContext = generator.NeedContext; this.Variant = generator.Variant; this.Version = generator.Version; this.GeneratorType = generator.GetType(); }
/// <summary>Add the given generator to the interal list</summary> /// <param name="Generator">The generator to add to the list</param> public static void Add(IUUIDGenerator Generator) { Int32 Variant = Generator.Variant; Int32 Version = Generator.Version; if (UUIDFactory._Generators.Length <= Version) { Array.Resize(ref UUIDFactory._Generators, Version + 1); } if (UUIDFactory._Generators[Version] == null) { UUIDFactory._Generators[Version] = new GeneratorInfo[Variant + 1]; } if (UUIDFactory._Generators[Version].Length <= Variant) { Array.Resize(ref UUIDFactory._Generators[Version], Variant + 1); } UUIDFactory._Generators[Version][Variant] = new GeneratorInfo(Generator); }
/// <summary>Generate a <see cref="UUID"/>[] using the specified version and variant and specified amount</summary> /// <param name="Amount">The amount of UUID to generate</param> /// <param name="Version">The version of the generator</param> /// <param name="Variant">The variant of the generator</param> /// <param name="Context">The context needed to generate the UUID(s)</param> /// <returns>Generate a <see cref="UUID"/>[] using the specified version and variant and specified amount</returns> public static UUID[] CreateUUIDs(Int32 Amount, Int32 Version, Int32 Variant, Object[] Context = default) { IUUIDGenerator generator = UUIDFactory.CreateGenerator(Version, Variant); return(generator.Generate(Amount, Context)); }
/// <summary>Generate a <see cref="UUID"/> using the specified version and variant</summary> /// <param name="Version">The version of the generator</param> /// <param name="Variant">The variant of the generator</param> /// <param name="Context">The context needed to generate the UUID(s)</param> /// <returns>Generate a <see cref="UUID"/> using the specified version and variant and specified amount</returns> public static UUID CreateUUID(Int32 Version, Int32 Variant, Object Context = default) { IUUIDGenerator generator = UUIDFactory.CreateGenerator(Version, Variant); return(generator.Generate(Context)); }
/// <summary> /// /// </summary> /// <param name="Generator"></param> /// <param name="sw"></param> /// <param name="ItemCount"></param> public void Add(IUUIDGenerator Generator, Stopwatch sw, Int32 ItemCount) { this.Add(Generator.Version, Generator.Variant, sw.ElapsedMilliseconds, sw.ElapsedTicks, ItemCount); }