You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.3 KiB

using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using Serilog;
using Serilog.Core;
using Volo.Abp.DependencyInjection;
using Win.Abp.Snowflakes;
namespace Win.Abp.Snowflakes.Test
{
public class SnowflakesTestService : ITransientDependency
{
private ISnowflakeIdGenerator _snowflakeIdGenerator;
private AbpSnowflakeIdGeneratorOptions _options;
public SnowflakesTestService(
ISnowflakeIdGenerator snowflakeIdGenerator,
IOptions<AbpSnowflakeIdGeneratorOptions> options
)
{
_snowflakeIdGenerator = snowflakeIdGenerator;
_options = options.Value;
}
public async Task RunAsync()
{
Log.Information("SnowflakeId Generator Test");
await TestSnowflakeIdGenerator();
}
private async Task TestSnowflakeIdGenerator()
{
for (var i = 0; i < 10; i++)
{
var id = _snowflakeIdGenerator.Create();
var info = $"{_options.DefaultDatacenterId} {_options.DefaultWorkerId} {DateTime.Now} {id}";
Log.Information(info);
await Task.Delay(100);
}
}
}
}