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.
105 lines
3.9 KiB
105 lines
3.9 KiB
//using Application.Domain.Entities;
|
|
//using Infrastructure.Data;
|
|
//using Infrastructure.Extensions;
|
|
//using IoT.Shared.Infrastructure;
|
|
//using Microsoft.AspNetCore.SignalR.Client;
|
|
//using Microsoft.EntityFrameworkCore;
|
|
//using Microsoft.Extensions.Configuration;
|
|
//using Microsoft.Extensions.DependencyInjection;
|
|
//using System;
|
|
//using System.Linq;
|
|
//using System.Net.Http;
|
|
//using System.Threading.Tasks;
|
|
|
|
//namespace FBeeService
|
|
//{
|
|
// public class ClientService : BaseClientService
|
|
// {
|
|
// public ClientService(IServiceProvider applicationServices, IConfiguration configuration) : base(applicationServices, configuration)
|
|
// {
|
|
// }
|
|
|
|
// public override void OnConnected()
|
|
// {
|
|
// using (var scope = this.applicationServices.CreateScope())
|
|
// {
|
|
// var deviceInfoRepo = scope.ServiceProvider.GetService<IRepository<DeviceInfo>>();
|
|
// var deviceInfos = deviceInfoRepo.ReadOnlyTable().ToList();
|
|
// foreach (var deviceInfo in deviceInfos)
|
|
// {
|
|
// this.SendDeviceInfo(deviceInfo);
|
|
// }
|
|
|
|
// var deviceRepo = scope.ServiceProvider.GetService<IRepository<Device>>();
|
|
// var devices = deviceRepo.ReadOnlyTable().Include(o => o.Data).ToList();
|
|
// foreach (var device in devices)
|
|
// {
|
|
// this.SendDevice(device);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// public override void OnServerToClient(string method, string message, string fromConnectionId)
|
|
// {
|
|
// if (method == "GetDeviceInfo")
|
|
// {
|
|
// var infoNumber = message;
|
|
// using (var scope = this.applicationServices.CreateScope())
|
|
// {
|
|
// var deviceInfoRepo = scope.ServiceProvider.GetService<IRepository<DeviceInfo>>();
|
|
// var deviceInfo = deviceInfoRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == infoNumber);
|
|
// if (deviceInfo == null)
|
|
// {
|
|
// throw new Exception($"not has infoNumber:{infoNumber}");
|
|
// }
|
|
// this.SendDeviceInfo(deviceInfo);
|
|
// }
|
|
// }
|
|
// else if (method == "CallDeviceMethod")
|
|
// {
|
|
// using (var scope = this.applicationServices.CreateScope())
|
|
// {
|
|
// var serviceProvider = scope.ServiceProvider;
|
|
// var cfg = serviceProvider.GetService<IConfiguration>();
|
|
// var port = cfg["server.urls"].Split(':')[2];
|
|
// var url = $"http://localhost:{port}{message}";
|
|
// var httpClient = serviceProvider.GetService<IHttpClientFactory>().CreateClient();
|
|
// var result = httpClient.GetStringAsync(url).Result;
|
|
// this.Connection.SendAsync("ClientToServer", "ApiCallback", result, cfg["connectId"]);
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// public void SendDevice(Device device)
|
|
// {
|
|
// Task.Run(() =>
|
|
// {
|
|
// try
|
|
// {
|
|
// Console.WriteLine("send device to server");
|
|
// this.ClientToServer("UpdateDevice", device.ToJson());
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.PrintStack();
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
// public void SendDeviceInfo(DeviceInfo deviceInfo)
|
|
// {
|
|
// Task.Run(() =>
|
|
// {
|
|
// try
|
|
// {
|
|
// Console.WriteLine("send device to server");
|
|
// this.ClientToServer("UpdateDeviceInfo", deviceInfo.ToJson());
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// ex.PrintStack();
|
|
// }
|
|
// });
|
|
// }
|
|
// }
|
|
//} |