Ejemplo n.º 1
0
        private void resetParams(Device d, string high_threshold, string low_threshold, string param1, string factor)
        {
            /**
             * 发送控制命令到二级的调用方法
             * */
            DeviceCommandBox dcb = new DeviceCommandBox();

            dcb.load(d.DeviceId, d.CabId, high_threshold, low_threshold, param1, factor);
            List <Box> lb = new List <Box>();

            lb.Add(dcb);
            String data = PackageWorker.pack(lb);

            MainController.sendCommand("192.168.0.105", "6003", data);

            //SocketConnection con = new SocketConnection("127.0.0.1", "58888");
            //con.Connect();
            //DeviceCommandBox box = new DeviceCommandBox();
            //box.load(d.DeviceId, d.CabId, high_threshold, low_threshold, param1, factor);
            //List<Box> boxes = new List<Box>();
            //boxes.Add(box);
            //string package = PackageWorker.pack(boxes);
            //con.Send(package);
            //con.exit();
            //Console.WriteLine("发送参数!");
        }
Ejemplo n.º 2
0
        private void doWork(object obj)
        {
            List <PackageWorkEventArgs <T> > packages = (List <PackageWorkEventArgs <T> >)obj;

            foreach (PackageWorkEventArgs <T> package in packages)
            {
                try
                {
                    if (PackageWorker != null)
                    {
                        PackageWorker.Invoke(this, package);
                    }
                }
                catch (Exception ex)
                {
                    package.Exception    = ex;
                    package.HasException = true;

                    //CurrentUser user = CurrentUser.Instance;
                    //SmartSchool.ExceptionHandler.BugReporter.ReportException("SmartSchool", user.SystemVersion, ex, false);
                }
            }
        }
Ejemplo n.º 3
0
        public static void receiveCommandData(string data)
        {
            List <Box> boxes = PackageWorker.unpack(data);

            foreach (Box item in boxes)
            {
                if (item.className() == DeviceCommandEchoBox.classNameString) //控制命令单独处理
                {
                    DeviceCommandEchoBox tempItem = (DeviceCommandEchoBox)item;
                    if (tcpConnection.ConnectState)
                    {
                        if (tempItem.code == "1")
                        {
                            MessageBox.Show("修改成功");
                        }
                        else
                        {
                            MessageBox.Show("修改失败");
                        }
                        tcpConnection.exit();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private void repairAProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CommonOpenFileDialog fb = new CommonOpenFileDialog();

            fb.IsFolderPicker   = true;
            fb.Title            = "Please select the directory that your project resides in.";
            fb.EnsurePathExists = true;
            CommonFileDialogResult rs = fb.ShowDialog();

            if (rs == CommonFileDialogResult.Cancel)
            {
                return;
            }

            // Get the path.
            string dir = fb.FileName;

            // Check if it is empty or if the user clicked Cancel.
            if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir))
            {
                return;
            }

            // Check if it is a valid project.
            if (!Directory.Exists(dir + "/Package") || !File.Exists(dir + "/data.sqlite"))
            {
                MessageBox.Show("The selected project is not a valid project.", "Repairing Mod Builder project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Ask if the user wants to generate a new database, or to just add the tables.
            DialogResult result = MessageBox.Show("Should the existing database be truncated? Answering no will instead try to add all missing data.", "Reparing project", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            // New instance of the mod editor.
            modEditor me = new modEditor();

            // Fiddle with the database.
            me.generateSQL(dir, (result == DialogResult.Yes), ModParser.parsePackageInfo(dir + "/Package/package-info.xml"));

            // Do /Source and /Package exist?
            if (!Directory.Exists(dir + "/Source"))
            {
                Directory.CreateDirectory(dir + "/Source");
            }
            if (!Directory.Exists(dir + "/Package"))
            {
                Directory.CreateDirectory(dir + "/Package");
            }

            // Ask if the user wants to load the project.
            result = MessageBox.Show("Your project has been repaired. Do you want to load the project now?", "Project repaired", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            // Yes? Load the project.
            if (result == DialogResult.Yes)
            {
                PackageWorker.bootstrapLoad(dir);
            }

            /*
             * {
             * // Show a loadProject dialog.
             * loadProject lp = new loadProject();
             * lp.Show();
             *
             * // Load the project.
             * bool stat = lp.openProjDir(dir);
             *
             * // Check the status.
             * if (stat == false)
             *  MessageBox.Show("An error occured while loading the project.", "Loading project", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *
             * // Close the loadProject dialog.
             * lp.Close();
             * }*/
        }
Ejemplo n.º 5
0
        public void receiveData(string data) //收到二级发送过来的数据后触发
        {
            List <Box> boxes = new List <Box>();

            if (data == null || data.Equals(""))
            {
                return;
            }
            try
            {
                boxes = PackageWorker.unpack(data);
                Console.WriteLine("收到数据包中包含的设备:" + boxes.Count);
            }
            catch (Exception e)
            {
                Alarm("收到数据包格式异常,无法解析!");
            }
            if (boxes == null || boxes.Count == 0)
            {
                return;
            }
            Device deviceInMap    = null;
            Device deviceToChange = null;

            try
            {
                foreach (DeviceDataBox_Base item in boxes)
                {
                    if (item.className() != DeviceCommandEchoBox.classNameString) //控制命令单独处理
                    {
                        DeviceDataBox_Base tempItem = (DeviceDataBox_Base)item;
                        if (tempItem == null)
                        {
                            break;
                        }

                        deviceInMap            = GlobalMapForShow.globalMapForDevice[tempItem.systemId + "_" + tempItem.devId];
                        deviceInMap.Value      = item;
                        deviceInMap.Type       = item.className();
                        deviceInMap.NowValue   = tempItem.value;
                        deviceInMap.BuildingId = tempItem.systemId;
                        deviceInMap.CabId      = tempItem.cabId;
                        deviceInMap.DeviceId   = tempItem.devId;
                        deviceInMap.State      = tempItem.state.ToString();

                        if (!deviceInMap.NowValue.Equals(""))
                        {
                            if (float.Parse(deviceInMap.NowValue) > deviceInMap.Highthreshold)
                            {
                                tempItem.state    = DeviceDataBox_Base.State.H_Alert;
                                deviceInMap.State = DeviceDataBox_Base.State.H_Alert.ToString();
                            }
                            else if (float.Parse(deviceInMap.NowValue) < deviceInMap.Lowthreshold)
                            {
                                tempItem.state    = DeviceDataBox_Base.State.L_Alert;
                                deviceInMap.State = DeviceDataBox_Base.State.L_Alert.ToString();
                            }
                        }

                        //高低阈值被修改,将修改后的参数入库
                        if ((!tempItem.lowThreshold.Equals("") && deviceInMap.Lowthreshold != float.Parse(tempItem.lowThreshold)) ||
                            (!tempItem.highThreshold.Equals("") && deviceInMap.Highthreshold != float.Parse(tempItem.highThreshold)) ||
                            !tempItem.factor.Equals("") && deviceInMap.CorrectFactor != float.Parse(tempItem.factor))
                        {
                            if (!tempItem.lowThreshold.Equals(""))
                            {
                                deviceInMap.Lowthreshold = float.Parse(tempItem.lowThreshold);
                            }
                            if (!tempItem.highThreshold.Equals(""))
                            {
                                deviceInMap.Highthreshold = float.Parse(tempItem.highThreshold);
                            }
                            if (!tempItem.factor.Equals(""))
                            {
                                deviceInMap.CorrectFactor = float.Parse(tempItem.factor);
                            }
                            if (dataOfDevice.UpdateDeviceInfo("deviceInfo", deviceInMap) == 1) //修改成功
                            {
                                LogUtil.Log(true, deviceInMap.SubSystemName + " 设备 " + deviceInMap.Type + " 设备编号:" + deviceInMap.DeviceId +
                                            "高低阈值修改成功!当前高阈值:" + deviceInMap.Highthreshold + ",低阈值:" + deviceInMap.Lowthreshold + ",修正因子:" + deviceInMap.CorrectFactor, (int)ErrorCode.ERR_CODE.OK);
                            }
                        }

                        deviceToChange = tempItem.fromBoxToDevice();
                        //收到状态不正常的数据时,触发警报,并把相应的cab和building的状态更改为相应的报警状态
                        if (tempItem.state != DeviceDataBox_Base.State.Normal)
                        {
                            Alarm(deviceToChange);
                        }
                        //更改柜子的状态
                        GlobalMapForShow.globalMapForCab[tempItem.systemId + "_" + tempItem.cabId].State =
                            GlobalMapForShow.globalMapForCab[tempItem.systemId + "_" + tempItem.cabId].isStateNormal() ? DeviceDataBox_Base.State.Normal.ToString() : DeviceDataBox_Base.State.Alert.ToString();

                        //更改监测点的状态
                        GlobalMapForShow.globalMapForBuiding[tempItem.systemId].State = GlobalMapForShow.globalMapForBuiding[tempItem.systemId].isStateNormal() ? DeviceDataBox_Base.State.Normal.ToString() : DeviceDataBox_Base.State.Alert.ToString();

                        //遍历所有楼宇的状态,存在有一栋楼有异常状态 ,就报警或者维持报警状态,否则停止报警
                        if (GlobalMapForShow.isAllBuildingNormal())
                        {
                            alarmBuzzer(false);
                        }
                        else
                        {
                            alarmBuzzer(true);
                        }

                        bq.Enqueue(deviceToChange);  //将获取到的数据插入队列
                    }
                }//end for
            }
            catch (Exception e)
            {
                Alarm("收到数据包格式异常,无法解析!" + "(" + DateTime.Now.ToString() + ")");
            }
            finally
            {
                boxes       = null;
                deviceInMap = null;
                dataChartUpdate();
            }
        }