FilesStatistics
public class FilesStatistics : ITransferStatistics, IFileProcessingStatistics, IProcessingStatistics, IStateful
using kCura.WinEDDS;
using Relativity.DataExchange.Export.VolumeManagerV2.Batches;
using Relativity.DataExchange.Io;
using Relativity.DataExchange.Logger;
using Relativity.DataExchange.Transfer;
using Relativity.Logging;
using System;
namespace Relativity.DataExchange.Export.VolumeManagerV2.Statistics
{
public class FilesStatistics : ITransferStatistics, IFileProcessingStatistics, IProcessingStatistics, IStateful
{
private double _savedThroughput;
private long _savedFileBytes;
private TimeSpan _savedFileTime;
private readonly kCura.WinEDDS.Statistics _statistics;
private readonly IFile _fileWrapper;
private readonly ILog _logger;
private readonly object _lock = new object();
public FilesStatistics(kCura.WinEDDS.Statistics statistics, IFile fileWrapper, ILog logger)
{
_statistics = statistics.ThrowIfNull("statistics");
_fileWrapper = fileWrapper.ThrowIfNull("fileWrapper");
_logger = logger.ThrowIfNull<ILog>("logger");
}
public void Subscribe(ITapiBridge tapiBridge)
{
tapiBridge.ThrowIfNull("tapiBridge");
_logger.LogVerbose("Attached tapi bridge {TapiBridgeInstanceId} to the file statistics.", new object[1] {
tapiBridge.InstanceId
});
tapiBridge.TapiProgress += OnProgress;
tapiBridge.TapiStatistics += TapiBridgeOnTapiStatistics;
}
private void TapiBridgeOnTapiStatistics(object sender, TapiStatisticsEventArgs e)
{
lock (_lock) {
_statistics.FileTransferThroughput = e.TransferRateBytes;
}
}
private void OnProgress(object sender, TapiProgressEventArgs e)
{
_logger.LogVerbose("Progress event for file {fileName} with status {Successful}.", new object[2] {
e.FileName.Secure(),
e.Successful
});
if (e.Successful) {
lock (_lock) {
_statistics.FileTransferredBytes += e.FileBytes;
_statistics.FileTransferDuration += e.EndTime - e.StartTime;
_statistics.NativeFilesTransferredCount++;
}
}
}
public void Unsubscribe(ITapiBridge tapiBridge)
{
tapiBridge.ThrowIfNull("tapiBridge");
_logger.LogVerbose("Detached tapi bridge {TapiBridgeInstanceId} from the file statistics.", new object[1] {
tapiBridge.InstanceId
});
tapiBridge.TapiProgress -= OnProgress;
tapiBridge.TapiStatistics -= TapiBridgeOnTapiStatistics;
}
public void UpdateStatisticsForFile(string path)
{
lock (_lock) {
if (_fileWrapper.Exists(path))
_statistics.FileTransferredBytes += _fileWrapper.GetFileSize(path);
else
_logger.LogWarning("Trying to add statistics for file {path}, but file doesn't exist.", new object[1] {
path.Secure()
});
}
}
public void SaveState()
{
lock (_lock) {
_savedThroughput = _statistics.FileTransferThroughput;
_savedFileBytes = _statistics.FileTransferredBytes;
_savedFileTime = _statistics.FileTransferDuration;
}
}
public void RestoreLastState()
{
lock (_lock) {
_statistics.FileTransferThroughput = _savedThroughput;
_statistics.FileTransferredBytes = _savedFileBytes;
_statistics.FileTransferDuration = _savedFileTime;
}
}
}
}