Release-Notes/sessionsample.txt
... ...
@@ -0,0 +1,103 @@
1
+using AdHoc.DataStorage;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Web;
6
+using System.Web.SessionState;
7
+
8
+public class CustomSessionStorage : IDataStorage
9
+{
10
+ private HttpSessionState SessionNullable
11
+ {
12
+ get
13
+ {
14
+ HttpContext context = HttpContext.Current;
15
+ if (context != null)
16
+ return context.Session;
17
+ return null;
18
+ }
19
+ }
20
+
21
+ private HttpSessionState Session
22
+ {
23
+ get
24
+ {
25
+ HttpSessionState session = SessionNullable;
26
+ if (session != null)
27
+ return session;
28
+ throw new Exception("Session data storage provider was not available");
29
+ }
30
+ }
31
+
32
+ public bool ProviderAvailable
33
+ {
34
+ get { return SessionNullable != null; }
35
+ }
36
+
37
+ public string ProviderInstanceID
38
+ {
39
+ get { return Session.SessionID; }
40
+ }
41
+
42
+ public object Get(string key)
43
+ {
44
+ if (Session == null)
45
+ return null;
46
+ return Session[key];
47
+ }
48
+
49
+ public void Set(string key, object value)
50
+ {
51
+ Session[key] = value;
52
+ }
53
+
54
+ public void Remove(string key)
55
+ {
56
+ HttpSessionState session = Session;
57
+ if (session != null)
58
+ session.Remove(key);
59
+ }
60
+
61
+ public bool Contains(string key)
62
+ {
63
+ return Session[key] != null;
64
+ }
65
+
66
+ public void Clear()
67
+ {
68
+ HttpSessionState session = Session;
69
+ if (session != null)
70
+ session.Clear();
71
+ }
72
+
73
+ public object this[string key]
74
+ {
75
+ get
76
+ {
77
+ return Get(key);
78
+ }
79
+ set
80
+ {
81
+ Set(key, value);
82
+ }
83
+ }
84
+
85
+ public string[] AllKeys
86
+ {
87
+ get
88
+ {
89
+ HttpSessionState session = Session;
90
+ List<string> allKeys = new List<string>();
91
+ foreach (string key in session.Keys)
92
+ allKeys.Add(key);
93
+ return allKeys.ToArray();
94
+ }
95
+ }
96
+
97
+ public CustomSessionStorage()
98
+ {
99
+ HttpSessionState session = SessionNullable;
100
+ if (session !=null && session.IsCookieless)
101
+ throw new Exception("CookieLess mode not supported.");
102
+ }
103
+}
... ...
\ No newline at end of file