forked from vaishaksuresh/webdevchecklist.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChecklist.cs
More file actions
102 lines (80 loc) · 2.56 KB
/
Checklist.cs
File metadata and controls
102 lines (80 loc) · 2.56 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
using System.Xml;
/// <summary>
/// Summary description for DataProvider
/// </summary>
public static class Checklist
{
public static Dictionary<string, XmlDocument> Docs = new Dictionary<string, XmlDocument>();
public const string Title = "Web Developer";
private static string folder = HostingEnvironment.MapPath("~/app_data/");
static Checklist()
{
BuildCache(folder);
}
public static XmlDocument GetXmlDocument(HttpRequestBase request)
{
string name = GetFileName(request.RawUrl);
if (HttpRuntime.Cache["data"] == null)
{
BuildCache(folder);
HttpRuntime.Cache.Insert("data", "test", new CacheDependency(folder));
}
var result = Docs.FirstOrDefault(d => d.Key.Equals(name, StringComparison.OrdinalIgnoreCase));
if (result.Value != null)
{
return result.Value;
}
return Docs["items"]; ;
}
private static void BuildCache(string folder)
{
Docs.Clear();
foreach (string file in Directory.GetFiles(folder, "*.xml", SearchOption.TopDirectoryOnly))
{
XmlDocument doc = new XmlDocument();
doc.Load(file);
string key = Path.GetFileName(file).Replace(Path.GetExtension(file), string.Empty);
Docs.Add(key, doc);
}
}
public static string PageName(HttpRequestBase request)
{
string name = GetFileName(request.RawUrl);
var result = Docs.FirstOrDefault(d => d.Key.Equals(name, StringComparison.OrdinalIgnoreCase));
if (result.Value != null)
{
return result.Key;
}
return Title;
}
public static string Subtitle(HttpRequestBase request)
{
if (PageName(request) != Title)
{
int index = request.RawUrl.IndexOf('/', 1);
if (index > -1)
{
return request.RawUrl.Substring(index);
}
return string.Empty;
}
return request.RawUrl;
}
static private string GetFileName(string path)
{
string clean = path.Trim('/');
int index = clean.IndexOf('/');
if (index > -1)
{
clean = clean.Substring(0, index);
}
return clean;
}
}