-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileSetupBase.cs
101 lines (85 loc) · 2.75 KB
/
FileSetupBase.cs
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
using System;
using System.IO;
using TeleScope.Persistence.Abstractions.Enumerations;
namespace TeleScope.Persistence.Abstractions
{
/// <summary>
/// This abstract base class provides properties and
/// a default constructor signature for concrete file setup classes.
/// </summary>
public abstract class FileSetupBase
{
// -- fields
private FileInfo info;
// -- properties
/// <summary>
/// Gets the complete filenmane with path and the extension of the file.
/// </summary>
public string File => info.FullName;
/// <summary>
/// Gets the name of the file.
/// </summary>
public string Filename => info.Name;
/// <summary>
/// Gets the extension or type of the file.
/// </summary>
public string Extension => info.Extension;
/// <summary>
/// Gets the complete path, where the file is located.
/// </summary>
public string Location => info.Directory.FullName;
/// <summary>
/// Gets the information if the file info instance exists or not.
/// </summary>
public bool Exists => info.Exists;
/// <summary>
/// Gets the flags of permissions how files may be treated.
/// </summary>
public WritePermissions Permissions { get; set; }
// -- constructors
/// <summary>
/// The constructor sets the file propterties and the <see cref="WritePermissions"/>.
/// </summary>
/// <param name="file">The file that will get accessed by a file storage.</param>
/// <param name="permissions">The information about the write permissions.</param>
protected FileSetupBase(string file,
WritePermissions permissions = WritePermissions.Create | WritePermissions.Delete)
: this(permissions)
{
SetFile(new FileInfo(file));
}
/// <summary>
/// The constructor sets the file propterties and the <see cref="WritePermissions"/>.
/// </summary>
/// <param name="fileInfo">The information about the file that will get accessed by a file storage.</param>
/// <param name="permissions">The information about the write permissions.</param>
protected FileSetupBase(FileInfo fileInfo,
WritePermissions permissions = WritePermissions.Create | WritePermissions.Delete)
: this(permissions)
{
SetFile(fileInfo);
}
private FileSetupBase(WritePermissions permissions)
{
Permissions = permissions;
}
// -- methods
/// <summary>
/// Gets the reference to the FileInfo object, that was given to the constructor.
/// </summary>
/// <returns></returns>
public FileInfo Info()
{
return info;
}
/// <summary>
/// Sets or updates the reference to the FileInfo object.
/// </summary>
/// <param name="fileInfo">The new FileInfo object.</param>
public void SetFile(FileInfo fileInfo)
{
_ = fileInfo ?? throw new ArgumentNullException(nameof(fileInfo));
info = fileInfo;
}
}
}