Example #1
0
        /// <summary>
        /// Generates one GDID from the supplied provider taking its scope and sequence name from <see cref="UniqueSequenceAttribute"/>
        /// </summary>
        /// <param name="provider">Provider to use</param>
        /// <param name="tDoc">Type of data Doc</param>
        /// <returns>One GDID</returns>
        public static GDID GenerateGdidFor(this Idgen.IGdidProvider provider, Type tDoc)
        {
            provider.NonNull(nameof(provider));
            tDoc.IsOfType <Doc>(nameof(tDoc));

            var atr = UniqueSequenceAttribute.GetForDocType(tDoc);

            atr.NonNull($"`{tDoc.Name}` decorated with `{nameof(UniqueSequenceAttribute)}`");

            var result = provider.GenerateOneGdid(atr.Scope, atr.Sequence);

            return(result);
        }
Example #2
0
        /// <summary>
        /// Tries to generate many consecutive Globally-Unique distributed ID (GDID) from the same authority for the supplied sequence name.
        /// If the reserved block gets exhausted, then the returned ID array length may be less than requested
        /// The scope and sequence name are taken from <see cref="UniqueSequenceAttribute"/>
        /// </summary>
        /// <param name="provider">Provider to use</param>
        /// <param name="tDoc">Type of data Doc</param>
        /// <param name="gdidCount">How many GDIDS to generate</param>
        /// <returns>The GDID[] instance which may have less elements than requested by gdidCount</returns>
        public static GDID[] TryGenerateManyConsecutiveGdidsFor(this Idgen.IGdidProvider provider, Type tDoc, int gdidCount)
        {
            provider.NonNull(nameof(provider));
            tDoc.IsOfType <Doc>(nameof(tDoc));
            gdidCount.IsTrue(v => v > 0, "gdidCount > 0");

            var atr = UniqueSequenceAttribute.GetForDocType(tDoc);

            atr.NonNull($"`{tDoc.Name}` decorated with `{nameof(UniqueSequenceAttribute)}`");

            var result = provider.TryGenerateManyConsecutiveGdids(atr.Scope, atr.Sequence, gdidCount);

            return(result);
        }