Ejemplo n.º 1
0
 public void DBAdapter(object SQL)
 {
     MyInvoke mi = new MyInvoke(miCMDSQL);
     MyInvoke end = new MyInvoke(miEND);
     MainForm f1 = new MainForm();
     UpdateItemInfo uii = new UpdateItemInfo(f1.GetItemInfo);
     DataSet ds = new DataSet();
     MySqlConnection Conn = new MySqlConnection(MainForm.GetConnStr());
     MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
     MySqlDataAdapter adp = new MySqlDataAdapter(SQL.ToString(), Conn);
     try
     {
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         adp.Fill(ds);
         this.Invoke(uii, ds);
         this.Invoke(mi, "执行成功!");
         Thread.Sleep(1000);
         this.Invoke(end, "true");
     }
     catch (Exception err)
     {
         ItemInfo.Stat = false;
         this.Invoke(mi, "执行失败!");
         this.Invoke(end, err.Message);
     }
 }
Ejemplo n.º 2
0
 public void DBCMD(object SQL)
 {
     MyInvoke mi = new MyInvoke(miCMDSQL);
     MyInvoke end = new MyInvoke(miEND);
     MySqlConnection Conn = new MySqlConnection(MainForm.GetConnStr());
     MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
     MySqlCommand cmd = new MySqlCommand(SQL.ToString(), Conn);
     try
     {
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         cmd.ExecuteNonQuery();
         cmd.Dispose();
         this.Invoke(mi, "执行成功!");
         Thread.Sleep(1500);
         this.Invoke(end, "true");
     }
     catch (Exception err)
     {
         this.Invoke(mi, "执行失败!");
         this.Invoke(end, err.Message);
     }
     finally
     {
         Conn.Close();
     }
 }
Ejemplo n.º 3
0
 private void Execute(object sender)
 {
     MyInvoke mi = new MyInvoke(miExecute);
     string[] SQLS = GetValues("[^\\n\\r;]+;", SqlTextBox.Text.Trim());
     MySqlConnection Conn = new MySqlConnection(MainForm.GetConnStr());
     MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
     ResaultDataSet = new DataSet[SQLS.Length];
     try
     {
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         //ResaultList.Items.Clear();
         for(int i=0;i<SQLS.Length;i++)
         {
             try
             {
                 MySqlDataAdapter adp = new MySqlDataAdapter(SQLS[i].ToString(), Conn);
                 ResaultDataSet[i] = new DataSet();
                 adp.Fill(ResaultDataSet[i]);
                 //ResaultList.Items.Add((i+1).ToString() + "-成功");
                 this.Invoke(mi, (i + 1).ToString() + "-成功");
             }
             catch(Exception err)
             {
                 ResaultDataSet[i].Tables.Add(new DataTable("ExecuteResault"));
                 if (err.Message.ToString() == "值不能为空。\r\n参数名: dataReader")
                 {
                     ResaultDataSet[i].Tables[0].Columns.Add("执行结果");
                     ResaultDataSet[i].Tables[0].Rows.Add("命令成功完成。");
                     //ResaultList.Items.Add((i+1).ToString() + "-成功");
                     this.Invoke(mi, (i + 1).ToString() + "-成功");
                 }
                 else
                 {
                     ResaultDataSet[i].Tables[0].Columns.Add("错误信息");
                     ResaultDataSet[i].Tables[0].Rows.Add(new object[] { err.Message });
                     //ResaultList.Items.Add((i+1).ToString() + "-失败");
                     this.Invoke(mi, (i + 1).ToString() + "-失败");
                 }
             }
         }
     }
     catch (Exception err)
     {
         ResaultDataSet[0] = new DataSet();
         ResaultDataSet[0].Tables.Add();
         ResaultDataSet[0].Tables[0].Columns.Add("错误信息");
         ResaultDataSet[0].Tables[0].Rows.Add(new object[] { err.Message });
         //dataGridView1.Columns.Clear();
         //dataGridView1.Rows.Clear();
         //dataGridView1.Columns.Add("ErrInfo", "错误信息");
         //dataGridView1.Rows.Add(err.Message.ToString());
         this.Invoke(mi, "出现错误");
     }
     //ResaultList.SelectedItem = ResaultList.Items[0];
     //ExecuteBtn.Enabled = true;
     this.Invoke(mi, "ExecuteFinished");
 }
Ejemplo n.º 4
0
        public void Startscan(Object state)
        {
            string ip = state.ToString();
            int list = 0;
            threadnum++;
            if (endscan == false)
            {
                    try
                    {
                        IPHostEntry HostA = new IPHostEntry();
                        HostA = Dns.Resolve(ip);
                        string ipt = HostA.HostName.ToString();

                        TcpClient tcp = new TcpClient();
                        tcp.Connect(ipt, int.Parse(textBox2.Text));

                        //list = portlist.Items.Add(port.ToString() + "端口开放" ,false);
                        MyInvoke mi = new MyInvoke(UpdateUIport);
                        this.BeginInvoke(mi, new object[] { ip + "开放" });
                        list = list + 1;

                    }
                    catch
                    {
                        //portlist1.Items.Add(port.ToString() + "端口无法连接");
                        MyInvoke mi = new MyInvoke(UpdateUI);
                        this.BeginInvoke(mi, new object[] { ip + "无法连接" });

                    }
                    finally
                    {
                        Thread.Sleep(0);
                        //loglist.Items.Add("结束线程" + port.ToString());
                        //委托调用
                        MyInvoke mi = new MyInvoke(UpdateUI2);
                        this.BeginInvoke(mi, new object[] { "结束线程" +ip });

                        asyncOpsAreDone.Close();
                        // label5.Text = portnum.ToString();

                        MyInvoke mi3 = new MyInvoke(UpdateUI3);
                        this.BeginInvoke(mi3, new object[] { list.ToString()});
                    }

            }

            if (endscan == true || ip==textBox1.Text)
            {
                // button1.Enabled = true;
                // button2.Enabled = false;
                asyncOpsAreDone.Close();
                MyInvoke mi4 = new MyInvoke(UpdateUI4);
                this.BeginInvoke(mi4, new object[] { "344" });

            }
        }
Ejemplo n.º 5
0
 public void showText(string str)
 {
     if (txt_output.InvokeRequired)
     {
         MyInvoke invoke = new MyInvoke(showText);
         this.Invoke(invoke, str);
     }
     else
     {
         txt_output.Text += str + " [" + DateTime.Now + "]\r\n";
     }
 }
 public void showMsg(string msg)
 {
     {
     //在线程里以安全方式调用控件
     if (receiveMsg.InvokeRequired)
     {
         MyInvoke _myinvoke = new MyInvoke(showMsg);
         receiveMsg.Invoke(_myinvoke, new object[] { msg });
     }
     else
     {
         receiveMsg.AppendText(msg);
     }
     }
 }
Ejemplo n.º 7
0
 public void SearchItem(object key)
 {
     key = key.ToString().Replace("'", "''");
     string SQL = "select entry,name,displayid from item_template where name " + AllAccord[0] + " '"+AllAccord[1] + key.ToString() + AllAccord[1]+"';";
     MyInvoke end = new MyInvoke(miEND);
     SearchResault = new DataSet();
     MySqlConnection Conn = new MySqlConnection(MainForm.GetConnStr());
     MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
     MySqlDataAdapter adp = new MySqlDataAdapter(SQL.ToString(), Conn);
     try
     {
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         adp.Fill(SearchResault);
         this.Invoke(end, "true");
     }
     catch (Exception err)
     {
         this.Invoke(end, err.Message);
     }
 }
Ejemplo n.º 8
0
        public void loadthread()
        {
            MyInvoke mi = new MyInvoke(loadjiedian);

            BeginInvoke(mi);
        }
Ejemplo n.º 9
0
        void Send_Thread_run()
        {
            //分包
            byte[,] packet = new byte[packetSum, 1024];//定义一个二维数组 来分包保存数据
            for (int n = 0; n < packetSum; n++)
            {
                for (int i = 0; i < 1024; i++)
                {
                    packet[n, i] = binchar[n * 1024 + i];
                    if ((binchar.Length - 1) == (n * 1024 + i)) //传送完成
                    {
                        for (int j = i + 1; j < 1024; j++)
                        {
                            packet[n, j] = 0xff;
                        }
                        n = packetSum;
                        break;
                    }
                }
            }
            //最后一包由于可能不满,所以不能像上面一样填充
            //for(int i = 0; i<(binchar.Length - (packetSum-1)*1024),i++)



            Timeout timeout       = new Timeout(5);
            Timeout RcvMsgTimeout = new Timeout(5);

            packetNumber = 1;

            while (true)
            {
                if (state == 1)
                {
                    if (RvcMsgError == true)//如果信息包出错了
                    {
                        MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                        this.BeginInvoke(mi, new Object[] { "信息包通讯失败,请重新下载" });

                        state       = 1;
                        RvcMsgError = false;
                        break;
                    }
                    if (RcvMsgTimeout.IsTimeout())
                    {
                        MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                        this.BeginInvoke(mi, new Object[] { "信息包应答超时,请重新下载" });
                        break;
                    }
                }
                else
                {
                    if (allowSend)
                    {
                        System.Threading.Thread.Sleep(500);//如果不延时 下位机将无法接收到第一个包
                        //label_downState.Text = "下载中";
                        MyInvoke mi = new MyInvoke(updataRvcUI_downloadState);
                        this.BeginInvoke(mi, new Object[] { "下载中" });
                        //timeout.updataLastTime();
                        SendDataPacket(packet, packetNumber); //发送一包数据
                                                              //记录时间

                        allowSend = false;

                        //Thread.Sleep(500); //延时500毫秒
                    }
                    if (packetgError || checkError) //如果是包号出错 或者是校验出错
                    {
                        packetgError = false;
                        checkError   = false;
                        allowSend    = true;
                    }

                    if (packetNumber > packetSum)//全部包都传送了
                    {
                        MyInvoke mi1 = new MyInvoke(updataRvcUI_downloadState);
                        this.BeginInvoke(mi1, new Object[] { "下载完成" });

                        MyInvoke mi2 = new MyInvoke(updataRvcUI_boxshow);
                        this.BeginInvoke(mi2, new Object[] { "下载完成,将自动运行新程序" });


                        state = 3;//下载结束
                        break;
                    }
                }
                //if(timeout.IsTimeout())
                //{
                //    allowSend = true;
                //    if (packetNumber > 1 && timeoutSend ==0) //超时重传数为0,在接收包处置零
                //        packetNumber--;//重传上一个包
                //    if (++timeoutSend>3)
                //    {
                //        state = 1;
                //        packetNumber = 1;
                //        label_downState.Text = "停止下载";
                //        break;
                //       // 3次超时重传后退出下载
                //    }

                //    //超时
                //}

                //if (state != 2) //如果状态不是下载中了 就直接退出下载
                //{
                //    packetNumber = 1;
                //    label_downState.Text = "停止下载";
                //    break;
                //}
            }
        }
Ejemplo n.º 10
0
        private void addText(String addData, int ID)
        {
            MyInvoke mi = new MyInvoke(addTextMethod);

            this.Invoke(mi, addData, ID);
        }
Ejemplo n.º 11
0
        void DoMakeMPQ(object param)
        {
            MyInvoke miUI  = new MyInvoke(miUpdateUI);
            MyInvoke miFin = new MyInvoke(miFinish);
            string   sql   = string.Empty;

            if (ConnInfo.Dbstruct == "3.3.5(TC2)")
            {
                sql = "SELECT entry,class,subclass,SoundOverrideSubclass,material,displayid,InventoryType,sheath FROM item_template ORDER BY entry ASC;";
            }
            //else if (ConnInfo.Dbstruct == "3.1.X")
            //{
            //    sql = "SELECT entry,displayid,InventoryType,sheath FROM item_template ORDER BY entry ASC;";
            //}
            else
            {
                sql = "SELECT entry,class,subclass,unk0,material,displayid,InventoryType,sheath FROM item_template ORDER BY entry ASC;";
            }
            DataSet          ds      = new DataSet();
            MySqlConnection  Conn    = new MySqlConnection(MainForm.GetConnStr());
            MySqlCommand     setname = new MySqlCommand("set names 'gbk';", Conn);
            MySqlDataAdapter adp     = new MySqlDataAdapter(sql, Conn);

            this.Invoke(miUI, "查询物品信息...");
            try
            {
                Conn.Open();
                adp.Fill(ds);
            }
            catch (ThreadAbortException err)
            {
                return;
            }
            catch (Exception err)
            {
                this.Invoke(miFin, "无法查询物品信息。" + err.Message);
                return;
            }
            finally
            {
                Conn.Close();
            }
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count < 1)
                {
                    this.Invoke(miFin, "没有任何物品信息,操作已终止。");
                    return;
                }
            }
            else
            {
                this.Invoke(miFin, "查询物品信息发生错误。");
                return;
            }
            string mastdbcfilename = Application.StartupPath + @"\Data\Item.dbc";
            string dbcfilename     = Application.StartupPath + @"\Item.dbc";

            this.Invoke(miUI, "筛选自定义物品...");
            DataTable dt_items = null;

            if (File.Exists(mastdbcfilename))
            {
                DataTable dt_mastitems = null;
                DataTable dt_additems  = new DataTable();
                try
                {
                    dt_mastitems = LibDBC.GetData(mastdbcfilename);
                    //if (dt_mastitems.Rows.Count == 0 || dt_mastitems.Columns.Count != 8)
                    if (dt_mastitems.Columns.Count != ds.Tables[0].Columns.Count)
                    {
                        this.Invoke(miFin, "Item.dbc格式不正确。\r\n请从服务端dbc目录拷贝此文件到软件Data目录下。");
                        return;
                    }
                    foreach (DataColumn dc in dt_mastitems.Columns)
                    {
                        dt_additems.Columns.Add(dc.ColumnName, dc.DataType);
                    }
                }
                catch (Exception err)
                {
                    this.Invoke(miFin, "无法读取Item.dbc。" + err.Message + "\r\n请从服务端dbc目录拷贝此文件到软件Data目录下。");
                    return;
                }
                try
                {
                    int rowIndex = 0;
                    dt_mastitems.DefaultView.Sort = dt_mastitems.Columns[0].ColumnName + " ASC";
                    dt_mastitems = dt_mastitems.DefaultView.ToTable();
                    for (int i = 0; i < dt_mastitems.Rows.Count; i++)
                    {
                        if (i >= dt_mastitems.Rows.Count)
                        {
                            break;
                        }
                        this.Invoke(miUI, "筛选自定义物品..." + (i * 100 / dt_mastitems.Rows.Count).ToString() + "%");
                        DataRow curdr    = dt_mastitems.Rows[i];
                        bool    isExists = false;
                        for (int j = rowIndex; j < ds.Tables[0].Rows.Count; j++)
                        {
                            DataRow dr = ds.Tables[0].Rows[j];
                            if (int.Parse(dr[0].ToString()) > int.Parse(curdr[0].ToString()))
                            {
                                break;
                            }
                            if (curdr[0].ToString() == dr[0].ToString())
                            {
                                isExists = true;
                                rowIndex = j + 1;
                                break;
                            }
                        }
                        if (!isExists)
                        {
                            dt_additems.Rows.Add(curdr.ItemArray);
                        }
                    }
                    foreach (DataRow dr in dt_additems.Rows)
                    {
                        ds.Tables[0].Rows.Add(dr.ItemArray);
                    }
                    ds.Tables[0].DefaultView.Sort = ds.Tables[0].Columns[0].ColumnName + " ASC";
                    dt_items = ds.Tables[0].DefaultView.ToTable();
                }
                catch (ThreadAbortException err)
                {
                    return;
                }
            }
            else
            {
                this.Invoke(miFin, "文件Item.dbc不存在。\r\n请从服务端dbc目录拷贝此文件到软件Data目录下。");
                return;
            }
            this.Invoke(miUI, "生成DBC文件...");
            try
            {
                LibDBC.SaveData(dbcfilename, dt_items);
            }
            catch (ThreadAbortException err)
            {
                return;
            }
            catch (Exception err)
            {
                this.Invoke(miFin, "无法生成DBC文件。" + err.Message);
                return;
            }
            if (File.Exists(this.fileName))
            {
                try
                {
                    File.Delete(this.fileName);
                }
                catch (ThreadAbortException err)
                {
                    return;
                }
                catch (Exception err)
                {
                    this.Invoke(miFin, "无法替换保存位置的文件。" + err.Message);
                    return;
                }
            }
            try
            {
                int  handle = -1;
                int  pro    = 0x00030200;
                bool b      = false;
                handle = LibMPQ.MpqOpenArchiveForUpdate(this.fileName, 1, 4096);
                if (handle > 0)
                {
                    b = LibMPQ.MpqAddFileToArchive(handle, dbcfilename, @"DBFilesClient\Item.dbc", pro);
                    if (!b)
                    {
                        this.Invoke(miFin, "无法对MPQ添加Item.dbc文件。");
                        return;
                    }

                    b = LibMPQ.MpqCompactArchive(handle);
                    if (!b)
                    {
                        this.Invoke(miFin, "无法编译MPQ文件。");
                        return;
                    }
                    b = LibMPQ.SFileCloseArchive(handle);
                    if (!b)
                    {
                        this.Invoke(miFin, "无法关闭MPQ文件。");
                        return;
                    }
                    try
                    {
                        File.Delete(dbcfilename);
                    }
                    catch
                    { }
                    this.Invoke(miFin, "success");
                    return;
                }
                else
                {
                    this.Invoke(miFin, "获取文件指针错误。");
                    return;
                }
            }
            catch (ThreadAbortException err)
            {
                return;
            }
            catch (Exception err)
            {
                this.Invoke(miFin, "无法生成MPQ文件。" + err.Message);
                return;
            }
        }
Ejemplo n.º 12
0
 //用来往richtextbox框中显示消息
 public void showClientMsg(string msg)
 {
     //在线程里以安全方式调用控件
     if (showinfo.InvokeRequired)
     {
         MyInvoke _myinvoke = new MyInvoke(showClientMsg);
         showinfo.Invoke(_myinvoke, new object[] { msg });
     }
     else
     {
         showinfo.AppendText(msg);
     }
 }
Ejemplo n.º 13
0
        private void Execute(object sender)
        {
            MyInvoke mi = new MyInvoke(miExecute);

            string[]        SQLS    = GetValues("[^\\n\\r;]+;", SqlTextBox.Text.Trim());
            MySqlConnection Conn    = new MySqlConnection(MainForm.GetConnStr());
            MySqlCommand    setname = new MySqlCommand("set names 'gbk';", Conn);

            ResaultDataSet = new DataSet[SQLS.Length];
            try
            {
                Conn.Open();
                setname.ExecuteNonQuery();
                setname.Dispose();
                //ResaultList.Items.Clear();
                for (int i = 0; i < SQLS.Length; i++)
                {
                    try
                    {
                        MySqlDataAdapter adp = new MySqlDataAdapter(SQLS[i].ToString(), Conn);
                        ResaultDataSet[i] = new DataSet();
                        adp.Fill(ResaultDataSet[i]);
                        //ResaultList.Items.Add((i+1).ToString() + "-成功");
                        this.Invoke(mi, (i + 1).ToString() + "-成功");
                    }
                    catch (Exception err)
                    {
                        ResaultDataSet[i].Tables.Add(new DataTable("ExecuteResault"));
                        if (err.Message.ToString() == "值不能为空。\r\n参数名: dataReader")
                        {
                            ResaultDataSet[i].Tables[0].Columns.Add("执行结果");
                            ResaultDataSet[i].Tables[0].Rows.Add("命令成功完成。");
                            //ResaultList.Items.Add((i+1).ToString() + "-成功");
                            this.Invoke(mi, (i + 1).ToString() + "-成功");
                        }
                        else
                        {
                            ResaultDataSet[i].Tables[0].Columns.Add("错误信息");
                            ResaultDataSet[i].Tables[0].Rows.Add(new object[] { err.Message });
                            //ResaultList.Items.Add((i+1).ToString() + "-失败");
                            this.Invoke(mi, (i + 1).ToString() + "-失败");
                        }
                    }
                }
            }
            catch (Exception err)
            {
                ResaultDataSet[0] = new DataSet();
                ResaultDataSet[0].Tables.Add();
                ResaultDataSet[0].Tables[0].Columns.Add("错误信息");
                ResaultDataSet[0].Tables[0].Rows.Add(new object[] { err.Message });
                //dataGridView1.Columns.Clear();
                //dataGridView1.Rows.Clear();
                //dataGridView1.Columns.Add("ErrInfo", "错误信息");
                //dataGridView1.Rows.Add(err.Message.ToString());
                this.Invoke(mi, "出现错误");
            }
            //ResaultList.SelectedItem = ResaultList.Items[0];
            //ExecuteBtn.Enabled = true;
            this.Invoke(mi, "ExecuteFinished");
        }
Ejemplo n.º 14
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //获取计算机当前时间
            int intHour   = DateTime.Now.Hour;
            int intMinute = DateTime.Now.Minute;
            int intSecond = DateTime.Now.Second;

            //获取设定的时间
            int _intHour   = Convert.ToInt32(Text_Time_Hour.Value);
            int _intMinute = Convert.ToInt32(Text_Time_Minute.Value);
            int _intSecond = Convert.ToInt32(Text_Time_Second.Value);

            if (intHour == _intHour && intMinute == _intMinute && intSecond == _intSecond)
            {
                string XmlFilePath = Application.StartupPath + "\\FilePath.xml";

                if (System.IO.File.Exists(XmlFilePath))
                {
                    //创建XML实例
                    XmlDocument xmlDoc = new XmlDocument();
                    //加载XML文件
                    xmlDoc.Load(XmlFilePath);
                    //选择一个匹配的节点
                    XmlNode xn = xmlDoc.SelectSingleNode("FileLists");
                    //获取这个节点的所有子节点
                    XmlNodeList xnl = xn.ChildNodes;

                    string[,] datalist = new string[xnl.Count, 2];
                    //循环读取所有子节点,并显示节点的信息
                    foreach (XmlNode xnf in xnl)
                    {
                        XmlElement xe = (XmlElement)xnf;

                        //想ListView中添加数据
                        //ListViewItem p = new ListViewItem();
                        //p = new ListViewItem(new string[] { xe.GetAttribute("FileName"), xe.GetAttribute("FilePath") });
                        if (System.IO.File.Exists(xe.GetAttribute("FilePath")))
                        {
                            System.IO.FileInfo fi = new System.IO.FileInfo(xe.GetAttribute("FilePath"));

                            //文件包数量
                            string tmp_BagCount = Convert.ToInt32(fi.Length / (long)Text_PackSize.Value).ToString();
                            //最后一个包的大小
                            string tmp_LastBagSize = (fi.Length - Convert.ToInt32(tmp_BagCount) * (long)(Text_PackSize.Value)).ToString();

                            D_StartSendFIle my_D_StartSendFIle = new D_StartSendFIle(StartSendFile);
                            my_D_StartSendFIle.BeginInvoke(
                                false,
                                Text_ServerIP.Text,
                                Text_ServerPort.Value.ToString(),
                                xe.GetAttribute("FilePath"),
                                Text_PackSize.Value.ToString(),
                                tmp_LastBagSize,
                                tmp_BagCount,
                                xe.GetAttribute("FileName"),
                                fi.Length.ToString(),
                                null,
                                null
                                );
                        }
                        else
                        {
                            MyInvoke _myInvoke = new MyInvoke(UpMsgLog);
                            BeginInvoke(_myInvoke, new object[] { "ERROR:" + xe.GetAttribute("FilePath") + "文件不存在!" });
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
 private void GetDBList(object sender)
 {
     MyInvoke mi = new MyInvoke(miGetDBList);
     try
     {
         MySqlConnection Conn = new MySqlConnection(GetConnStr());
         MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
         MySqlDataAdapter adp = new MySqlDataAdapter("SHOW DATABASES;", Conn);
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         adp.Fill(DBListSet);
         this.Invoke(mi, "true");
     }
     catch
     {
         this.Invoke(mi, "false");
     }
 }
Ejemplo n.º 16
0
        //开始抓取节目信息
        private void getInfo()
        {
            MyInvoke mi = new MyInvoke(SetProgressValue);

            string sql = "select * from tv_provider ";
            DataSet ds = DBHelper.ExecuteDataSet(sql);
            DataTable dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                Provider p = new Provider(dr);
                this.BeginInvoke(mi, p.name);
                bool hasInfo = hasInfomation(p.id);
                //没有获取节目信息才往下走

                if (!hasInfo)
                {
                    switch (p.functionname)
                    {
                        case "getInfomation1":
                            try
                            {
                                getInfomation1(p.website, p.id, p.name + "11频道", "01");
                                getInfomation1(p.website, p.id, p.name + "12频道", "03");
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation2":
                            try
                            {
                                getInfomation2(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation3":
                            try
                            {
                                getInfomation3(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation4":
                            try
                            {
                                getInfomation4(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation5":
                            try
                            {
                                getInfomation5(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation6":
                            try { getInfomation6(p.website, p.id, p.name); }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        //到此为止
                        case "getInfomation7":
                            try { getInfomation7(p.website, p.id, p.name); }
                            catch (Exception exc) { error = error + "," + p.name + ":" + p.id; }
                            break;
                        case "getInfomation8":
                            try
                            {
                                getInfomation8(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation9":
                            try
                            {
                                getInfomation9(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation10":
                            try
                            {
                                getInfomation10(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation11":
                            try
                            {
                                getInfomation11(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation12":
                            try
                            {
                                getInfomation12(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation13":
                            try
                            {
                                getInfomation13(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation14":
                            try
                            {
                                getInfomation14(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation15":
                            try
                            {
                                getInfomation15(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation16":
                            try
                            {
                                getInfomation16(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation17":
                            try
                            {
                                getInfomation17(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation18":
                            try
                            {
                                getInfomation18(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;
                        case "getInfomation19":
                            try
                            {
                                getInfomation19(p.website, p.id, p.name);
                            }
                            catch (Exception exc)
                            {
                                error = error + "," + p.name + ":" + p.id;
                            }
                            break;

                    }

                }

            }
            Application.Exit();
            if (!string.IsNullOrEmpty(error))
            {
                MessageBox.Show(error + "抓取错误");
            }
        }
Ejemplo n.º 17
0
 private void TestConn(object strConn)
 {
     MySqlConnection Conn = null;
     Conn = new MySqlConnection(strConn.ToString());
     MyInvoke mi = new MyInvoke(miTestConn);
     try
     {
         Conn.Open();
         this.Invoke(mi, "true");
     }
     catch(Exception err)
     {
         this.Invoke(mi, "false" + err.Message);
     }
     finally
     {
         Conn.Close();
     }
 }
Ejemplo n.º 18
0
 private void GetDBList(object strConn)
 {
     MyInvoke mi = new MyInvoke(miGetDBList);
     try
     {
         MySqlConnection Conn = new MySqlConnection(strConn.ToString());
         MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
         MySqlDataAdapter adp = new MySqlDataAdapter("SHOW DATABASES;", Conn);
         DataSet ds = new DataSet();
         Conn.Open();
         setname.ExecuteNonQuery();
         setname.Dispose();
         adp.Fill(ds);
         DBListInfo.DBList1 = ds;
         this.Invoke(mi, "true");
     }
     catch
     {
         this.Invoke(mi, "false");
     }
 }
Ejemplo n.º 19
0
        public void DoWork(string deliveryId)
        {
            MyInvoke mi = new MyInvoke(dataload(deliveryId));

            this.BeginInvoke(mi);
        }
Ejemplo n.º 20
0
        private void ImageConvertThread()
        {
            if (path1 == null)
            {
                MessageBox.Show("Please select images");
                return;
            }
            if (path2 == null)
            {
                MessageBox.Show("please select save path");
                return;
            }
            FileStream fs = new FileStream(path2, FileMode.Create);

            fs.SetLength(0x40000);
            BmpINFO bmpinfo = new BmpINFO();

            for (int i = 0; i < path1.Length; i++)
            {
                byte[] byteArray = new byte[8];
                //1.获取图片信息
                //FileInfo f = new FileInfo(path1[i]);
                //2将不是bmp格式的图片转换为bmp格式
                string ImgType;
                string ImagePath = path2.Substring(0, path2.LastIndexOf("\\") + 1);
                //获取图片类型
                Image img = System.Drawing.Image.FromFile(path1[i]);


                System.Drawing.Imaging.ImageFormat _img_format = GetImageFormat(img, out ImgType);
                if (ImgType != ".bmp")
                {
                    Bitmap myImage = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppRgb);
                    using (Graphics g = Graphics.FromImage(myImage))
                    {
                        g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        g.DrawImage(img, 0, 0);
                    }
                    path1[i] = Path.ChangeExtension(path1[i], ".TGUStemp");
                    img.Save(path1[i], ImageFormat.Bmp);

                    myImage.Dispose();
                }
                Bitmap bitmap;//定义Bitmap类
                bitmap = new Bitmap(path1[i]);
                bitmap = ToBgr565(bitmap);
                Color clr = bitmap.GetPixel(0, 0);
                bmpinfo.Transparent = (UInt16)(((clr.R >> 3) << 11) | ((clr.G >> 2) << 5) | ((clr.B >> 3)));

                bmpinfo.width  = (byte)bitmap.Width;
                bmpinfo.height = (byte)bitmap.Height;
                bitmap.RotateFlip(RotateFlipType.Rotate180FlipX);//垂直翻转   十分重要

                switch (Com_SelectIndex)
                {
                case 0:
                    bitmap.RotateFlip(RotateFlipType.RotateNoneFlipNone);
                    break;

                case 1:
                    bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);    //不进行翻转的 180 度旋转。
                    break;

                case 2:
                    bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);    //指定不进行翻转的 270 度旋转 
                    break;

                case 3:
                    bitmap.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;

                case 4:
                    bitmap.RotateFlip(RotateFlipType.RotateNoneFlipX);    //X轴镜像
                    break;

                case 5:
                    bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);    //Y轴镜像
                    break;
                }
                bmpinfo.width  = (byte)bitmap.Width;
                bmpinfo.height = (byte)bitmap.Height;
                ImagePath     += "\\" + (i + 1) + ".TGUSbmp";//保存临时文件
                bitmap.Save(ImagePath, ImageFormat.Bmp);
                Stream stream = File.OpenRead(ImagePath);

                byte[] buffer = new byte[stream.Length];//将位图数据读到buffer里面
                stream.Read(buffer, 0, (int)stream.Length);

                UInt32 byteoffset = 0;//图片数据的偏移量
                for (int j = 0; j < 4; j++)
                {
                    byteoffset <<= 8;
                    byteoffset  |= buffer[13 - j];
                }
                bmpinfo.Location = (UInt32)fs.Length / 2;
                byte[] bmpinfobyte = new byte[8];
                bmpinfobyte = StructToBytes(bmpinfo);
                byte temp;
                temp           = bmpinfobyte[2];
                bmpinfobyte[2] = bmpinfobyte[7];
                bmpinfobyte[7] = temp;
                temp           = bmpinfobyte[3];
                bmpinfobyte[3] = bmpinfobyte[6];
                bmpinfobyte[6] = temp;
                temp           = bmpinfobyte[4];
                bmpinfobyte[4] = bmpinfobyte[5];
                bmpinfobyte[5] = temp;
                //List<byte> array = new List<byte>
                fs.Position = fs.Seek(8 * (i + 1), SeekOrigin.Begin);
                fs.Write(bmpinfobyte, 0, 8);
                fs.Position = fs.Length;
                byte[] fbyte = new byte[buffer.Length - byteoffset];
                Array.Copy(buffer, byteoffset, fbyte, 0, fbyte.Length);
                for (int leng = 0; leng < fbyte.Length; leng += 2)
                {
                    fbyte[leng]     = (byte)(fbyte[leng] ^ fbyte[leng + 1]);
                    fbyte[leng + 1] = (byte)(fbyte[leng] ^ fbyte[leng + 1]);
                    fbyte[leng]     = (byte)(fbyte[leng] ^ fbyte[leng + 1]);
                }
                if (bmpinfo.width % 2 == 1)
                {
                    int    iii  = 0;
                    byte[] fnew = new byte[fbyte.Length - bmpinfo.height * 2];
                    for (int ii = 0; ii < bmpinfo.height; ii++)
                    {
                        for (int j = 0; j < (bmpinfo.width * 2 + 2); j++)
                        {
                            if (j < bmpinfo.width * 2)
                            {
                                fnew[iii] = fbyte[ii * (bmpinfo.width * 2 + 2) + j];

                                iii++;
                            }
                        }
                    }
                    fs.Write(fnew, 0, fnew.Length);
                }
                else
                {
                    fs.Write(fbyte, 0, fbyte.Length);
                }


                img.Dispose();
                bitmap.Dispose();
                stream.Close();
                MyInvoke mi  = new MyInvoke(UpdateForm);
                string   con = string.Empty;
                if (Main_Form.LanguageType == "English")
                {
                    con = "Converted";
                }
                else
                {
                    con = "已转换";
                }
                this.BeginInvoke(mi, con, i);
            }
            fs.Close();
            //文件夹路径
            DirectoryInfo dyInfo = new DirectoryInfo(path2.Substring(0, path2.LastIndexOf("\\") + 1));

            //获取文件夹下所有的文件
            foreach (FileInfo feInfo in dyInfo.GetFiles())
            {
                //判断文件后缀
                if (feInfo.Extension == ".TGUStemp" || feInfo.Extension == ".TGUSbmp")
                {
                    feInfo.Delete();
                }
            }
            dyInfo = new DirectoryInfo(path1[0].Substring(0, path1[0].LastIndexOf("\\") + 1));
            foreach (FileInfo feInfo in dyInfo.GetFiles())
            {
                //判断文件后缀
                if (feInfo.Extension == ".TGUStemp" || feInfo.Extension == ".TGUSbmp")
                {
                    feInfo.Delete();
                }
            }
            if (Main_Form.LanguageType == "English")
            {
                toolStripStatusLabel1.Text = "Picture conversion complete";
            }
            else
            {
                toolStripStatusLabel1.Text = "图片转换全部完成";
            }
        }
Ejemplo n.º 21
0
        private void MixToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Pipeline pipe = new Pipeline();
            var      cfg  = new Config();

            cfg.EnableStream(Stream.Depth, 1280, 720, Format.Z16);
            cfg.EnableStream(Stream.Color, 1280, 720, Format.Bgr8);

            var pp = pipe.Start(cfg);

            Task.Run(() =>
            {
                mat_color     = new Mat(720, 1280, DepthType.Cv8U, 3);
                mat_color_map = new Mat(mappingColor, DepthType.Cv8U, 3);
                mat_depth     = new Mat(720, 1280, DepthType.Cv8U, 1);
                mat_show      = new Mat(720, 1280, DepthType.Cv8U, 3);

                yoloWrapper = new YoloWrapper("modle\\yolov3-tiny-3obj.cfg", "modle\\yolov3-tiny-3obj_3cup.weights", "modle\\obj.names");
                string detectionSystemDetail = string.Empty;
                if (!string.IsNullOrEmpty(yoloWrapper.EnvironmentReport.GraphicDeviceName))
                {
                    detectionSystemDetail = $"({yoloWrapper.EnvironmentReport.GraphicDeviceName})";
                }
                Console.WriteLine($"Detection System:{yoloWrapper.DetectionSystem}{detectionSystemDetail}");

                loop = true;
                while (loop)
                {
                    using (var frames = pipe.WaitForFrames())
                    {
                        mat_color        = RS_color(frames.ColorFrame.DisposeWith(frames), matrix);
                        mat_depth        = RS_depth(frames.DepthFrame);
                        Mat mat_depth_c3 = new Mat(720, 1280, DepthType.Cv8U, 3);
                        CvInvoke.CvtColor(mat_depth, mat_depth_c3, ColorConversion.Gray2Bgr);
                        CvInvoke.AddWeighted(mat_color, 0.5, mat_depth_c3, 0.5, 0.0, mat_show);

                        CvInvoke.Imwrite("yolo1.png", mat_color);
                        try { items = yoloWrapper.Detect(@"yolo1.png"); }
                        catch { break; }

                        foreach (YoloItem item in items)
                        {
                            string name  = item.Type;
                            int x        = item.X;
                            int y        = item.Y;
                            int H        = item.Height;
                            int W        = item.Width;
                            Point center = item.Center();

                            CvInvoke.PutText(mat_show, name, new Point(x, y), FontFace.HersheySimplex, 1, new MCvScalar(50, 230, 230));
                            CvInvoke.PutText(mat_show, item.Confidence.ToString("0.0"), new Point(x, y - 20), FontFace.HersheySimplex, 0.5, new MCvScalar(50, 230, 230));
                            CvInvoke.Rectangle(mat_show, new Rectangle(x, y, W, H), new MCvScalar(50, 230, 230), 3);
                            byte depth = MyInvoke.GetValue <byte>(mat_depth, center.Y, center.X);
                            if (name == "blue cup")//index 0
                            {
                                process(cups[0], mat_Bcup, label_Bcup_msg, label_Bcup_state);
                            }
                            else if (name == "pink cup")//index 1
                            {
                                process(cups[1], mat_Pcup, label_Pcup_msg, label_Pcup_state);
                            }

                            void process(Objects detectObject, Mat mat, Label label_msg, Label label_s)
                            {
                                detectObject.setPos_mm(0, 0, (float)depth.Unit_mm());
                                Objects.states s = detectObject.State();
                                this.Invoke((MethodInvoker)(() => label_s.Text = s.ToString()));
                                if (s == Objects.states.stop)
                                {
                                    CvInvoke.Line(mat, new Point(timeTick, 30), new Point(timeTick, 70), new MCvScalar(50, 50, 50));
                                }
                                else if (s == Objects.states.move)
                                {
                                    CvInvoke.Line(mat, new Point(timeTick, 30), new Point(timeTick, 70), new MCvScalar(50, 150, 150));
                                    if (handing == detectObject)//如果拿著的東西跟移動的東西一樣,代表繼續移動
                                    {
                                    }
                                    else//如果拿著的東西跟移動的東西"不"一樣,代表要新增東西
                                    {
                                        //if (handing == new Objects())//代表第一次
                                        if (cups.All(cup => cup != handing))//代表前面不是杯子 這樣才會有place
                                        {
                                        }
                                        else//代表前面有東西
                                        {
                                            ActionBaseAdd("Place", handing.Name, color1: Color.FromArgb(240, 230, 176), color2: handing.color);
                                        }

                                        ActionBaseAdd("Pick up", detectObject.Name, color1: Color.FromArgb(255, 200, 14), color2: detectObject.color);
                                    }
                                    handing = detectObject;
                                }
                                this.Invoke((MethodInvoker)(() => label_msg.Text = (detectObject.getZ_m() * 1000).ToString("0.0") + "mm"));
                            }

                            //CvInvoke.PutText(mat_show, (depth.Unit_mm()).ToString("0.00") + "mm", center, FontFace.HersheySimplex, 1, new MCvScalar(50, 230, 230));
                        } //foreach cups
                        timeTick++;
                    }     //using depth image

                    imageBox_Pcup.Image = mat_Pcup;
                    imageBox_Bcup.Image = mat_Bcup;
                    imageBox_RS.Image   = mat_show;
                }
            });
        }
Ejemplo n.º 22
0
 /// <summary>
 /// 起用下一步按钮
 /// </summary>
 /// <param name="State"></param>
 private void EnableNext(string State)
 {
     if (btnnext.InvokeRequired)
     {
         MyInvoke _myInvoke = new MyInvoke(EnableNext);
         this.Invoke(_myInvoke, new object[] { State });
     }
     else
     {
         btnnext.Enabled = true;
     }
 }
Ejemplo n.º 23
0
        bool ParseMulReadFrameDataProcess()
        {
            string epc_tmp = "";
            string tid_tmp = "";
            byte[] byte_epc = new byte[64];
            byte[] byte_tid = new byte[64];
            byte[] byte_rssi = new byte[2];
            Int16 rssi;
            int antid;
            DateTime nowTime = DateTime.Now;
            TagInfo tmp = new TagInfo("", 0, 0, 1, nowTime);
            int length = 0;
            int rlength = 0;
            int i;

            length = (g_Revbuf[5] >> 3) * 2;
            rlength = (g_Revbuf[2] << 8) + g_Revbuf[3];

            System.Array.Copy(g_Revbuf, 7, byte_epc, 0, length);
            for (i = 0; i < length; i++)
            {
                epc_tmp += byte_epc[i].ToString("X2");
                if (i < length - 1)
                {
                    epc_tmp += "-";
                }
            }

            if (rlength > (length + 8 + 5))
            {
                System.Array.Copy(g_Revbuf, (7 + length), byte_tid, 0, length);
                for (i = 0; i < (rlength - length - 8 - 5); i++)
                {
                    tid_tmp += byte_tid[i].ToString("X2");
                    if (i < length - 1)
                    {
                        tid_tmp += "-";
                    }
                }
            }

            rssi = (Int16)(g_Revbuf[rlength - 6] << 8);
            rssi += (Int16)(g_Revbuf[rlength - 5]);
            antid = g_Revbuf[rlength - 4];
            tmp.epcid = epc_tmp;
            tmp.tid = tid_tmp;
            tmp.rxrssi = (Int16)(rssi / 10);
            tmp.readcnt = 1;
            tmp.antID = antid;

            AddTagToBuf(tmp);
            MyInvoke mi = new MyInvoke(UpdataListViewDisp);

            //this.BeginInvoke(mi, new Object[] { m_Tags[tmp.epcid] });
            Thread thread = new Thread(() => UpdataListViewDisp(m_Tags[tmp.epcid]));
            thread.Start();

            return true;
        }
Ejemplo n.º 24
0
        private void deal_login()
        {
            MyInvoke im = new MyInvoke(Button_login);

            this.BeginInvoke(im);
        }
Ejemplo n.º 25
0
        void DoMakeMPQ(object param)
        {
            MyInvoke miUI = new MyInvoke(miUpdateUI);
            MyInvoke miFin = new MyInvoke(miFinish);
            string sql = string.Empty;
            if (ConnInfo.Dbstruct == "3.3.5(TC2)")
            {
                sql = "SELECT entry,class,subclass,SoundOverrideSubclass,material,displayid,InventoryType,sheath FROM item_template ORDER BY entry ASC;";
            }
            //else if (ConnInfo.Dbstruct == "3.1.X")
            //{
            //    sql = "SELECT entry,displayid,InventoryType,sheath FROM item_template ORDER BY entry ASC;";
            //}
            else
            {
                sql = "SELECT entry,class,subclass,unk0,material,displayid,InventoryType,sheath FROM item_template ORDER BY entry ASC;";
            }
            DataSet ds = new DataSet();
            MySqlConnection Conn = new MySqlConnection(MainForm.GetConnStr());
            MySqlCommand setname = new MySqlCommand("set names 'gbk';", Conn);
            MySqlDataAdapter adp = new MySqlDataAdapter(sql, Conn);
            this.Invoke(miUI, "查询物品信息...");
            try
            {
                Conn.Open();
                adp.Fill(ds);
            }
            catch (ThreadAbortException err)
            {
                return;
            }
            catch (Exception err)
            {
                this.Invoke(miFin, "无法查询物品信息。" + err.Message);
                return;
            }
            finally
            {
                Conn.Close();
            }
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count < 1)
                {
                    this.Invoke(miFin, "没有任何物品信息,操作已终止。");
                    return;
                }
            }
            else
            {
                this.Invoke(miFin, "查询物品信息发生错误。");
                return;
            }
            string mastdbcfilename = Application.StartupPath + @"\Data\Item.dbc";
            string dbcfilename = Application.StartupPath + @"\Item.dbc";
            this.Invoke(miUI, "筛选自定义物品...");
            DataTable dt_items = null;
            if (File.Exists(mastdbcfilename))
            {
                DataTable dt_mastitems = null;
                DataTable dt_additems = new DataTable();
                try
                {
                    dt_mastitems = LibDBC.GetData(mastdbcfilename);
                    //if (dt_mastitems.Rows.Count == 0 || dt_mastitems.Columns.Count != 8)
                    if (dt_mastitems.Columns.Count != ds.Tables[0].Columns.Count)
                    {
                        this.Invoke(miFin, "Item.dbc格式不正确。\r\n请从服务端dbc目录拷贝此文件到软件Data目录下。");
                        return;
                    }
                    foreach (DataColumn dc in dt_mastitems.Columns)
                    {
                        dt_additems.Columns.Add(dc.ColumnName, dc.DataType);
                    }
                }
                catch (Exception err)
                {
                    this.Invoke(miFin, "无法读取Item.dbc。" + err.Message + "\r\n请从服务端dbc目录拷贝此文件到软件Data目录下。");
                    return;
                }
                try
                {
                    int rowIndex = 0;
                    dt_mastitems.DefaultView.Sort = dt_mastitems.Columns[0].ColumnName + " ASC";
                    dt_mastitems = dt_mastitems.DefaultView.ToTable();
                    for (int i = 0; i < dt_mastitems.Rows.Count; i++)
                    {
                        if (i >= dt_mastitems.Rows.Count)
                            break;
                        this.Invoke(miUI, "筛选自定义物品..." + (i * 100 / dt_mastitems.Rows.Count).ToString() + "%");
                        DataRow curdr = dt_mastitems.Rows[i];
                        bool isExists = false;
                        for (int j = rowIndex; j < ds.Tables[0].Rows.Count; j++)
                        {
                            DataRow dr = ds.Tables[0].Rows[j];
                            if (int.Parse(dr[0].ToString()) > int.Parse(curdr[0].ToString()))
                                break;
                            if (curdr[0].ToString() == dr[0].ToString())
                            {
                                isExists = true;
                                rowIndex = j + 1;
                                break;
                            }
                        }
                        if (!isExists)
                        {
                            dt_additems.Rows.Add(curdr.ItemArray);
                        }
                    }
                    foreach (DataRow dr in dt_additems.Rows)
                    {
                        ds.Tables[0].Rows.Add(dr.ItemArray);
                    }
                    ds.Tables[0].DefaultView.Sort = ds.Tables[0].Columns[0].ColumnName + " ASC";
                    dt_items = ds.Tables[0].DefaultView.ToTable();
                }
                catch (ThreadAbortException err)
                {
                    return;
                }
            }
            else
            {
                this.Invoke(miFin, "文件Item.dbc不存在。\r\n请从服务端dbc目录拷贝此文件到软件Data目录下。");
                return;
            }
            this.Invoke(miUI, "生成DBC文件...");
            try
            {
                LibDBC.SaveData(dbcfilename, dt_items);
            }
            catch (ThreadAbortException err)
            {
                return;
            }
            catch (Exception err)
            {
                this.Invoke(miFin, "无法生成DBC文件。" + err.Message);
                return;
            }
            if (File.Exists(this.fileName))
            {
                try
                {
                    File.Delete(this.fileName);
                }
                catch (ThreadAbortException err)
                {
                    return;
                }
                catch (Exception err)
                {
                    this.Invoke(miFin, "无法替换保存位置的文件。" + err.Message);
                    return;
                }
            }
            try
            {
                int handle = -1;
                int pro = 0x00030200;
                bool b = false;
                handle = LibMPQ.MpqOpenArchiveForUpdate(this.fileName, 1, 4096);
                if (handle > 0)
                {
                    b = LibMPQ.MpqAddFileToArchive(handle, dbcfilename, @"DBFilesClient\Item.dbc", pro);
                    if (!b)
                    {
                        this.Invoke(miFin, "无法对MPQ添加Item.dbc文件。");
                        return;
                    }

                    b = LibMPQ.MpqCompactArchive(handle);
                    if (!b)
                    {
                        this.Invoke(miFin, "无法编译MPQ文件。");
                        return;
                    }
                    b = LibMPQ.SFileCloseArchive(handle);
                    if (!b)
                    {
                        this.Invoke(miFin, "无法关闭MPQ文件。");
                        return;
                    }
                    try
                    {
                        File.Delete(dbcfilename);
                    }
                    catch
                    { }
                    this.Invoke(miFin, "success");
                    return;
                }
                else
                {
                    this.Invoke(miFin, "获取文件指针错误。");
                    return;
                }
            }
            catch (ThreadAbortException err)
            {
                return;
            }
            catch (Exception err)
            {
                this.Invoke(miFin, "无法生成MPQ文件。" + err.Message);
                return;
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// ��FC7002B�������ݣ���tcp�����ٹ��쵼��ճ��
        /// </summary>
        /// <param name="s_command">���͵������ַ���</param>
        /// <returns>void</returns>
        private void OnDataReceived1(object sender, Communications.ChannelEventArgs e)
        {
            try
            {

                string retStr = HexBytesToString(e.Data, 0, e.Data.Length);
                MyInvoke mi = new MyInvoke(UpdateTextBox);
                MyInvoke1 mi1 = new MyInvoke1(UpdateDataGridView);
                pkt_num++;
                this.BeginInvoke(mi, new object[] { "����" + pkt_num.ToString(), retStr, true });

                //���һ���ֻ���
                if (dt.Rows.Count >= 40)
                {
                    dt.Rows.Remove(dt.Rows[dt.Rows.Count - 1]);
                    dataGridView1.DataSource = dt;
                }

                if (e.Data.Length < 3)
                {
                    return;
                }

                int deal_len = 0;
                int pof = 0;
                while (deal_len < e.Data.Length)
                {
                    int read_len = 0;

                    if (e.Data[0 + pof] != 0x64 || e.Data[1 + pof] != 0x70 || e.Data[2 + pof] != 0x69)
                    {
                        return;
                    }
                    read_len += 3;

                    UInt16 total_len = (UInt16)(((UInt16)e.Data[3 + pof] * 256) + (UInt16)(e.Data[4 + pof]));

                    read_len += 2;

                    DataRow dr = dt.NewRow();
                    while (total_len - read_len > 0)
                    {
                        if (checkBox_utf8.Checked)
                        {
                            parse_tlv_data(e.Data, pof, total_len, ref read_len, dr);
                        }
                        else
                        {
                            parse_tlv_data_gbk(e.Data, pof, total_len, ref read_len, dr);
                        }

                    }
                    dr["���"] = ++rlt_num;
                    dt.Rows.InsertAt(dr, 0);
                    this.BeginInvoke(mi1, new object[] { });

                    deal_len += total_len;
                }
                return;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
 public EditPageMetaWindow(MyInvoke myInvoke)
 {
     InitializeComponent();
     this.mi = myInvoke;
 }
Ejemplo n.º 28
0
 private void ClearBoard()
 {
     MyInvoke.setToZero(ref mat);
     MyInvoke.setToZero(ref mat_layer_drag);
     ImageUpdate();
 }
Ejemplo n.º 29
0
 public void userListOperateR(string msg)
 {
     //在线程里以安全方式调用控件
     if (userList.InvokeRequired)
     {
         MyInvoke _myinvoke = new MyInvoke(userListOperateR);
         userList.Invoke(_myinvoke, new object[] { msg });
     }
     else
     {
         userList.Items.Remove(msg);
     }
 }
Ejemplo n.º 30
0
        private void Btn_InductiveSegment_Click(object sender, RoutedEventArgs e)
        {
            //按下 開始計算 ,就不要這次路徑了
            demoTask.environment.AbortThisSeg();
            ClearBoard();


            demoTask.ZeroAllKeys();
            int segmentIndex = 0;

            for (; segmentIndex < demoTask.generations[0].segments.Count(); segmentIndex++)
            {
                for (int G = 1; G < demoTask.generations.Count() - 1; G++)//generations 會多一 ,因為示範結束就++,但還沒示範就進到這裡了
                {
                    //ABS 比較
                    CompareTwoTrajectory(
                        demoTask.generations[0].segments[segmentIndex].AbsoluteTrajectory,
                        demoTask.generations[G].segments[segmentIndex].AbsoluteTrajectory,
                        absToleranceRange,
                        ignoreStartValue);
                    //Rel 比較
                    for (int O = 0; O < demoTask.environment.DemoObject.Count(); O++)
                    {
                        CompareTwoTrajectory(
                            demoTask.generations[0].segments[segmentIndex].RelativeTrajectory[O],
                            demoTask.generations[G].segments[segmentIndex].RelativeTrajectory[O],
                            relToleranceRange,
                            ignoreStartValue);
                    }
                    //注意!! key path 只存到 generations[0]
                }



                //draw keyPath on UI
                int threshold = demoTask.generations.Count() - 2;// 示範完會++ 所以少一,互相比較,所以若N代又要全部都是key 會需要N-1個(比喻:雙循環賽 全贏)
                demoTask.generations[0].segments[segmentIndex].AbsoluteTrajectory.DrawKeyOn(mat, new Point(0, 0), threshold, new MCvScalar(55, 5, 200));
                for (int O = 0; O < demoTask.environment.DemoObject.Count(); O++)
                {
                    demoTask.generations[0].segments[segmentIndex].RelativeTrajectory[O].DrawKeyOn(mat, demoTask.environment.DemoObject[O].Position, threshold, new MCvScalar(55, 5, 200), 4, 1);
                }

                int interactObject = demoTask.generations[0].segments[segmentIndex].InteractObjectIndex;

                List <Point> path = new List <Point>();
                for (int k = 0; k < demoTask.generations[0].segments[segmentIndex].AbsoluteTrajectory.PathKeyMatch.Count(); k++)//PathKeyCount.Count() 都會一樣
                {
                    if (demoTask.generations[0].segments[segmentIndex].AbsoluteTrajectory.PathKeyMatch[k] >= threshold)
                    {
                        path.Add(demoTask.generations[0].segments[segmentIndex].AbsoluteTrajectory.PathList[k]);
                    }
                    else
                    {    //RelativeTrajectory 有多個物件
                        for (int O = 0; O < demoTask.environment.DemoObject.Count(); O++)
                        {
                            if (demoTask.generations[0].segments[segmentIndex].RelativeTrajectory[O].PathKeyMatch[k] >= threshold)
                            {
                                Point Pr = new Point(demoTask.generations[0].segments[segmentIndex].RelativeTrajectory[O].PathList[k].X + demoTask.environment.DemoObject[O].Position.X,
                                                     demoTask.generations[0].segments[segmentIndex].RelativeTrajectory[O].PathList[k].Y + demoTask.environment.DemoObject[O].Position.Y);
                                path.Add(Pr);
                                break;
                            }
                        }
                    }
                }

                if (path.Count() == 0)
                {
                    MessageBox.Show("No key path found!");
                    return;
                }
                //draw
                CvInvoke.Line(mat, demoTask.environment.DemoObject[interactObject].Position, path[0], demoTask.environment.DemoObject[interactObject].Color, 2);
                for (int i = 1; i < path.Count(); i++)
                {
                    CvInvoke.Line(mat, path[i - 1], path[i], demoTask.environment.DemoObject[interactObject].Color, 2);
                }
            }
            // ImageUpdate();
            image1.Source = MyInvoke.MatToBitmap(mat); //BitmapSourceConvert.ToBitmapSource(mat);
        }
Ejemplo n.º 31
0
        private void updateText(String updateData, int ID)
        {
            MyInvoke mi = new MyInvoke(updateTextMethod);

            this.Invoke(mi, updateData, ID);
        }
Ejemplo n.º 32
0
        public void DoWork()
        {
            MyInvoke mi = new MyInvoke(UpdataForm);         //使用代理更新界面

            this.BeginInvoke(mi, new Object[] { ShowStr }); //开始代理
        }
Ejemplo n.º 33
0
        private void Run()
        {
            byte[] head = new byte[2];
            while (true)
            {
                if (serialCom1.ReadBytes(ref head, 2))      //如果读取到了包头
                {
                    if (head[0] == 0xbb && head[1] == 0xaa) //如果是信息应答包
                    {
                        byte[]  body        = new byte[3];
                        Timeout msg_outtime = new Timeout(5);

                        while (true)
                        {
                            if (msg_outtime.IsTimeout())
                            {
                                MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                                this.BeginInvoke(mi, new Object[] { "信息包应答超时!!!" });
                                RvcMsgError = true;
                                break;//超时退出
                            }
                            if (serialCom1.ReadBytes(ref body, 3))
                            {
                                if (body[0] + body[1] == body[2]) //校验和
                                {
                                    if (body[0] == 0x01)          //下位机接收成功了信息包
                                    {
                                        allowSend = true;
                                        state     = 2;

                                        MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                                        this.BeginInvoke(mi, new Object[] { "信息包接收成功,开始传输数据" });
                                    }
                                    else //下位机接收信息包出错
                                    {
                                        RvcMsgError = true;
                                        MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                                        this.BeginInvoke(mi, new Object[] { "下位机接收信息包失败" });
                                    }
                                    Array.Clear(body, 0, body.Length); //清空数组
                                    break;
                                }
                                else
                                {
                                    RvcMsgError = true;
                                    break;
                                }
                            }
                        }
                    }
                    else if (head[0] == 0xbb && head[1] == 0xbb)//如果是数据应答包
                    {
                        byte[]  body         = new byte[3];
                        Timeout data_outtime = new Timeout(5);
                        while (true)
                        {
                            if (data_outtime.IsTimeout())
                            {
                                MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                                this.BeginInvoke(mi, new Object[] { "超时!!!" });
                                break;//超时退出
                            }
                            if (serialCom1.ReadBytes(ref body, 3))
                            {
                                if (body[0] + body[1] == body[2]) //校验和
                                {
                                    timeoutSend = 0;              //将超时重传数置零
                                    if (body[0] == 2)             //如果下位机校验错误
                                    {
                                        //重传 body[1]号包

                                        packetNumber = body[1]; //从该包从新开始传输
                                        MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                                        this.BeginInvoke(mi, new Object[] { "发送包校验错误" });
                                        checkError = true;
                                    }
                                    else if (body[0] == 3) //如果包号错误
                                    {
                                        //重传 body[1]号包

                                        packetNumber = body[1]; //从该包从新开始传输
                                        MyInvoke mi = new MyInvoke(updataRvcUI_boxshow);
                                        this.BeginInvoke(mi, new Object[] { "发送包号错误" });
                                        packetgError = true;
                                    }
                                    else //如果接收成功
                                    {
                                        label_setbacks.Invoke(new GetTextHandler(updataRvcUI_setbacks)); //显示进度
                                        packetNumber++;
                                        allowSend = true;
                                    }
                                    Array.Clear(body, 0, body.Length); //清空数组
                                    break;
                                }
                                else
                                {
                                    //校验失败 这里不知道下位机是不是正确接收?
                                    break;
                                }
                            }
                        }
                    }
                    else if (head[0] == 0xbb && head[1] == 0xcc)//如果是状态包
                    {
                    }
                    else if (head[0] == 0xbb && head[1] == 0xff) //进入IAP程序后会发送此信息
                    {
                        Timeout start_outtime = new Timeout(5);
                        while (!serialCom1.ReadBytes(ref head, 2)) //如果又读取到两个字节
                        {
                            if (start_outtime.IsTimeout())
                            {
                                break;
                            }
                        }
                        if (head[0] == 0xbb && head[1] == 0xff)
                        {
                            state = 1;//进入准备下载状态
                            MyInvoke mi = new MyInvoke(updataRvcUI_Label_show1);
                            this.BeginInvoke(mi, new Object[] { "下位机已经进入下载状态,允许下载" });
                        }
                        else
                        {
                            state = 0;
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                    Array.Clear(head, 0, head.Length); //清空数组
                }
            }
        }
Ejemplo n.º 34
0
 private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
 {
     SerialPort sp = (SerialPort)sender;
     byte[] rb1 = new byte[255];
     int rb2 = sp.Read(rb1, 0, 255);
     if (rb2 > 0)
     {
         myinvoke1 = new MyInvoke(SetTxt);
         this.Invoke(myinvoke1, new object[3] { rb1, 0, rb2 });
     }
 }
Ejemplo n.º 35
0
 private void SetText(NET.Message mes)
 {
     if (this.listView1.InvokeRequired)
     {
         MyInvoke _myInvoke = new MyInvoke(SetText);
         this.Invoke(_myInvoke, new object[] { mes });
     }
     else
     {
         NET.Message m = mes as NET.Message;
         ListViewItem[] lvi = new ListViewItem[m.Result.Count];
         NET.FileInfo fi;
         for (int i = 0; i < m.Result.Count; i++)
         {
             fi = m.Result[i];
             lvi[i] = new ListViewItem(new string[] { fi.fileName, fi.IP, fi.Path, fi.introduction });
         }
         this.listView1.Items.AddRange(lvi);
     }
 }
Ejemplo n.º 36
0
 public string getproxy()
 {
     //使用顺序代理13
     //使用随机代理24
     string proxystring = "";
     Random rd = new Random();
     switch (proxytype)
     {
         case 1:
             proxyid += 1;
             proxystring = proxylist[proxyid];
             if (proxyid == proxylist.Count) { proxyid = 0; }
             break;
         case 2:
             proxystring = proxylist[rd.Next(1, proxylist.Count + 1)];
             break;
         case 3:
             proxyid += 1;
             proxystring = proxylist[proxyid];
             if (proxyid == proxylist.Count) { proxyid = 0; }
             break;
         case 4:
             proxystring = proxylist[rd.Next(1, proxylist.Count + 1)];
             break;
     }
     if (Settings.Default.debug_msg)
     {
         MyInvoke UpdateMsgAdd = new MyInvoke(UpdateMsgTextBoxAdd);
         output_text.BeginInvoke(UpdateMsgAdd, new object[] { "线程:" + Thread.CurrentThread.Name + ",获取代理IP:" + proxystring });
     }
     return proxystring;
 }
Ejemplo n.º 37
0
 private void AddShowMsg(string msg)
 {
     if (lbItems.InvokeRequired)
     {
         MyInvoke _myInvoke = new MyInvoke(AddShowMsg);
         this.Invoke(_myInvoke, new object[] { msg });
     }
     else
     {
         lbItems.Items.Add(msg);
     }
 }
Ejemplo n.º 38
0
 private void stopThread()
 {
     stoplistThread();
     MyInvoke UpdateMsg = new MyInvoke(UpdateMsgBox);
     submit_state.BeginInvoke(UpdateMsg, new object[] { "" });
     submit_button_change(0);
     //UpdateMsgBox("");
 }
Ejemplo n.º 39
0
        public void Receive_Data(byte[] ReceiveData)
        {
            MyInvoke mi = new MyInvoke(Updata);

            this.BeginInvoke(mi, new Object[] { ReceiveData });
        }
Ejemplo n.º 40
0
        /// <summary>
        /// 可选显示共享航班
        /// </summary>
        /// <param name="lv"></param>
        /// <param name="b_display_no_seat">否显示无座舱位</param>
        /// <param name="pWays">显示方式:最低价,全部</param>
        /// <param name="b_share">是否显示共享航班</param>
        /// <param name="b_spec">是否显示特殊舱位</param>
        public void ToListView(ListView lv, bool b_display_no_seat, TO_LIST_WAYS pWays, bool b_share)
        {
            if (lv.InvokeRequired)
            {
                if (mi == null)
                {
                    mi = new MyInvoke(ToListView);
                    lv.Invoke(mi, new object[] { lv, b_display_no_seat, pWays, b_share });
                    //ToListView(lv, b_display_no_seat, pWays);
                    return;
                }
            }
            else
            {
                try
                {
                    if (lv == null)
                    {
                        throw new Exception("未创建LV_LOWEST吗");
                    }

                    for (int i = 0; i < si.Length; ++i)
                    {
                        if (!si[i].b_directly && pWays == TO_LIST_WAYS.LOWEST)
                        {
                            continue;                                                   //filter the not direct arrive flight, 全部显示时,是否有直飞由AV指令控制,不需要在这里控制
                        }
                        for (int j = 0; j < si[i].fi.Length; ++j)
                        {
                            if (si[i].fi[j].SharedFlight && (!b_share))
                            {
                                continue;                                         //jump over shared flight
                            }
                            if (m_shield_airline.IndexOf(si[i].fi[j].info_AirLine) >= 0)
                            {
                                continue;                                                         //jump over shield airline
                            }
                            ListViewItem lvi = new ListViewItem();
                            si[i].fi[j].Price = m_price;
                            si[i].fi[j].ToListViewItem(lvi, b_display_no_seat, pWays, m_base_id, m_display_seat_amount);
                            lv.Items.Add(lvi);
                        }
                    }
                    //{ "序号","航空公司","航班","起飞城市","抵达城市","起飞时间","抵达时间","机型"}
                    //switch (pWays)
                    //{//这是增加的第一行的
                    //    case TO_LIST_WAYS.ALL:
                    //        if (!string.IsNullOrEmpty(lv.Items[0].Text))
                    //        {
                    //            ListViewItem lvi = new ListViewItem();
                    //            lvi.Text = "";
                    //            lvi.SubItems.Add("");// lvi.SubItems.Add(m_airline + m_int_flighno.ToString());
                    //            lvi.SubItems.Add("");//lvi.SubItems.Add(m_policy_string);
                    //            lvi.SubItems.Add("");//lvi.SubItems.Add(m_citypair);
                    //            lvi.SubItems.Add("");//lvi.SubItems.Add(m_time_begin);
                    //            lvi.SubItems.Add("");//lvi.SubItems.Add(m_time_end);
                    //            lvi.SubItems.Add("");//lvi.SubItems.Add(m_plane_type);
                    //            lvi.SubItems.Add("");
                    //            int[] a_rebates = new int[] { 150, 130, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30 };
                    //            for (int i = 0; i < a_rebates.Length; ++i)
                    //            {
                    //                lvi.SubItems.Add(egString.TicketPrice(m_price, a_rebates[i]).ToString()+"元");
                    //            }
                    //            lv.Items.Insert(0, lvi);
                    //        }
                    //        break;
                    //}
                    for (int i = 0; i < lv.Items.Count; ++i)
                    {
                        ListViewItem lvi = lv.Items[i];
                        if (i % 2 == 1)
                        {
                            lvi.BackColor = Color.LightGray;
                        }
                    }
                }
                catch (Exception ex)
                {
                    EagleFileIO.LogWrite("AvResult.ToListView:" + ex.Message);
                }
                mi = null;
            }
        }
Ejemplo n.º 41
0
        private void StartProcessingBlock(CustomProcessingBlock processingBlock, PipelineProfile pp, Action <VideoFrame> updateColor, Pipeline pipeline)
        {
            float[,,] posMap = new float[1280, 720, 3];

            Size RS_depthSize = new Size(1280, 720);
            Mat  processMat   = new Mat(RS_depthSize, DepthType.Cv8U, 3);

            processingBlock.Start(f =>
            {
                using (var frames = FrameSet.FromFrame(f))
                {
                    //var color_frame = frames.ColorFrame.DisposeWith(frames);
                    //color_frame.CopyTo(processMat.DataPointer);

                    var depthintr   = (pp.GetStream(Stream.Depth) as VideoStreamProfile).GetIntrinsics();
                    var depth_frame = frames.DepthFrame.DisposeWith(frames);

                    //float depth = depth_frame.GetDistance((int)thePoint.X,(int)thePoint.Y); //From
                    //thePos = HelperClass.DeprojectPixelToPoint(depthintr, thePoint, depth);

                    unsafe
                    {
                        Int16 *pixelPtr_byte = (Int16 *)depth_frame.Data;
                        for (int i = 0; i < 1280; i++)
                        {
                            for (int j = 0; j < 720; j++)
                            {
                                var tmpF        = HelperClass.DeprojectPixelToPoint(depthintr, new PointF(i, j), (float)pixelPtr_byte[j * 1280 + i] / 1000f);
                                posMap[i, j, 0] = tmpF[0];
                                posMap[i, j, 1] = tmpF[1];
                                posMap[i, j, 2] = tmpF[2];
                            }
                        }
                    }
                    // Dispatcher.Invoke(DispatcherPriority.Render, updateColor, color_frame);//顯示用
                }
            });


            //start
            var token = _tokenSource.Token;
            Action <VideoFrame> updateOriginColor = UpdateImage(Img_main);
            var t = Task.Factory.StartNew(() =>
            {
                Mat color_orig   = new Mat(RS_depthSize, DepthType.Cv8U, 3);
                Mat color_resize = new Mat(RS_depthSize, DepthType.Cv8U, 3);

                yoloWrapper = new YoloWrapper("modle\\yolov3-tiny-3obj.cfg", "modle\\yolov3-tiny-3obj_3cup.weights", "modle\\obj.names");
                string detectionSystemDetail = string.Empty;
                if (!string.IsNullOrEmpty(yoloWrapper.EnvironmentReport.GraphicDeviceName))
                {
                    detectionSystemDetail = $"({yoloWrapper.EnvironmentReport.GraphicDeviceName})";
                }
                Console.WriteLine($"Detection System:{yoloWrapper.DetectionSystem}{detectionSystemDetail}");

                while (!token.IsCancellationRequested)
                {
                    using (var frames = pipeline.WaitForFrames())
                    {
                        if (showType == imgType.color)
                        {
                            VideoFrame color_frame = frames.ColorFrame.DisposeWith(frames);
                            color_frame.CopyTo(color_orig.DataPointer);

                            CvInvoke.WarpPerspective(color_orig, color_resize, matrix, new Size(1280, 720));


                            //CvInvoke.Imwrite("yolo1.png", color_resize);
                            //try { items = yoloWrapper.Detect(@"yolo1.png"); }
                            //catch { break; }
                            CvInvoke.Imwrite("yolo2.png", color_orig);
                            try { items = yoloWrapper.Detect(@"yolo2.png"); }
                            catch { break; }

                            CvInvoke.CvtColor(color_resize, color_resize, ColorConversion.Bgr2Rgb);
                            processingBlock.ProcessFrames(frames);

                            foreach (YoloItem item in items)
                            {
                                string name = item.Type;
                                //int x = item.X;
                                //int y = item.Y;
                                mapToRsImg(item.X, item.Y, out int x, out int y);
                                mapToRsImg(item.X + item.Width, item.Y + item.Height, out int x2, out int y2);

                                //int H = item.Height;
                                //int W = item.Width;
                                int H = y2 - y;
                                int W = x2 - x;

                                mapToRsImg(item.Center().X, item.Center().Y, out int Cx, out int Cy);
                                //Point center = item.Center();
                                Point center = new Point(Cx, Cy);

                                int evilLine   = 500;
                                int evilLinex1 = 580;
                                int evilLinex2 = 660;
                                if (showEvilLine)
                                {
                                    CvInvoke.Line(color_resize, new Point(0, evilLine), new Point(1280, evilLine), new MCvScalar(100, 100, 250), 2);         //以上代表可能在咖啡機
                                    CvInvoke.Line(color_resize, new Point(evilLinex1, 0), new Point(evilLinex1, evilLine), new MCvScalar(100, 100, 250), 2); //
                                    CvInvoke.Line(color_resize, new Point(evilLinex2, 0), new Point(evilLinex2, evilLine), new MCvScalar(100, 100, 250), 2); //
                                }

                                if (y > evilLine || x < evilLinex1 || x > evilLinex2) //代不再咖啡機附近
                                {
                                    if (item.Confidence < 0.5)                        //沒信心的東西就跳過,避免偵測到其他東西
                                    {
                                        continue;
                                    }
                                }


                                float[] objPos = new float[] { posMap[center.X, center.Y, 0], posMap[center.X, center.Y, 1], posMap[center.X, center.Y, 2] };

                                if (objPos[0] == 0 || objPos[1] == 0 || objPos[2] == 0)//不然會影響平均
                                {
                                    continue;
                                }

                                if (name == "blue cup")//index 0
                                {
                                    //evil color check
                                    MCvScalar clr = MyInvoke.GetColorM(color_resize, center.Y - 5, center.X);
                                    if (clr.V0 > clr.V2)//R>B  //YOLO搞錯
                                    {
                                        continue;
                                    }

                                    //  CvInvoke.PutText(color_resize, "B", new Point(x, y), FontFace.HersheySimplex, 1.2, new MCvScalar(80, 150, 220), 2);
                                    CvInvoke.PutText(color_resize, item.Confidence.ToString("0.0"), new Point(x, y), FontFace.HersheySimplex, 1.2, new MCvScalar(80, 150, 220), 3);
                                    CvInvoke.Rectangle(color_resize, new Rectangle(x, y, W, H), new MCvScalar(80, 150, 220), 3);

                                    process_actionOfCups(cups[0], mat_cup, TB_Bcup_msg, TB_Bcup_state, objPos, 10, 40);
                                    //this.Dispatcher.Invoke((Action)(() => { TB_Bcup.Text = $"({posMap[center.X, center.Y, 0].ToString("0.000")},{posMap[center.X, center.Y, 1].ToString("0.000")},{posMap[center.X, center.Y, 2].ToString("0.000")})"; }));
                                    CvInvoke.Circle(color_resize, center, 10, new MCvScalar(200, 200, 20), -1);
                                }
                                else if (name == "pink cup")//index 1
                                {
                                    //evil color check
                                    MCvScalar clr = MyInvoke.GetColorM(color_resize, center.Y - 5, center.X);
                                    if (clr.V0 < clr.V2)//R<B  //YOLO搞錯
                                    {
                                        continue;
                                    }

                                    // CvInvoke.PutText(color_resize, "P", new Point(x, y), FontFace.HersheySimplex, 1.2, new MCvScalar(250, 80, 80), 2);
                                    CvInvoke.PutText(color_resize, item.Confidence.ToString("0.0"), new Point(x, y), FontFace.HersheySimplex, 1.2, new MCvScalar(250, 80, 80), 3);
                                    CvInvoke.Rectangle(color_resize, new Rectangle(x, y, W, H), new MCvScalar(250, 80, 80), 3);

                                    process_actionOfCups(cups[1], mat_cup, TB_Pcup_msg, TB_Pcup_state, objPos, 60, 90);
                                    //this.Dispatcher.Invoke((Action)(() => { TB_Pcup.Text = $"({posMap[center.X, center.Y, 0].ToString("0.000")},{posMap[center.X, center.Y, 1].ToString("0.000")},{posMap[center.X, center.Y, 2].ToString("0.000")})"; }));
                                    CvInvoke.Circle(color_resize, center, 10, new MCvScalar(200, 200, 20), -1);
                                }
                            }//foreach cups
                            timeTick++;
                            this.Dispatcher.Invoke((Action)(() =>
                            {
                                img_cupState.Source = BitmapSourceConvert.ToBitmapSource(mat_cup);
                            }));
                            color_frame.CopyFrom(color_resize.DataPointer);
                            Dispatcher.Invoke(DispatcherPriority.Render, updateOriginColor, color_frame);
                        }
                        else if (showType == imgType.mix)//顯示 mix 圖
                        {
                            processingBlock.ProcessFrames(frames);
                        }
                    }
                }
            }, token);
        }
Ejemplo n.º 42
0
 private void threadexit()
 {
     listThread.Remove(Thread.CurrentThread);
     MyInvoke UpdateMsg = new MyInvoke(UpdateMsgBox);
     if (listThread.Count == 0)
     {
         submit_state.BeginInvoke(UpdateMsg, new object[] { "" });
         submit_button_change(0);
     }
     else { submit_state.BeginInvoke(UpdateMsg, new object[] { "当前正在提交的数量:" + listThread.Count.ToString() }); }
     Thread.CurrentThread.Abort();
 }
Ejemplo n.º 43
0
 private void stoplistThread()
 {
     if (listThread.Count > 0)
     {
         try
         {
             MyInvoke UpdateMsgAdd = new MyInvoke(UpdateMsgTextBoxAdd);
             MyInvoke UpdateMsg = new MyInvoke(UpdateMsgBox);
             int scount = 0;
             foreach (Thread tempThread in listThread)
             {
                 output_text.BeginInvoke(UpdateMsgAdd, new object[] { "线程" + tempThread.Name + ":已停止" });
                 submit_state.BeginInvoke(UpdateMsg, new object[] { "当前正在提交的数量:" + (listThread.Count - scount).ToString() });
                 //UpdateMsgTextBoxAdd("线程" + tempThread.Name + ":已停止");
                 tempThread.Abort();
                 scount++;
                 //listThread.Remove(tempThread);
                 //if (tempThread.Name == "Thread3")
                 //{
                 //    Console.WriteLine(tempThread.Name + " 线程已关闭");
                 //    tempThread.Abort();
                 //}
             }
             listThread.Clear();
         }
         catch (Exception)
         {
             //stoplistThread();
         }
     }
     else
     {
         UpdateMsgTextBoxAdd("请求线程已全部停止");
     }
 }
        //用于定时回收(回收耗费性能)
        //public static int ClearTimeCount = 0;
        private void ProfilerThread(Object state)
        {
            MyInvoke mi = new MyInvoke(UpdateForm);
            MyInvoke2 mi2 = new MyInvoke2(AfterStepExec);
            try
            {
                while (!m_NeedStop && m_Rdr.TraceIsActive)
                {
                    ProfilerEvent evt = m_Rdr.Next();
                    if (evt != null)
                    {
                        //lbSPID.Text=evt.SPID.ToString();
                        this.BeginInvoke(mi, new Object[] { evt.SPID.ToString(), "test" });
                        lock (this)
                        {
                            m_events.Enqueue(evt);
                        }

                        //回收耗费性能,不建议使用。
                        //定时清理回收
                        //ClearTimeCount++;
                        //if (ClearTimeCount > 100)
                        //{
                        //    ClearMemory();
                        //    ClearTimeCount = 0;
                        //}

                        if (BIsStepExec)
                        {
                            StepLoop++;
                            if (StepLoop > StepCounts)
                            {
                                //置为初始
                                BIsStepExec = false;
                                StepCounts = 0;
                                StepLoop = 0;

                                this.BeginInvoke(mi2, new Object[] { "param1", "param2" });
                                return;
                            }
                        }

                    }
                }
            }
            catch (Exception e)
            {
                lock (this)
                {
                    if (!m_NeedStop && m_Rdr.TraceIsActive)
                    {
                        m_profilerexception = e;
                    }
                }
            }

            mi = null;
            //ClearMemory();
        }
Ejemplo n.º 45
0
        private void submit(int Tid)
        {
            MyInvoke UpdateMsgAdd = new MyInvoke(UpdateMsgTextBoxAdd);
            MyInvoke UpdateMsg = new MyInvoke(UpdateMsgBox);
            submit_state.BeginInvoke(UpdateMsg, new object[] { "当前正在提交的数量:" + listThread.Count.ToString() });
            string url = GetFullUrl();
            //byte[] buffer;

            if (tiancity_login.Checked)
            {
                if (LoginControlSelectedIndex == 0)
                {
                    if (!Login_HTTPRequest())
                    {
                        output_text.BeginInvoke(UpdateMsgAdd, new object[] { tiancity_userid.Text + ":登录失败" });
                        threadexit();
                        return;
                    }
                    else
                    {
                        if (Settings.Default.debug_msg)
                        {
                            output_text.BeginInvoke(UpdateMsgAdd, new object[] { tiancity_userid.Text + ":登录成功" });
                        }
                    }
                }
                else if (LoginControlSelectedIndex == 1)
                {
                    string[] info;
                    string strinfo = userinfo[Tid];
                    if (strinfo.IndexOf(',') > 0)
                    {
                        info = strinfo.Split(',');
                    }
                    else
                    {
                        info = new string[] { strinfo, "" };
                    }
                    //string[] info = userinfo[Tid].Split(new char[1] {','});
                    //bool loginsuccess = HTTPRequest();
                    if (!Login_HTTPRequest(info[0], info[1], Tid))
                    {
                        output_text.BeginInvoke(UpdateMsgAdd, new object[] { info[0] + ":登录失败" });
                        threadexit();
                        return;
                    }
                    else
                    {
                        if (Settings.Default.debug_msg)
                        {
                            output_text.BeginInvoke(UpdateMsgAdd, new object[] { info[0] + ":登录成功" });
                        }
                    }
                }
                else if (LoginControlSelectedIndex == 2)
                {
                    cookie_login_list.Add(Tid, usercookie[Tid]);
                }
            }

            string ResponseText;
            int runnumber = 1;
            TimeSpan timeover = TimeSpan.Zero;

            if (continue_numbers.Checked || continue_times.Checked)
            {
                if (continue_times.Checked)
                {
                    timeover = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) + continue_times_value;
                    if (continue_numbers.Checked) { runnumber = Convert.ToInt32(continue_numbers_input.Text); }
                    else { runnumber = -1; }
                }
                else
                {
                    timeover = TimeSpan.MaxValue;
                    runnumber = Convert.ToInt32(continue_numbers_input.Text);
                }
            }

            for (int i = 0; i != runnumber; runnumber--)
            {
                if (file_count > 0)
                {
                    ResponseText = HTTPRequest(url, GetBodyStream());
                }
                else
                {
                    ResponseText = HTTPRequest(url, GetBodyText());
                }

                ////
                string findstr = "";
                if (outputsearch_reg.Checked)
                {
                    Regex reg = new Regex(outputsearch_reg_input.Text);
                    Match regmatch = reg.Match(ResponseText);
                    findstr = regmatch.Value;
                }
                else if (outputsearch_side.Checked)
                {
                    findstr = search_string(ResponseText, outputsearch_side_L.Text, outputsearch_side_R.Text);
                }
                if (MemoryKey.Text.Length > 0 && findstr.Length > 0)
                {
                    ShareMemory.init(MemoryKey.Text, 1024);
                    ShareMemory.setdata_string(findstr, Encoding.Default);
                    if (Settings.Default.debug_msg)
                    {
                        output_text.BeginInvoke(UpdateMsgAdd, new object[] { "已在内存" + MemoryKey.Text + "中存入:" + findstr });
                    }
                }

                browser.text = ResponseText;
                output_text.BeginInvoke(UpdateMsgAdd, new object[] { ResponseText });
                if (timeover == TimeSpan.Zero || timeover <= TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss"))) { break; }
                if (continue_speed.Checked && (continue_numbers.Checked || continue_times.Checked)) { Thread.Sleep(continue_interval_millisecond); }
                if (runnumber < 0) { runnumber = -1; }
            }
            threadexit();
        }
Ejemplo n.º 46
0
        /// <summary>
        /// 文件发送函数
        /// </summary>
        /// <param name="IP"></param>
        /// <param name="Port"></param>
        /// <param name="FilePath"></param>
        /// <param name="PackSize"></param>
        /// <param name="LastPackSize"></param>
        /// <param name="PackCount"></param>
        public void StartSendFile(bool Sate, string IP, string Port, string FilePath, string PackSize, string LastPackSize, string PackCount, string FileName, string FileSize)
        {
            try
            {
                //设置进度条
                if (Sate == true)
                {
                    if (Convert.ToInt32(PackCount) > 0)
                    {
                        D_UpFileSendProgressMax _D_UpFileSendProgressMax = new D_UpFileSendProgressMax(UpFileSendProgressMax);
                        this.BeginInvoke(_D_UpFileSendProgressMax, new object[] { Convert.ToInt32(PackCount) });
                    }
                    else
                    {
                        D_UpFileSendProgressMax _D_UpFileSendProgressMax = new D_UpFileSendProgressMax(UpFileSendProgressMax);
                        this.BeginInvoke(_D_UpFileSendProgressMax, new object[] { 1 });
                    }
                }
                //指向远程服务器
                IPEndPoint iped = new IPEndPoint(IPAddress.Parse(IP), int.Parse(Port));
                //创建套接字
                Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                //连接到远程服务器
                client.Connect(iped);

                IPEndPoint clientep = (IPEndPoint)client.RemoteEndPoint;

                //MsgLog.Items.Add();

                D_UpMsgLog _D_UpMsgLog = new D_UpMsgLog(UpMsgLog);
                this.BeginInvoke(_D_UpMsgLog, new object[] { System.DateTime.Now.ToString() + ":发送文件【" + FileName + "】->[" + clientep.Address.ToString() + "]" });

                //发送文件名
                NetClassLibrary.TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(FileName));
                //发送文件大小
                NetClassLibrary.TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(FileSize));
                //发送包的大小
                NetClassLibrary.TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(PackSize));
                //发送包的数量
                NetClassLibrary.TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(PackCount));
                //发送最后一个包的大小
                NetClassLibrary.TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(LastPackSize));
                //发送文件MD5值
                //NetClassLibrary.TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(Text_FileMD5.Text.ToString()));


                System.IO.FileInfo tmp_FileInfo = new System.IO.FileInfo(FilePath);


                //打开文件
                System.IO.FileStream _fileStream = tmp_FileInfo.OpenRead();

                //定义数据包
                byte[] SendbagData = new byte[Convert.ToInt32(Text_PackSize.Value)];

                //开始循环发送数据包
                for (int i = 0; i < Convert.ToInt32(PackCount); i++)
                {
                    //从文件流中读取指定大小的数据,并填充到SendbagData字节变量中
                    _fileStream.Read(SendbagData, 0, SendbagData.Length);

                    //发送读取的数据包
                    NetClassLibrary.TransferFiles.SendVarData(client, SendbagData);


                    if (Sate == true)
                    {
                        //更新发包的数量(文本框中显示)
                        D_UpSendBagNu _D_UpSendBagNu = new D_UpSendBagNu(UpSendBagNu);
                        this.BeginInvoke(_D_UpSendBagNu, new object[] { (i + 1).ToString() });

                        //更新进度条
                        FileSendProgressB B = new FileSendProgressB(UpB);
                        this.BeginInvoke(B, new object[] { i + 1 });
                    }
                }

                if (Convert.ToInt32(LastPackSize) != 0)
                {
                    //读取最后一个包
                    SendbagData = new byte[Convert.ToInt32(Convert.ToInt32(LastPackSize))];
                    //发送最后一个包
                    _fileStream.Read(SendbagData, 0, SendbagData.Length);
                    NetClassLibrary.TransferFiles.SendVarData(client, SendbagData);


                    if (Sate == true)
                    {
                        if (Convert.ToInt32(PackCount) == 0)
                        {
                            //更新进度条
                            FileSendProgressB B = new FileSendProgressB(UpB);
                            this.BeginInvoke(B, new object[] { 1 });
                        }
                    }
                }


                MyInvoke _myInvoke = new MyInvoke(UpMsgLog);
                BeginInvoke(_myInvoke, new object[] { System.DateTime.Now.ToString() + ":【" + FileName + "】发送完成!" });


                //发送文件MD5值
                // NetClassLibrary.TransferFiles.SendVarData(client, System.Text.Encoding.Unicode.GetBytes(Text_FileMD5.Text.ToString()));

                //关闭读取的文件


                _fileStream.Close();

                //关闭网络连接
                client.Close();



                D_SendBtState _D_SendBtState = new D_SendBtState(SendBtState);
                this.BeginInvoke(_D_SendBtState, new object[] { true });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 47
0
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string url = GetFullUrl();
            MyInvoke UpdateMsgAdd = new MyInvoke(UpdateMsgTextBoxAdd);
            //byte[] buffer;
            if (tiancity_login.Checked)
            {
                //bool loginsuccess = HTTPRequest(true);
                if (!Login_HTTPRequest())
                {
                    output_text.BeginInvoke(UpdateMsgAdd, new object[] { tiancity_userid.Text + ":登录失败" });
                    //MessageBox.Show("登录失败");
                    return;
                }
            }
            string responsetxt;
            int runnumber = 1;
            TimeSpan timeover = TimeSpan.Zero;

            if (continue_numbers.Checked || continue_times.Checked)
            {
                if (continue_times.Checked)
                {
                    timeover = TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss")) + continue_times_value;
                    if (continue_numbers.Checked) { runnumber = Convert.ToInt32(continue_numbers_input.Text); }
                    else { runnumber = -1; }
                }
                else
                {
                    timeover = TimeSpan.MaxValue;
                    runnumber = Convert.ToInt32(continue_numbers_input.Text);
                }
            }

            for (int i = 0; i != runnumber; runnumber--)
            {
                if (backgroundWorker.CancellationPending) { e.Cancel = true; return; };
                if (file_count > 0) { responsetxt = HTTPRequest(url, GetBodyStream()); }
                else { responsetxt = HTTPRequest(url, GetBodyText()); }
                browser.text = responsetxt;
                output_text.BeginInvoke(UpdateMsgAdd, new object[] { responsetxt });
                if (timeover == TimeSpan.Zero || timeover <= TimeSpan.Parse(DateTime.Now.ToString("HH:mm:ss"))) { break; }
                if (continue_speed.Checked) { Thread.Sleep(continue_interval_millisecond); }
                if (runnumber < 0) { runnumber = -1; }
            }
        }
Ejemplo n.º 48
0
 public void DoWork()
 {
     mi = new MyInvoke(CapScreen);
     this.BeginInvoke(mi, new Object[] { pDown, pUp });
 }