You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
490 lines
14 KiB
490 lines
14 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
// using System.ComponentModel; |
|
using System.Diagnostics; |
|
using System.Drawing; |
|
using System.IO; |
|
using System.Linq; |
|
using System.Net; |
|
using System.Reflection; |
|
using System.Text; |
|
using System.Threading; |
|
using System.Web.Script.Serialization; |
|
using System.Windows.Forms; |
|
using Alchemy; |
|
using Alchemy.Classes; |
|
using iMonitorApp.Properties; |
|
|
|
namespace iMonitorApp |
|
{ |
|
// Token: 0x02000016 RID: 22 |
|
public partial class StackAlarm : Form |
|
{ |
|
// Token: 0x0600008E RID: 142 RVA: 0x0000642E File Offset: 0x0000462E |
|
public StackAlarm() |
|
{ |
|
this.InitializeComponent(); |
|
this.LoadForm(); |
|
} |
|
|
|
// Token: 0x0600008F RID: 143 RVA: 0x00006460 File Offset: 0x00004660 |
|
private void LoadForm() |
|
{ |
|
this.li = new BindingListInvoked<ParseStackAlarms>(this.dataGridView1); |
|
this.dataGridView1.AutoGenerateColumns = true; |
|
this.dataGridView1.DataSource = this.li; |
|
Thread thread = new Thread(new ThreadStart(this.LaunchListener)); |
|
thread.Start(); |
|
this._themeEmails = new ThemeEmails(); |
|
this.heartBeatTimer = new System.Threading.Timer(new TimerCallback(this.SendAMHeartBeat), null, 100, Settings.Default.ExternalHeartbeatTimer * 1000); |
|
} |
|
|
|
// Token: 0x06000090 RID: 144 RVA: 0x000064EC File Offset: 0x000046EC |
|
public void SendAMHeartBeat(object state) |
|
{ |
|
bool primary = Settings.Default.Primary; |
|
if (primary) |
|
{ |
|
try |
|
{ |
|
Stopwatch stopwatch = new Stopwatch(); |
|
stopwatch.Start(); |
|
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Settings.Default.ExternalHeartbeatURL); |
|
string str = Convert.ToBase64String(Encoding.ASCII.GetBytes(Settings.Default.ExternalHeartbeatUsername + ":" + Settings.Default.ExternalHeartbeatPassword)); |
|
httpWebRequest.Headers.Add("Authorization", "Basic " + str); |
|
httpWebRequest.ReadWriteTimeout = 20000; |
|
httpWebRequest.Timeout = 20000; |
|
httpWebRequest.Method = "GET"; |
|
HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); |
|
stopwatch.Stop(); |
|
httpWebResponse.Close(); |
|
httpWebRequest.Abort(); |
|
} |
|
catch |
|
{ |
|
} |
|
} |
|
} |
|
|
|
// Token: 0x06000091 RID: 145 RVA: 0x000065E0 File Offset: 0x000047E0 |
|
private void LaunchWebSocketListener() |
|
{ |
|
this._webSocketServer = new WebSocketServer(12345, IPAddress.Any) |
|
{ |
|
OnReceive = new OnEventDelegate(this.OnWebSocketServerReceive), |
|
OnSend = new OnEventDelegate(this.OnWebSocketServerSend), |
|
OnConnected = new OnEventDelegate(this.OnWebSocketServerConnected), |
|
OnDisconnect = new OnEventDelegate(this.OnWebSocketServerDisconnected), |
|
TimeOut = new TimeSpan(0, 50, 0) |
|
}; |
|
this._webSocketClientContextList = new List<UserContext>(); |
|
this._clientUserMap = new Dictionary<string, string>(); |
|
this._clientUserMapExtension = new Dictionary<string, string>(); |
|
this._webSocketServer.Start(); |
|
} |
|
|
|
// Token: 0x06000092 RID: 146 RVA: 0x00006688 File Offset: 0x00004888 |
|
private void OnWebSocketServerConnected(UserContext context) |
|
{ |
|
Console.WriteLine("Client Connected From : " + context.ClientAddress.ToString()); |
|
bool flag = (from t in this._webSocketClientContextList |
|
where t.ClientAddress == context.ClientAddress |
|
select t).Count<UserContext>() == 0; |
|
if (flag) |
|
{ |
|
this._webSocketClientContextList.Add(context); |
|
} |
|
bool flag2 = !this._clientUserMap.ContainsKey(context.ClientAddress.ToString()); |
|
if (flag2) |
|
{ |
|
this._clientUserMap.Add(context.ClientAddress.ToString(), ""); |
|
} |
|
} |
|
|
|
// Token: 0x06000093 RID: 147 RVA: 0x0000673C File Offset: 0x0000493C |
|
private void OnWebSocketServerDisconnected(UserContext context) |
|
{ |
|
Console.WriteLine("OnDisconnected: " + context.ClientAddress.ToString()); |
|
UserContext userContext = (from p in this._webSocketClientContextList |
|
where p.ClientAddress == context.ClientAddress |
|
select p).FirstOrDefault<UserContext>(); |
|
bool flag = userContext != null; |
|
if (flag) |
|
{ |
|
this._webSocketClientContextList.Remove(userContext); |
|
} |
|
bool flag2 = this._clientUserMap.ContainsKey(context.ClientAddress.ToString()); |
|
if (flag2) |
|
{ |
|
this._clientUserMap.Remove(context.ClientAddress.ToString()); |
|
} |
|
} |
|
|
|
// Token: 0x06000094 RID: 148 RVA: 0x000067E4 File Offset: 0x000049E4 |
|
private void OnWebSocketServerReceive(UserContext context) |
|
{ |
|
Console.WriteLine("OnSend: " + context.ClientAddress.ToString()); |
|
string text = context.DataFrame.ToString(); |
|
bool flag = text != "" && text != null; |
|
if (flag) |
|
{ |
|
bool flag2 = text.Split(new char[] |
|
{ |
|
',' |
|
}).Count<string>() == 2; |
|
if (flag2) |
|
{ |
|
string text2 = text.Split(new char[] |
|
{ |
|
',' |
|
})[0]; |
|
string text3 = text.Split(new char[] |
|
{ |
|
',' |
|
})[1]; |
|
bool flag3 = this._clientUserMap.ContainsKey(context.ClientAddress.ToString()); |
|
if (flag3) |
|
{ |
|
this._clientUserMap[context.ClientAddress.ToString()] = text3; |
|
} |
|
else |
|
{ |
|
this._clientUserMap.Add(context.ClientAddress.ToString(), text3); |
|
} |
|
try |
|
{ |
|
IEnumerable<ParseStackAlarms> source = (from t in this.li |
|
orderby t.ReceivingTime descending |
|
select t).Take(50); |
|
foreach (ParseStackAlarms parseStackAlarms in from t in source |
|
orderby t.ReceivingTime |
|
select t) |
|
{ |
|
bool flag4 = parseStackAlarms.Recipients.Split(new char[] |
|
{ |
|
',' |
|
}).Select((string t) => t.ToLower()).ToList<string>().Contains(text3 + "@4ecap.com"); |
|
if (flag4) |
|
{ |
|
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); |
|
string aString = javaScriptSerializer.Serialize(parseStackAlarms); |
|
context.Send(aString, false, false); |
|
} |
|
} |
|
} |
|
catch |
|
{ |
|
context.Send("Unable to fetch history<>-", false, false); |
|
} |
|
} |
|
} |
|
} |
|
|
|
// Token: 0x06000095 RID: 149 RVA: 0x00006A20 File Offset: 0x00004C20 |
|
private void OnWebSocketServerSend(UserContext context) |
|
{ |
|
Console.WriteLine("OnReceived: " + context.ClientAddress.ToString()); |
|
} |
|
|
|
// Token: 0x06000096 RID: 150 RVA: 0x00006A40 File Offset: 0x00004C40 |
|
private void UpdateWebUI(string speech, string users, DateTime receivedTime) |
|
{ |
|
List<string> list = (from p in users.Split(new char[] |
|
{ |
|
',' |
|
}) |
|
select p.Replace("@4ecap.com", "").ToLower()).ToList<string>(); |
|
foreach (UserContext userContext in this._webSocketClientContextList) |
|
{ |
|
bool flag = list.Contains(this._clientUserMap[userContext.ClientAddress.ToString()]); |
|
if (flag) |
|
{ |
|
userContext.Send(speech + "<>" + receivedTime.ToShortTimeString(), false, false); |
|
} |
|
} |
|
} |
|
|
|
// Token: 0x06000097 RID: 151 RVA: 0x00006B08 File Offset: 0x00004D08 |
|
private void UpdateWebUI(ParseStackAlarms pa) |
|
{ |
|
List<string> list = (from p in pa.Recipients.Split(new char[] |
|
{ |
|
',' |
|
}) |
|
select p.Replace("@4ecap.com", "").ToLower()).ToList<string>(); |
|
foreach (UserContext userContext in this._webSocketClientContextList) |
|
{ |
|
bool flag = list.Contains(this._clientUserMap[userContext.ClientAddress.ToString()]); |
|
if (flag) |
|
{ |
|
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); |
|
string aString = javaScriptSerializer.Serialize(pa); |
|
userContext.Send(aString, false, false); |
|
} |
|
} |
|
} |
|
|
|
// Token: 0x06000098 RID: 152 RVA: 0x00006BD8 File Offset: 0x00004DD8 |
|
private void LaunchListener() |
|
{ |
|
AsynchronousSocketListenerStackAlarms asynchronousSocketListenerStackAlarms = new AsynchronousSocketListenerStackAlarms(Settings.Default.CurrentIP, Settings.Default.EmailPort); |
|
AsynchronousSocketListenerStackAlarms.Received += this.AsynchronousSocketListener_Received; |
|
AsynchronousSocketListenerStackAlarms.StartListening(); |
|
Debug.WriteLine("Listening....."); |
|
} |
|
|
|
// Token: 0x06000099 RID: 153 RVA: 0x00006C18 File Offset: 0x00004E18 |
|
private void AsynchronousSocketListener_Received(object sender, EventArgs e) |
|
{ |
|
this.BackupListAndClear(); |
|
bool flag = sender.ToString() == "Command: GETLIVE<EOF>"; |
|
if (flag) |
|
{ |
|
Thread thread = new Thread(new ThreadStart(this.DumpLiveLogs)); |
|
thread.Start(); |
|
} |
|
else |
|
{ |
|
object obj = this.locker; |
|
lock (obj) |
|
{ |
|
ParseStackAlarms parseStackAlarms = new ParseStackAlarms(sender.ToString(), this._themeEmails); |
|
this.li.Add(parseStackAlarms); |
|
try |
|
{ |
|
bool phoneit = parseStackAlarms.Phoneit; |
|
if (phoneit) |
|
{ |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
new Thread(new ParameterizedThreadStart(this.ProcessThread)) |
|
{ |
|
IsBackground = true |
|
}.Start(parseStackAlarms); |
|
} |
|
} |
|
} |
|
|
|
// Token: 0x0600009A RID: 154 RVA: 0x00006CFC File Offset: 0x00004EFC |
|
public void ProcessThread(object sa) |
|
{ |
|
((ParseStackAlarms)sa).Process(); |
|
bool flag = ((ParseStackAlarms)sa).SendingEmailStatus.StartsWith("Error"); |
|
if (flag) |
|
{ |
|
this.consecutiveFails++; |
|
} |
|
else |
|
{ |
|
this.consecutiveFails = 0; |
|
} |
|
bool flag2 = this.consecutiveFails > Settings.Default.ConsecutiveEmailFailCounter; |
|
if (flag2) |
|
{ |
|
SocketClient.Send(Settings.Default.CurrentIP, Settings.Default.PhonePort, Settings.Default.CatchAllPhone + "<EOF>"); |
|
} |
|
try |
|
{ |
|
bool invokeRequired = this.dataGridView1.InvokeRequired; |
|
if (invokeRequired) |
|
{ |
|
this.dataGridView1.Invoke(new Action(delegate() |
|
{ |
|
this.UpdateDataGridView(); |
|
})); |
|
} |
|
else |
|
{ |
|
this.UpdateDataGridView(); |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
} |
|
|
|
// Token: 0x0600009B RID: 155 RVA: 0x00006DD8 File Offset: 0x00004FD8 |
|
public void Log(string text, bool clear = false) |
|
{ |
|
bool invokeRequired = this.tb_log.InvokeRequired; |
|
if (invokeRequired) |
|
{ |
|
this.tb_log.Invoke(new Action(delegate() |
|
{ |
|
bool clear3 = clear; |
|
if (clear3) |
|
{ |
|
this.tb_log.Text = ""; |
|
} |
|
else |
|
{ |
|
this.tb_log.Text = text + "\r\n" + this.tb_log.Text; |
|
} |
|
})); |
|
} |
|
else |
|
{ |
|
bool clear2 = clear; |
|
if (clear2) |
|
{ |
|
this.tb_log.Text = ""; |
|
} |
|
else |
|
{ |
|
this.tb_log.Text = text + "\r\n" + this.tb_log.Text; |
|
} |
|
} |
|
} |
|
|
|
// Token: 0x0600009C RID: 156 RVA: 0x00006E74 File Offset: 0x00005074 |
|
public void UpdateDataGridView() |
|
{ |
|
this.dataGridView1.Refresh(); |
|
try |
|
{ |
|
foreach (object obj in ((IEnumerable)this.dataGridView1.Rows)) |
|
{ |
|
DataGridViewRow dataGridViewRow = (DataGridViewRow)obj; |
|
try |
|
{ |
|
bool flag = dataGridViewRow.Cells[1].Value.ToString().StartsWith("Error"); |
|
if (flag) |
|
{ |
|
dataGridViewRow.DefaultCellStyle.ForeColor = Color.Red; |
|
} |
|
bool flag2 = dataGridViewRow.Cells[1].Value.ToString().StartsWith("Proce"); |
|
if (flag2) |
|
{ |
|
dataGridViewRow.DefaultCellStyle.ForeColor = Color.Orange; |
|
} |
|
bool flag3 = dataGridViewRow.Cells[1].Value.ToString().StartsWith("Sent"); |
|
if (flag3) |
|
{ |
|
dataGridViewRow.DefaultCellStyle.ForeColor = Color.Green; |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
} |
|
} |
|
catch |
|
{ |
|
} |
|
} |
|
|
|
// Token: 0x0600009D RID: 157 RVA: 0x00006FB8 File Offset: 0x000051B8 |
|
public void BackupListAndClear() |
|
{ |
|
try |
|
{ |
|
bool flag = this.li.Count >= Settings.Default.BackupCount; |
|
if (flag) |
|
{ |
|
bool flag2 = (from p in this.li |
|
where p.SendingEmailStatus == "" |
|
select p).Count<ParseStackAlarms>() == 0; |
|
if (flag2) |
|
{ |
|
this.WriteCSV<ParseStackAlarms>(this.li, "C:\\tempFiles\\iMonitorLogs\\", "test"); |
|
this.li.Clear(); |
|
this.Log("", true); |
|
this.Log("Backed up logs - Cleared UI", false); |
|
} |
|
} |
|
} |
|
catch |
|
{ |
|
this.Log("Error backing up data", false); |
|
} |
|
} |
|
|
|
// Token: 0x0600009E RID: 158 RVA: 0x00007084 File Offset: 0x00005284 |
|
public void DumpLiveLogs() |
|
{ |
|
try |
|
{ |
|
this.WriteCSV<ParseStackAlarms>(this.li, "C:\\tempFiles\\iMonitorLogs\\", "live.csv"); |
|
this.Log("Live Logs Dumped", false); |
|
} |
|
catch |
|
{ |
|
this.Log("Error dumping log file", false); |
|
} |
|
} |
|
|
|
// Token: 0x0600009F RID: 159 RVA: 0x000070DC File Offset: 0x000052DC |
|
public void WriteCSV<T>(IEnumerable<T> items, string path, string filename = "") |
|
{ |
|
bool flag = !Directory.Exists(path); |
|
if (flag) |
|
{ |
|
Directory.CreateDirectory(path); |
|
} |
|
bool flag2 = filename == ""; |
|
if (flag2) |
|
{ |
|
filename = "iMonitor_" + DateTime.Now.ToString("ddMMMyy_hh_mm") + ".csv"; |
|
} |
|
Type typeFromHandle = typeof(T); |
|
IOrderedEnumerable<PropertyInfo> source = from p in typeFromHandle.GetProperties(BindingFlags.Instance | BindingFlags.Public) |
|
orderby p.Name |
|
select p; |
|
using (StreamWriter streamWriter = new StreamWriter(path + filename)) |
|
{ |
|
string text = string.Join("^^", from p in source |
|
select p.Name); |
|
text = text.Replace(",", ";").Replace("^^", ", "); |
|
streamWriter.WriteLine(text); |
|
using (IEnumerator<T> enumerator = items.GetEnumerator()) |
|
{ |
|
while (enumerator.MoveNext()) |
|
{ |
|
T item = enumerator.Current; |
|
string text2 = string.Join<object>("^^", from p in source |
|
select p.GetValue(item, null)); |
|
text2 = text2.Replace(",", ";").Replace("^^", ", "); |
|
streamWriter.WriteLine(text2); |
|
} |
|
} |
|
} |
|
} |
|
|
|
// Token: 0x060000A0 RID: 160 RVA: 0x00007288 File Offset: 0x00005488 |
|
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e) |
|
{ |
|
e.ThrowException = false; |
|
} |
|
|
|
// Token: 0x0400005C RID: 92 |
|
public object locker = new object(); |
|
|
|
// Token: 0x0400005D RID: 93 |
|
public BindingListInvoked<ParseStackAlarms> li; |
|
|
|
// Token: 0x0400005E RID: 94 |
|
public WebSocketServer _webSocketServer; |
|
|
|
// Token: 0x0400005F RID: 95 |
|
public List<UserContext> _webSocketClientContextList; |
|
|
|
// Token: 0x04000060 RID: 96 |
|
public Dictionary<string, string> _clientUserMap; |
|
|
|
// Token: 0x04000061 RID: 97 |
|
public Dictionary<string, string> _clientUserMapExtension; |
|
|
|
// Token: 0x04000062 RID: 98 |
|
private System.Threading.Timer heartBeatTimer; |
|
|
|
// Token: 0x04000063 RID: 99 |
|
private ThemeEmails _themeEmails; |
|
|
|
// Token: 0x04000064 RID: 100 |
|
public int consecutiveFails = 0; |
|
} |
|
}
|
|
|