小编Aut*_*zer的帖子

Angular - Type Pipe 没有“?mod”属性

我正在尝试创建一个自定义管道,该管道将返回表中数组的总和,但无论出于何种原因,Angular 都在抱怨我的管道没有“emod”属性。

我的管子:

import { Injectable, Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'fieldSum',
  pure: false
})
@Injectable()
export class FieldSumPipe implements PipeTransform {
  transform(items: any[], attr: string): number {
    return items.reduce((a, b) => a + b[attr], 0);
  }
}
Run Code Online (Sandbox Code Playgroud)

我的模块:

import { SomeComponent} from './some.component';
import { SomeRoutingModule} from './some-routing.module';
import { FieldSumPipe } from '../../../shared/pipes/fieldsum.pipe';
// Other imports...

@NgModule({
    imports: [
        CommonModule,
        SomeRoutingModule,
        FieldSumPipe, // other imports removed for brevity
    ],
    declarations: [
        SomeComponent,
    ],
    exports: [
        FieldSumPipe …
Run Code Online (Sandbox Code Playgroud)

pipe angular

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

工人服务意外停止工作

我有 .NET Core 3+ 工作服务,它每 10 秒检查一次“一些东西”。有一次,它“随机”停止这样做,我不知道为什么。到目前为止它发生了两次并且没有异常日志或类似的东西,所以我只能假设我应该在try-catch内部添加一个ExecuteAsync,但我的问题是:是否有任何已知问题可能导致类似的行为,工作人员刚刚停止执行?

是的,没有请求取消(否则,我想它会记录消息“发件人正在停止”)。

public class Worker : BackgroundService
{
    private readonly ILogger<Worker> _logger;

    public Worker(ILogger<Worker> logger)
    {
        _logger = logger;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        _logger.LogInformation("Sender is starting");
        stoppingToken.Register(() => _logger.LogInformation("Sender is stopping"));

        while (!stoppingToken.IsCancellationRequested)
        {
            await Task.Delay(10000, stoppingToken);

            _logger.LogDebug("Worker running at: {time}", DateTimeOffset.Now);

            if (!stoppingToken.IsCancellationRequested)
                await SendPendingMessages();
        }
    }

    private async Task SendPendingMessages()
    {
        var list = ...

        foreach (var item in list)
        {
            try
            {
                // Do stuff …
Run Code Online (Sandbox Code Playgroud)

c# worker service-worker .net-core

4
推荐指数
1
解决办法
780
查看次数

.NET Core 输出格式化程序顺序

我有 3 个输出格式化程序,其中之一是我的自定义输出格式化程序,当 SupportedMediaType 为 Excel ( Content-type: application/vnd.ms-excel)时应触发该格式化程序。

      services.AddControllers(options =>
      {
            options.OutputFormatters.Add(new ExcelOutputFormatter());; // Excel stylesheet XML
      }).AddNewtonsoftJson().AddXmlSerializerFormatters();
Run Code Online (Sandbox Code Playgroud)

但是,如果我的标题是Accept: */*,应用程序会将我发送到 ExcelOutputFormatter。有没有办法让我默认使用 JSON 输出格式化程序而不是 Excel 格式化程序?

c# .net-core asp.net-core-webapi

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