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

NestedArtifactCache

public class NestedArtifactCache
using kCura.WinEDDS.Service; using Microsoft.VisualBasic.CompilerServices; using System; using System.Collections; using System.Data; using System.Text; namespace kCura.WinEDDS { public class NestedArtifactCache { private Hashtable _ht; private IHierarchicArtifactManager _manager; private int _rootArtifactID; private int _caseContextArtifactID; private string _nestedItemDelimiter; private int _createCount; public int CreationCount => _createCount; public object[] SelectedIds { get { string[] array = artifactPath.Trim(_nestedItemDelimiter.ToCharArray()).Split(_nestedItemDelimiter.ToCharArray()); ArrayList arrayList = new ArrayList(); string[] array2 = array; foreach (string text in array2) { if (Operators.CompareString(text.Trim(), "", false) != 0) arrayList.Add(text.Trim()); } array = (string[])arrayList.ToArray(typeof(string)); if (array.Length != 0) { StringBuilder stringBuilder = new StringBuilder(); string[] array3 = array; foreach (string str in array3) { stringBuilder.Append(_nestedItemDelimiter + str); } string text2 = stringBuilder.ToString(); int artifactID; if (_ht.ContainsKey(text2)) artifactID = ((ArtifactCacheItem)_ht[text2]).ArtifactID; else { ArtifactCacheItem newArtifact = GetNewArtifact(text2); if (!_ht.ContainsKey(text2)) _ht.Add(text2, newArtifact); artifactID = newArtifact.ArtifactID; } ArrayList arrayList2 = new ArrayList(); if (array.Length != 1) { string text3 = ""; int num = checked(array.Length - 1); for (int k = 0; k <= num; k = checked(k + 1)) { text3 += _nestedItemDelimiter; text3 += array[k]; arrayList2.Add(new object[2] { ((ArtifactCacheItem)_ht[text3]).ArtifactID, text3 }); } return (object[])arrayList2.ToArray(typeof(object[])); } return new object[1] { new object[2] { artifactID, array[0] } }; } return new object[0]; } } private ArtifactCacheItem GetNewArtifact(string fullPath) { ArrayList arrayList = new ArrayList(); string artifactPath = (Operators.CompareString(fullPath, "", false) != 0 && Operators.CompareString(fullPath, _nestedItemDelimiter, false) != 0) ? fullPath.Substring(0, fullPath.LastIndexOf(_nestedItemDelimiter)) : _nestedItemDelimiter; arrayList.Add(fullPath.Substring(checked(fullPath.LastIndexOf(_nestedItemDelimiter) + 1))); ArtifactCacheItem parentArtifact = FindParentArtifact(artifactPath, arrayList); return CreateArtifacts(parentArtifact, arrayList); } private unsafe ArtifactCacheItem CreateArtifacts(ArtifactCacheItem parentArtifact, ArrayList artifactNames) { if (artifactNames.Count <= 0) return parentArtifact; string text = Conversions.ToString(artifactNames[0]); artifactNames.RemoveAt(0); int num = _manager.Read(_caseContextArtifactID, parentArtifact.ArtifactID, text); if (num < 1) { num = _manager.Create(_caseContextArtifactID, parentArtifact.ArtifactID, text); if (num > 0) { ref int createCount; *(ref createCount = ref _createCount) = checked(createCount + 1); } } string str = (Operators.CompareString(parentArtifact.Path, _nestedItemDelimiter, false) != 0) ? parentArtifact.Path : ""; ArtifactCacheItem artifactCacheItem = new ArtifactCacheItem(text, str + _nestedItemDelimiter + text, num); parentArtifact.AddChild(artifactCacheItem); _ht.Add(artifactCacheItem.Path, artifactCacheItem); return CreateArtifacts(artifactCacheItem, artifactNames); } private ArtifactCacheItem FindParentArtifact(string artifactPath, ArrayList pathToDestination) { if (!_ht.ContainsKey(artifactPath)) { string text = artifactPath.Substring(checked(artifactPath.LastIndexOf(_nestedItemDelimiter) + 1)); if (Operators.CompareString(text, "", false) != 0) { pathToDestination.Insert(0, text); return FindParentArtifact(artifactPath.Substring(0, artifactPath.LastIndexOf(_nestedItemDelimiter)), pathToDestination); } return (ArtifactCacheItem)_ht[_nestedItemDelimiter]; } return (ArtifactCacheItem)_ht[artifactPath]; } public NestedArtifactCache(IHierarchicArtifactManager artifactManager, int rootArtifactID, int caseContextArtifactID, string nestedItemDelimiter) { _ht = new Hashtable(); _createCount = 0; _ht = new Hashtable(); _manager = artifactManager; _caseContextArtifactID = caseContextArtifactID; _rootArtifactID = rootArtifactID; _nestedItemDelimiter = nestedItemDelimiter; DataSet dataSet = _manager.RetrieveArtifacts(_caseContextArtifactID, rootArtifactID); dataSet.Relations.Add("NodeRelation", dataSet.Tables[0].Columns["ArtifactID"], dataSet.Tables[0].Columns["ParentArtifactID"]); IEnumerator enumerator = default(IEnumerator); try { enumerator = dataSet.Tables[0].Rows.GetEnumerator(); while (enumerator.MoveNext()) { DataRow dataRow = (DataRow)enumerator.Current; if (dataRow["ParentArtifactID"] is DBNull) { ArtifactCacheItem artifactCacheItem = new ArtifactCacheItem("", _nestedItemDelimiter, _rootArtifactID); if (!_ht.ContainsKey(artifactCacheItem.Path)) _ht.Add(artifactCacheItem.Path, artifactCacheItem); RecursivelyPopulate(dataRow, artifactCacheItem); } } } finally { if (enumerator is IDisposable) (enumerator as IDisposable).Dispose(); } } private void RecursivelyPopulate(DataRow dataRow, ArtifactCacheItem parent) { DataRow[] childRows = dataRow.GetChildRows("NodeRelation"); foreach (DataRow dataRow2 in childRows) { ArtifactCacheItem artifactCacheItem = new ArtifactCacheItem(path: (Operators.CompareString(parent.Path, _nestedItemDelimiter, false) != 0) ? (parent.Path + _nestedItemDelimiter + dataRow2["Name"].ToString()) : (_nestedItemDelimiter + dataRow2["Name"].ToString()), name: dataRow2["Name"].ToString(), artifactID: Conversions.ToInteger(dataRow2["ArtifactID"])); if (!_ht.ContainsKey(artifactCacheItem.Path)) { _ht.Add(artifactCacheItem.Path, artifactCacheItem); parent.AddChild(artifactCacheItem); } RecursivelyPopulate(dataRow2, artifactCacheItem); } } } }