ExportSearchProcess
using kCura.WinEDDS.Exporters;
using kCura.WinEDDS.Service.Export;
using Monitoring;
using Monitoring.Sinks;
using Relativity.DataExchange;
using Relativity.DataExchange.Logger;
using Relativity.DataExchange.Process;
using Relativity.DataExchange.Transfer;
using Relativity.Logging;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Threading;
namespace kCura.WinEDDS
{
public class ExportSearchProcess : MonitoredProcessBase
{
private readonly ILoadFileHeaderFormatterFactory _loadFileHeaderFormatterFactory;
private readonly IExportConfig _exportConfig;
public ExportFile ExportFile;
[CompilerGenerated]
[AccessedThroughProperty("_searchExporter")]
private Exporter __searchExporter;
private int _errorCount;
private int _warningCount;
private string _uploadModeText;
private bool _hasErrors;
private TapiClient _tapiClient;
[CompilerGenerated]
private TelemetryConstants.TransferDirection _TransferDirection;
[CompilerGenerated]
private IUserNotification _UserNotification;
[CompilerGenerated]
private Func<Exporter, IUserNotification> _UserNotificationFactory;
private virtual Exporter _searchExporter {
[CompilerGenerated]
get {
return __searchExporter;
}
[MethodImpl(MethodImplOptions.Synchronized)]
[CompilerGenerated]
set {
IExporterStatusNotification.FileTransferMultiClientModeChangeEventEventHandler obj = _searchExporter_FileTransferModeChangeEvent;
IExporterStatusNotification.StatusMessageEventHandler obj2 = _productionExporter_StatusMessage;
IExporterStatusNotification.FatalErrorEventEventHandler obj3 = _productionExporter_FatalErrorEvent;
Exporter.ShutdownEventEventHandler obj4 = _searchExporter_ShutdownEvent;
Exporter _searchExporter = __searchExporter;
if (_searchExporter != null) {
_searchExporter.FileTransferMultiClientModeChangeEvent -= obj;
_searchExporter.StatusMessage -= obj2;
_searchExporter.FatalErrorEvent -= obj3;
_searchExporter.ShutdownEvent -= obj4;
}
__searchExporter = value;
_searchExporter = __searchExporter;
if (_searchExporter != null) {
_searchExporter.FileTransferMultiClientModeChangeEvent += obj;
_searchExporter.StatusMessage += obj2;
_searchExporter.FatalErrorEvent += obj3;
_searchExporter.ShutdownEvent += obj4;
}
}
}
protected override TelemetryConstants.TransferDirection TransferDirection { get; }
protected override TapiClient TapiClient => _tapiClient;
protected override Statistics Statistics => _searchExporter.Statistics;
public IUserNotification UserNotification { get; set; }
public Func<Exporter, IUserNotification> UserNotificationFactory { get; set; }
[Obsolete("This constructor is marked for deprecation. Please use the constructor that requires a logger instance.")]
public ExportSearchProcess(ILoadFileHeaderFormatterFactory loadFileHeaderFormatterFactory, IExportConfig exportConfig, Func<string> correlationIdFunc)
: this(loadFileHeaderFormatterFactory, exportConfig, RelativityLogger.Instance, new RunningContext(), correlationIdFunc)
{
}
public ExportSearchProcess(ILoadFileHeaderFormatterFactory loadFileHeaderFormatterFactory, IExportConfig exportConfig, ILog logger, IRunningContext runningContext, Func<string> correlationIdFunc)
: this(loadFileHeaderFormatterFactory, exportConfig, new MetricService(new ImportApiMetricSinkConfig()), runningContext, logger, correlationIdFunc)
{
}
[Obsolete("This constructor is marked for deprecation. Please use the constructor that requires a logger instance.")]
public ExportSearchProcess(ILoadFileHeaderFormatterFactory loadFileHeaderFormatterFactory, IExportConfig exportConfig, IMetricService metricService, Func<string> correlationIdFunc)
: this(loadFileHeaderFormatterFactory, exportConfig, metricService, new RunningContext(), RelativityLogger.Instance, correlationIdFunc)
{
}
public ExportSearchProcess(ILoadFileHeaderFormatterFactory loadFileHeaderFormatterFactory, IExportConfig exportConfig, IMetricService metricService, IRunningContext runningContext, ILog logger, Func<string> correlationIdFunc)
: base(metricService, runningContext, logger, correlationIdFunc)
{
_uploadModeText = null;
_tapiClient = TapiClient.None;
_TransferDirection = TelemetryConstants.TransferDirection.Export;
_loadFileHeaderFormatterFactory = loadFileHeaderFormatterFactory;
_exportConfig = exportConfig;
}
protected override long GetTotalRecordsCount()
{
return _searchExporter.TotalExportArtifactCount;
}
protected override long GetCompletedRecordsCount()
{
return _searchExporter.DocumentsExported;
}
protected override void OnSuccess()
{
base.OnSuccess();
base.Context.PublishStatusEvent("", "Export completed");
base.Context.PublishProcessCompleted();
}
protected override void OnHasErrors()
{
base.OnHasErrors();
base.Context.PublishProcessCompleted(false, _searchExporter.ErrorLogFileName, true);
}
protected override bool HasErrors()
{
return _hasErrors;
}
protected override bool IsCancelled()
{
return _searchExporter.IsCancelledByUser;
}
private Exporter GetExporter()
{
if (!ExportFile.UseCustomFileNaming)
return new Exporter(ExportFile, base.Context, new WebApiServiceFactory(ExportFile), _loadFileHeaderFormatterFactory, _exportConfig, base.Logger, base.CancellationTokenSource.Token, base.GetCorrelationId) {
InteractionManager = UserNotification
};
return new ExtendedExporter(ExportFile as ExtendedExportFile, base.Context, new WebApiServiceFactory(ExportFile), _loadFileHeaderFormatterFactory, _exportConfig, base.Logger, base.CancellationTokenSource.Token, base.GetCorrelationId) {
InteractionManager = UserNotification
};
}
protected override void Initialize()
{
base.Initialize();
_warningCount = 0;
_errorCount = 0;
_searchExporter = GetExporter();
if (UserNotificationFactory != null) {
IUserNotification userNotification = UserNotificationFactory(_searchExporter);
if (userNotification != null) {
_searchExporter.InteractionManager = userNotification;
UserNotification = userNotification;
}
}
}
protected override bool Run()
{
_hasErrors = !_searchExporter.ExportSearch();
return !_hasFatalErrorOccured;
}
protected override MetricJobEndReport BuildEndMetric(TelemetryConstants.JobStatus jobStatus)
{
MetricJobEndReport metricJobEndReport = base.BuildEndMetric(jobStatus);
metricJobEndReport.ExportedNativeCount = _searchExporter.Statistics.ExportedNativeCount;
metricJobEndReport.ExportedPdfCount = _searchExporter.Statistics.ExportedPdfCount;
metricJobEndReport.ExportedImageCount = _searchExporter.Statistics.ExportedImageCount;
metricJobEndReport.ExportedLongTextCount = _searchExporter.Statistics.ExportedLongTextCount;
return metricJobEndReport;
}
private void _searchExporter_FileTransferModeChangeEvent(object sender, TapiMultiClientEventArgs args)
{
if (_uploadModeText == null)
_uploadModeText = TapiModeHelper.BuildDocText();
string message = TapiModeHelper.BuildExportStatusText((ExportFile.ExportImages && ExportFile.VolumeInfo.CopyImageFilesFromRepository) || (ExportFile.ExportNative && ExportFile.VolumeInfo.CopyNativeFilesFromRepository), args.TransferClients);
_tapiClient = TapiModeHelper.GetTapiClient(args.TransferClients);
OnTapiClientChanged();
base.Context.PublishStatusBarChanged(message, _uploadModeText);
base.Logger.LogInformation("Export transfer mode changed: {@TransferClients}", new object[1] {
args.TransferClients
});
}
private void _productionExporter_StatusMessage(ExportEventArgs e)
{
int documentsExported;
switch (e.EventType) {
case EventType2.Error: {
Interlocked.Increment(ref _errorCount);
Statistics.DocsErrorsCount = _errorCount;
ProcessContext context3 = base.Context;
documentsExported = e.DocumentsExported;
context3.PublishErrorEvent(documentsExported.ToString(), e.Message);
break;
}
case EventType2.Progress:
SendMetricJobProgress(e.Statistics, true);
base.Context.PublishStatusEvent("", e.Message);
break;
case EventType2.Statistics:
SendMetricJobProgress(e.Statistics, true);
break;
case EventType2.Status: {
ProcessContext context2 = base.Context;
documentsExported = e.DocumentsExported;
context2.PublishStatusEvent(documentsExported.ToString(), e.Message);
break;
}
case EventType2.Warning: {
Interlocked.Increment(ref _warningCount);
ProcessContext context = base.Context;
documentsExported = e.DocumentsExported;
context.PublishWarningEvent(documentsExported.ToString(), e.Message);
break;
}
case EventType2.ResetStartTime:
SetStartTime();
break;
}
IDictionary metadata = null;
if (e.AdditionalInfo != null && e.AdditionalInfo is IDictionary)
metadata = (IDictionary)e.AdditionalInfo;
base.Context.PublishProgress(e.TotalDocuments, e.DocumentsExported, _warningCount, _errorCount, base.StartTime, default(DateTime), e.Statistics.MetadataTransferThroughput, e.Statistics.FileTransferThroughput, base.ProcessId, null, null, metadata);
}
private void _productionExporter_FatalErrorEvent(string message, Exception ex)
{
base.Context.PublishFatalException(ex);
_hasFatalErrorOccured = true;
}
private void _searchExporter_ShutdownEvent()
{
base.Context.PublishShutdown();
}
}
}