예제 #1
0
        public static FingerAccount AccountFromHTTP(string request)
        {
            var    payload = request.Split(new string[] { "\r\n\r\n" }, StringSplitOptions.None).Last();
            var    data    = payload.Split('&').Select(n => n.Trim('\n', '\r'));
            int    id      = 0;
            string name    = "";
            bool   scan    = false;

            foreach (var ssssssssss in data)
            {
                switch (ssssssssss.Split('=')[0].ToLower())
                {
                case "a":
                    var val = ssssssssss.Split('=').Last();
                    if (val.ToLower() == "on")
                    {
                        scan = true;
                    }
                    else
                    {
                        scan = false;
                    }
                    break;

                case "b":
                    id = int.Parse(ssssssssss.Split('=').Last());
                    break;

                case "c":
                    name = ssssssssss.Split('=').Last();
                    break;
                }
            }
            if (scan && name.Length > 0)
            {
                return(new FingerAccount(name, FingerWizard.CreateAScan(id)));
            }
            else
            {
                return(new FingerAccount(name, id));
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            while (arduino == null)
            {
                string port = Log.QueryMultiChoice("Port name?", SerialPort.GetPortNames().ToList());
                ushort baud = Convert.ToUInt16(Log.QueryMultiChoice("Baud rate?", new List <string>()
                {
                    "9600", "57600"
                }));
                arduino = new SerialPort(port, baud);
                try
                {
                    arduino.Open();
                    Task.Run(() => ListenPort(arduino));
                }
                catch (Exception e)
                {
                    Log.Error("Could not open " + port, e);
                    arduino = null;
                }
            }

            while (HostName == null)
            {
                HostName = Log.Query("Hostname?", "iansweb.org");
                if (!(HostName.Length > 1))
                {
                    Console.WriteLine("Invalid Address");
                    HostName = null;
                }
            }

            Console.WriteLine($"COM Port: {arduino.PortName}");
            Console.WriteLine($"Baud Rate: {arduino.BaudRate}");
            Console.WriteLine($"HostName: {HostName}");
            Console.WriteLine($"Port: {Port}");
            Task.Run(StartWebServer);

            fingerRelay    = new FingerRelay(arduino);
            fingerAccounts = parseJson();
            Task.Run(AutoSaveDatabase);
            Log.Info("Autosaving databases every " + new TimeSpan(0, 0, 600000).Minutes + " minutes");
            while (true)
            {
                string choice = Log.QueryMultiChoice("Main Menu", mainMenuItems.ToList());
                if (choice == mainMenuItems[0])
                {
                    //View keys
                    foreach (var fingeraccount in fingerAccounts)
                    {
                        Console.WriteLine($"{fingeraccount.Name}, {fingeraccount.loggedIn}, {fingeraccount.templateId}");
                    }
                    Console.ReadKey(true);
                }
                else if (choice == mainMenuItems[1])
                {
                    //Add key
                    int id = 0;

                    while (id == 0)
                    {
                        if (Log.QueryBool("Create new scan?"))
                        {
                            id = FingerWizard.CreateAScan();
                        }
                        else
                        {
                            try
                            {
                                id = Convert.ToInt16(Log.Query("Template Id", (fingerRelay.TemplateCount + 1).ToString()));
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Invalid Integer");
                            }
                        }
                    }
                    var newuser = new FingerAccount(Log.Query("User's Name", ("user" + (fingerRelay.TemplateCount + 1).ToString())), id);
                    fingerAccounts.Add(newuser);
                }
                else if (choice == mainMenuItems[2])
                {
                    //Log In
                    var users = fingerAccounts.Where(n => !(n.loggedIn));
                    if (users.Count() > 0)
                    {
                        string user    = Log.QueryMultiChoice("User to log in?", users.Select(n => n.Name).ToList());
                        var    matches = fingerAccounts.Where(n => n.Name == user && !(n.loggedIn));
                        if (matches.Count() > 0)
                        {
                            Console.WriteLine($"Logged in the first account that has the name of {matches.First().Name}");
                            matches.First().LogIn();
                        }
                        else
                        {
                            Console.WriteLine("No matches found");
                        }
                    }
                    else
                    {
                        Console.WriteLine("No users are logged out");
                    }
                }
                else if (choice == mainMenuItems[3])
                {
                    //Log Out
                    var users = fingerAccounts.Where(n => n.loggedIn);
                    if (users.Count() > 0)
                    {
                        string user    = Log.QueryMultiChoice("User to log out?", users.Select(n => n.Name).ToList());
                        var    matches = fingerAccounts.Where(n => n.Name == user && n.loggedIn);
                        if (matches.Count() > 0)
                        {
                            Console.WriteLine($"Logged out the first account that has the name of {matches.First().Name}");
                            matches.First().LogOut();
                        }
                        else
                        {
                            Console.WriteLine("No matches found");
                        }
                    }
                    else
                    {
                        Console.WriteLine("No users are logged in");
                    }
                }
                else if (choice == mainMenuItems[4])
                {
                    if (fingerAccounts.Count > 0)
                    {
                        //DirectoryInfo directoryInfo = new DirectoryInfo(".");
                        //System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(new System.Drawing.Bitmap(Log.QueryMultiChoice("Source bitmap?", directoryInfo.EnumerateFiles().Where(n => n.Name.EndsWith(".bmp")).Select(n => n.Name).ToList())));
                        //var finger = FingerOperations.GetFingerAccount(bitmap, fingerAccounts);
                        //Console.WriteLine($"{finger.Name}, {finger.loggedIn}");
                        Log.Info("Place thumb on scanner");
                        while (true)
                        {
                            var scan = FingerWizard.Scan(false, false);
                            if (scan < 0)
                            {
                                Log.Info("Scan failed");
                            }
                            else
                            {
                                if (fingerAccounts.Any(n => n.templateId == scan))
                                {
                                    var acc = fingerAccounts.Where(n => n.templateId == scan).First();
                                    Log.Success("Scan found " + acc.Name + ", template id " + scan);
                                    acc.ToggleLogINOUT();
                                    if (acc.loggedIn)
                                    {
                                        Log.Info("Logged in");
                                    }
                                    else
                                    {
                                        Log.Info("Logged out");
                                    }
                                }
                                else
                                {
                                    Log.Info($"No accounts found for this scan Id:{scan}");
                                }
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No fingers for comparison!");
                    }
                }
                else if (choice == mainMenuItems[5])
                {
                    if (fingerRelay != null)
                    {
                        Console.WriteLine($"{fingerRelay.TemplateCount} Templates");
                    }
                    else
                    {
                        Console.WriteLine("FingerRelay non-existant");
                    }
                }
                else if (choice == mainMenuItems[6])
                {
                    var dele = Log.QueryMultiChoice("Clear what?", new List <string>()
                    {
                        "Users", "Templates", "Both", "Go back"
                    });
                    switch (dele)
                    {
                    case "Users":
                        fingerAccounts = new List <FingerAccount>();
                        break;

                    case "Templates":
                        fingerRelay.SendCommandGetData(FingerRelay.Commands.CLEAR_DATABASE);
                        break;

                    case "Both":
                        fingerAccounts = new List <FingerAccount>();
                        fingerRelay.SendCommandGetData(FingerRelay.Commands.CLEAR_DATABASE);
                        break;

                    case "Go back":
                        break;
                    }
                }
                else if (choice == mainMenuItems[7])
                {
                    SaveJson().GetAwaiter();
                }
                else if (choice == mainMenuItems[8])
                {
                    FingerWizard.DeleteWizard();
                }
            }
        }