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

PreviewChoicesHelper

public class PreviewChoicesHelper
using kCura.WinEDDS.Api; using Microsoft.VisualBasic.CompilerServices; using Relativity.DataExchange.Service; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Data; using System.Runtime.CompilerServices; namespace kCura.WinEDDS { public class PreviewChoicesHelper { private HybridDictionary _totalFolders; public PreviewChoicesHelper() { _totalFolders = new HybridDictionary(); } public DataTable BuildFoldersAndCodesDataSource(List<object> al, HybridDictionary previewCodeCount) { return BuildFoldersAndCodesDataSource(new ArrayList(al), previewCodeCount); } public DataTable BuildFoldersAndCodesDataSource(ArrayList al, HybridDictionary previewCodeCount) { int folderCount = GetFolderCount(al); DataTable dataTable = new DataTable(); ArrayList codeFieldColumnIndexes = GetCodeFieldColumnIndexes((Array)al[0]); dataTable.Columns.Add("Field Name"); dataTable.Columns.Add("Count"); ArrayList arrayList = new ArrayList { "Folders" }; if (folderCount != -1) arrayList.Add(folderCount.ToString()); else arrayList.Add("0"); dataTable.Rows.Add(arrayList.ToArray()); ArrayList arrayList2 = new ArrayList { "", "" }; dataTable.Rows.Add(arrayList2.ToArray()); if (codeFieldColumnIndexes.Count != 0) { IEnumerator enumerator = default(IEnumerator); try { enumerator = previewCodeCount.Keys.GetEnumerator(); while (enumerator.MoveNext()) { string text = Conversions.ToString(enumerator.Current); ArrayList arrayList3 = new ArrayList(); arrayList3.Add(text.Split("_".ToCharArray(), 2)[1]); HybridDictionary hybridDictionary = (HybridDictionary)previewCodeCount[text]; arrayList3.Add(hybridDictionary.Count); dataTable.Rows.Add(arrayList3.ToArray()); hybridDictionary.Clear(); } return dataTable; } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } } dataTable.Columns.Add(" "); dataTable.Rows.Add("No choice fields have been mapped"); return dataTable; } public int GetFolderCount(ArrayList al) { _totalFolders.Clear(); int folderColumnIndex = GetFolderColumnIndex((Array)al[0]); if (folderColumnIndex == -1) return -1; IEnumerator enumerator = default(IEnumerator); try { enumerator = al.GetEnumerator(); while (enumerator.MoveNext()) { object objectValue = RuntimeHelpers.GetObjectValue(enumerator.Current); if (objectValue != null) { ArtifactField[] array = (ArtifactField[])objectValue; if (folderColumnIndex != -1) { string valueAsString = array[folderColumnIndex].ValueAsString; AddFoldersToTotalFolders(valueAsString); } } } } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } return _totalFolders.Count; } private int GetFolderColumnIndex(Array firstRow) { int result = -1; int num = 0; IEnumerator enumerator = default(IEnumerator); try { enumerator = firstRow.GetEnumerator(); while (enumerator.MoveNext()) { ArtifactField artifactField = (ArtifactField)enumerator.Current; if ((artifactField.ArtifactID == -2) & (Operators.CompareString(artifactField.DisplayName, "Parent Folder Identifier", false) == 0)) result = num; num = checked(num + 1); } return result; } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } } public ArrayList GetCodeFieldColumnIndexes(Array firstRow) { ArrayList arrayList = new ArrayList(); int num = 0; IEnumerator enumerator = default(IEnumerator); try { enumerator = firstRow.GetEnumerator(); while (enumerator.MoveNext()) { ArtifactField artifactField = (ArtifactField)enumerator.Current; if (artifactField.Type == FieldType.Code || artifactField.Type == FieldType.MultiCode) arrayList.Add(num); num = checked(num + 1); } return arrayList; } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } } private void AddFoldersToTotalFolders(string folderPath) { if (Operators.CompareString(folderPath, string.Empty, false) != 0 && Operators.CompareString(folderPath, "\\", false) != 0) { if (folderPath.LastIndexOf('\\') < 1) { if (!_totalFolders.Contains(folderPath)) _totalFolders.Add(folderPath, string.Empty); } else { if (!_totalFolders.Contains(folderPath)) _totalFolders.Add(folderPath, string.Empty); AddFoldersToTotalFolders(folderPath.Substring(0, folderPath.LastIndexOf('\\'))); } } } } }