Repository navigation
Expand file tree
/
Copy pathStegoSession.cs
More file actions
188 lines (171 loc) · 6.52 KB
/
Copy pathStegoSession.cs
File metadata and controls
188 lines (171 loc) · 6.52 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using KeePass.Util.SendInputExt;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using static Stego.StegoExt;
namespace Stego
{
internal class StegoSession
{
private System.Timers.Timer beenAWhileTimer;
private System.Timers.Timer responseTimer;
private bool dialogHasResponse = true;
private bool screenLocked = false;
private bool checkedOut = false;
private StegoExt.CheckOutType checkedOutType;
private List<string> stegos;
public StegoSession(double beenAWhileTimeInMinutes, double responseTimeInMinutes)
{
beenAWhileTimeInMinutes *= 60000;
responseTimeInMinutes *= 60000;
beenAWhileTimer = new System.Timers.Timer(beenAWhileTimeInMinutes);
beenAWhileTimer.Elapsed += BeenAWhileTimerIsGoingOff;
responseTimer = new System.Timers.Timer(responseTimeInMinutes);
responseTimer.Elapsed += ResponseTimerIsGoingOff;
SystemEvents.SessionSwitch += HandleSessionSwitch;
stegos = new List<string>();
}
public event SessionRequiresCheckInHanlder OnSessionRequiresCheckIn;
public event SessionRequiresCheckOutHanlder OnSessionRequiresCheckOut;
public bool DialogHasResponse { get { return dialogHasResponse; } }
public List<string> Stegos { get { return stegos; } }
public StegoExt.CheckOutType CheckedOutType { get {return checkedOutType; } set {checkedOutType = value; } }
public bool CheckedOut
{
set
{
if (value == true)
{
beenAWhileTimer.Enabled = true;
checkedOut = true;
}
else
{
checkedOut = false;
}
}
get { return checkedOut; }
}
public void AddStegos(string stegoName)
{
stegos.Add(stegoName);
}
public void RemoveStegos(string stegoName)
{
stegos.Remove(stegoName);
}
public void EndSession()
{
beenAWhileTimer.Dispose();
responseTimer.Dispose();
beenAWhileTimer.Elapsed -= BeenAWhileTimerIsGoingOff;
responseTimer.Elapsed -= ResponseTimerIsGoingOff;
SystemEvents.SessionSwitch -= HandleSessionSwitch;
}
private void BeenAWhileTimerIsGoingOff(object source, ElapsedEventArgs e)
{
responseTimer.Enabled = true;
beenAWhileTimer.Enabled = false;
dialogHasResponse = false;
DialogResult dialogResult = MessageBox.Show("Do you still need your stegos?", "It's been a while", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly);
if (dialogResult == DialogResult.Yes)
{
if (screenLocked)
{
screenLocked = false;
MessageBox.Show("It looks like you locked your screen.\nPlease check out your stegos manually.", "Check Out Manually", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}
else if (!(checkedOut))
{
beenAWhileTimer.Enabled = true;
if (OnSessionRequiresCheckOut != null)
{
OnSessionRequiresCheckOut(this, new SessionRequiresCheckOut(checkedOutType));
}
else
{
throw new NotImplementedException("No hanlder exists for SessionRequiresCheckOut");
}
}
else
{
beenAWhileTimer.Enabled = true;
}
}
else if (dialogResult == DialogResult.No)
{
if (OnSessionRequiresCheckIn != null)
{
OnSessionRequiresCheckIn(this, new SessionRequiresCheckIn("User no longer needs Stegos"));
}
else
{
throw new NotImplementedException("No hanlder exists for SessionRequiresCheckIn");
}
}
responseTimer.Enabled = false;
dialogHasResponse = true;
}
private void ResponseTimerIsGoingOff(object source, ElapsedEventArgs e)
{
if (OnSessionRequiresCheckIn != null)
{
OnSessionRequiresCheckIn(this, new SessionRequiresCheckIn("User hasn't responded to dialog in time."));
}
else
{
throw new NotImplementedException("No hanlder exists for SessionRequiresCheckIn");
}
responseTimer.Enabled = false;
}
private void HandleSessionSwitch(object sender, SessionSwitchEventArgs e)
{
if (checkedOut)
{
if (OnSessionRequiresCheckIn != null)
{
OnSessionRequiresCheckIn(this, new SessionRequiresCheckIn("User has triggered session switch (locked screen, logged off, etc.)"));
}
else
{
throw new NotImplementedException("No hanlder exists for SessionRequiresCheckIn");
}
if (!dialogHasResponse)
{
screenLocked = true;
}
}
}
}
public delegate void SessionRequiresCheckInHanlder(object source, SessionRequiresCheckIn e);
public class SessionRequiresCheckIn : EventArgs
{
private readonly string Reason;
public SessionRequiresCheckIn(string reason)
{
Reason = reason;
}
public string GetInfo()
{
return Reason;
}
}
public delegate void SessionRequiresCheckOutHanlder(object source, SessionRequiresCheckOut e);
public class SessionRequiresCheckOut : EventArgs
{
private readonly CheckOutType CheckedOutType;
public SessionRequiresCheckOut(CheckOutType checkedOutType)
{
CheckedOutType = checkedOutType;
}
public CheckOutType GetInfo()
{
return CheckedOutType;
}
}
}