Squirrowse/Squirrowse.Client/Service/StreamService.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2019-11-01 19:04:24 +01:00
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Squirrowse.Client.Service
{
public class StreamService : IStreamService
{
private readonly IConnectionManager connectionManager;
private readonly ILogger<StreamService> logger;
public StreamService(ILogger<StreamService> logger, IConnectionManager connectionManager)
{
this.connectionManager = connectionManager;
this.logger = logger;
}
public async Task SendStreamAsync(IAsyncEnumerable<byte[]> asb)
{
var con = connectionManager.Connect();
try
{
logger.LogInformation($"{nameof(SendStreamAsync)} Start stream");
await con.StartAsync();
await con.SendAsync("UploadByteStream", asb, default);
}
finally
{
logger.LogInformation($"{nameof(SendStreamAsync)} End stream");
await con.StopAsync();
}
}
}
}