ConnectionDetailsProcess
using kCura.WinEDDS.Service;
using kCura.WinEDDS.Service.Kepler;
using kCura.WinEDDS.Service.Replacement;
using Microsoft.VisualBasic.CompilerServices;
using Relativity.DataExchange;
using Relativity.DataExchange.Logger;
using Relativity.DataExchange.Process;
using Relativity.DataExchange.Service;
using Relativity.DataExchange.Transfer;
using Relativity.Logging;
using Relativity.Transfer;
using System;
using System.IO;
using System.Net;
using System.Security.Principal;
using System.Threading;
using System.Web;
using System.Web.Services.Protocols;
namespace kCura.WinEDDS
{
public class ConnectionDetailsProcess : ProcessBase2
{
private readonly NetworkCredential _credential;
private readonly CookieContainer ;
private readonly CaseInfo _caseInfo;
private readonly Func<string> _correlationIdFunc;
private readonly Lazy<bool> _useLegacyWebApiLazy;
[Obsolete("This constructor is marked for deprecation. Please use the constructor that requires a logger instance.")]
public ConnectionDetailsProcess(NetworkCredential credential, CookieContainer cookieContainer, CaseInfo caseInfo, Func<string> correlationIdFunc)
: this(credential, cookieContainer, caseInfo, RelativityLogger.Instance, correlationIdFunc)
{
}
public ConnectionDetailsProcess(NetworkCredential credential, CookieContainer cookieContainer, CaseInfo caseInfo, ILog logger, Func<string> correlationIdFunc)
: base(logger)
{
_credential = credential;
_cookieContainer = cookieContainer;
_caseInfo = caseInfo;
_correlationIdFunc = correlationIdFunc;
_useLegacyWebApiLazy = new Lazy<bool>(UseLegacyWebApi);
}
protected override void OnExecute()
{
CheckBcp();
WriteStatus("");
CheckDownloadHandlerURL();
WriteStatus("");
RelativityConnectionInfo relativityConnectionInfo = ((ITapiObjectService)new TapiObjectService(new RelativityManagerServiceFactory(), _useLegacyWebApiLazy.Value)).CreateRelativityConnectionInfo(new TapiBridgeParameters2 {
Credentials = _credential,
TimeoutSeconds = base.AppSettings.HttpTimeoutSeconds,
WebCookieContainer = _cookieContainer,
WebServiceUrl = base.AppSettings.WebApiServiceUrl,
WorkspaceId = _caseInfo.ArtifactID
});
using (RelativityTransferLog relativityTransferLog = new RelativityTransferLog(base.Logger)) {
RelativityTransferHost val = new RelativityTransferHost(relativityConnectionInfo, (ITransferLog)relativityTransferLog);
try {
DiagnosticsContext diagnosticsContext = new DiagnosticsContext();
DiagnosticsConfiguration diagnosticsConfiguration = new DiagnosticsConfiguration(diagnosticsContext, _cookieContainer);
diagnosticsConfiguration.MaxHttpRetryAttempts = 1;
diagnosticsConfiguration.MaxJobRetryAttempts = 2;
diagnosticsConfiguration.UseLegacyWebApi = _useLegacyWebApiLazy.Value;
try {
diagnosticsContext.DiagnosticMessage += DiagnosticsContext_OnDiagnosticMessage;
val.ConnectionChecksAsync(diagnosticsConfiguration, CancellationToken.None).GetAwaiter().GetResult();
} catch (Exception ex) {
ProjectData.SetProjectError(ex);
Exception ex2 = ex;
WriteStatus($"""{ex2.Message}");
ProjectData.ClearProjectError();
} finally {
diagnosticsContext.DiagnosticMessage -= DiagnosticsContext_OnDiagnosticMessage;
}
} finally {
((IDisposable)val)?.Dispose();
}
}
}
private void DiagnosticsContext_OnDiagnosticMessage(object sender, DiagnosticMessageEventArgs e)
{
WriteStatus(e.Message);
}
private void CheckDownloadHandlerURL()
{
WriteStatus("Validate Download URL:");
try {
if (!_useLegacyWebApiLazy.Value) {
WriteStatus("URL validated");
return;
}
} catch (Exception ex) {
ProjectData.SetProjectError(ex);
Exception ex2 = ex;
WriteStatus("Cannot find URL");
WriteStatus(ex2.ToString());
ProjectData.ClearProjectError();
return;
}
string baseUrlAndCombine = UrlHelper.GetBaseUrlAndCombine(base.AppSettings.WebApiServiceUrl, _caseInfo.DownloadHandlerURL);
WriteStatus(baseUrlAndCombine);
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(baseUrlAndCombine + "AccessDenied.aspx");
try {
httpWebRequest.UseDefaultCredentials = true;
httpWebRequest.GetResponse();
WriteStatus("URL validated");
} catch (WebException ex3) {
ProjectData.SetProjectError(ex3);
WebException ex4 = ex3;
HttpWebResponse httpWebResponse = (HttpWebResponse)ex4.Response;
if (httpWebResponse.StatusCode == HttpStatusCode.Forbidden && Operators.CompareString(httpWebResponse.StatusDescription, "kcuraaccessdeniedmarker", false) == 0)
WriteStatus("URL validated");
else {
WriteStatus("Cannot find URL");
WriteStatus(ex4.ToString());
}
httpWebResponse = null;
ProjectData.ClearProjectError();
} catch (Exception ex5) {
ProjectData.SetProjectError(ex5);
Exception ex6 = ex5;
WriteStatus("Cannot find URL");
WriteStatus(ex6.ToString());
ProjectData.ClearProjectError();
}
}
private void CheckBcp()
{
WriteStatus("Checking Bulk Share Configuration");
IFileIO fileIO = ManagerFactory.CreateFileIO(_credential, _cookieContainer, _correlationIdFunc);
string bcpSharePath;
try {
bcpSharePath = fileIO.GetBcpSharePath(_caseInfo.ArtifactID);
WriteStatus("Selected BCP folder: " + bcpSharePath);
} catch (Exception ex) {
ProjectData.SetProjectError(ex);
Exception ex2 = ex;
WriteStatus("Error retrieving BCP folder - WebAPI error");
WriteStatus("Ensure that relativity service account has rights to create/delete files and subdirectories in the BCP folder");
WriteStatus("Exact error: " + ex2.ToString());
ProjectData.ClearProjectError();
return;
}
try {
Directory.CreateDirectory(bcpSharePath);
string str = bcpSharePath.TrimEnd(new char[1] {
'\\'
}) + "\\";
File.Create(str + "123").Close();
File.Delete(str + "123");
WriteStatus("Your account (" + WindowsIdentity.GetCurrent().Name + ") has direct access to BCP folder");
} catch (Exception ex3) {
ProjectData.SetProjectError(ex3);
Exception ex4 = ex3;
WriteStatus("Valid: No direct access to BCP folder from direct account - using Relativity service account and Web Service for access");
ProjectData.ClearProjectError();
}
try {
WriteStatus("Validating bulk insert rights");
if (fileIO.ValidateBcpShare(_caseInfo.ArtifactID))
WriteStatus("Bulk insert rights validated");
else
WriteStatus("Bulk share configured incorrectly or does not exist");
} catch (Exception ex5) {
ProjectData.SetProjectError(ex5);
Exception ex6 = ex5;
WriteStatus("Error running bulk insert");
WriteStatus("Ensure that EDDSDBO login has bulk admin rights on case DB");
WriteStatus("Ensure that the security account that SQL Server is running under has rights to the selected BCP folder");
string text = ex6.ToString();
if (ex6 is SoapException)
text = HttpUtility.HtmlDecode(text);
WriteStatus("Exact error: " + text);
ProjectData.ClearProjectError();
return;
}
try {
WriteStatus("Retrieving bulk directory drive information:");
string[][] bcpShareSpaceReport = fileIO.GetBcpShareSpaceReport(_caseInfo.ArtifactID);
WriteStatus("Success - report follows:");
WriteOutReportString(bcpShareSpaceReport);
} catch (Exception ex7) {
ProjectData.SetProjectError(ex7);
Exception ex8 = ex7;
WriteStatus("Error retrieving space information on bulk share - make sure relativity service account has full rights to the share if you want to see this report");
WriteStatus("Exact error: " + ex8.ToString());
ProjectData.ClearProjectError();
}
}
private void WriteOutReportString(string[][] input)
{
foreach (string[] array in input) {
WriteStatus("\t" + array[0] + ": " + array[1]);
}
}
private void WriteStatus(string message)
{
base.Context.PublishStatusEvent("", message);
}
private bool UseLegacyWebApi()
{
Uri webApiUrl = new Uri(base.AppSettings.WebApiServiceUrl);
return !new WebApiVsKeplerFactory(base.Logger).Create(webApiUrl, _credential, _correlationIdFunc).UseKepler();
}
}
}