小编pan*_*mic的帖子

ElasticSearch Nest BulkAll 在收到无法从 _bulk 重试的失败后停止

使用BulkAll()批量插入时我收到这个奇怪的错误

BulkAll halted after receiving failures that can not be retried from _bulk
Run Code Online (Sandbox Code Playgroud)

但是,当我检查异常时,我仍然得到成功的响应:

Successful low level call on POST: /cf-lblogs-2019.01.23/cloudflareloadbalancinglogelasticentity/_bulk?
Run Code Online (Sandbox Code Playgroud)

我在这里做错了什么?下面是代码片段:

var waitHandle = new CountdownEvent(1);

var bulk = _client.BulkAll(group.ToList(), a => a
                .Index(_index.Replace("*", string.Empty) + group.Key)
                .BackOffRetries(2)
                .BackOffTime("30s")
                .RefreshOnCompleted(true)
                .MaxDegreeOfParallelism(4)
                .Size(group.Count()));

bulk.Subscribe(new BulkAllObserver(
                onNext: response => _logger.LogInformation($"Indexed {response.Page * group.Count()} with {response.Retries} retries"),
                onError: HandleInsertError,
                onCompleted: () => waitHandle.Signal()
            ));

waitHandle.Wait();


private void HandleInsertError(Exception e)
    {
        var exceptionString = e.ToString(); 
        _logger.LogError(exceptionString);
    }
Run Code Online (Sandbox Code Playgroud)

巢 6.4.2。

弹性6.5.4。

c# elasticsearch nest

6
推荐指数
2
解决办法
7847
查看次数

使用任务获取“未将对象引用设置为对象的实例”

首先,我已经在许多 NullReferenceException 问题中搜索了 SO。这里这里

当我尝试调用时收到错误“对象引用未设置为对象的实例” Task.WaitAll(tasks);

我确信在尝试调用方法之前我正在初始化所有对象。下面是代码片段:

public IList<ResourceFreeBusyDto> GetResourceFreeBusy(int requesterId, int[] resourceIds, DateTime start, DateTime end)
    {
        IList<ResourceFreeBusyDto> result = new List<ResourceFreeBusyDto>();

        ValidateFreeBusyInputs(resourceIds, start, end);

        List<Task<IList<ResourceFreeBusyDto>>> tasks = new List<Task<IList<ResourceFreeBusyDto>>>();
        TimeSpan timeout = new TimeSpan(0,0,30); // 30 seconds          

        // Split resources to persons and meetingRooms
        List<int> personIds;
        List<int> meetingRoomIds;

        SplitResourceIds(resourceIds, out personIds, out meetingRoomIds);

        // Go online for persons
        if (personIds.Count > 0)
        {
            //result.AddRange(GetResourceFreeBusyOnline(requesterId, personIds.ToArray(), start, end)); // paralelizovat
            Task<IList<ResourceFreeBusyDto>> task = Task.Factory.StartNew(() => GetResourceFreeBusyOnline(requesterId, …
Run Code Online (Sandbox Code Playgroud)

c# task nullreferenceexception

5
推荐指数
1
解决办法
1万
查看次数

正则表达式获取匹配后的文本,该文本必须是最后一次出现

我想在 C# 应用程序中使用正则表达式最后一次出现“cn=”后提取字符串。所以我需要的是最后一次出现“cn=”和\字符之间的字符串请注意源字符串可能包含空格。

例子:

ou=company\ou=country\ou=site\cn=office\cn=name\ou=pet

结果:

姓名

到目前为止,我已经(?<=cn=).*使用正向后视来选择 cn= 之后的文本并(?:.(?!cn=))+$找到最后一次出现,但我不知道如何将它组合在一起以获得所需的结果。

c# regex

5
推荐指数
1
解决办法
3024
查看次数

.net core Worker Service (BackgroundService) 无法加载用户机密

拥有 .net core 版本 3.1.8 和 asp.net core 版本 3.1.8 的 .net core 工作服务 我在从工作服务加载用户密钥时遇到问题,但在 asp.net core 项目中同样有效。

从 ASP.NET Core 和 .NET Core Worker 服务调用的通用方法

public static string GetFioApiKey(this IConfiguration configuration)
            => configuration["PaymentServiceSecrets:FioApiKey"];
Run Code Online (Sandbox Code Playgroud)

工人服务的 csproj

<Project Sdk="Microsoft.NET.Sdk.Worker">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UserSecretsId>8d19c97d-a2fb-4a51-a694-9635b9c0c42c</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.8" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.8" />
  </ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

Worker服务的startup.cs

public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration(config => config.AddUserSecrets(Assembly.GetExecutingAssembly()))
                .ConfigureServices((hostContext, services) =>
                {
                    // simplified
                    

                    services.AddSingleton<IApplicationSettings>(applicationSettings =>
                    {
                        var appSettings = new ApplicationSettings
                        {
                            FioApiKey …
Run Code Online (Sandbox Code Playgroud)

c# .net-core asp.net-core

5
推荐指数
2
解决办法
2680
查看次数

Automapper 映射到可为空的 DateTime 属性

使用 Automapper 3.1.1 我无法编译这张地图:

Mapper.CreateMap<Domain.DomainObjects.Entities.Patient, PatientDto>()
                .ForMember(x => x.Deleted, opt => opt.MapFrom(input => input.Deleted.HasValue ? 
                    new DateTime(input.Deleted.Value.Ticks, DateTimeKind.Utc) : null ));
Run Code Online (Sandbox Code Playgroud)

错误:

Type of conditional expression cannot be determined because there is no implicit conversion between '<null>' and 'DateTime'

实体:

public class Patient : Entity
{
        // more properties
        public virtual DateTime? Deleted { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

感觉我错过了一些明显的东西,但无法弄清楚究竟是什么。

注意:DTO包含DateTime? Deleted太多

c# automapper

3
推荐指数
1
解决办法
4422
查看次数