-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSessionDashboardStorage.cs
58 lines (51 loc) · 2.01 KB
/
SessionDashboardStorage.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
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using System.Web;
using System.Web.SessionState;
namespace DevExpress.PublicDemo {
public class SessionDashboardStorage : DashboardStorageBase {
const string DashboardStorageKey = "DashboardStorage";
private static SessionDashboardStorage instance = null;
public static SessionDashboardStorage Instance {
get {
if(instance == null) {
instance = new SessionDashboardStorage();
}
return instance;
}
}
Dictionary<string, XDocument> Storage {
get {
HttpSessionState session = HttpContext.Current.Session;
if(session != null) {
Dictionary<string, XDocument> storage = session[DashboardStorageKey] as Dictionary<string, XDocument>;
if(storage == null) {
storage = new Dictionary<string, XDocument>();
session[DashboardStorageKey] = storage;
return storage;
}
return storage;
}
throw new ArgumentNullException("Session is not available");
}
}
protected SessionDashboardStorage() : base() {
}
protected override IEnumerable<string> GetAvailableDashboardsID() {
return Storage.Keys;
}
protected override XDocument LoadDashboard(string dashboardID) {
return Storage[dashboardID];
}
protected override void SaveDashboard(string dashboardID, XDocument dashboard, bool createNew) {
if(createNew ^ Storage.ContainsKey(dashboardID))
Storage[dashboardID] = dashboard;
}
public void RegisterDashboard(string dashboardID, XDocument dashboard) {
SaveDashboard(dashboardID, dashboard, true);
}
}
}