示例#1
0
        public static void CheckSailAndPriceUpdateStartThread(int id)
        {
            Color.WriteLineColor("Запущено обновление информации по штрихкоду " + CheckThisBar.GetBarOnID(id), ConsoleColor.DarkYellow);

            CheckThisBar.UpdatePrice(id);

            CheckThisBar.GetLsTradeSail(id);

            CheckThisBar.GetUkmSailParametrs(id);

            CheckThisBar.UpdateCountOut(id);
        }
示例#2
0
        public static void GetSailAndPrice(int id)
        {
            Color.WriteLineColor("[Thread] GetSailAndPrice запущен... ", ConsoleColor.DarkYellow);

            Color.WriteLineColor("Запущено обновление информации по штрихкоду " + CheckThisBar.GetBarOnID(id), ConsoleColor.DarkYellow);

            CheckThisBar.UpdatePrice(id);

            CheckThisBar.GetLsTradeSail(id);

            CheckThisBar.GetUkmSailParametrs(id);

            CheckThisBar.UpdateCountOut(id);

            CheckSail.CheckAll();

            Color.WriteLineColor("[Thread] GetSailAndPrice завершен.", ConsoleColor.DarkYellow);
        }
示例#3
0
        public static void parse(string p_id, int com, string msg, User user, System.Net.Sockets.Socket r_client)
        {
            switch (p_id)
            {
            case "LsTradeAgent":
                switch (com)
                {
                case 0:
                    Color.WriteLineColor(msg, ConsoleColor.Blue);
                    Color.WriteLineColor("Модуль связи с LsTrade отключен!", ConsoleColor.Red);
                    Thread.Sleep(3000);
                    r_client.Disconnect(false);
                    r_client.Close();
                    Server.clients.Remove(r_client);
                    break;

                case 1:
                    user.userid = 2;
                    Server.clients[r_client] = p_id;
                    Color.WriteLineColor("Модуль связи с LsTrade загружен!", ConsoleColor.Cyan);
                    Msg.SendUser("LsTradeAgent", "LS", 1, "Идентификация пройдена.");
                    break;
                }
                break;

            case "PrioritySale":

                user.userid = 0;

                switch (com)
                {
                case 0:
                    string[] split_data = msg.Replace("\0", "").Replace(" ", "").Split(new Char[] { ':' });

                    var username = split_data[0];
                    var hash     = split_data[1];

                    using (MySqlConnection conn = new MySqlConnection(Connector.BarrierStringConnecting))
                        using (MySqlCommand cmd = new MySqlCommand("SELECT username,hash FROM users WHERE username = '******' AND hash = '" + hash + "'", conn))
                            using (MySqlDataReader dr = cmd.ExecuteReader())
                            {
                                try { conn.Open(); }
                                catch (MySqlException ex)
                                {
                                    Log.LogWriteDebug("[USERAUTH] [" + ex.Number + "] [" + ex.Message + "]");

                                    switch (ex.Number)
                                    {
                                    case 1042:
                                        Server.clients[r_client] = username;
                                        Msg.SendUser(username, "PrioritySale", 4, "         Mysql недоступен");
                                        break;

                                    default:
                                        Server.clients[r_client] = username;
                                        Msg.SendUser(username, "PrioritySale", 4, "         Код: " + ex.Number);
                                        break;
                                    }
                                }

                                if (dr == null)
                                {
                                    Log.Write("Запрос вернул null", "Exception", "Exception");
                                    Log.ExcWrite("[AUTH] Запрос вернул null");
                                    return;
                                }

                                if (dr.Read())
                                {
                                    Server.clients[r_client] = username;
                                    Color.WriteLineColor(username + " Добавлен!", ConsoleColor.Cyan);
                                    Msg.SendUser(username, "PrioritySale", 1, username);
                                    user.username = username;
                                    Packages.connector.ExecuteNonQuery("UPDATE `users` SET `online`='1',`ip`='" + IPAddress.Parse(((IPEndPoint)r_client.RemoteEndPoint).Address.ToString()) + "' WHERE `username`='" + username + "'");
                                    Log.Write(username, "[AUTH_S]", "AUTHLOG");
                                }
                                else
                                {
                                    Server.clients[r_client] = username;
                                    Msg.SendUser(username, "PrioritySale", 0, "Идентификация не пройдена.");
                                    Color.WriteLineColor(username + " авторизация неудачна", ConsoleColor.Red);
                                    Log.Write(username, "[AUTH_F]", "AUTHLOG");
                                }

                                Color.WriteLineColor(username + " " + hash, ConsoleColor.DarkGray);
                                break;
                            }

                case 4:
                case 5:
                    Int32 _LastId;

                    if (PriorityAddBarcode(msg, user, out _LastId))
                    {
                        Color.WriteLineColor("Присвоен уникальный номер " + _LastId, ConsoleColor.Green);

                        Thread th = new Thread(delegate() {
                            CheckThisBar.GetSailAndPrice(_LastId);
                        });;
                        th.Name = "GetUkmSailParametrs";
                        th.Start();
                    }
                    break;

                case 6:
                    Color.WriteLineColor("[" + user.username + "] " + msg, ConsoleColor.DarkGreen);

                    if (msg.Contains("отказался"))
                    {
                        Log.Write("[" + user.username + "] " + msg, "[DECLINE]", "Decline");
                    }
                    else if (msg.Contains("выполнил"))
                    {
                        CheckStatusUpdate(msg);
                    }

                    foreach (DicEnt de in Server.clients)
                    {
                        Msg.SendUser((de.Value).ToString(), "PrioritySale", 9, Packages.StatusString + ";" + DateTime.Now);
                    }
                    break;

                case 7:
                    Color.WriteLineColor("Есть новые сообщение на доске объявлений.Отправка уведомления...", ConsoleColor.Yellow);

                    foreach (DicEnt de in Server.clients)
                    {
                        Msg.SendUser((de.Value).ToString(), "PrioritySale", 6, "");
                    }
                    break;

                case 8:
                    Color.WriteLineColor("Версия очередности обновлена у клиента " + user.username, ConsoleColor.Yellow);
                    break;

                case 9:
                    if (msg == StatusString)
                    {
                        Color.WriteLineColor("Версия очередности у клиента " + user.username + " проверена успешно!", ConsoleColor.Green);
                    }
                    else
                    {
                        Color.WriteLineColor("Версия очередности устарела у клиента " + user.username + ".", ConsoleColor.DarkYellow);
                        Msg.SendUser(user.username, "PrioritySale", 9, Packages.StatusString + ";" + DateTime.Now);
                    }
                    break;
                }
                break;

            case "BalanceModule":
                switch (com)
                {
                case 0:
                    user.userid = 1;
                    Server.clients[r_client] = "BalanceModule";
                    Color.WriteLineColor("Модуль проверки весов загружен!", ConsoleColor.Cyan);
                    Msg.SendUser("BalanceModule", "BS", 1, "Идентификация пройдена.");
                    break;

                case 1:
                    Color.WriteLineColor(msg, ConsoleColor.Cyan);
                    break;

                case 2:
                    user.userid = 1;
                    Server.clients[r_client] = "BalanceModule";
                    break;

                case 9:
                    Color.WriteLineColor("Модуль проверки весов отключен!", ConsoleColor.Red);
                    Thread.Sleep(3000);
                    r_client.Disconnect(false);
                    r_client.Close();
                    Server.clients.Remove(r_client);
                    break;
                }
                break;

            case "User":
                switch (com)
                {
                case 0000:
                    Color.WriteLineColor(Server.clients[r_client] + ": Завершение сеанса.", ConsoleColor.Red);
                    Packages.connector.ExecuteNonQuery("UPDATE `barrierserver`.`users` SET `online`='0' WHERE `username`='" + user.username + "'");
                    Thread.Sleep(3000);
                    r_client.Disconnect(false);
                    r_client.Close();
                    Server.clients.Remove(r_client);
                    break;
                }
                break;
            }
        }
        static void Main(string[] args)
        {
            _handler += new EventHandler(Handler);
            SetConsoleCtrlHandler(_handler, true);

            if (System.Diagnostics.Process.GetProcessesByName(Application.ProductName).Length > 1)
            {
                Color.WriteLineColor("\n", ConsoleColor.Red);
                Color.WriteLineColor("Приложение уже запущено!", ConsoleColor.Red);
                Color.WriteLineColor("\n", ConsoleColor.Red);
                Color.WriteLineColor("Запускаю завершение работы...", ConsoleColor.Red);
                Color.WriteLineColor("\n", ConsoleColor.Red);

                another_run();
            }
            else
            {
                CheckDll();

                ShowWindow(ConsoleHandle, SW_MAXIMIZE);

                Packages.connector.ExecuteNonQuery(@"DELETE FROM `log`");

                Logo LogoLoad = new Logo();

                LogoLoad.LogoLoad();

                Server.ServerStart();

                Thread th = new Thread(delegate()
                {
                    Thread.Sleep(3000);

                    while (true)
                    {
                        Color.WriteLineColor("[THREAD] CheckSailAndPriceUpdate запущен", ConsoleColor.DarkYellow);

                        CheckThisBar.CheckSailAndPriceUpdate();

                        CheckSail.CheckAll();

                        Color.WriteLineColor("[THREAD] CheckSailAndPriceUpdate завершен", ConsoleColor.DarkYellow);

                        Int32 timeScheduler = 30;
                        try { timeScheduler = (Int32.Parse(Config.GetParametr("timeScheduler"))); }
                        catch (Exception exc) { Color.WriteLineColor("[timeScheduler]" + exc.Message, ConsoleColor.Red); }

                        Color.WriteLineColor("Запланирована проверка через " + timeScheduler + " минут.", ConsoleColor.Blue);
                        Thread.Sleep(timeScheduler * 60000);
                        Color.WriteLineColor("Начало запланированной проверки", ConsoleColor.Blue);
                    }
                });
                th.Name = "Проверка общая";
                th.Start();

                Thread tha = new Thread(delegate()
                {
                    Thread.Sleep(120000);
                    CheckTasks.StartCheck();
                });
                tha.Name = "Проверка задач";
                tha.Start();

                Thread ths = new Thread(delegate()
                {
                    while (true)
                    {
                        Command.SwitchCommand("uptime");
                        Thread.Sleep(3600000);
                    }
                });
                ths.Name = "Проверка общая";
                ths.Start();
            }

            Thread.Sleep(1000);

            while (true)
            {
                Color.WriteLineColor("\nВведите комманду:", ConsoleColor.Green);

                var com = Console.ReadLine().ToLower();

                Color.WriteLineColor(Command.SwitchCommand(com), ConsoleColor.Yellow);
            }
        }