TransferPath
using Relativity.Transfer.Resources;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace Relativity.Transfer
{
public class TransferPath : IEquatable<TransferPath>
{
private const TransferPathAttributes DefaultTransferPathAttributes = TransferPathAttributes.File;
private string sourcePath;
private string targetPath;
public long Bytes { get; set; }
public IReadOnlyDictionary<string, object> Data { get; set; }
public TransferDirection Direction { get; set; }
public int Order { get; set; }
public TransferPathAttributes PathAttributes { get; set; }
public string SourcePath {
get {
return sourcePath;
}
set {
if (string.IsNullOrEmpty(PreResolvedSourcePath))
PreResolvedSourcePath = sourcePath;
sourcePath = value;
}
}
public long? SourcePathId { get; set; }
public object Tag { get; set; }
public string TargetPath {
get {
return targetPath;
}
set {
if (string.IsNullOrEmpty(PreResolvedTargetPath))
PreResolvedTargetPath = targetPath;
targetPath = value;
}
}
public string TargetFileName { get; set; }
internal string PreResolvedSourcePath { get; set; }
internal string PreResolvedTargetPath { get; set; }
public TransferPath()
{
Bytes = 0;
Data = null;
Direction = TransferDirection.None;
PathAttributes = TransferPathAttributes.File;
Order = 0;
PreResolvedSourcePath = null;
PreResolvedTargetPath = null;
SourcePath = null;
SourcePathId = null;
Tag = null;
TargetFileName = null;
TargetPath = null;
}
public TransferPath(string sourcePath)
: this(sourcePath, string.Empty, TransferDirection.None)
{
}
public TransferPath(string sourcePath, TransferPathAttributes pathAttributes)
: this(sourcePath, pathAttributes, string.Empty, TransferDirection.None)
{
}
public TransferPath(string sourcePath, string targetPath)
: this(sourcePath, targetPath, TransferDirection.None)
{
}
public TransferPath(string sourcePath, TransferPathAttributes pathAttributes, string targetPath)
: this(sourcePath, pathAttributes, targetPath, TransferDirection.None)
{
}
public TransferPath(string sourcePath, string targetPath, TransferDirection direction)
: this(sourcePath, targetPath, direction, string.Empty)
{
}
public TransferPath(string sourcePath, TransferPathAttributes pathAttributes, string targetPath, TransferDirection direction)
: this(sourcePath, pathAttributes, targetPath, direction, string.Empty)
{
}
public TransferPath(string sourcePath, string targetPath, TransferDirection direction, string targetFileName)
: this(sourcePath, TransferPathAttributes.File, targetPath, direction, targetFileName)
{
}
public TransferPath(string sourcePath, string targetPath, TransferDirection direction, long bytes)
: this(sourcePath, TransferPathAttributes.File, targetPath, direction, null, bytes)
{
}
public TransferPath(string sourcePath, TransferPathAttributes pathAttributes, string targetPath, TransferDirection direction, string targetFileName)
: this(sourcePath, pathAttributes, targetPath, direction, targetFileName, 0)
{
}
public TransferPath(string sourcePath, TransferPathAttributes pathAttributes, string targetPath, TransferDirection direction, string targetFileName, long bytes)
{
Data = null;
Direction = direction;
Bytes = bytes;
Order = 0;
PathAttributes = pathAttributes;
PreResolvedSourcePath = null;
PreResolvedTargetPath = null;
SourcePath = sourcePath;
SourcePathId = null;
Tag = null;
TargetFileName = targetFileName;
TargetPath = targetPath;
}
public TransferPath(TransferPath source)
{
if (source == (TransferPath)null)
throw new ArgumentNullException("source");
Bytes = source.Bytes;
Data = ((source.Data != null) ? new ConcurrentDictionary<string, object>(source.Data) : null);
Direction = source.Direction;
PathAttributes = source.PathAttributes;
Order = source.Order;
SourcePath = source.SourcePath;
SourcePathId = source.SourcePathId;
Tag = source.Tag;
TargetFileName = source.TargetFileName;
TargetPath = source.TargetPath;
PreResolvedSourcePath = source.PreResolvedSourcePath;
PreResolvedTargetPath = source.PreResolvedTargetPath;
}
public static bool operator ==(TransferPath x, TransferPath y)
{
if ((object)x == y)
return true;
if ((object)x == null)
return false;
if ((object)y == null)
return false;
if (x.Direction == y.Direction && x.Bytes == y.Bytes && Convert.ToUInt64(x.PathAttributes) == Convert.ToUInt64(y.PathAttributes) && string.Compare(x.SourcePath, y.SourcePath, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(x.TargetFileName, y.TargetFileName, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(x.TargetPath, y.TargetPath, StringComparison.OrdinalIgnoreCase) == 0) {
if (x.Data != null || y.Data != null)
return ((ConcurrentDictionary<string, object>)x.Data).IsEqual((ConcurrentDictionary<string, object>)y.Data);
return true;
}
return false;
}
public static bool operator !=(TransferPath x, TransferPath y)
{
return !(x == y);
}
public void AddData(string key, object value)
{
if (string.IsNullOrEmpty(key))
throw new ArgumentNullException("key");
if (Data == null)
Data = new ConcurrentDictionary<string, object>();
((ConcurrentDictionary<string, object>)Data).TryAdd(key, value);
}
public override int GetHashCode()
{
int num = (SourcePath != null) ? SourcePath.GetHashCode() : 0;
num = ((num * 397) ^ Bytes.GetHashCode());
num = ((num * 397) ^ Direction.GetHashCode());
num = ((num * 397) ^ PathAttributes.GetHashCode());
num = ((num * 397) ^ ((!string.IsNullOrEmpty(TargetFileName)) ? TargetFileName.GetHashCode() : 0));
num = ((num * 397) ^ ((!string.IsNullOrEmpty(TargetPath)) ? TargetPath.GetHashCode() : 0));
if (Data != null)
num = ((num * 397) ^ Data.GetHashCode());
return num;
}
public TransferPath DeepCopy()
{
return new TransferPath(this);
}
public override bool Equals(object obj)
{
return Equals(obj as TransferPath);
}
public bool Equals(TransferPath other)
{
if ((object)other == null)
return false;
if ((object)this == other)
return true;
if (Direction == other.Direction && Bytes == other.Bytes && Convert.ToUInt64(PathAttributes) == Convert.ToUInt64(other.PathAttributes) && string.Compare(SourcePath, other.SourcePath, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(TargetFileName, other.TargetFileName, StringComparison.OrdinalIgnoreCase) == 0 && string.Compare(TargetPath, other.TargetPath, StringComparison.OrdinalIgnoreCase) == 0) {
if (Data != null || other.Data != null)
return ((ConcurrentDictionary<string, object>)Data).IsEqual((ConcurrentDictionary<string, object>)other.Data);
return true;
}
return false;
}
public void RevertPaths()
{
if (!string.IsNullOrEmpty(PreResolvedSourcePath)) {
SourcePath = PreResolvedSourcePath;
PreResolvedSourcePath = SourcePath;
}
if (!string.IsNullOrEmpty(PreResolvedTargetPath)) {
TargetPath = PreResolvedTargetPath;
PreResolvedTargetPath = TargetPath;
}
}
public void ValidateAttributes()
{
if ((!PathAttributes.HasFlag(TransferPathAttributes.File) && !PathAttributes.HasFlag(TransferPathAttributes.Directory)) || PathAttributes.HasFlag(TransferPathAttributes.None))
throw new TransferPathAttributeException(CoreStrings.TransferPathMustBeFileOrDirectoryExceptionMessage);
if (PathAttributes.HasFlag(TransferPathAttributes.File) && PathAttributes.HasFlag(TransferPathAttributes.Directory))
throw new TransferPathAttributeException(CoreStrings.TransferPathCannotBeFileAndDirectoryExceptionMessage);
if (PathAttributes.HasFlag(TransferPathAttributes.File) && PathAttributes.HasFlag(TransferPathAttributes.Empty))
throw new TransferPathAttributeException(CoreStrings.TransferPathEmptyFileExceptionMessage);
}
}
}