Exemple #1
0
 public JT808TcpClient(
     JT808DeviceConfig deviceConfig,
     IServiceProvider serviceProvider)
 {
     DeviceConfig                = deviceConfig;
     SendAtomicCounterService    = serviceProvider.GetRequiredService <JT808SendAtomicCounterService>();
     ReceiveAtomicCounterService = serviceProvider.GetRequiredService <JT808ReceiveAtomicCounterService>();
     JT808Serializer             = serviceProvider.GetRequiredService <IJT808Config>().GetSerializer();
     Logger = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger("JT808TcpClient");
 }
Exemple #2
0
 public JT808TcpClient(
     JT808DeviceConfig deviceConfig,
     IServiceProvider serviceProvider)
 {
     DeviceConfig                = deviceConfig;
     WriteableTimeout            = DateTime.UtcNow.AddSeconds(DeviceConfig.Heartbeat);
     heartbeatCTS                = new CancellationTokenSource();
     SendAtomicCounterService    = serviceProvider.GetRequiredService <JT808SendAtomicCounterService>();
     ReceiveAtomicCounterService = serviceProvider.GetRequiredService <JT808ReceiveAtomicCounterService>();
     JT808Serializer             = serviceProvider.GetRequiredService <IJT808Config>().GetSerializer();
     Logger   = serviceProvider.GetRequiredService <ILoggerFactory>().CreateLogger <JT808TcpClient>();
     producer = serviceProvider.GetRequiredService <IJT808MessageProducer>();
     RetryBlockingCollection = serviceProvider.GetRequiredService <JT808RetryBlockingCollection>();
 }
        public async ValueTask <JT808TcpClient> Create(JT808DeviceConfig deviceConfig, CancellationToken cancellationToken)
        {
            if (dict.TryGetValue(deviceConfig.TerminalPhoneNo, out var client))
            {
                return(client);
            }
            else
            {
                JT808TcpClient jT808TcpClient = new JT808TcpClient(deviceConfig, serviceProvider);
                var            successed      = await jT808TcpClient.ConnectAsync(new IPEndPoint(IPAddress.Parse(deviceConfig.TcpHost), deviceConfig.TcpPort));

                if (successed)
                {
                    jT808TcpClient.StartAsync(cancellationToken);
                    dict.TryAdd(deviceConfig.TerminalPhoneNo, jT808TcpClient);
                    return(jT808TcpClient);
                }
                return(default);