예제 #1
0
        /// <summary>
        /// 异步生成标识。
        /// </summary>
        /// <param name="clock">给定的 <see cref="IClockService"/>。</param>
        /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param>
        /// <returns>返回一个包含字符串的异步操作。</returns>
        public virtual Task <MonggoIdentificationDescriptor> GenerateIdDescriptorAsync(IClockService clock,
                                                                                       CancellationToken cancellationToken = default)
        => cancellationToken.RunOrCancelAsync(() =>
        {
            var timestamp = GetTimestamp(clock);

            var buffer = ComputeHex(timestamp);
            return(MonggoIdentificationDescriptor.Create(buffer));
        });
예제 #2
0
        public virtual string GenerateId(IClockService clock,
                                         out MonggoIdentificationDescriptor result)
        {
            clock.NotNull(nameof(clock));

            var timestamp = GetTimestamp(clock);

            var buffer = ComputeHex(timestamp);

            result = MonggoIdentificationDescriptor.Create(buffer);

            return(result.ToString());
        }