예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string configFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DockPanel.config");

            if (File.Exists(configFile))
            {
                dockPanel1.LoadFromXml(configFile, m_deserializeDockContent);
            }

            #region 队列

            //Action<RabbitmqMessageCallback, RabbitmqConnectCallback> doS = (val, rbCon) =>
            //{

            //};
            doWorkD = new RabbitmqMessageCallback(doWork);
            rabbitmqConnectCallback = new RabbitmqConnectCallback(RabbitmqConnected);
            try
            {
                RabbitMQClientHandler.GetInstance(doWorkD, rabbitmqConnectCallback).SyncDataFromServer("work");
            }
            catch (Exception er)
            {
                MessageBox.Show("连接队列失败!!!");
                Environment.Exit(0);
            }
            //MySmartThreadPool.Instance().QueueWorkItem(doS, doWorkD, rabbitmqConnectCallback);
            #endregion
        }
예제 #2
0
        /// <summary>
        /// 改变工作状态,暂停和继续
        /// </summary>
        public void changeStatus()
        {
            if (workPause)
            {
                if (isLeisure == false)
                {
                    return;
                }
                pStatus.Visible = false;
                pcbDetails.changePause("暂停", false);
                workPause = false;
                RabbitMQClientHandler.Resume();
            }
            else
            {
                workPause = true;
                MessageBox.Show("完成当前的板子后不再接受新的板子", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (isLeisure) // 空闲状态下,暂停可以直接恢复
                {
                    pcbDetails.changePause("恢复", true);
                    this.Text = "检验端-v2.0 [暂停中...]";
                }
                else
                {
                    pcbDetails.changePause("恢复", false);
                }
            }
        }
        /// <summary>
        /// AI检测结束共用函数
        /// </summary>
        /// <param name="oneStitchSidePcb"></param>
        public void aiDone(string savePath)
        {
            Console.WriteLine(allDetectNum);
            if (allDetectNum == nowPcb.AllPhotoNum)
            {
                this.BeginInvoke((Action)(() =>
                {
                    fuckDetectNum = 0;
                    try
                    {
                        MySmartThreadPool.InstanceSmall().WaitForIdle();
                        Console.WriteLine("InstanceSmall: " + MySmartThreadPool.InstanceSmall().InUseThreads);
                        Console.WriteLine("Instance: " + MySmartThreadPool.Instance().InUseThreads);
                        //这里可以直接发送了!!!!!!
                        //结束计时
                        //MessageBox.Show("执行查询总共使用了, total :" + times + "s 秒");
                        try
                        {
                            JsonData <Pcb> jsonData = new JsonData <Pcb>();
                            jsonData.data = nowPcb;
                            jsonData.executionTime = 11;
                            jsonData.ngNum = nowPcb.results.Count;
                            var jSetting = new JsonSerializerSettings {
                                NullValueHandling = NullValueHandling.Ignore
                            };
                            string[] props = { "FrontPcb", "BackPcb" }; //排除掉,不能让前端看到的字段。为true的话就是只保留这些字段
                            jSetting.ContractResolver = new LimitPropsContractResolver(props, false);

                            string res = JsonConvert.SerializeObject(jsonData, jSetting);
                            RabbitMQClientHandler.GetInstance()
                            .TopicExchangePublishMessageToServerAndWaitConfirm("", "work", "work", res);

                            File.WriteAllText(Path.Combine(savePath, "result.json"), ConvertJsonString(res));
                        }
                        catch (Exception er)
                        {
                            MessageBox.Show(" 发送队列出错" + er.Message);
                            //LogHelper.WriteLog("连接队列失败!!!", er);
                        }
                    }
                    catch (Exception er)
                    {
                    }
                    finally
                    {
                        allDetectNum = 0;
                    }
                }));
            }
        }
예제 #4
0
        public void doLeisure(bool clearAll)
        {
            isLeisure = true;

            try
            {
                RabbitMQClientHandler.ListenChannel.BasicAck(RabbitMQClientHandler.deliveryTag, false);
            }
            catch (Exception)
            {
                LogHelper.WriteLog("队列释放失败\n" + RabbitMQClientHandler.deliveryTag);
            }

            pcbDetails.lvListFront.Items.Clear();
            pcbDetails.lvListBack.Items.Clear();
            pcbDetails.lbPcbNumber.Text        = "";
            pcbDetails.lbSurfaceNumber.Text    = "";
            pcbDetails.lbPcbWidth.Text         = "";
            pcbDetails.lbPcbLength.Text        = "";
            pcbDetails.lbPcbChildenNumber.Text = "";
            pcbDetails.lbResult.Text           = "";

            if (workPause)
            {
                this.Text = "检验端-v2.0 [暂停中...]";
                pcbDetails.changePause("恢复", true);
                RabbitMQClientHandler.Pause();
                pStatus.Visible = true;
            }
            else
            {
                this.Text = "检验端-v2.0 [等待最新的校验信息...]";
            }


            if (clearAll)
            {
                twoSidesPcb.BeginInvoke((Action)(() =>
                {
                    twoSidesPcb.showFrontImg(null);
                    twoSidesPcb.showBackImg(null);
                }));
                partOfPcb.BeginInvoke((Action)(() =>
                {
                    partOfPcb.showImg(null);
                }));
            }
        }
예제 #5
0
        /// <summary>
        /// 加载配置
        /// </summary>
        public void LoadSettings()
        {
            MQTTConfig config = new MQTTConfig();

            config.HostName            = ConfigurationManager.AppSettings["Mqtt_Server"];
            config.Port                = int.Parse(ConfigurationManager.AppSettings["Mqtt_Port"]);
            config.UserName            = ConfigurationManager.AppSettings["Mqtt_User"];
            config.Password            = ConfigurationManager.AppSettings["Mqtt_Password"];
            config.DefaultExchangeName = ConfigurationManager.AppSettings["Mqtt_Exchange"];
            ILogWrite _log = ServiceLocator.Current.GetInstance <ILogWrite>();

            rabbitMQClientHandler = new RabbitMQClientHandler(config, _log);
            rabbitMQClientHandler.Connect();//连接

            ExchangeName     = config.DefaultExchangeName;
            DispatchQueue    = ConfigurationManager.AppSettings["Mqtt_DispatchQueue"];
            DispatchRouteKey = ConfigurationManager.AppSettings["Mqtt_DispatchRouteKey"];
            List <RabbitQueueBind> list = new List <RabbitQueueBind>();

            list.Add(new RabbitQueueBind()
            {
                ExchangeName = ExchangeName,
                QueueName    = DispatchQueue,
                RouteKey     = DispatchRouteKey
            });

            StatusQueue    = ConfigurationManager.AppSettings["Mqtt_StatusQueue"];
            StatusRouteKey = ConfigurationManager.AppSettings["Mqtt_StatusRouteKey"];
            list.Add(new RabbitQueueBind()
            {
                ExchangeName = ExchangeName,
                QueueName    = StatusQueue,
                RouteKey     = StatusRouteKey
            });

            rabbitMQClientHandler.ExchangeAndQueueInitial(ExchangeName, ExchangeType.Topic, list); //初始化交换机和队列的绑定关系

            rabbitMQClientHandler.RabbitmqMessageConsume(DispatchQueue);                           //订阅队列:派送队列
            rabbitMQClientHandler.MessageReceivedRaised += RabbitMQClientHandler_MessageReceivedRaised;
        }
        private void btnFuckTest_Click(object sender, EventArgs e)
        {
            //thiscard = true;
            //isBabyYiNing = true;
            nowPcb = Pcb.CreatePcb();

            try
            {
                JsonData <Pcb> jsonData = new JsonData <Pcb>();
                jsonData.data          = nowPcb;
                jsonData.executionTime = 11;
                jsonData.ngNum         = nowPcb.results.Count;
                var jSetting = new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                };
                string[] props = { "FrontPcb", "BackPcb" }; //排除掉,不能让前端看到的字段。为true的话就是只保留这些字段
                jSetting.ContractResolver = new LimitPropsContractResolver(props, false);

                string res = JsonConvert.SerializeObject(jsonData, jSetting);
                RabbitMQClientHandler.GetInstance()
                .TopicExchangePublishMessageToServerAndWaitConfirm("", "work", "work", res);

                //File.WriteAllText(Path.Combine(savePath, "result.json"), ConvertJsonString(res));
            }
            catch (Exception er)
            {
                //LogHelper.WriteLog("连接队列失败!!!", er);
            }
            //string imgPath = "testpic.png";
            //OpenFileDialog ofd = new OpenFileDialog();
            //DialogResult fdr = ofd.ShowDialog();
            //if (fdr == DialogResult.OK)
            //{
            //    imgPath = ofd.FileName;
            //}
            //DirectoryInfo info = new DirectoryInfo(imgPath);
            //string fuckpath = info.Parent.FullName;

            //nowPcb.FrontPcb.allCols = 24;
            //nowPcb.FrontPcb.allRows = 10;
            //nowPcb.FrontPcb.allNum = 240;
            //nowPcb.FrontPcb.or_hl = 0.3;
            //nowPcb.FrontPcb.or_hu = 0.4;
            //nowPcb.FrontPcb.or_vl = 0.1;
            //nowPcb.FrontPcb.or_vu = 0.5;
            //nowPcb.FrontPcb.dr_hu = 0.02;
            //nowPcb.FrontPcb.dr_vu = 0.02;
            //MySmartThreadPool.Instance().QueueWorkItem(() =>
            //{
            //    DirectoryInfo root = new DirectoryInfo(fuckpath);
            //    //int i = 0;
            //    for (int i = 1; i <= nowPcb.FrontPcb.allNum; i++)
            //    {
            //        Bitmap fBitmap = new Bitmap(fuckpath + "/F" + i + ".jpg");
            //        fBitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);  //指定不进行翻转的 180 度旋转  (垂直翻转+水平翻转)
            //        nowPcb.FrontPcb.bitmaps.Enqueue(new OneStitchSidePcb.BitmapInfo() { bitmap = (Bitmap)BitmapScaleHelper.ScaleToSize(fBitmap, (float)0.4).Clone(), name = "/F" + i + ".jpg" });
            //        fBitmap.Dispose();

            //        //Aoi.StitchMain(nowPcb.FrontPcb, onStitchCallBack);
            //        MySmartThreadPool.Instance().QueueWorkItem(() =>
            //        {
            //            lock (nowPcb.FrontPcb)
            //            {
            //                Aoi.StitchMain(nowPcb.FrontPcb, onStitchCallBack);
            //            }
            //        });
            //    }
            //});
        }