-
Notifications
You must be signed in to change notification settings - Fork 287
/
PlatformFile.cs
81 lines (66 loc) · 1.91 KB
/
PlatformFile.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
namespace Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.Implementation
{
using System;
using System.IO;
internal class PlatformFile : IPlatformFile
{
private readonly FileInfo file;
public PlatformFile(FileInfo file)
{
if (file == null)
{
throw new ArgumentNullException("file");
}
this.file = file;
}
public string Name
{
get { return this.file.Name; }
}
public string Extension
{
get { return this.file.Extension; }
}
public long Length
{
get { return this.file.Length; }
}
public DateTimeOffset DateCreated
{
get { return this.file.CreationTime; }
}
public bool Exists
{
get { return this.file.Exists; }
}
public void Delete()
{
if (!File.Exists(this.file.FullName))
{
throw new FileNotFoundException();
}
this.file.Delete();
}
public void Rename(string newName)
{
// Check argument manually for consistent behavior on both Silverlight and Windows runtimes
if (newName == null)
{
throw new ArgumentNullException("fileName");
}
if (string.IsNullOrWhiteSpace(newName))
{
throw new ArgumentException("fileName");
}
if (!File.Exists(this.file.FullName))
{
throw new FileNotFoundException("Could not find the file to rename.", this.file.Name);
}
this.file.MoveTo(Path.Combine(this.file.DirectoryName, newName));
}
public Stream Open()
{
return this.file.Open(FileMode.Open, FileAccess.ReadWrite);
}
}
}