private void actionMenuUnlock_Click(object sender, EventArgs e)
 {
     foreach (DataGridViewRow row in this.dataGridViewLocks.Rows)
     {
         DataGridViewCheckBoxCell c = (DataGridViewCheckBoxCell)row.Cells["dataGridViewSelectItem"];
         //if (c.Value == null) {
         //    if (c.Selected) { c.Value = c.TrueValue; } else { c.Value = c.FalseValue; }
         //}
         if ((bool)c.EditedFormattedValue == true && (row.Cells[8].Value.ToString() == Cyberarms.IntrusionDetection.Shared.Lock.LOCK_STATUS_SOFTLOCK.ToString() ||
                                                      row.Cells[8].Value.ToString() == Cyberarms.IntrusionDetection.Shared.Lock.LOCK_STATUS_HARDLOCK.ToString().ToString()))
         {
             long lockId;
             if (long.TryParse(row.Cells[7].Value.ToString(), out lockId))
             {
                 Lock l = Locks.GetLockById(lockId);
                 if (l != null)
                 {
                     l.Status = Lock.LOCK_STATUS_UNLOCK_REQUESTED;
                     l.Save();
                 }
                 row.Cells[2].Value = LockStatusAdapter.GetLockStatusName((int)Lock.LOCK_STATUS_MANUAL);
             }
         }
     }
 }
Esempio n. 2
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());
        }