Example #1
0
        private void NewCardPresented(PanelMonitor pnlmon, PanelEventArgs pnlevargs)
        {
            try
            {
                using (MySqlConnection sqlconn = new MySqlConnection(dbconnprop.ConnectionString))
                {
                    sqlconn.Open();

                    //lookup
                    using (MySqlCommand cmdName = new MySqlCommand("select data from `" + table_name + "` where uid=" + pnlevargs.PanelState.Card.UID, sqlconn))
                        using (MySqlDataReader reader = cmdName.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                if (reader[0] != DBNull.Value)
                                {
                                    byte[] bytes = (byte[])reader["data"];

                                    AccessProperties accessprop;
                                    using (MemoryStream ms = new MemoryStream())
                                    {
                                        ms.Write(bytes, 0, bytes.Length);
                                        ms.Position = 0;
                                        accessprop  = (AccessProperties)bf.Deserialize(ms);
                                    }

                                    //add to processing queue
                                    if (!accessprop.ForceDisable)
                                    {
                                        if (accessprop.EnabledFrom <= DateTime.Now || accessprop.ForceEnable)
                                        {
                                            if (accessprop.EnabledTo >= DateTime.Now || accessprop.ForceEnable)
                                            {
                                                //card is active; continue verifying

                                                List <ExpanderModificationProperties> temp = accessprop.ProcessActivations();
                                                int associated_car = pnlmon.AssociatedCar;

                                                if (temp.Count > 0)
                                                {
                                                    pnlmon.AnimateLED(PanelCommand.ANIMATION_APPROVAL);

                                                    PanelMonitor      monitor = pnlmon;
                                                    AccessControlCard card    = pnlevargs.PanelState.Card;

                                                    Task.Run(delegate()
                                                    {
                                                        AccessControlLogManager.AddAccessControlLogEntry(card.UID, new AccessControlLogEntry(DateTime.Now, "User Approved Entry", card,
                                                                                                                                             expmon.ToString(), monitor.ToString()));
                                                    });
                                                }
                                                else
                                                {
                                                    pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);

                                                    PanelMonitor      monitor = pnlmon;
                                                    AccessControlCard card    = pnlevargs.PanelState.Card;

                                                    Task.Run(delegate()
                                                    {
                                                        AccessControlLogManager.AddAccessControlLogEntry(card.UID, new AccessControlLogEntry(DateTime.Now, "User Declined Entry", card,
                                                                                                                                             expmon.ToString(), monitor.ToString()));
                                                    });
                                                }

                                                foreach (ExpanderModificationProperties expmodprop in temp)
                                                {
                                                    expmodprop.AssociatedCar = associated_car;
                                                    expmodprops.Add(expmodprop);
                                                }
                                            }
                                            else
                                            {
                                                pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                            }
                                        }
                                        else
                                        {
                                            pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                        }
                                    }
                                    else
                                    {
                                        pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                                    }
                                }
                            }
                            else
                            {
                                pnlmon.AnimateLED(PanelCommand.ANIMATION_DECLINE);
                            }
                        }
                }
            }
            catch (MySqlException mysqlex)
            {
                ErrorLogManager.AppendLog("AltMonitor - MySqlException Occured During Card Lookup", true);
            }
            catch (Exception ex)
            {
                ErrorLogManager.AppendLog("AltMonitor - General Error Occured During Card Lookup", true);
            }
        }