-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathInventoryPart.cs
More file actions
122 lines (96 loc) · 3.54 KB
/
InventoryPart.cs
File metadata and controls
122 lines (96 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using ByteSync.Common.Business.Inventories;
using ByteSync.Common.Business.Misc;
using ByteSync.Models.FileSystems;
namespace ByteSync.Models.Inventories;
public class InventoryPart
{
public InventoryPart()
{
FileDescriptions = new List<FileDescription>();
DirectoryDescriptions = new List<DirectoryDescription>();
}
public InventoryPart(Inventory inventory, string rootPath, FileSystemTypes inventoryPartType) : this()
{
Inventory = inventory;
RootPath = rootPath;
InventoryPartType = inventoryPartType;
}
public Inventory Inventory { get; set; }
public string RootPath { get; set; }
public FileSystemTypes InventoryPartType { get; set; }
public string Code { get; set; }
public List<FileDescription> FileDescriptions { get; set; }
public List<DirectoryDescription> DirectoryDescriptions { get; set; }
public bool IsIncompleteDueToAccess { get; set; }
public Dictionary<SkipReason, int> SkippedCountsByReason { get; set; } = new();
public int SkippedCount => SkippedCountsByReason.Values.Sum();
public string RootName
{
get
{
string directorySeparatorChar;
switch (Inventory.Endpoint.OSPlatform)
{
case OSPlatforms.Windows:
directorySeparatorChar = "\\";
break;
case OSPlatforms.Linux:
case OSPlatforms.MacOs:
directorySeparatorChar = "/";
break;
default:
throw new ArgumentOutOfRangeException(nameof(directorySeparatorChar));
}
return RootPath.Substring(RootPath.LastIndexOf(directorySeparatorChar, StringComparison.Ordinal));
}
}
protected bool Equals(InventoryPart other)
{
return Equals(Inventory, other.Inventory) && RootPath == other.RootPath && InventoryPartType == other.InventoryPartType;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((InventoryPart)obj);
}
public override int GetHashCode()
{
unchecked
{
var hashCode = Inventory.GetHashCode();
hashCode = (hashCode * 397) ^ RootPath.GetHashCode();
hashCode = (hashCode * 397) ^ (int)InventoryPartType;
return hashCode;
}
}
public override string ToString()
{
#if DEBUG
return $"InventoryPart {RootName} {RootPath}";
#endif
#pragma warning disable 162
return base.ToString();
#pragma warning restore 162
}
public void AddFileSystemDescription(FileSystemDescription fileSystemDescription)
{
if (fileSystemDescription.FileSystemType == FileSystemTypes.File)
{
FileDescriptions.Add((FileDescription)fileSystemDescription);
}
else
{
DirectoryDescriptions.Add((DirectoryDescription)fileSystemDescription);
}
}
public int GetSkippedCountByReason(SkipReason reason)
{
return SkippedCountsByReason.TryGetValue(reason, out var count) ? count : 0;
}
public void RecordSkippedEntry(SkipReason reason)
{
SkippedCountsByReason[reason] = GetSkippedCountByReason(reason) + 1;
}
}