Skip to content

Commit

Permalink
Merge pull request #1 from relativitydev/rel-879811-isolate-transfer-sdk
Browse files Browse the repository at this point in the history
REL-879811 - Isolate samples - transfer-api-samples
  • Loading branch information
sameerrelone authored Nov 17, 2023
2 parents 5a87e46 + 8def712 commit cf6abad
Show file tree
Hide file tree
Showing 20 changed files with 1,398 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Server.Transfer.SDK.Samples/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!--TransferMode acceptable values are: Aspera, Fileshare.-->
<add key="TransferMode" value="Fileshare" />
<add key="RelativityUrl" value="https://p-dv-vm-sew1tie" />
<add key="RelativityUserName" value="[email protected]" />
<add key="RelativityPassword" value="Test1234!" />
<add key="WorkspaceId" value="1018580" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Renci.SshNet" publicKeyToken="1cee9f8bde3db106" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2020.0.2.0" newVersion="2020.0.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
102 changes: 102 additions & 0 deletions Server.Transfer.SDK.Samples/AutoDeleteDirectory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// ----------------------------------------------------------------------------
// <copyright file="AutoDeleteDirectory.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
// ----------------------------------------------------------------------------

namespace Relativity.Server.Transfer.SDK.Samples
{
using System;
using System.Globalization;
using System.IO;

/// <summary>
/// Represents a class object that creates a sub-directory and automatically deletes it through the <see cref="Dispose"/> method.
/// </summary>
public class AutoDeleteDirectory : IDisposable
{
/// <summary>
/// The disposed backing.
/// </summary>
private bool disposed;

/// <summary>
/// Initializes a new instance of the <see cref="AutoDeleteDirectory" /> class.
/// </summary>
public AutoDeleteDirectory()
{
string downloadUniqueFolder = string.Format(CultureInfo.InvariantCulture, "Downloads-{0:MM-dd-yyyy-hh-mm-ss}", DateTime.Now);
this.Path = System.IO.Path.Combine(Environment.CurrentDirectory, downloadUniqueFolder);
Directory.CreateDirectory(this.Path);
}

/// <summary>
/// Gets the directory path.
/// </summary>
/// <value>
/// The full path.
/// </value>
public string Path
{
get;
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="disposing">
/// <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.
/// </param>
private void Dispose(bool disposing)
{
if (this.disposed)
{
return;
}

if (disposing)
{
if (!string.IsNullOrEmpty(this.Path) && Directory.Exists(this.Path))
{
try
{
string[] files = Directory.GetFiles(this.Path, "*", SearchOption.AllDirectories);
foreach (string file in files)
{
FileAttributes attributes = File.GetAttributes(file);
File.SetAttributes(file, attributes & ~FileAttributes.ReadOnly);
File.Delete(file);
}

Directory.Delete(this.Path, true);
}
catch (IOException e)
{
Console2.WriteLine(
ConsoleColor.Red,
$"Failed to tear down the '{this.Path}' temp directory due to an I/O issue. Exception: "
+ e);
}
catch (UnauthorizedAccessException e)
{
Console2.WriteLine(
ConsoleColor.Red,
$"Failed to tear down the '{this.Path}' temp directory due to unauthorized access. Exception: "
+ e);
}
}
}

this.disposed = true;
}
}
}
53 changes: 53 additions & 0 deletions Server.Transfer.SDK.Samples/ClientConfigurationFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ----------------------------------------------------------------------------
// <copyright file="ClientConfigurationFactory.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
// ----------------------------------------------------------------------------

namespace Relativity.Server.Transfer.SDK.Samples
{
using System.ComponentModel;
using Relativity.Transfer;
using Relativity.Transfer.Aspera;
using Relativity.Transfer.FileShare;
using Relativity.Server.Transfer.SDK.Samples.Enums;

public class ClientConfigurationFactory
{
public ClientConfiguration Create()
{
TransferMode transferMode = SampleRunner.GetTransferMode();

switch (transferMode)
{
case TransferMode.Aspera:
return new AsperaClientConfiguration
{
// Common properties
BadPathErrorsRetry = false,
FileNotFoundErrorsRetry = false,
MaxHttpRetryAttempts = 2,
PreserveDates = true,
TargetDataRateMbps = 5,

// Aspera specific properties
EncryptionCipher = "AES_256",
OverwritePolicy = "ALWAYS",
Policy = "FAIR",
};
case TransferMode.Fileshare:
return new FileShareClientConfiguration()
{
// Common properties
BadPathErrorsRetry = false,
FileNotFoundErrorsRetry = false,
MaxHttpRetryAttempts = 2,
PreserveDates = true,
TargetDataRateMbps = 5,
};
default:
throw new InvalidEnumArgumentException("Specified TransferMode enum value is invalid");
}
}
}
}
87 changes: 87 additions & 0 deletions Server.Transfer.SDK.Samples/Console2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// ----------------------------------------------------------------------------
// <copyright file="Console2.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
// ----------------------------------------------------------------------------

namespace Relativity.Server.Transfer.SDK.Samples
{
using System;

/// <summary>
/// Represents extensions to the <see cref="Console"/> class to write headers and write colored text.
/// </summary>
public static class Console2
{
private static ConsoleColor DefaultConsoleColor = ConsoleColor.Gray;

public static void Initialize()
{
DefaultConsoleColor = Console.ForegroundColor;
}

public static void WriteStartHeader(string message)
{
int bannerLength = Console.WindowWidth - 6;
string asterisks = new string('*', (bannerLength - message.Length - 1) / 2);
message = $"{asterisks} {message} {asterisks}".Substring(0, bannerLength);
WriteLine(string.Empty);
WriteLine(DefaultConsoleColor, message);
}

public static void WriteEndHeader()
{
int bannerLength = Console.WindowWidth - 6;
string asterisks = new string('*', bannerLength);
string message = $"{asterisks}{asterisks}".Substring(0, bannerLength);
WriteLine(DefaultConsoleColor, message);
}

public static void WriteLine()
{
WriteLine(string.Empty);
}

public static void WriteLine(string format, params object[] args)
{
WriteLine(ConsoleColor.White, format, args);
}

public static void WriteLine(ConsoleColor color, string format, params object[] args)
{
WriteLine(color, string.Format(format, args));
}

public static void WriteLine(string message)
{
WriteLine(ConsoleColor.White, message);
}

public static void WriteLine(ConsoleColor color, string message)
{
ConsoleColor existingColor = Console.ForegroundColor;

try
{
Console.ForegroundColor = color;
Console.WriteLine(message);
}
finally
{
Console.ForegroundColor = existingColor;
}
}

public static void WriteTerminateLine(int exitCode)
{
Console2.WriteLine();
Console2.WriteLine(
exitCode == 0
? "The sample successfully completed. Exit code: {0}"
: "The sample failed to complete. Exit code: {0}",
exitCode);
Console2.WriteLine("Press any key to terminate.");
Console.ReadLine();
}
}
}
75 changes: 75 additions & 0 deletions Server.Transfer.SDK.Samples/ConsolePrinter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ----------------------------------------------------------------------------
// <copyright file="ConsolePrinter.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
// ----------------------------------------------------------------------------

namespace Relativity.Server.Transfer.SDK.Samples
{
using System;
using System.Diagnostics;

using Relativity.DataTransfer.Nodes;
using Relativity.Transfer;

public class ConsolePrinter
{
public void DisplayFileShare(RelativityFileShare fileShare)
{
Console2.WriteLine("Artifact ID: {0}", fileShare.ArtifactId);
Console2.WriteLine("ModeName: {0}", fileShare.Name);
Console2.WriteLine("UNC Path: {0}", fileShare.Url);
Console2.WriteLine("Cloud Instance: {0}", fileShare.CloudInstance);

// RelativityOne specific properties.
Console2.WriteLine("Number: {0}", fileShare.Number);
Console2.WriteLine("Tenant ID: {0}", fileShare.TenantId);
}

public void DisplayTransferResult(ITransferResult result)
{
// The original request can be accessed within the transfer result.
Console2.WriteLine();
Console2.WriteLine("Transfer Summary");
Console2.WriteLine("ModeName: {0}", result.Request.Name);
Console2.WriteLine("Direction: {0}", result.Request.Direction);
if (result.Status == TransferStatus.Successful || result.Status == TransferStatus.Canceled)
{
Console2.WriteLine("Result: {0}", result.Status);
}
else
{
Console2.WriteLine(ConsoleColor.Red, "Result: {0}", result.Status);
if (result.TransferError != null)
{
Console2.WriteLine(ConsoleColor.Red, "Error: {0}", result.TransferError.Message);
}
else
{
Console2.WriteLine(ConsoleColor.Red, "Error: Check the error log for more details.");
}
}

Console2.WriteLine("Elapsed time: {0:hh\\:mm\\:ss}", result.Elapsed);
Console2.WriteLine("Total files: Files: {0:n0}", result.TotalTransferredFiles);
Console2.WriteLine("Total bytes: Files: {0:n0}", result.TotalTransferredBytes);
Console2.WriteLine("Total files not found: {0:n0}", result.TotalFilesNotFound);
Console2.WriteLine("Total bad path errors: {0:n0}", result.TotalBadPathErrors);
Console2.WriteLine("Data rate: {0:#.##} Mbps", result.TransferRateMbps);
Console2.WriteLine("Retry count: {0}", result.RetryCount);
}

public void DisplaySearchSummary(
IDirectory sourceNode,
Stopwatch stopWatch,
long totalFileCount,
long totalByteCount)
{
Console2.WriteLine("Local Path: {0}", sourceNode.AbsolutePath);
Console2.WriteLine("Elapsed time: {0:hh\\:mm\\:ss}", stopWatch.Elapsed);
Console2.WriteLine("Total files: {0:n0}", totalFileCount);
Console2.WriteLine("Total bytes: {0:n0}", totalByteCount);
Console2.WriteEndHeader();
}
}
}
14 changes: 14 additions & 0 deletions Server.Transfer.SDK.Samples/Enums/TransferMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ----------------------------------------------------------------------------
// <copyright file="TransferMode.cs" company="Relativity ODA LLC">
// © Relativity All Rights Reserved.
// </copyright>
// ----------------------------------------------------------------------------

namespace Relativity.Server.Transfer.SDK.Samples.Enums
{
public enum TransferMode
{
Aspera,
Fileshare
}
}
Loading

0 comments on commit cf6abad

Please sign in to comment.