如何在打字稿中使用C#并发字典?

我正在基于c#/打字稿的小页面上工作。在后端,我有并发字典,其中包含键值对数据。我有一类作为值传递的对象。现在,服务器必须在请求数据后立即将该数据发送到客户端。我已经在打字稿中实现了从服务器获取数据的功能。该函数有效,但不返回任何内容。另外,我们正在使用signalR处理数据。我想至少在控制台上获取数据。请指教

C#代码

MsgPrinterUIStatus.cs
using BaseLibrary;
using System;
using System.Collections.Generic;
using System.Text;

namespace Messages.PrinterStatusUI {
    public class MsgPrinterStatusUI : IMessage {
        // Identity Details
        public int ID;
        public string Name;
        public string Location;
        public string IP;
        public string Port;
        // Status Details
        public bool printerConnection;
        public string printerStatus;
        public bool paperOutFlg;
        public bool headUpFlg;
        public bool ribbonOutFlg;
        public char printMode;
        public int labelsRemaining;

        public string GetRoutingKey() {
            return RoutingKeys.PrinterStatusUI;
        }
    }
}

PrinterInfo.cs
namespace PrintAndApply.Class
{
    public class PrinterInfo
    {
        public  ConcurrentDictionary<int, MsgPrinterStatusUI> printerDetails = new ConcurrentDictionary<int, MsgPrinterStatusUI>();

    }
}

Hub service
using Microsoft.AspNetCore.SignalR;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BaseLibrary;
using Messages.PrinterStatusUI;
using PrintAndApply.Class;

namespace PrintAndApply.Hubs
{
    public class PrinterHub : Hub
    {
        private static ILogger log = BaseLib.GetLogger("PrinterHub");
        public PrinterInfo printerInfo;

        public PrinterHub(PrinterInfo printerInfo)
        {
            Program.printer = printerInfo;
        }

        public override async Task OnConnectedAsync()
        {
            log.Trace($"New client connected: {Context.ConnectionId}");
            log.Trace("Key" + Program.printer.printerDetails.Keys);
            foreach (var item in Program.printer.printerDetails)
            {
                log.Trace("CALLING FROM PRINTERHUB");
                log.Trace("Key---" + item.Key);
                log.Trace("Value----" + item.Value.Name);

                await Clients.All.SendAsync("ShowPrinterStatus", item.Key,
                        item.Value.Name, item.Value.printerStatus, item.Value.printerConnection);
            }

            log.Info("Sending Printer status to client");
            await base.OnConnectedAsync();
        }
        public override async Task OnDisconnectedAsync(Exception ex)
        {
            await Clients.All.SendAsync("UserDisconnected", Context.ConnectionId);
            await base.OnDisconnectedAsync(ex);
        }
    }
}

Typescript end
MsgPrinterUIStatus.ts
export interface MsgPrinterStatusUI {
    ID: number;
    Name: string;
    Location: string;
    IP: string;
    Port: string;
    printerConnection: boolean;
    printerStatus: string;
    paperOutFlg: boolean;
    headUpFlg: boolean;
    ribbonOutFlg: boolean;
    printMode: string;
    labelsRemaining: number;

}

signalr.service
import { Injectable } from '@angular/core';
import { AppService } from './app.service';
import { MsgPrinterStatusUI } from '../Class/MsgPrinterStatusUI';
import * as signalR from '@aspnet/signalr';
@Injectable({
  providedIn: 'root'
})
export class SignalRService {

    //public data: MsgPrinterStatusUI[];
    public data: { [key: number]: MsgPrinterStatusUI[] } = {};

    private hubConnection: signalR.HubConnection;

    constructor(private appService: AppService) { }

    public startConnection = () => {
        this.hubConnection = new signalR.HubConnectionBuilder()
            .withUrl(this.appService.hubUrl, {
                skipNegotiation: true,
                transport: signalR.HttpTransportType.WebSockets,
            })
            .configureLogging(signalR.LogLevel.Debug)
            .build();

        console.log("Starting.....");

        this.hubConnection
            .start()
            .then(() => console.log('Connection Established'))
            .catch(error => console.log('Failure with connection-->' + error))
    }

    public receivePrinterStatus = () => {
        console.log("Calling ReceivePrinterStatus");
        this.hubConnection.on("ShowPrinterStatus", (data) => {
            this.data = data;
            console.log(data);
            console.log("Yay, got printer status");

        });
    }
}

controller.ts
import { Component, OnInit } from '@angular/core';
import { SignalRService } from '../Services/signal-r.service';
@Component({
  selector: 'app-printer-status',
  templateUrl: './printer-status.component.html',
  styleUrls: ['./printer-status.component.scss']
})
export class PrinterStatusComponent implements OnInit {

    constructor(private signalRService: SignalRService) { }

    ngOnInit(): void {

        console.log("Starting Connection");
        this.signalRService.startConnection();
        this.signalRService.receivePrinterStatus();
  }

}