Core: Fix FileClosed events are not triggered after file close.

This commit is contained in:
genteure 2022-04-06 21:03:45 +08:00
parent 4b7eed172c
commit 70eb0b4244

View File

@ -85,25 +85,20 @@ namespace BililiveRecorder.Core.Recording
this.timer.Stop();
this.RequestStop();
try
{
var openingEventArgs = this.fileOpeningEventArgs;
if (openingEventArgs is not null)
this.OnRecordFileClosed(new RecordFileClosedEventArgs(this.room)
{
SessionId = this.SessionId,
FullPath = openingEventArgs.FullPath,
RelativePath = openingEventArgs.RelativePath,
FileOpenTime = openingEventArgs.FileOpenTime,
FileCloseTime = DateTimeOffset.Now,
Duration = 0,
FileSize = file.Length,
});
}
catch (Exception ex)
{
this.logger.Warning(ex, "Error calling OnRecordFileClosed");
}
RecordFileClosedEventArgs recordFileClosedEvent;
if (this.fileOpeningEventArgs is { } openingEventArgs)
recordFileClosedEvent = new RecordFileClosedEventArgs(this.room)
{
SessionId = this.SessionId,
FullPath = openingEventArgs.FullPath,
RelativePath = openingEventArgs.RelativePath,
FileOpenTime = openingEventArgs.FileOpenTime,
FileCloseTime = DateTimeOffset.Now,
Duration = 0,
FileSize = file.Length,
};
else
recordFileClosedEvent = null;
try
{ file.Dispose(); }
@ -114,6 +109,16 @@ namespace BililiveRecorder.Core.Recording
{ stream.Dispose(); }
catch (Exception) { }
try
{
if (recordFileClosedEvent is not null)
this.OnRecordFileClosed(recordFileClosedEvent);
}
catch (Exception ex)
{
this.logger.Warning(ex, "Error calling OnRecordFileClosed");
}
this.OnRecordSessionEnded(EventArgs.Empty);
this.logger.Information("录制结束");