-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWDContentType.cs
62 lines (53 loc) · 1.98 KB
/
WDContentType.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using System.Text.Json;
using System.Runtime.InteropServices.JavaScript;
using System.Text.Json.Nodes;
using System.ComponentModel;
using static System.Formats.Asn1.AsnWriter;
using System.IO;
namespace CLARiNET
{
// ContentTypes.json from https://raw.githubusercontent.com/patrickmccallum/mimetype-io/master/src/mimeData.json
public class WDContentType
{
public static SortedDictionary<string, string> wdContentTypes = new SortedDictionary<string, string>();
public static void Load()
{
//string[] keys = Resources.WorkdayContentTypes.Split("\n");
string[] keys = ResourceFile.Read("WorkdayContentTypes.txt").Split("\n");
var doc = JsonDocument.Parse(ResourceFile.Read("ContentTypes.json"));
foreach (string key in keys)
{
foreach (var item in doc.RootElement.EnumerateArray())
{
if (item.GetProperty("name").ToString() == key)
{
var fileTypes = item.GetProperty("fileTypes");
foreach (var fileType in fileTypes.EnumerateArray())
{
if (!wdContentTypes.ContainsKey(fileType.ToString()))
{
wdContentTypes.Add(fileType.ToString(), key);
}
}
}
}
}
}
public static string Lookup(string filename)
{
string ext = Path.GetExtension(filename).ToLower();
string contentType = "application/octet-stream";
if (wdContentTypes.ContainsKey(ext))
{
contentType = wdContentTypes[ext];
}
return contentType;
}
}
}