<PackageReference Include="Relativity.Server.Import.SDK" Version="2.9.2" />

LoadFileBase

public abstract class LoadFileBase : ImportTapiBase
using kCura.EDDS.WebAPI.DocumentManagerBase; using kCura.WinEDDS.Api; using kCura.WinEDDS.CodeValidator; using kCura.WinEDDS.Exceptions; using kCura.WinEDDS.Service; using kCura.WinEDDS.Service.Replacement; using Microsoft.VisualBasic; using Microsoft.VisualBasic.CompilerServices; using Relativity.DataExchange; using Relativity.DataExchange.Data; using Relativity.DataExchange.Io; using Relativity.DataExchange.Service; using Relativity.Logging; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Data; using System.IO; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Text; using System.Threading; namespace kCura.WinEDDS { public abstract class LoadFileBase : ImportTapiBase { [Serializable] public class ExtractedTextTooLargeException : ImporterException { public ExtractedTextTooLargeException() : base(string.Format("Extracted text is too large.")) { } protected ExtractedTextTooLargeException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class IdentifierOverlapException : ImporterException { public IdentifierOverlapException(string identityValue, string previousLineNumber) : base($"""{identityValue}""{previousLineNumber}""") { } protected IdentifierOverlapException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class MissingFullTextFileException : ImporterException { public MissingFullTextFileException(int row, int column) : base(row, column, string.Format("Error: full text file specified does not exist.")) { } protected MissingFullTextFileException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class MissingUserException : ImporterException { public MissingUserException(int row, int column, string invalidEmailaddress) : base(row, column, $"""{invalidEmailaddress}""") { } protected MissingUserException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class CodeCreationException : ImporterException { [CompilerGenerated] private bool _IsFatal; public bool IsFatal { get; } public CodeCreationException(int row, int column, bool isFatal, string errorText) : base(row, column, errorText) { _IsFatal = isFatal; } protected CodeCreationException(SerializationInfo info, StreamingContext context) : base(info, context) { _IsFatal = info.GetBoolean("IsFatal"); } public override void GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("IsFatal", IsFatal); base.GetObjectData(info, context); } } [Serializable] public class ColumnCountMismatchException : ImporterException { public ColumnCountMismatchException(int row, int expecting, int actual) : base(row, -1, $"""{expecting}""{actual}""") { } protected ColumnCountMismatchException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class DuplicateObjectReferenceException : ImporterException { public DuplicateObjectReferenceException(int row, int column, string fieldName) : base(row, column, $"""{fieldName}""") { } protected DuplicateObjectReferenceException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class NonExistentParentException : ImporterException { public NonExistentParentException(int row, int column, string fieldName) : base(row, column, string.Format("Object references a parent object that does not exist.", fieldName)) { } protected NonExistentParentException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class ParentObjectReferenceRequiredException : ImporterException { public ParentObjectReferenceRequiredException(int row, int column) : base(row, column, string.Format("Null parent object identifier found, this is required for the Parent Info field.")) { } protected ParentObjectReferenceRequiredException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [Serializable] public class DuplicateMulticodeValueException : ImporterException { public DuplicateMulticodeValueException(int row, int column, string codeName) : base(row, column, $"""{codeName}""") { } protected DuplicateMulticodeValueException(SerializationInfo info, StreamingContext context) : base(info, context) { } } [CompilerGenerated] internal sealed class _Closure$__120-0 { public int $VB$Local_currentRetryAttempt; public int $VB$Local_maxRetryAttempts; public _Closure$__120-1 $VB$NonLocal_$VB$Closure_3; public _Closure$__120-0(_Closure$__120-0 arg0) { if (arg0 != null) { $VB$Local_currentRetryAttempt = arg0.$VB$Local_currentRetryAttempt; $VB$Local_maxRetryAttempts = arg0.$VB$Local_maxRetryAttempts; } } internal TimeSpan _Lambda$__0(int count) { $VB$Local_currentRetryAttempt = count; return TimeSpan.FromSeconds((double)AppSettings.Instance.IoErrorWaitTimeInSeconds); } internal void _Lambda$__1(Exception exception, TimeSpan span) { $VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.PublishIoRetryMessage(exception, span, $VB$Local_currentRetryAttempt, $VB$Local_maxRetryAttempts); } } [CompilerGenerated] internal sealed class _Closure$__120-1 { public bool $VB$Local_performExtractedTextFileLocationValidation; public string $VB$Local_value; public _Closure$__120-2 $VB$NonLocal_$VB$Closure_2; public _Closure$__120-1(_Closure$__120-1 arg0) { if (arg0 != null) { $VB$Local_performExtractedTextFileLocationValidation = arg0.$VB$Local_performExtractedTextFileLocationValidation; $VB$Local_value = arg0.$VB$Local_value; } } internal int? _Lambda$__2(CancellationToken token) { int? result = null; if ($VB$Local_performExtractedTextFileLocationValidation) { string existingFilePath = $VB$NonLocal_$VB$Closure_2.$VB$Me.GetExistingFilePath($VB$Local_value, false); if (string.IsNullOrEmpty(existingFilePath)) throw new MissingFullTextFileException($VB$NonLocal_$VB$Closure_2.$VB$Me.CurrentLineNumber, $VB$NonLocal_$VB$Closure_2.$VB$Local_columnIndex); if (!string.Equals($VB$Local_value, existingFilePath)) { string message = $"""{$VB$Local_value}""{$VB$NonLocal_$VB$Closure_2.$VB$Local_columnIndex}""{$VB$NonLocal_$VB$Closure_2.$VB$Me.CurrentLineNumber}""{existingFilePath}"""; $VB$NonLocal_$VB$Closure_2.$VB$Me.PublishIoWarningEvent(new IoWarningEventArgs(message, $VB$NonLocal_$VB$Closure_2.$VB$Me.CurrentLineNumber)); $VB$Local_value = existingFilePath; } } Encoding encoding = $VB$NonLocal_$VB$Closure_2.$VB$Me._extractedTextFileEncoding; if (!$VB$NonLocal_$VB$Closure_2.$VB$Me.SkipExtractedTextEncodingCheck) { DeterminedEncodingStream determinedEncodingStream = Utility.DetectEncoding($VB$Local_value, false, $VB$Local_performExtractedTextFileLocationValidation); encoding = determinedEncodingStream.DeterminedEncoding; } if ($VB$Local_performExtractedTextFileLocationValidation && $VB$NonLocal_$VB$Closure_2.$VB$Me.GetFileLength($VB$Local_value, false) > $VB$NonLocal_$VB$Closure_2.$VB$Me.GetMaxExtractedTextLength(encoding)) throw new ExtractedTextTooLargeException(); if ($VB$NonLocal_$VB$Closure_2.$VB$Local_forPreview) { DeterminedEncodingStream determinedEncodingStream = Utility.DetectEncoding($VB$Local_value, false); encoding = determinedEncodingStream.DeterminedEncoding; Encoding encoding2 = (encoding == null) ? $VB$NonLocal_$VB$Closure_2.$VB$Me._extractedTextFileEncoding : encoding; StreamReader streamReader = new StreamReader(determinedEncodingStream.UnderlyingStream, encoding2); int num = 0; StringBuilder stringBuilder = new StringBuilder(); while (streamReader.Peek() != -1 && num < 100) { stringBuilder.Append(Strings.ChrW(streamReader.Read())); num = checked(num + 1); } if (num == 100) stringBuilder.Append("..."); result = encoding2.CodePage; streamReader.Close(); determinedEncodingStream.Close(); $VB$NonLocal_$VB$Closure_2.$VB$Local_field.Value = stringBuilder.ToString(); } else $VB$NonLocal_$VB$Closure_2.$VB$Local_field.Value = $VB$Local_value; return result; } } [CompilerGenerated] internal sealed class _Closure$__120-2 { public int $VB$Local_columnIndex; public bool $VB$Local_forPreview; public ArtifactField $VB$Local_field; public LoadFileBase $VB$Me; public _Closure$__120-2(_Closure$__120-2 arg0) { if (arg0 != null) { $VB$Local_columnIndex = arg0.$VB$Local_columnIndex; $VB$Local_forPreview = arg0.$VB$Local_forPreview; $VB$Local_field = arg0.$VB$Local_field; } } } protected bool _columnsAreInitialized; protected IDocumentManager _documentManager; protected ICodeManager _codeManager; protected IFolderManager _folderManager; protected IFieldQuery _fieldQuery; protected IBulkImportManager _bulkImportManager; protected IUserManager _usermanager; protected IObjectManager _objectManager; protected string _filePathColumn; protected int _filePathColumnIndex; protected bool _firstLineContainsColumnNames; protected DocumentField[] _docFields; protected char[] _multiValueSeparator; protected SqlDataView _allCodes; protected SqlDataView _allCodeTypes; protected int _folderID; protected int _caseSystemID; protected int _caseArtifactID; protected int _timeZoneOffset; protected bool _autoDetect; protected bool _uploadFiles; protected LoadFileFieldMap _fieldMap; protected bool _createFolderStructure; protected string _destinationFolder; protected bool _fullTextColumnMapsToFileLocation; private UserCollection _users; protected Encoding _sourceFileEncoding; protected Encoding _extractedTextFileEncoding; protected string _extractedTextFileEncodingName; protected int _artifactTypeID; protected Hashtable MulticodeMatrix; protected string _hierarchicalMultiValueFieldDelmiter; protected HybridDictionary _previewCodeCount; protected long _startLineNumber; protected int _keyFieldID; protected LoadFile _settings; private Base _codeValidator; [CompilerGenerated] [AccessedThroughProperty("_artifactReader")] private IArtifactReader __artifactReader; protected ExecutionSource _executionSource; protected IRunningContext _runningContext; [CompilerGenerated] private bool _SkipExtractedTextEncodingCheck; [CompilerGenerated] private bool _LoadImportedFullTextFromServer; [CompilerGenerated] private bool _DisableExtractedTextFileLocationValidation; [CompilerGenerated] private bool _OIFileIdMapped; [CompilerGenerated] private string _OIFileIdColumnName; [CompilerGenerated] private string _OIFileTypeColumnName; [CompilerGenerated] private bool _FileSizeMapped; [CompilerGenerated] private string _FileSizeColumn; [CompilerGenerated] private string _FileNameColumn; [CompilerGenerated] private string _SupportedByViewerColumn; [CompilerGenerated] private Dictionary<Tuple<int, string>, DataSet> __artifactIDDataSetCache; protected abstract bool UseTimeZoneOffset { get; } protected virtual IArtifactReader _artifactReader { [CompilerGenerated] get { return __artifactReader; } [MethodImpl(MethodImplOptions.Synchronized)] [CompilerGenerated] set { IArtifactReader.OnIoWarningEventHandler obj = _artifactReader_OnIoWarning; IArtifactReader _artifactReader = __artifactReader; if (_artifactReader != null) _artifactReader.OnIoWarning -= obj; __artifactReader = value; _artifactReader = __artifactReader; if (_artifactReader != null) _artifactReader.OnIoWarning += obj; } } public bool SkipExtractedTextEncodingCheck { get; set; } public bool LoadImportedFullTextFromServer { get; set; } public bool DisableExtractedTextFileLocationValidation { get; set; } public bool OIFileIdMapped { get; set; } public string OIFileIdColumnName { get; set; } public string OIFileTypeColumnName { get; set; } public bool FileSizeMapped { get; set; } public string FileSizeColumn { get; set; } public string FileNameColumn { get; set; } public string SupportedByViewerColumn { get; set; } private Dictionary<Tuple<int, string>, DataSet> _artifactIDDataSetCache { get; set; } public SqlDataView AllCodes { get { InitializeCodeTables(); return _allCodes; } set { _allCodes = value; } } public SqlDataView AllCodeTypes { get { InitializeCodeTables(); return _allCodeTypes; } set { _allCodeTypes = value; } } public int SingleCodesCreated => _codeValidator.CreatedCodeCount; public UserCollection Users { get { if (_users == null) _users = new UserCollection(_usermanager, _caseArtifactID); return _users; } } protected override int CurrentLineNumber => _artifactReader.CurrentLineNumber; protected virtual IBulkImportManager BulkImportManager { get { if (_bulkImportManager == null) _bulkImportManager = ManagerFactory.CreateBulkImportManager(_settings.Credentials, _settings.CookieContainer, GetCorrelationId); return _bulkImportManager; } } protected virtual string GetCorrelationId() { return CorrelationIdFunc?.Invoke(); } protected abstract Base GetSingleCodeValidator(); protected abstract IArtifactReader GetArtifactReader(); protected void AdvanceLine() { _artifactReader.AdvanceRecord(); } protected LoadFileBase(LoadFile args, IIoReporter reporter, ILog logger, int timezoneoffset, bool doRetryLogic, bool autoDetect, CancellationTokenSource cancellationToken, Func<string> correlationIdFunc, IRunningContext runningContext = null) : this(args, reporter, logger, timezoneoffset, doRetryLogic, autoDetect, cancellationToken, true, correlationIdFunc, runningContext) { } protected LoadFileBase(LoadFile args, IIoReporter reporter, ILog logger, int timezoneoffset, bool doRetryLogic, bool autoDetect, CancellationTokenSource cancellationToken, bool initializeArtifactReader, Func<string> correlationIdFunc, IRunningContext runningContext = null) : base(reporter, logger, cancellationToken, correlationIdFunc) { _previewCodeCount = new HybridDictionary(); _settings = args; OIFileIdColumnName = args.OIFileIdColumnName; OIFileIdMapped = args.OIFileIdMapped; OIFileTypeColumnName = args.OIFileTypeColumnName; FileSizeMapped = args.FileSizeMapped; FileSizeColumn = args.FileSizeColumn; FileNameColumn = args.FileNameColumn; SupportedByViewerColumn = args.SupportedByViewerColumn; _timeZoneOffset = timezoneoffset; _autoDetect = autoDetect; _executionSource = (runningContext?.ExecutionSource ?? ExecutionSource.Unknown); _runningContext = runningContext; InitializeManagers(args); if (initializeArtifactReader) InitializeArtifactReader(); } protected void InitializeArtifactReader() { LoadFile settings = _settings; _caseArtifactID = settings.CaseInfo.ArtifactID; _artifactReader = GetArtifactReader(); _docFields = settings.FieldMap.DocumentFields; _filePathColumn = settings.NativeFilePathColumn; _firstLineContainsColumnNames = settings.FirstLineContainsHeaders; _fieldMap = settings.FieldMap; _keyFieldID = settings.IdentityFieldId; _multiValueSeparator = settings.MultiRecordDelimiter.ToString().ToCharArray(); _folderID = settings.DetermineDestinationFolderID(); _caseSystemID = settings.CaseInfo.RootArtifactID; _uploadFiles = settings.LoadNativeFiles; _createFolderStructure = settings.CreateFolderStructure; _destinationFolder = settings.FolderStructureContainedInColumn; _fullTextColumnMapsToFileLocation = settings.FullTextColumnContainsFileLocation; _sourceFileEncoding = settings.SourceFileEncoding; _extractedTextFileEncoding = settings.ExtractedTextFileEncoding; _extractedTextFileEncodingName = settings.ExtractedTextFileEncodingName; _artifactTypeID = settings.ArtifactTypeID; _hierarchicalMultiValueFieldDelmiter = Conversions.ToString(settings.HierarchicalValueDelimiter); _previewCodeCount = settings.PreviewCodeCount; _startLineNumber = settings.StartLineNumber; _codeValidator = GetSingleCodeValidator(); _artifactIDDataSetCache = new Dictionary<Tuple<int, string>, DataSet>(); MulticodeMatrix = new Hashtable(); if (_keyFieldID == -1) { DocumentField[] docFields = _docFields; int num = 0; DocumentField documentField; while (true) { if (num >= docFields.Length) return; documentField = docFields[num]; if (documentField.FieldCategory == global::Relativity.DataExchange.Service.FieldCategory.Identifier) break; num = checked(num + 1); } _keyFieldID = documentField.FieldID; } } protected virtual void InitializeManagers(LoadFile args) { _documentManager = ManagerFactory.CreateDocumentManager(args.Credentials, args.CookieContainer, GetCorrelationId); _codeManager = ManagerFactory.CreateCodeManager(args.Credentials, args.CookieContainer, GetCorrelationId); _folderManager = ManagerFactory.CreateFolderManager(args.Credentials, args.CookieContainer, GetCorrelationId); _fieldQuery = ManagerFactory.CreateFieldQuery(args.Credentials, args.CookieContainer, GetCorrelationId); _usermanager = ManagerFactory.CreateUserManager(args.Credentials, args.CookieContainer, GetCorrelationId); _objectManager = ManagerFactory.CreateObjectManager(args.Credentials, args.CookieContainer, GetCorrelationId); } private void InitializeCodeTables() { if (_autoDetect && _allCodes == null) { DataSet dataSet = _codeManager.RetrieveCodesAndTypesForCase(_caseArtifactID); _allCodes = new SqlDataView(dataSet.Tables["AllCodes"]); _allCodeTypes = new SqlDataView(dataSet.Tables["AllCodeTypes"]); } } public int? GetCode(string value, int column, ArtifactField field, bool forPreview) { try { return _codeValidator.ValidateSingleCode(field, value); } catch (kCura.WinEDDS.CodeValidator.CodeCreationException ex) { ProjectData.SetProjectError(ex); kCura.WinEDDS.CodeValidator.CodeCreationException ex2 = ex; throw new CodeCreationException(CurrentLineNumber, column, ex2.IsFatal, ex2.Message); } } private bool CheckNestedChoicesNameLength(string codeStr) { string[] array = codeStr.Split(new char[1] { Conversions.ToChar(_hierarchicalMultiValueFieldDelmiter) }); for (int i = 0; i < array.Length; i = checked(i + 1)) { if (array[i].Length > 200) return true; } return false; } public virtual int?[] GetMultiCode(string[] value, int column, ArtifactField field, bool forPreview) { try { ArrayList arrayList = new ArrayList(value); ArrayList arrayList2 = new ArrayList(); IEnumerator enumerator = default(IEnumerator); try { enumerator = arrayList.GetEnumerator(); while (enumerator.MoveNext()) { string text = Conversions.ToString(enumerator.Current); text = text.Trim(); if (Operators.CompareString(text, "", false) != 0) { if (arrayList2.Contains(text)) throw new DuplicateMulticodeValueException(CurrentLineNumber, column, text); if (CheckNestedChoicesNameLength(text)) throw new CodeCreationException(CurrentLineNumber, column, false, "Proposed choice name '" + text + "' exceeds 200 characters, which is the maximum allowable."); arrayList2.Add(text); } } } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } string[] obj = (string[])arrayList2.ToArray(typeof(string)); IHierarchicArtifactManager artifactManager = (!forPreview) ? ((IHierarchicArtifactManager)new FieldSpecificCodeManager(_codeManager, field.CodeTypeID)) : ((IHierarchicArtifactManager)new FieldSpecificCodePreviewer(_codeManager, field.CodeTypeID)); if (!MulticodeMatrix.Contains(field.CodeTypeID)) MulticodeMatrix.Add(field.CodeTypeID, new NestedArtifactCache(artifactManager, _caseSystemID, _caseArtifactID, _hierarchicalMultiValueFieldDelmiter)); NestedArtifactCache nestedArtifactCache = (NestedArtifactCache)MulticodeMatrix[field.CodeTypeID]; ArrayList arrayList3 = new ArrayList(); string[] array = obj; foreach (string text2 in array) { object[] array2 = nestedArtifactCache.get_SelectedIds(_hierarchicalMultiValueFieldDelmiter + text2.Trim(_hierarchicalMultiValueFieldDelmiter.ToCharArray())); for (int j = 0; j < array2.Length; j = checked(j + 1)) { object[] array3 = (object[])array2[j]; if (Conversions.ToInteger(array3[0]) == -200) throw new Exception("This choice or multi-choice field is not enabled as unicode. Upload halted"); if (forPreview) { arrayList3.Add(Conversions.ToInteger(array3[0])); AddToCodeCountPreviewHashTable(field.ArtifactID, field.DisplayName, Conversions.ToString(array3[1])); } else if (!arrayList3.Contains(Conversions.ToInteger(array3[0]))) { arrayList3.Add(Conversions.ToInteger(array3[0])); } } } if (arrayList3.Count <= 0) return new int?[0]; checked { int?[] array4 = new int?[arrayList3.Count - 1 + 1]; int num = array4.Length - 1; for (int k = 0; k <= num; k++) { array4[k] = Conversions.ToInteger(arrayList3[k]); } return array4; } } catch (CodeCreationFailedException ex) { ProjectData.SetProjectError(ex); CodeCreationFailedException ex2 = ex; throw new CodeCreationException(CurrentLineNumber, column, true, ex2.ToString()); } } public virtual Hashtable GetObjects(string[] value, int column, ArtifactField field, int associatedObjectTypeID, bool shouldRetrieveIdFromServer) { ArrayList arrayList = new ArrayList(value); ArrayList arrayList2 = new ArrayList(); IEnumerator enumerator = default(IEnumerator); try { enumerator = arrayList.GetEnumerator(); while (enumerator.MoveNext()) { string text = Conversions.ToString(enumerator.Current); text = text.Trim(); if (Operators.CompareString(text, string.Empty, false) != 0) { if (arrayList2.Contains(text)) throw new DuplicateObjectReferenceException(CurrentLineNumber, column, text); arrayList2.Add(text); } } } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } string[] obj = (string[])arrayList2.ToArray(typeof(string)); Hashtable hashtable = new Hashtable(); string[] array = obj; foreach (string text2 in array) { if (text2.Length > field.TextLength) throw new StringImporterException(CurrentLineNumber, column, text2.Length, field.TextLength, field.DisplayName); hashtable[text2] = (shouldRetrieveIdFromServer ? LookupArtifactIDForName(text2, associatedObjectTypeID) : (-1)); } return hashtable; } public virtual string LookupNameForArtifactID(int objectArtifactID, int associatedObjectTypeID) { DataSet dataSet = _objectManager.RetrieveTextIdentifierOfMappedObject(_caseArtifactID, objectArtifactID, associatedObjectTypeID); string result = string.Empty; if (dataSet.Tables[0].Rows.Count > 0) result = (string)dataSet.Tables[0].Rows[0][0]; return result; } public virtual int LookupArtifactIDForName(string objectName, int associatedObjectTypeID) { DataSet value = null; Tuple<int, string> key = new Tuple<int, string>(associatedObjectTypeID, objectName); if (!_artifactIDDataSetCache.TryGetValue(key, out value)) { value = _objectManager.RetrieveArtifactIdOfMappedObject(_caseArtifactID, objectName, associatedObjectTypeID); _artifactIDDataSetCache.Add(key, value); } int result = -1; if (value.Tables[0].Rows.Count > 0) result = Conversions.ToInteger(value.Tables[0].Rows[0][0]); return result; } public virtual Hashtable GetObjectsByArtifactID(string[] value, int column, ArtifactField field, int associatedObjectTypeID) { ArrayList arrayList = new ArrayList(value); ArrayList arrayList2 = new ArrayList(); IEnumerator enumerator = default(IEnumerator); try { enumerator = arrayList.GetEnumerator(); while (enumerator.MoveNext()) { string text = Conversions.ToString(enumerator.Current); text = text.Trim(); if (Operators.CompareString(text, string.Empty, false) != 0) { if (arrayList2.Contains(text)) throw new DuplicateObjectReferenceException(CurrentLineNumber, column, text); arrayList2.Add(text); } } } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } string[] obj = (string[])arrayList2.ToArray(typeof(string)); Hashtable hashtable = new Hashtable(); string[] array = obj; foreach (string text2 in array) { if (text2.Length > field.TextLength) throw new StringImporterException(CurrentLineNumber, column, text2.Length, field.TextLength, field.DisplayName); hashtable[text2] = LookupNameForArtifactID(Conversions.ToInteger(text2), associatedObjectTypeID); } return hashtable; } protected bool FieldValueContainsTextFileLocation(ArtifactField field) { bool flag = _fullTextColumnMapsToFileLocation && field.Category == global::Relativity.DataExchange.Service.FieldCategory.FullText; if (!flag) flag = field.DisplayName.Equals(_settings.LongTextColumnThatContainsPathToFullText, StringComparison.InvariantCultureIgnoreCase); return flag; } public void SetFieldValue(ArtifactField field, int columnIndex, bool forPreview, string identityValue, ref int extractedTextFileCodePageId, kCura.EDDS.WebAPI.DocumentManagerBase.ImportBehaviorChoice? importBehavior) { _Closure$__120-2 arg = new _Closure$__120-2(arg); arg.$VB$Me = this; arg.$VB$Local_field = field; arg.$VB$Local_columnIndex = columnIndex; arg.$VB$Local_forPreview = forPreview; if (arg.$VB$Local_field.Value is Exception) throw (Exception)arg.$VB$Local_field.Value; switch (arg.$VB$Local_field.Type) { case global::Relativity.DataExchange.Service.FieldType.Boolean: arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue((bool?)arg.$VB$Local_field.Value); break; case global::Relativity.DataExchange.Service.FieldType.Integer: arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue((int?)arg.$VB$Local_field.Value); break; case global::Relativity.DataExchange.Service.FieldType.Decimal: case global::Relativity.DataExchange.Service.FieldType.Currency: arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue((decimal?)arg.$VB$Local_field.Value); break; case global::Relativity.DataExchange.Service.FieldType.Date: arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue((DateTime?)arg.$VB$Local_field.Value, true); break; case global::Relativity.DataExchange.Service.FieldType.User: { string value = string.Empty; if (arg.$VB$Local_field.Value == null) arg.$VB$Local_field.Value = string.Empty; else if (Operators.CompareString(arg.$VB$Local_field.Value.ToString(), string.Empty, false) != 0) { value = arg.$VB$Local_field.ValueAsString; arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue(GetUserArtifactID(arg.$VB$Local_field.Value.ToString(), arg.$VB$Local_columnIndex)); } if (arg.$VB$Local_forPreview) arg.$VB$Local_field.Value = value; break; } case global::Relativity.DataExchange.Service.FieldType.Code: { string text3 = (arg.$VB$Local_field.Value != null) ? arg.$VB$Local_field.Value.ToString().Trim() : string.Empty; string text4 = string.Copy(text3); int? code = GetCode(text3, arg.$VB$Local_columnIndex, arg.$VB$Local_field, arg.$VB$Local_forPreview); text3 = NullableTypesHelper.ToEmptyStringOrValue(code); if (arg.$VB$Local_forPreview) { if (Operators.CompareString(text3, "-1", false) == 0) text3 = "[new code]"; if (Operators.CompareString(text3, string.Empty, false) != 0) AddToCodeCountPreviewHashTable(arg.$VB$Local_field.ArtifactID, arg.$VB$Local_field.DisplayName, text4); } arg.$VB$Local_field.Value = text3; if (this is BulkLoadFileImporter) { text3 = " " + text4 + " "; arg.$VB$Local_field.Value = text3; if (Operators.CompareString(text4, string.Empty, false) != 0) { ((BulkLoadFileImporter)this).WriteCodeLineToTempFile(identityValue, int.Parse(NullableTypesHelper.ToEmptyStringOrValue(code)), arg.$VB$Local_field.CodeTypeID); arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue(code); } else arg.$VB$Local_field.Value = string.Empty; } break; } case global::Relativity.DataExchange.Service.FieldType.MultiCode: { string[] array = null; if (arg.$VB$Local_field.Value != null) array = (string[])arg.$VB$Local_field.Value; if (arg.$VB$Local_field.Value == null) array = new string[0]; checked { if (array.Length == 0) { arg.$VB$Local_field.Value = string.Empty; if (this is BulkLoadFileImporter) arg.$VB$Local_field.Value = string.Empty; } else { int?[] multiCode = GetMultiCode(array, arg.$VB$Local_columnIndex, arg.$VB$Local_field, arg.$VB$Local_forPreview); string text = string.Empty; if (multiCode.Length > 0) { text += multiCode[0].ToString(); if (arg.$VB$Local_forPreview & (Operators.CompareString(text, "-1", false) == 0)) text = "[new code]"; if (multiCode.Length > 1) { int num = multiCode.Length - 1; for (int i = 1; i <= num; i++) { string text2 = NullableTypesHelper.ToEmptyStringOrValue(multiCode[i]); if (arg.$VB$Local_forPreview & (Operators.CompareString(text2, "-1", false) == 0)) text2 = "[new code]"; text = text + ";" + text2; } } } arg.$VB$Local_field.Value = text; if (this is BulkLoadFileImporter) { if (multiCode.Length == 0) arg.$VB$Local_field.Value = string.Empty; else { arg.$VB$Local_field.Value = " " + array.ToDelimitedString(" ", "", "{0}") + " "; int?[] array2 = multiCode; for (int j = 0; j < array2.Length; j++) { int? nullable2 = array2[j]; if (nullable2.HasValue) unchecked((BulkLoadFileImporter)this).WriteCodeLineToTempFile(identityValue, nullable2.Value, arg.$VB$Local_field.CodeTypeID); } StringBuilder stringBuilder = new StringBuilder(); int?[] array3 = multiCode; for (int k = 0; k < array3.Length; k++) { int? nullable3 = array3[k]; if (nullable3.HasValue) { stringBuilder.Append(nullable3.Value); stringBuilder.Append(","); } } arg.$VB$Local_field.Value = stringBuilder.ToString().TrimEnd(new char[1] { ',' }); } } } break; } } case global::Relativity.DataExchange.Service.FieldType.Varchar: if (arg.$VB$Local_field.Value == null) arg.$VB$Local_field.Value = string.Empty; arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue(GetNullableFixedString(arg.$VB$Local_field.ValueAsString, arg.$VB$Local_columnIndex, arg.$VB$Local_field.TextLength, arg.$VB$Local_field.DisplayName)); if (arg.$VB$Local_field.Category == global::Relativity.DataExchange.Service.FieldCategory.Relational && Operators.CompareString(arg.$VB$Local_field.Value.ToString(), string.Empty, false) == 0 && importBehavior.HasValue && importBehavior.Value == kCura.EDDS.WebAPI.DocumentManagerBase.ImportBehaviorChoice.ReplaceBlankValuesWithIdentifier) arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue(GetNullableFixedString(identityValue, arg.$VB$Local_columnIndex, arg.$VB$Local_field.TextLength, arg.$VB$Local_field.DisplayName)); break; case global::Relativity.DataExchange.Service.FieldType.Object: if (arg.$VB$Local_field.Value == null) arg.$VB$Local_field.Value = string.Empty; arg.$VB$Local_field.Value = NullableTypesHelper.ToEmptyStringOrValue(GetNullableAssociatedObjectName(arg.$VB$Local_field.Value.ToString(), arg.$VB$Local_columnIndex, arg.$VB$Local_field.TextLength, arg.$VB$Local_field.DisplayName)); if (arg.$VB$Local_forPreview) arg.$VB$Local_field.Value = arg.$VB$Local_field.Value.ToString().Trim(); break; case global::Relativity.DataExchange.Service.FieldType.Objects: if (_settings.ObjectFieldIdListContainsArtifactId != null && _settings.ObjectFieldIdListContainsArtifactId.Contains(arg.$VB$Local_field.ArtifactID)) SetFieldValueObjectsByArtifactID(arg.$VB$Local_field, arg.$VB$Local_columnIndex, arg.$VB$Local_forPreview, identityValue); else SetFieldValueObjectsByName(arg.$VB$Local_field, arg.$VB$Local_columnIndex, arg.$VB$Local_forPreview, identityValue); break; case global::Relativity.DataExchange.Service.FieldType.Text: case global::Relativity.DataExchange.Service.FieldType.OffTableText: if (FieldValueContainsTextFileLocation(arg.$VB$Local_field)) { _Closure$__120-1 arg2 = new _Closure$__120-1(arg2); arg2.$VB$NonLocal_$VB$Closure_2 = arg; arg2.$VB$Local_value = arg2.$VB$NonLocal_$VB$Closure_2.$VB$Local_field.ValueAsString; arg2.$VB$Local_performExtractedTextFileLocationValidation = !DisableExtractedTextFileLocationValidation; if (Operators.CompareString(arg2.$VB$Local_value, string.Empty, false) != 0) try { _Closure$__120-0 closure$__120-; closure$__120-.$VB$NonLocal_$VB$Closure_3 = arg2; closure$__120-.$VB$Local_maxRetryAttempts = AppSettings.Instance.IoErrorNumberOfRetries; closure$__120-.$VB$Local_currentRetryAttempt = 0; int? nullable = CreateWaitAndRetryPolicy().WaitAndRetry(RetryExceptionHelper.CreateRetryPredicate(base.RetryOptions), delegate(int count) { closure$__120-.$VB$Local_currentRetryAttempt = count; return TimeSpan.FromSeconds((double)AppSettings.Instance.IoErrorWaitTimeInSeconds); }, delegate(Exception exception, TimeSpan span) { closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.PublishIoRetryMessage(exception, span, closure$__120-.$VB$Local_currentRetryAttempt, closure$__120-.$VB$Local_maxRetryAttempts); }, delegate { int? result = null; if (closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_performExtractedTextFileLocationValidation) { string existingFilePath = closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.GetExistingFilePath(closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value, false); if (string.IsNullOrEmpty(existingFilePath)) throw new MissingFullTextFileException(closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.CurrentLineNumber, closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Local_columnIndex); if (!string.Equals(closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value, existingFilePath)) { string message = $"""{closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value}""{closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Local_columnIndex}""{closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.CurrentLineNumber}""{existingFilePath}"""; closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.PublishIoWarningEvent(new IoWarningEventArgs(message, closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.CurrentLineNumber)); closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value = existingFilePath; } } Encoding encoding = closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me._extractedTextFileEncoding; if (!closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.SkipExtractedTextEncodingCheck) { DeterminedEncodingStream determinedEncodingStream = Utility.DetectEncoding(closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value, false, closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_performExtractedTextFileLocationValidation); encoding = determinedEncodingStream.DeterminedEncoding; } if (closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_performExtractedTextFileLocationValidation && closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.GetFileLength(closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value, false) > closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me.GetMaxExtractedTextLength(encoding)) throw new ExtractedTextTooLargeException(); if (closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Local_forPreview) { DeterminedEncodingStream determinedEncodingStream = Utility.DetectEncoding(closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value, false); encoding = determinedEncodingStream.DeterminedEncoding; Encoding encoding2 = (encoding == null) ? closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Me._extractedTextFileEncoding : encoding; StreamReader streamReader = new StreamReader(determinedEncodingStream.UnderlyingStream, encoding2); int num2 = 0; StringBuilder stringBuilder2 = new StringBuilder(); while (streamReader.Peek() != -1 && num2 < 100) { stringBuilder2.Append(Strings.ChrW(streamReader.Read())); num2 = checked(num2 + 1); } if (num2 == 100) stringBuilder2.Append("..."); result = encoding2.CodePage; streamReader.Close(); determinedEncodingStream.Close(); closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Local_field.Value = stringBuilder2.ToString(); } else closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$NonLocal_$VB$Closure_2.$VB$Local_field.Value = closure$__120-.$VB$NonLocal_$VB$Closure_3.$VB$Local_value; return result; }, base.CancellationToken); if (nullable.HasValue) extractedTextFileCodePageId = nullable.Value; } catch (FileNotFoundException ex) { ProjectData.SetProjectError(ex); FileNotFoundException ex2 = ex; throw; } catch (IOException ex3) { ProjectData.SetProjectError(ex3); IOException ex4 = ex3; if (ExceptionHelper.IsOutOfDiskSpaceException(ex4)) throw; throw new ImportIOException($"""{arg2.$VB$NonLocal_$VB$Closure_2.$VB$Local_field.DisplayName}""", ex4); } else arg2.$VB$NonLocal_$VB$Closure_2.$VB$Local_field.Value = string.Empty; } break; default: throw new Exception("Unsupported Field Type '" + arg.$VB$Local_field.Type.ToString() + "'"); } } private void SetFieldValueObjectsByName(ArtifactField field, int columnIndex, bool forPreview, string identityValue) { string[] array = null; if (field.Value != null) array = (string[])field.Value; if (field.Value == null) array = new string[0]; if (array.Length == 0) field.Value = string.Empty; else { Hashtable objects = GetObjects(array, columnIndex, field, field.AssociatedObjectTypeID, ShouldGetIdsFromServer(forPreview)); string text = string.Empty; if (objects.Count > 0) { IEnumerator enumerator = default(IEnumerator); try { enumerator = objects.Keys.GetEnumerator(); while (enumerator.MoveNext()) { string text2 = Conversions.ToString(enumerator.Current); text = ((!(forPreview & ((int)objects[text2] == -1))) ? (text + ";" + text2) : (text + ";[new object]")); } } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } } text = (string)(field.Value = text.TrimStart(new char[1] { ';' })); if (this is BulkLoadFileImporter) { if (objects.Count == 0) field.Value = ""; else { field.Value = " " + array.ToDelimitedString(" ", "", "{0}") + " "; StringBuilder stringBuilder = new StringBuilder(); IEnumerator enumerator2 = default(IEnumerator); try { enumerator2 = objects.Keys.GetEnumerator(); while (enumerator2.MoveNext()) { string text4 = Conversions.ToString(enumerator2.Current); ((BulkLoadFileImporter)this).WriteObjectLineToTempFile(identityValue, text4, Conversions.ToInteger(objects[text4]), field.AssociatedObjectTypeID, field.ArtifactID); stringBuilder.Append("'" + text4 + "'"); stringBuilder.Append(","); } } finally { if (enumerator2 is IDisposable) (enumerator2 as IDisposable).Dispose(); } field.Value = stringBuilder.ToString().TrimEnd(new char[1] { ',' }); } } } } private bool ShouldGetIdsFromServer(bool forPreview) { if (!forPreview && _runningContext != null) return _runningContext.ImportExportWebApiVersion < VersionConstants.AssociatedDocsImportServerSideSupportFromWebApiVersion; return true; } private void SetFieldValueObjectsByArtifactID(ArtifactField field, int columnIndex, bool forPreview, string identityValue) { string[] array = null; if (field.Value != null) array = (string[])field.Value; if (field.Value == null) array = new string[0]; if (array.Length == 0) field.Value = string.Empty; else { Hashtable objectsByArtifactID = GetObjectsByArtifactID(array, columnIndex, field, field.AssociatedObjectTypeID); string text = string.Empty; if (objectsByArtifactID.Count > 0) { IEnumerator enumerator = default(IEnumerator); try { enumerator = objectsByArtifactID.Keys.GetEnumerator(); while (enumerator.MoveNext()) { string text2 = Conversions.ToString(enumerator.Current); text = ((!(forPreview & string.IsNullOrEmpty(objectsByArtifactID[text2].ToString()))) ? (text + ";" + text2) : (text + ";[new object]")); } } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } } text = (string)(field.Value = text.TrimStart(new char[1] { ';' })); if (this is BulkLoadFileImporter) { if (objectsByArtifactID.Count == 0) field.Value = ""; else { field.Value = " " + array.ToDelimitedString(" ", "", "{0}") + " "; StringBuilder stringBuilder = new StringBuilder(); IEnumerator enumerator2 = default(IEnumerator); try { enumerator2 = objectsByArtifactID.Keys.GetEnumerator(); while (enumerator2.MoveNext()) { string text4 = Conversions.ToString(enumerator2.Current); ((BulkLoadFileImporter)this).WriteObjectLineToTempFile(identityValue, objectsByArtifactID[text4].ToString(), Conversions.ToInteger(text4), field.AssociatedObjectTypeID, field.ArtifactID); stringBuilder.Append(text4); stringBuilder.Append(","); } } finally { if (enumerator2 is IDisposable) (enumerator2 as IDisposable).Dispose(); } field.Value = stringBuilder.ToString().TrimEnd(new char[1] { ',' }); } } } } public int GetMaxExtractedTextLength(Encoding encoding) { int result = Convert.ToInt32(1073741823.5); if (encoding != null) { if (encoding != Encoding.UTF8) return 2147483647; return result; } return result; } public void AddToCodeCountPreviewHashTable(int fieldID, string fieldName, string fieldValue) { string key = $"{fieldID}""{fieldName}"; if (_previewCodeCount.Contains(key)) { HybridDictionary hybridDictionary = (HybridDictionary)_previewCodeCount[key]; if (!hybridDictionary.Contains(fieldValue)) { hybridDictionary.Add(fieldValue, ""); _previewCodeCount[key] = hybridDictionary; } } else { HybridDictionary hybridDictionary2 = new HybridDictionary(); hybridDictionary2.Add(fieldValue.Trim(), ""); _previewCodeCount.Add(key, hybridDictionary2); } } public int? GetUserArtifactID(string value, int column) { if (Operators.CompareString(value, string.Empty, false) != 0) { int? result = Users[value]; if (!result.HasValue) throw new MissingUserException(CurrentLineNumber, column, value); return result; } return null; } public string GetNullableFixedString(string value, int column, int fieldLength, string displayName) { if (value.Length > fieldLength) throw new StringImporterException(CurrentLineNumber, column, value.Length, fieldLength, displayName); return NullableTypesHelper.DBNullString(value); } public string GetNullableAssociatedObjectName(string value, int column, int fieldLength, string fieldName) { if (value.Length > fieldLength) throw new ObjectNameImporterException(CurrentLineNumber, column, fieldLength, fieldName); return NullableTypesHelper.DBNullString(value); } private void _artifactReader_OnIoWarning(IoWarningEventArgs e) { if (e.Exception == null) PublishIoWarningEvent(new IoWarningEventArgs(e.Message, e.CurrentLineNumber)); else { string message = IoReporter.BuildIoReporterWarningMessage(e.Exception, (double)e.WaitTime); PublishIoWarningEvent(new IoWarningEventArgs(message, e.CurrentLineNumber)); } } } }