Esempio n. 1
0
        void logReader_Tick(object sender, EventArgs e)
        {
            DateTime metering = DateTime.Now;

            if (!IsUpdating && Database.Instance.IsConfigured)
            {
                IsUpdating = true;
                if (CurrentMenu == labelMenuSecurityLog && IntrusionLog.HasUpdates(LastLogId))
                {
                    IDataReader rdr      = IntrusionLog.ReadDifferential(LastLogId);
                    int         maxLogId = LastLogId;
                    while (rdr.Read())
                    {
                        int    action  = int.Parse(rdr["Action"].ToString());
                        string agentId = Shared.Db.DbValueConverter.ToString(rdr["AgentId"]);
                        PanelSecurityLog.AddLogEntry(int.Parse(rdr["id"].ToString()), action,
                                                     agentId,
                                                     IntrusionLog.GetStatusIcon(action),
                                                     IntrusionLog.GetStatusClass(action), DateTime.Parse(rdr["IncidentTime"].ToString()), rdr["ClientIP"].ToString(),
                                                     GetLogMessage(agentId, action));
                        if (Convert.ToInt32(rdr["Id"]) > maxLogId)
                        {
                            maxLogId = Convert.ToInt32(rdr["Id"]);
                        }
                    }
                    rdr.Close();
                    rdr.Dispose();
                    if (maxLogId > LastLogId)
                    {
                        LastLogId = maxLogId;
                    }
                }

                if (CurrentMenu == labelMenuCurrentLocks && Locks.HasUpdates(LastLockUpdate))
                {
                    LastLockUpdate = DateTime.Now;
                    PanelCurrentLocks.Clear();
                    IDataReader locksReader = Locks.ReadLocks();
                    while (locksReader.Read())
                    {
                        DateTime lockDate;
                        DateTime unlockDate;
                        DateTime.TryParse(locksReader["LockDate"].ToString(), out lockDate);
                        DateTime.TryParse(locksReader["UnlockDate"].ToString(), out unlockDate);
                        PanelCurrentLocks.Add(int.Parse(locksReader["LockId"].ToString()), global::Cyberarms.IntrusionDetection.Admin.Properties.Resources.logIcon_softLock,
                                              LockStatusAdapter.GetLockStatusName(int.Parse(locksReader["Status"].ToString())), locksReader["ClientIp"].ToString(),
                                              locksReader["DisplayName"].ToString(),
                                              lockDate, unlockDate, IntrusionDetection.Shared.Db.DbValueConverter.ToInt(locksReader["Status"]));
                    }
                    locksReader.Close();
                    locksReader.Dispose();
                }
                if (CurrentMenu == labelMenuHome)
                {
                    Dashboard.SetUnsuccessfulLogins(Locks.ReadUnsuccessfulLoginAttempts(DateTime.Now.AddDays(-30)));
                    foreach (SecurityAgent agent in SecurityAgents.Instance)
                    {
                        agent.UpdateStatistics();
                    }
                }
                if (CurrentMenu == labelMenuHome || CurrentMenu == labelMenuCurrentLocks)
                {
                    int softLocks = Locks.ReadCurrentSoftLocks();
                    int hardLocks = Locks.ReadCurrentHardLocks();
                    PanelCurrentLocks.SetSoftLocks(softLocks);
                    PanelCurrentLocks.SetHardLocks(hardLocks);
                    Dashboard.SetHardLocks(hardLocks);
                    Dashboard.SetSoftLocks(softLocks);
                }
                if (!IsInitialized || (CurrentMenu == labelMenuHome || CurrentMenu == labelMenuSecurityLog))
                {
                    // ??
                }
            }
            IsInitialized = true;
            IsUpdating    = false;
            System.Diagnostics.Debug.Print(DateTime.Now.Subtract(metering).TotalMilliseconds.ToString());
        }