SessionManager.cs
6.58 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using ADAM.AIA50.BusinessLayer.Utility;
using System.Data;
using ADAM.AIAHTML5.API.Models;
namespace ADAM.AIA50.BusinessLayer.Utility
{
//[RemotingService("Adam Manage User Service")]
/// <summary>
/// This class is main resposible to handle the session mechanism.
/// This class need for handling the user state maintinence.
/// </summary>
public class SessionManager
{
// This is the static variable to have a singleton instance of the class.
private static SessionManager _instance = null;
/// <summary>
/// private Constructor of the class to make class singleton.
/// </summary>
private SessionManager()
{
}
/// <summary>
/// This function use to add a session value as per the user id, license id, edition id and user session id
/// so that this can be check user is logged in or not.
/// </summary>
/// <param name="intUserID">user id</param>
/// <param name="intLicenseID">license id</param>
/// <param name="intEditionID">eidtion id</param>
public void AddSession(int intUserID, int intLicenseID, byte byteEditionID)
{
// check if session is not created then create new
string strSessionName = "ADAMSessionID";
/* below if condition is commented as session check on culster envirnment
* can give be false
*
if (FluorineFx.Context.FluorineContext.Current.Session[strSessionName] == null)
{
FluorineFx.Context.FluorineContext.Current.Session.Add(strSessionName, intUserID);
string strSessionID = FluorineFx.Context.FluorineContext.Current.Session.SessionID;
CacheManager.GetInstance().Add(strSessionID, intUserID, intLicenseID, byteEditionID);
}
*/
//FluorineFx.Context.FluorineContext.Current.Session.Add(strSessionName, intUserID);
//string strSessionID = FluorineFx.Context.FluorineContext.Current.Session.SessionID;
//CacheManager.GetInstance().Add(strSessionID, intUserID, intLicenseID, byteEditionID);
}
/// <summary>
/// This function use to update the session login time
/// </summary>
/// <returns> number of rows updated ( Integer value )</returns>
//public int UpdateSession()
//{
// check session is not null the it will update that session id login time
// /* below if condition is commented as session check on culster envirnment
// * can give be false
// string strSessionName = "ADAMSessionID";
// if (FluorineFx.Context.FluorineContext.Current.Session[strSessionName] != null)
// {
// string strSessionID = FluorineFx.Context.FluorineContext.Current.Session.SessionID;
// CacheManager.GetInstance().Update(strSessionID);
// }
// */
// string strSessionID = FluorineFx.Context.FluorineContext.Current.Session.SessionID;
// int rowUpdated = CacheManager.GetInstance().Update(strSessionID);
// return rowUpdated;
//}
/// <summary>
/// This function use to delete a session id entry when user logged out from the system.
/// </summary>
public void DeleteSession()
{
string strSessionName = "ADAMSessionID";
// check if session is not null then delete
/* below if condition is commented as session check on culster envirnment
* can give be false
if (FluorineFx.Context.FluorineContext.Current.Session[strSessionName] != null)
{
string strSessionID = FluorineFx.Context.FluorineContext.Current.Session.SessionID;
CacheManager.GetInstance().Delete(strSessionID);
FluorineFx.Context.FluorineContext.Current.Session.Remove(strSessionName);
}
*/
//string strSessionID = FluorineFx.Context.FluorineContext.Current.Session.SessionID;
//CacheManager.GetInstance().Delete(strSessionID);
//FluorineFx.Context.FluorineContext.Current.Session.Remove(strSessionName);
}
/// <summary>
/// This function count the row from the sessionmanage table on the basis of License id and edition id
/// </summary>
/// <param name="intLicenseID">license id</param>
/// <param name="intEditionID">edition id</param>
/// <returns>number of row in the session table</returns>
public int CountSession(int intLicenseID, byte byteEditionID)
{
DataTable dtblSessionManager = DBModel.GetSessionByLicenseEditionId(intLicenseID, byteEditionID);
//Count only those logged since 20min or less
//NOTE: GM Changed to 5 minutes because 20 is too long to wait to detect a browser crash
//NOTE: this could be moved in the Sql Query for more speed
DateTime currentDateMinutesAgo = DateTime.Now.AddMinutes(-20); // 11.45 =11:25
int count = 0;
for (int i = 0; i < dtblSessionManager.Rows.Count; i++)
{
DateTime loginTime = DateTime.Parse(dtblSessionManager.Rows[i][2].ToString()); //LoginTime
if (currentDateMinutesAgo <= loginTime) // 11:20/11:50
count++;
}
return count;
}
public void AddModSession(string exSessionName, string intValue)
{
// check if session is not created then create new
string strSessionName = exSessionName;
// FluorineFx.Context.FluorineContext.Current.Session.Add(strSessionName, intValue);
}
/// <summary>
/// This function use to delete a session id entry when user logged out from the system.
/// </summary>
public void DeleteModSession(string exSessionName)
{
string strSessionName = exSessionName;
// FluorineFx.Context.FluorineContext.Current.Session.Remove(strSessionName);
}
/// <summary>
/// This method use to get the instance of this class
/// </summary>
/// <returns>instance on the same class</returns>
public static SessionManager GetInstance()
{
if (_instance == null)
{
_instance = new SessionManager();
}
return _instance;
}
}
}