forked from stevenh/HttpServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HttpFileCollection.cs
67 lines (62 loc) · 1.78 KB
/
HttpFileCollection.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
using System;
using System.Collections.Generic;
using System.IO;
namespace HttpServer
{
/// <summary>
/// Collection of files.
/// </summary>
public class HttpFileCollection
{
private readonly Dictionary<string, HttpFile> _files =
new Dictionary<string, HttpFile>(StringComparer.OrdinalIgnoreCase);
/// <summary>
/// Get a file
/// </summary>
/// <param name="name">Name in form</param>
/// <returns>File if found; otherwise <c>null</c>.</returns>
public HttpFile this[string name]
{
get
{
HttpFile file;
return _files.TryGetValue(name, out file) ? file : null;
}
}
/// <summary>
/// Checks if a file exists.
/// </summary>
/// <param name="name">Name of the file (form item name)</param>
/// <returns></returns>
public bool Contains(string name)
{
return _files.ContainsKey(name);
}
/// <summary>
/// Gets number of files
/// </summary>
public int Count
{
get { return _files.Count; }
}
/// <summary>
/// Add a new file.
/// </summary>
/// <param name="file">File to add.</param>
public void Add(HttpFile file)
{
_files.Add(file.Name, file);
}
/// <summary>
/// Remove all files from disk.
/// </summary>
public void Clear()
{
foreach (HttpFile file in _files.Values)
{
if (File.Exists(file.TempFileName))
File.Delete(file.TempFileName);
}
}
}
}