mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-16 11:42:22 +08:00
Update RecordTaskFactory
This commit is contained in:
parent
2d44a9ad1e
commit
bf8a4481e2
|
@ -40,6 +40,8 @@ namespace BililiveRecorder.Core.Recording
|
|||
};
|
||||
this.OnRecordFileOpening(this.fileOpeningEventArgs);
|
||||
|
||||
this.logger.Information("新建录制文件 {Path}", fullPath);
|
||||
|
||||
var file = new FileStream(fullPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read | FileShare.Delete);
|
||||
|
||||
_ = Task.Run(async () => await this.WriteStreamToFileAsync(stream, file).ConfigureAwait(false));
|
||||
|
|
|
@ -1,23 +1,35 @@
|
|||
using System;
|
||||
using BililiveRecorder.Core.Config.V2;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Serilog;
|
||||
|
||||
namespace BililiveRecorder.Core.Recording
|
||||
{
|
||||
public class RecordTaskFactory : IRecordTaskFactory
|
||||
{
|
||||
private readonly ILogger logger;
|
||||
private readonly IServiceProvider serviceProvider;
|
||||
private readonly ObjectFactory factoryRawData;
|
||||
private readonly ObjectFactory factoryStandard;
|
||||
|
||||
public RecordTaskFactory(IServiceProvider serviceProvider)
|
||||
public RecordTaskFactory(ILogger logger, IServiceProvider serviceProvider)
|
||||
{
|
||||
this.logger = logger?.ForContext<RecordTaskFactory>() ?? throw new ArgumentNullException(nameof(logger));
|
||||
this.serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
|
||||
|
||||
this.factoryRawData = ActivatorUtilities.CreateFactory(typeof(RawDataRecordTask), new[] { typeof(IRoom) });
|
||||
this.factoryStandard = ActivatorUtilities.CreateFactory(typeof(StandardRecordTask), new[] { typeof(IRoom) });
|
||||
}
|
||||
|
||||
public IRecordTask CreateRecordTask(IRoom room) =>
|
||||
room.RoomConfig.RecordMode switch
|
||||
public IRecordTask CreateRecordTask(IRoom room)
|
||||
{
|
||||
RecordMode.RawData => ActivatorUtilities.CreateInstance<RawDataRecordTask>(this.serviceProvider, room),
|
||||
_ => ActivatorUtilities.CreateInstance<StandardRecordTask>(this.serviceProvider, room)
|
||||
var recordMode = room.RoomConfig.RecordMode;
|
||||
this.logger.Debug("Create record task with mode {RecordMode} for room {RoomId}", recordMode, room.RoomConfig.RoomId);
|
||||
return recordMode switch
|
||||
{
|
||||
RecordMode.RawData => (IRecordTask)this.factoryRawData(this.serviceProvider, new[] { room }),
|
||||
_ => (IRecordTask)this.factoryStandard(this.serviceProvider, new[] { room })
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user