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);
            }
        }
        private new async Task Refresh()
        {
            UseWaitCursor = true;

            foreach (Control control in Controls)
            {
                control.Enabled = false;
            }

            treeView1.Nodes.Clear();

            Dictionary <UInt64, List <AccessControlLogEntry> > entries = await AccessControlLogManager.GetAccessControlLogEntries();

            TreeNode allnode = new TreeNode("All");

            treeView1.Nodes.Add(allnode);

            treeView1.AfterSelect += (x, y) =>
            {
                if (y.Node.Level == 0)
                {
                    dataGridView1.Rows.Clear();

                    if (y.Node == allnode)
                    {
                        foreach (var key in entries.Keys)
                        {
                            foreach (var entry in entries[key])
                            {
                                AddRow(entry);
                            }
                        }
                    }
                    else
                    {
                        foreach (var entry in entries[Convert.ToUInt64(y.Node.Text)])
                        {
                            AddRow(entry);
                        }
                    }
                }
            };

            foreach (var key in entries.Keys)
            {
                TreeNode keyroot = new TreeNode(key + "");

                string[] table_names = await DatabaseManager.GetTableNames(dbconnprop);

                foreach (string table_name in table_names)
                {
                    TreeNode table_node = new TreeNode(table_name);

                    keyroot.Nodes.Add(table_node);
                }

                treeView1.Nodes.Add(keyroot);
            }

            foreach (Control control in Controls)
            {
                control.Enabled = true;
            }

            UseWaitCursor = false;
        }