Esempio n. 1
0
        private bool CheckMacAddress()
        {
            ShowMessage = "验证终端设置绑定的Mac地址";
            //TODO:验证Mac地址
            ShowMessage = "获取本地MAC地址";
            List <string> localMacAdd;

            try
            {
                localMacAdd = GetMacAddress.GetLocalAddress();
            }
            catch (Exception ex)
            {
                ShowMessage = "本地MAC获取失败:" + ex.Message;
                return(false);
            }
            ShowMessage = "本地MAC获取成功,获取SystemObject单例";
            SystemObject clientObject = SystemObject.GetInstance();

            if (clientObject.ClientSetting == null)
            {
                ShowMessage = "获取终端设置失败, 请检查终端编号是否正确。";
                return(false);
            }
            ShowMessage = "获取SystemObject单例获取成功";

            if (!string.IsNullOrEmpty(clientObject.ClientSetting.TerminalMacAddress))//mac地址不为空
            {
                foreach (string macAdd in localMacAdd)
                {
                    if (clientObject.ClientSetting.TerminalMacAddress == macAdd)
                    {
                        return(true);
                    }
                }
                ShowMessage = "Mac地址验证失败,重新设置终端编号,您也可以通过本地设置程序强行将Mac地址和终端编号锁定";
                return(false);
            }
            if (localMacAdd.Count > 0)
            {
                //TODO:更新终端设置
                clientObject.ClientSetting.TerminalMacAddress = localMacAdd[0];
            }
            try
            {
                if (!string.IsNullOrEmpty(TerminalOperatorService.UpdateTeminalSetting(clientObject.ClientSetting)))
                {
                    ShowMessage = "尝试锁定终端设置的时候出现错误。";
                    return(false);
                }
                return(true);
            }
            catch
            {
                ShowMessage = "尝试锁定终端设置的时候出现错误。";
                return(false);
            }
        }
 private void button2_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(this.txtTerminalNum.Text))
     {
         toolTip1.SetToolTip(txtTerminalNum, "请输入终端号");
         toolTip1.Show("请输入终端号", txtTerminalNum, 5000);
         return;
     }
     if (terminal == null)
     {
         toolTip1.SetToolTip(txtTerminalNum, "终端编号错误");
         toolTip1.Show("终端编号错误", txtTerminalNum, 5000);
         return;
     }
     else if (terminal.TerminalMacAddress != GetMacAddress.GetLocalAddress()[0])
     {
         DialogResult result = MessageBox.Show("本机MAC地址和该编号绑定的MAC地址不一致,程序将只更新服务器上的配置,而不将编号保存到本地,是否继续?", "提示", MessageBoxButtons.YesNo);
         if (result == System.Windows.Forms.DialogResult.Yes)
         {
             GetNewConfig();
             if (SeatManage.Bll.ClientConfigOperate.UpdateTerminal(baseConfig.WCFConnString, terminal))
             {
                 lblResultMessage.Text = "修改成功";
             }
             else
             {
                 lblResultMessage.Text = "修改失败";
             }
         }
     }
     else
     {
         baseConfig.TerminalNum = this.txtTerminalNum.Text;
         if (!ReadSeatClientConfig.SaveConfig(baseConfig))
         {
             MessageBox.Show("文件保存失败,请检查配置文件的属性是否为只读。");
         }
         GetNewConfig();
         if (SeatManage.Bll.ClientConfigOperate.UpdateTerminal(baseConfig.WCFConnString, terminal))
         {
             lblResultMessage.Text = "修改成功";
         }
         else
         {
             lblResultMessage.Text = "修改失败,详情见错误日志";
         }
     }
 }
Esempio n. 3
0
        static void Main()
        {
            Console.WriteLine("skreven linje");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // authenticate
            FormelSamling form  = new FormelSamling();
            Login         login = new Login();

            //SQL.SqlConnect();
            GetMacAddress.GetPhysicalAddress();

            // run program
            Application.Run(login);
        }
Esempio n. 4
0
        private void SeatManageConfigTool_Load(object sender, EventArgs e)
        {
            Code.HostConfig             hostconfig          = new Code.HostConfig();
            Code.ClientBasicConfig      clientconfig        = new Code.ClientBasicConfig();
            Code.CardReaderBasicConfig  cardReaderConfig    = new Code.CardReaderBasicConfig();
            Code.WebConfigSetting       webConfigSeeting    = new Code.WebConfigSetting();
            Code.LeaveClientBesicConfig leaveConfigSetting  = new Code.LeaveClientBesicConfig();
            Code.DeviceSettingConfig    deviceSettingConfig = new Code.DeviceSettingConfig();
            Code.ShutDownConfig         shutDownConfig      = new Code.ShutDownConfig();
            if (Code.ReadSeatHostConfigV3.ReadConfig(ref hostconfig))
            {
                foreach (string server in hostconfig.HostServer)
                {
                    if (server == "WcfHost")
                    {
                        cb_WCF.Checked = true;
                    }
                    else if (server == "MonitorService")
                    {
                        cb_Watch.Checked = true;
                    }
                    else if (server == "DataTransferService")
                    {
                        cb_DT.Checked = true;
                    }
                }
                txt_DBIP.Text               = hostconfig.DBIP;
                txt_DBName.Text             = hostconfig.DBName;
                txt_DBpw.Text               = hostconfig.DBPW;
                txt_DBUser.Text             = hostconfig.DBUser;
                txt_SeverWCFConnString.Text = hostconfig.WCFString;
                txt_weixinendportwcf.Text   = hostconfig.WeChatWCFString;
                txt_FilePath.Text           = hostconfig.MediaFilePath;
                txt_ServerSchoolNo.Text     = hostconfig.SchoolNo;
                txt_ServerLoopTime.Text     = hostconfig.LoopTime;
                txt_Uploadtime.Text         = hostconfig.UploadTime;
                if (Code.WebConfig.ReadConfig(ref webConfigSeeting))
                {
                    cb_web_pw_change.Checked = webConfigSeeting.IsChangePW;
                }
                else
                {
                    MessageBox.Show("无法自动获取管理网站配置文件,请确保和Host服务文件夹放置在同一目录,并且文件夹为“SeatManageWebV5”");
                    gb_web.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[3].Controls)
                {
                    c.Enabled = false;
                }
            }
            else if (Code.ReadSeatClientConfig.GetSeatClientBaseConfig(ref clientconfig) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Select"))
            {
                clientmode = "Select";
                txt_clientwcfstring.Text = clientconfig.WCFConnString;
                txt_schoolno.Text        = clientconfig.SchoolNo;
                txt_campusno.Text        = clientconfig.CampusNo;
                txt_deviceno.Text        = clientconfig.TerminalNum;
                txt_defualtmedia.Text    = clientconfig.DefaultMedia;
                txt_adloop.Text          = clientconfig.SCLoopTime;
                txt_sentloop.Text        = clientconfig.SentStatusTime;
                txt_update.Text          = clientconfig.UpdateTime;
                txt_mac.Text             = GetMacAddress.GetLocalAddress()[0];
                gb_xzx.Enabled           = false;
                gb_mh.Enabled            = false;
                gb_fk.Enabled            = false;
                gb_gz.Enabled            = false;
                gb_cut.Enabled           = false;
                gb_dz.Enabled            = false;

                switch (cardReaderConfig.CardReaderTye)
                {
                case 0: rb_mh.Checked = true; break;

                case 1: rb_xzx.Checked = true; break;

                case 2: rb_fk.Checked = true; break;

                case 3: rb_gz.Checked = true; break;

                case 4: rb_cut.Checked = true; break;

                case 5: rb_dz.Checked = true; break;
                }
                if (cardReaderConfig.CardID10Or16 == 10)
                {
                    fk_10.Checked = true;
                    rb_10.Checked = true;
                }
                else
                {
                    fk_16.Checked = true;
                    rb_16.Checked = true;
                }
                cb_Isbeep.Checked     = cardReaderConfig.IsBeep;
                fk_port.Text          = cardReaderConfig.FKport;
                txt_xzx_ip.Text       = cardReaderConfig.XZX_ServerEndPort;
                txt_xzx_sys.Text      = cardReaderConfig.XZX_SysCode;
                txt_xzx_tre.Text      = cardReaderConfig.XZX_TerminalNo;
                xzx_addreader.Checked = cardReaderConfig.XZX_AddReader;
                xzx_off.Checked       = cardReaderConfig.XZX_Offline;
                if (cardReaderConfig.Hook_isCardNo)
                {
                    rb_gz_cardno.Checked = true;
                }
                else
                {
                    rb_gz_cardid.Checked = true;
                }
                if (cardReaderConfig.XZX_IsOnelyReaderCardId)
                {
                    rb_xzx_readcardid.Checked = true;
                }
                else
                {
                    rb_xzx_readcardno.Checked = true;
                }
                cb_change.Checked = cardReaderConfig.CardIDIsChange;
                fk_change.Checked = cardReaderConfig.CardIDIsChange;
                cb_add0.Checked   = cardReaderConfig.IsAdd0;
                fk_add0.Checked   = cardReaderConfig.IsAdd0;

                if (Code.DeviceSetting.GetDeviceSetting(ref deviceSettingConfig))
                {
                    txt_d_IP.Text       = deviceSettingConfig.IP;
                    txt_d_dns.Text      = deviceSettingConfig.DNS;
                    txt_d_getway.Text   = deviceSettingConfig.Gateway;
                    txt_d_mask.Text     = deviceSettingConfig.Mask;
                    txt_pc_name.Text    = deviceSettingConfig.PCName;
                    cb_staticIP.Checked = deviceSettingConfig.IsStaticIP;
                }
                if (Code.DeviceSetting.GetShotDownSetting(ref shutDownConfig))
                {
                    cb_sd.Checked = shutDownConfig.IsUsed;
                    txt_sd_h.Text = shutDownConfig.ShutDownHour;
                    txt_sd_m.Text = shutDownConfig.ShutDownMin;
                    txt_sd_s.Text = shutDownConfig.ShutDownWaitSec;
                }
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                tabControl1.SelectedIndex = 1;
            }
            else if (Code.LeaveClientConfig.GetLeaveClientConfig(ref leaveConfigSetting) && Code.CardReaderConfig.GetCardReaderBaseConfig(ref cardReaderConfig, "Leave"))
            {
                clientmode             = "Leave";
                txt_leave_wcfconn.Text = leaveConfigSetting.WCFConnString;
                switch (leaveConfigSetting.LeaveMode)
                {
                case "0": rb_leave_s.Checked = true; break;

                case "1": rb_leave_sl.Checked = true; break;

                case "2": rb_leave_l.Checked = true; break;

                case "3": rb_leave_s.Checked = true; break;
                }
                if (leaveConfigSetting.SetUpMode == "1")
                {
                    rb_win_max.Checked = true;
                }
                else
                {
                    rb_win_min.Checked = true;
                }
                gb_xzx.Enabled = false;
                gb_mh.Enabled  = false;
                gb_fk.Enabled  = false;
                gb_gz.Enabled  = false;
                gb_cut.Enabled = false;
                gb_dz.Enabled  = false;

                switch (cardReaderConfig.CardReaderTye)
                {
                case 0: rb_mh.Checked = true; break;

                case 1: rb_xzx.Checked = true; break;

                case 2: rb_fk.Checked = true; break;

                case 3: rb_gz.Checked = true; break;

                case 4: rb_cut.Checked = true; break;

                case 5: rb_dz.Checked = true; break;
                }
                if (cardReaderConfig.CardID10Or16 == 10)
                {
                    fk_10.Checked = true;
                    rb_10.Checked = true;
                }
                else
                {
                    fk_16.Checked = true;
                    rb_16.Checked = true;
                }
                cb_Isbeep.Checked     = cardReaderConfig.IsBeep;
                fk_port.Text          = cardReaderConfig.FKport;
                txt_xzx_ip.Text       = cardReaderConfig.XZX_ServerEndPort;
                txt_xzx_sys.Text      = cardReaderConfig.XZX_SysCode;
                txt_xzx_tre.Text      = cardReaderConfig.XZX_TerminalNo;
                xzx_addreader.Checked = cardReaderConfig.XZX_AddReader;
                xzx_off.Checked       = cardReaderConfig.XZX_Offline;
                if (cardReaderConfig.Hook_isCardNo)
                {
                    rb_gz_cardno.Checked = true;
                }
                else
                {
                    rb_gz_cardid.Checked = true;
                }
                if (cardReaderConfig.XZX_IsOnelyReaderCardId)
                {
                    rb_xzx_readcardid.Checked = true;
                }
                else
                {
                    rb_xzx_readcardno.Checked = true;
                }
                cb_change.Checked = cardReaderConfig.CardIDIsChange;
                fk_change.Checked = cardReaderConfig.CardIDIsChange;
                cb_add0.Checked   = cardReaderConfig.IsAdd0;
                fk_add0.Checked   = cardReaderConfig.IsAdd0;
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                tabControl1.SelectedIndex = 2;
            }
            else
            {
                MessageBox.Show("获取配置文件失败,请把配置工具拷贝到宿主服务或者终端的根目录下,再次尝试!");
                foreach (Control c in tabControl1.TabPages[0].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[1].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[2].Controls)
                {
                    c.Enabled = false;
                }
                foreach (Control c in tabControl1.TabPages[3].Controls)
                {
                    c.Enabled = false;
                }
                btnBackupProgram.Enabled  = false;
                tabControl1.SelectedIndex = 4;
            }
        }
Esempio n. 5
0
        private static int DecodeDataDesktop(Dictionary <string, string> data, Socket sock)
        {
            Dictionary <string, string>   DatatoSend = new Dictionary <string, string>();
            KeyValuePair <string, string> r          = new KeyValuePair <string, string>();

            try
            {
                if (data["Type"] == "MacAddress")
                {
                    //Log("mac received " + data["value"]);
                    var           mac = data["value"].Split(',');
                    GetMacAddress gt  = new GetMacAddress();
                    r = gt.GetMac(mac);
                    if (r.Key != null)
                    {
                        Console.WriteLine("mac from database: " + r.Key + "mac : " + r.Value);
                        if (!DesktopList.Contains(r))
                        {
                            DesktopList.Add(r.Key, r.Value);
                        }
                        var client = new List <KeyValuePair <Socket, StateObject> >();
                        if (Clients.Any(x => x.Value.MacAddress == r.Key.ToUpper()))
                        {
                            client = Clients.Where(x => x.Value.MacAddress == r.Key.ToUpper()).ToList();
                        }
                        // Console.WriteLine("total clients by same mac addresses: " + client.Count());
                        if (client.Count() > 0)
                        {
                            foreach (var c in client)
                            {
                                ClearSocketDesktop(c.Value.workSocket);
                            }
                        }
                        if (Clients.Any(x => x.Value.workSocket == sock))
                        {
                            var cc = Clients.Where(x => x.Value.workSocket == sock).FirstOrDefault();
                            cc.Value.MacAddress = r.Key.ToUpper();
                        }
                        Console.WriteLine("total clients Desktop CLients: " + Clients.Count());
                        File.AppendAllText(docPath, Environment.NewLine + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString() + "mac from desktop key: " + r.Key + " value: " + r.Value);
                    }
                    else
                    {
                        File.AppendAllText(docPath, Environment.NewLine + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString() + "mac from database key: " + r.Key + " value: " + r.Value);
                        DatatoSend.Add("Type", "Reply");
                        DatatoSend.Add("Status", "404");

                        var    s = JsonSerializer.Serialize(DatatoSend);
                        byte[] b = Encoding.ASCII.GetBytes(s);
                        Send(sock, b);
                        ClearSocketDesktop(sock);
                    }
                    //SendToDesktop(r.Key, r.Value, "Shutdown");
                }
                if (data["Type"] == "Command")
                {
                    var code    = data["Code"];
                    var ccmac   = data["CCmac"].ToUpper();
                    var deskmac = data["Deskmac"].ToUpper();
                    File.AppendAllText(docPath, Environment.NewLine + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString() + "received " + code + " for machine with mac " + ccmac);
                    if (code == "Shutdown")
                    {
                        //Instructions ins = new Instructions();
                        //d = "SystemOffStrategy";

                        try
                        {
                            if (WaitList.ContainsKey(ccmac))
                            {
                                var d = WaitList.Where(x => x.Key == ccmac).Select(x => x.Value).FirstOrDefault();
                                if (d != null)
                                {
                                    var stid     = d.Strategyid;
                                    var stdescid = d.StrategyDescId;
                                    AsyncTcpListener.ReceiveMacFromDesktop(ccmac, "SystemOffStrategy", stid, stdescid);
                                }
                            }
                            DatatoSend.Clear();
                            DatatoSend.Add("Type", "Command");
                            DatatoSend.Add("Code", "ExeShutdown");
                            DatatoSend.Add("CCmac", ccmac.ToUpper());
                            DatatoSend.Add("Deskmac", deskmac.ToUpper());
                            var t = JsonSerializer.Serialize(DatatoSend);
                            File.AppendAllText(docPath, Environment.NewLine + " " + DateTime.Now.ToShortTimeString() + " data sent to desktop client: " + t);
                            Console.WriteLine(DateTime.Now.ToShortTimeString() + " data sent to desktop client: " + t);
                            byte[] b = Encoding.ASCII.GetBytes(t);
                            Send(sock, b);
                        }
#pragma warning disable CS0168 // The variable 'ex' is declared but never used
                        catch (Exception ex)
#pragma warning restore CS0168 // The variable 'ex' is declared but never used
                        {
                            File.AppendAllText(docPath, Environment.NewLine + " " + DateTime.Now.ToShortTimeString() +
                                               " Decode Desktop Data exception under send data to machine " + " " + ex.Message + " " + ex.StackTrace);
                            // Console.WriteLine(ex.Message);
                        }
                    }
                }

                Console.WriteLine(JsonSerializer.Serialize(data.ToList()));
            }
            catch (Exception ex)
            {
                //Log("Error in Decode Desktop data: " + ex.StackTrace);
                File.AppendAllText(docPath, Environment.NewLine + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString() + " Decode Desktop Data exception 2 " + " " + ex.Message + " " + ex.StackTrace);
                //  ClearSocketDesktop(ip, ((IPEndPoint)sock.RemoteEndPoint).Port);
            }
            return(1);
        }
Esempio n. 6
0
        /// <summary>
        /// 验证Mac地址,如果和本地不一致,则说明编号配置错误
        /// </summary>
        /// <returns></returns>
        private bool CheckMacAddress()
        {
            if (EventInitializeMessage != null)
            {
                EventInitializeMessage("验证终端设置绑定的Mac地址");
            }
            //TODO:验证Mac地址

            if (EventInitializeMessage != null)
            {
                EventInitializeMessage("获取本地MAC地址");
            }
            List <string> localMacAdd;

            try
            {
                localMacAdd = GetMacAddress.GetLocalAddress();
            }
            catch (Exception ex)
            {
                EventInitializeMessage("本地MAC获取失败:" + ex.Message);
                return(false);
            }
            if (EventInitializeMessage != null)
            {
                EventInitializeMessage("本地MAC获取成功,获取SystemObject单例");
            }
            SystemObject clientObject = SystemObject.GetInstance();

            if (clientObject.ClientSetting == null)
            {
                if (EventInitializeMessage != null)
                {
                    EventInitializeMessage("获取终端设置失败, 请检查终端编号是否正确。");
                }
                return(false);
            }
            if (EventInitializeMessage != null)
            {
                EventInitializeMessage("获取SystemObject单例获取成功");
            }
            if (!string.IsNullOrEmpty(clientObject.ClientSetting.TerminalMacAddress))//mac地址不为空
            {
                foreach (string macAdd in localMacAdd)
                {
                    if (clientObject.ClientSetting.TerminalMacAddress == macAdd)
                    {
                        return(true);
                    }
                }

                if (EventInitializeMessage != null)
                {
                    EventInitializeMessage("Mac地址验证失败,重新设置终端编号,您也可以通过本地设置程序强行将Mac地址和终端编号锁定");
                }
                return(false);
            }
            else
            {
                if (localMacAdd.Count > 0)
                {
                    //TODO:更新终端设置
                    clientObject.ClientSetting.TerminalMacAddress = localMacAdd[0];
                }
                try
                {
                    if (!ClientConfigOperate.UpdateTerminal(clientObject.ClientSetting))
                    {
                        if (EventInitializeMessage != null)
                        {
                            EventInitializeMessage("尝试锁定终端设置的时候出现错误。");
                        }
                        return(false);
                    }
                    return(true);
                }
                catch
                {
                    if (EventInitializeMessage != null)
                    {
                        EventInitializeMessage("尝试锁定终端设置的时候出现错误。");
                    }
                    return(false);
                }
            }
        }
        private static int DecodeDataDesktop(Dictionary <string, string> data, Socket sock)
        {
            string d = "";
            Dictionary <string, string>   DatatoSend = new Dictionary <string, string>();
            KeyValuePair <string, string> r          = new KeyValuePair <string, string>();

            try
            {
                if (data["Type"] == "MacAddress")
                {
                    //Log("mac received " + data["value"]);
                    var           mac = data["value"].Split(',');
                    GetMacAddress gt  = new GetMacAddress();
                    r = gt.GetMac(mac);

                    if (r.Key != null)
                    {
                        if (!DesktopList.Contains(r))
                        {
                            DesktopList.Add(r.Key, r.Value);
                        }
                        lock (Clients)
                        {
                            if (Clients.ContainsKey(sock))
                            {
                                var client = Clients[sock];
                                client.MacAddress = data["value"].ToUpper();
                            }
                        }
                    }
                    else
                    {
                        // Log("mac from database key: " + r.Key + " value: " + r.Value);
                        DatatoSend.Add("Type", "Reply");
                        DatatoSend.Add("Status", "404");

                        var    s = JsonSerializer.Serialize(DatatoSend);
                        byte[] b = Encoding.ASCII.GetBytes(s);
                        Send(sock, b);
                        ClearSocketDesktop(sock);
                    }
                    //SendToDesktop(r.Key, r.Value, "Shutdown");
                }
                if (data["Type"] == "Command")
                {
                    var code  = data["Code"];
                    var ccmac = data["CCmac"];
                    // Log("received " + code + " for machine with mac " + ccmac);
                    if (code == "Shutdown")
                    {
                        Instructions ins = new Instructions();
                        d = "SystemOffS";
                    }
                    try
                    {
                        AsynchronousMachineServer.ReceiveMacFromDesktop(ccmac, d);
                    }
#pragma warning disable CS0168 // The variable 'ex' is declared but never used
                    catch (Exception ex)
#pragma warning restore CS0168 // The variable 'ex' is declared but never used
                    {
                        //Log(" Decode Desktop Data exception under send data to machine " + " " + ex.Message + " " + ex.StackTrace);
                        // Console.WriteLine(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                // Log(" Decode Desktop Data exception 2 " + " " + ex.Message + " " + ex.StackTrace);
                //  ClearSocketDesktop(ip, ((IPEndPoint)sock.RemoteEndPoint).Port);
            }
            return(1);
        }
        /// <summary>
        /// Decodes the data desktop.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="sock">The sock.</param>
        /// please look into the method for data reference
        /// <returns>System.Int32.</returns>
        private static async Task <int> DecodeDataDesktop(Dictionary <string, string> data, Socket sock)
        {
            GetMacAddress gt = new GetMacAddress();
            Dictionary <string, string>   DatatoSend = new Dictionary <string, string>();
            KeyValuePair <string, string> r          = new KeyValuePair <string, string>();

            try
            {
                if (data["Type"] == "MacAddress")
                {
                    //Log("mac received " + data["value"]);
                    var mac = data["value"].Split(',');

                    r = gt.GetMac(mac);
                    if (r.Key != null)
                    {
                        loggerFile.Debug("mac from database: " + r.Key + " mac of machine : " + r.Value);
                        if (!DesktopList.Contains(r))
                        {
                            DesktopList.Add(r.Key, r.Value);
                        }
                        var client = new List <KeyValuePair <Socket, StateObject> >();
                        if (Clients.Any(x => x.Value.MacAddress == r.Key.ToUpper()))
                        {
                            client = Clients.Where(x => x.Value.MacAddress == r.Key.ToUpper()).ToList();
                        }
                        // loggerFile.Debug("total clients by same mac addresses: " + client.Count());
                        if (client.Count() > 0)
                        {
                            foreach (var c in client)
                            {
                                ClearSocketDesktop(c.Value.workSocket);
                            }
                        }
                        if (Clients.Any(x => x.Value.workSocket == sock))
                        {
                            var cc = Clients.Where(x => x.Value.workSocket == sock).FirstOrDefault();
                            cc.Value.MacAddress = r.Key.ToUpper();
                        }
                        DatatoSend.Add("Type", "MacAddress");
                        DatatoSend.Add("Deskmac", r.Key);
                        var    s = System.Text.Json.JsonSerializer.Serialize(DatatoSend);
                        byte[] b = Encoding.ASCII.GetBytes(s);
                        Send(sock, b);
                        loggerFile.Debug("total clients Desktop CLients: " + Clients.Count());

                        loggerFile.Debug("mac from desktop key: " + r.Key + " value: " + r.Value);
                    }
                    else
                    {
                        DatatoSend.Add("Type", "Reply");
                        DatatoSend.Add("Status", "404");
                        var    s = System.Text.Json.JsonSerializer.Serialize(DatatoSend);
                        byte[] b = Encoding.ASCII.GetBytes(s);
                        Send(sock, b);
                        ClearSocketDesktop(sock);
                        try
                        {
                            loggerFile.Debug(Environment.NewLine + DateTime.Now.ToLongDateString() + " " +
                                             DateTime.Now.ToLongTimeString() + " desktop mac from database key: " +
                                             r.Key + " value: " + r.Value);
                        }
                        catch (Exception) { }
                    }
                    //SendToDesktop(r.Key, r.Value, "Shutdown");
                }
                if (data["Type"] == "Command")
                {
                    var code    = data["Code"];
                    var ccmac   = data["CCmac"].ToUpper();
                    var deskmac = data["Deskmac"].ToUpper();

                    if (code == "Shutdown")
                    {
                        try
                        {
                            if (WaitList.ContainsKey(ccmac))
                            {
                                var d = WaitList.Where(x => x.Key == ccmac).Select(x => x.Value).FirstOrDefault();
                                if (d != null)
                                {
                                    var stid     = d.Strategyid;
                                    var stdescid = d.StrategyDescId;
                                    var instr    = d.Inst;
                                    var equipid  = d.EquipmentId;
                                    await AsyncTcpListener.ReceiveMacFromDesktop(ccmac, "CloseStrategy", stid, stdescid, instr, equipid);
                                }
                                WaitList.Remove(ccmac);
                            }

                            DatatoSend.Clear();
                            DatatoSend.Add("Type", "Command");
                            DatatoSend.Add("Code", "ExeShutdown");
                            DatatoSend.Add("CCmac", ccmac.ToUpper());
                            DatatoSend.Add("Deskmac", deskmac.ToUpper());
                            //DatatoSend.Add("isDev","on");
                            var t = System.Text.Json.JsonSerializer.Serialize(DatatoSend);

                            byte[] b = Encoding.ASCII.GetBytes(t);
                            Send(sock, b);
                            //loggerFile.Debug(DateTime.Now.ToLongTimeString() + " data sent to desktop client: " + t);
                            //loggerFile.Debug(Environment.NewLine + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "received " + code + " for machine with mac " + ccmac);
                            //loggerFile.Debug(Environment.NewLine + " " + DateTime.Now.ToLongTimeString() + " data sent to desktop client: " + t);
                        }
#pragma warning disable CS0168 // The variable 'ex' is declared but never used
                        catch (Exception ex)
#pragma warning restore CS0168 // The variable 'ex' is declared but never used
                        {
                            loggerFile.Debug(Environment.NewLine + " " + DateTime.Now.ToLongTimeString() +
                                             " Decode Desktop Data exception under send data to machine " + " " + ex.Message + " " + ex.StackTrace);
                            // Console.WriteLine(ex.Message);
                        }
                    }
                }

                if (data["Type"] == "DesktopEvent")
                {
                    var deskmac      = data["Deskmac"].ToString();
                    var action       = data["Action"].ToString();
                    int affectedRows = await gt.SaveInactiveDesktopAsync(deskmac, action);

                    var mes = new Dictionary <string, string>
                    {
                        { "Action", action }, { "Type", "DesktopEvent" }
                    };
                    AsyncTcpListener.SendDesktopEventToWebsocket(deskmac, mes);
                }
                Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(data.ToList()));
            }
            catch (Exception ex)
            {
                //Log("Error in Decode Desktop data: " + ex.StackTrace);
                loggerFile.Debug(Environment.NewLine + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + " Decode Desktop Data exception 2 " + " " + ex.Message + " " + ex.StackTrace);
                //  ClearSocketDesktop(ip, ((IPEndPoint)sock.RemoteEndPoint).Port);
            }
            return(1);
        }