2020-06-20 22:02:20 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2019-10-31 13:08:42 +01:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-06-20 22:02:20 +02:00
|
|
|
|
using Microsoft.AspNetCore.SignalR.Client;
|
2019-10-31 13:08:42 +01:00
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
2020-06-20 22:02:20 +02:00
|
|
|
|
namespace squirrowse.client
|
2019-10-31 13:08:42 +01:00
|
|
|
|
{
|
2019-11-06 11:49:39 +01:00
|
|
|
|
public class Worker : IHostedService
|
2019-10-31 13:08:42 +01:00
|
|
|
|
{
|
2019-11-06 13:47:00 +01:00
|
|
|
|
private readonly ILogger<Worker> logger;
|
2020-06-20 22:02:20 +02:00
|
|
|
|
private readonly IConnectionManager _connectionManager;
|
|
|
|
|
private Connection con =new Connection();
|
|
|
|
|
public Worker(ILogger<Worker> logger, IConnectionManager connectionManager)
|
2019-10-31 13:08:42 +01:00
|
|
|
|
{
|
2019-11-04 14:28:45 +01:00
|
|
|
|
this.logger = logger;
|
2019-11-06 13:47:00 +01:00
|
|
|
|
_connectionManager = connectionManager;
|
2020-06-20 22:02:20 +02:00
|
|
|
|
|
2019-10-31 13:08:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 11:49:39 +01:00
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
2019-10-31 13:08:42 +01:00
|
|
|
|
{
|
2020-06-20 22:02:20 +02:00
|
|
|
|
await _connectionManager.InitConnection();
|
|
|
|
|
|
|
|
|
|
//var d = _connectionManager.GetConnection();
|
|
|
|
|
if (_connectionManager.IsConnected())
|
2019-11-07 14:26:46 +01:00
|
|
|
|
{
|
2020-06-20 22:02:20 +02:00
|
|
|
|
var d =await _connectionManager.GetConnection();
|
|
|
|
|
await d.SendAsync("UploadStream", con.clientStreamData());
|
2019-11-07 14:26:46 +01:00
|
|
|
|
}
|
2019-11-06 11:49:39 +01:00
|
|
|
|
}
|
2019-11-05 10:30:31 +01:00
|
|
|
|
|
2019-11-06 11:49:39 +01:00
|
|
|
|
public async Task StopAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
await _connectionManager.Disconnect();
|
2019-10-31 13:08:42 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-20 22:02:20 +02:00
|
|
|
|
}
|