Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="owningTask"></param>
        /// <remarks>
        /// 可能包含读取并清除本地数据的后续指示(在Task.Tag中)
        /// </remarks>
        private void ProcessReadTotalCountCmd(ReadTotalCountCommand cmd, Task owningTask)
        {
            int recordCount = cmd.TotalCount;

            if (recordCount <= 0)
            {
                return;
            }

            XGStation st = (XGStation)cmd.Station;

            //Immediate task strategy 被加到tasks的最前端,所以要先加入,一般在读取完所有的记录后清空。
            //
            RemoveAllCommand clearCmd  = new RemoveAllCommand(st);
            Task             clearTask = new Task(clearCmd, new ImmediateTaskStrategy());

            Singles.S.TaskScheduler.Tasks.Add(clearTask);

            for (int i = 0; i < recordCount; i++)
            {
                ReadRecordCommand rdcmd = new ReadRecordCommand(st, i + 1);
                Task t = new Task(rdcmd, new ImmediateTaskStrategy());
                Singles.S.TaskScheduler.Tasks.Add(t);
            }
        }
Example #2
0
        private void CollXGData()
        {
            string stName = GetSelectStationName();

            if (stName == null || stName.Length == 0)
            {
                return;
            }

            XGStation xgst = Singles.S.XGStsCollection.GetXGStation(stName);

            if (xgst.ServerIP != XGConfig.Default.ServerIP)
            {
                MsgBox.Show(string.Format("站点 {0} 不连接到本台服务器,不能执行操作", xgst.StationName));
                return;
            }

            if (xgst != null)
            {
                string ip = xgst.DestinationIP;
                if (IsConnected(ip))
                {
                    ReadTotalCountCommand cmd = new ReadTotalCountCommand(xgst);
                    Task t = new Task(cmd, new ImmediateTaskStrategy());
                    Singles.S.TaskScheduler.Tasks.Add(t);
                }
                else
                {
                    MsgBox.Show(string.Format("站点 {0} 尚未与中心建立连接", xgst.StationName));
                }
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="owningTask"></param>
        /// <remarks>
        /// 可能包含读取并清除本地数据的后续指示(在Task.Tag中)
        /// </remarks>
        private void ProcessReadTotalCountCmd(ReadTotalCountCommand cmd, Task owningTask)
        {
            if (owningTask.Tag != null)
            {
                object[] tags = owningTask.Tag as object[];
                if (tags != null && tags.Length == 2)
                {
                    TagType tagType = (TagType)tags[0];
                    XGTask  xgtask  = (XGTask)tags[1];


                    //Immediate task strategy 被加到tasks的最前端,所以要先加入,一般在读取完所有的记录后清空。
                    //
                    RemoveAllCommand clearCmd  = new RemoveAllCommand(cmd.Station as XGStation);
                    Task             clearTask = new Task(clearCmd, new ImmediateTaskStrategy());
                    clearTask.Tag = xgtask;
                    clearTask.BeforeExecuteTask += new EventHandler(clearTask_BeforeExecuteTask);
                    Singles.S.TaskScheduler.Tasks.Add(clearTask);

                    for (int i = 0; i < cmd.TotalCount; i++)
                    {
                        ReadRecordCommand rdcmd = new ReadRecordCommand(cmd.Station as XGStation, i + 1);
                        Task t = new Task(rdcmd, new ImmediateTaskStrategy());
                        Singles.S.TaskScheduler.Tasks.Add(t);
                    }
                }
            }
        }
Example #4
0
        private void XGQueryCount(string remoteIP, int address)
        {
            XGStation xgSt = GetXGStation(remoteIP, address);

            if (xgSt != null)
            {
                ReadTotalCountCommand cmd = new ReadTotalCountCommand(xgSt);
                this.CreateImmediateTaskAndExecute(cmd);
            }
        }
Example #5
0
        /// <summary>
        /// 读取并清空巡更控制器中保存的本地数据
        /// </summary>
        /// <returns>巡更数据数组</returns>
        //private Record[] ReadAndClearXgData()
        private XGData[] ReadAndClearXgData()
        {
            try
            {
                ReadTotalCountCommand countCmd = new ReadTotalCountCommand(_xgStation);
                Task t = new Task(countCmd, new ImmediateTaskStrategy());

                //传递给通讯调度的附加对象,只是读取全部的本地数据并清空,
                //全部命令完成后,通知xgtask 已完成,ReadLocalXGDataComplete(), xgtask执行相关操作。
                object[] tags = new object[2];
                tags[0] = TagType.OP_ReadAndClearXgData;
                tags[1] = this;

                t.Tag = tags;

                Singles.S.TaskScheduler.Tasks.Add(t);
                return(null);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                return(null);
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Process(object sender, EventArgs e)
        {
            ArgumentChecker.CheckNotNull(sender);
            TaskScheduler sch  = (TaskScheduler)sender;
            Task          task = sch.ActiveTask;

            ArgumentChecker.CheckNotNull(task);

            CommCmdBase     cmd             = task.CommCmd;
            CommResultState commResultState = task.LastCommResultState;

            if (commResultState != CommResultState.Correct)
            {
                if (XGConfig.Default.LogCommFail)
                {
                    string s = string.Format("Send\t\t: {0}, {1}\r\nReceived\t: {2}, {3}\r\nCommResult\t: {4}\r\nCmdType\t\t: {5}\r\n",
                                             task.LastSendDateTime, CT.BytesToString(task.LastSendDatas),
                                             task.LastReceivedDateTime, CT.BytesToString(task.LastReceived),
                                             commResultState.ToString(), cmd.GetType().Name);
                    FileLog.CommFail.Add(s);
                }
                return;
            }

            if (cmd is ReadRecordCommand)
            {
                ReadRecordCommand readRecordCmd = cmd as ReadRecordCommand;
                ProcessReadRecordCmd(readRecordCmd);
            }

            if (cmd is ReadTotalCountCommand)
            {
                ReadTotalCountCommand readCountCmd = cmd as ReadTotalCountCommand;
                ProcessReadTotalCountCmd(readCountCmd, task);
            }
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="task"></param>
//        private void Process( string remoteIP, Task task )
        private void Process(Task task)
        {
            ArgumentChecker.CheckNotNull(task);

            string      remoteIP = task.CommCmd.Station.DestinationIP;
            CommCmdBase cmd      = task.CommCmd;
            Station     st       = cmd.Station;

            CommResultState commResultState = task.LastCommResultState;
            string          s = null;

            if (XGConfig.Default.LogCommIO)
            {
                if (s == null)
                {
                    //s = GetLogString( commPort, task );
                    s = GetLogString(remoteIP, task);
                }

                FileLog.CommIO.Add(s);
                if (XGConfig.Default.ShowLogForm)
                {
                    frmLogs.Default.AddLog(s);
                }
            }

            // log fail comm
            // 所有通讯失败情况在此处理
            //
            if (commResultState != CommResultState.Correct)
            {
                if (XGConfig.Default.LogCommFail)
                {
                    if (s == null)
                    {
                        s = GetLogString(remoteIP, task);
                    }

                    if (XGConfig.Default.LogCommFail)
                    {
                        FileLog.CommFail.Add(s);
                    }

                    if (XGConfig.Default.ShowLogForm)
                    {
                        //frmLogs.FailForm.AddLog( s );
                        frmLogs.Default.AddLogCommFail(s);
                    }
                }

                ProcessFreeData(task.CommCmd.Station.DestinationIP, task.LastReceived);  //, task);
                return;
            }

            // 以下只是处理通讯成功的情况
            //

            // 4. XG real total count command
            //
            if (cmd is ReadTotalCountCommand)
            {
                ReadTotalCountCommand readCountCmd = cmd as ReadTotalCountCommand;
                ProcessReadTotalCountCmd(readCountCmd, task);
            }

            // 5. XG real record
            //
            if (cmd is ReadRecordCommand)
            {
                ReadRecordCommand readRecordCmd = cmd as ReadRecordCommand;
                ProcessReadRecordCmd(readRecordCmd);
            }

            // 6. XG clear record command
            //

            // 读取供热控制器实时数据
            // 1. GR real data command
            //
            if (cmd is GRRealDataCommand)
            {
                GRRealDataCommand realDataCmd = ( GRRealDataCommand )cmd;
                //ProcessGRRealDataCmd( commPort, realDataCmd );
                ProcessGRRealDataCmd(remoteIP, realDataCmd);
            }

            // 2. GR set out side temperature command
            //
            if (cmd is GRSetOutSideTempCommand)
            {
                GRSetOutSideTempCommand c = (GRSetOutSideTempCommand)cmd;
                ProcessGRSetOutSideTempCmd(c);
            }

            // 3. GR remote set control params
            //
        }
Example #8
0
        /// <summary>
        /// 解析采集供热实时数据命令,
        /// parse xgdata read
        /// </summary>
        /// <returns></returns>
        private static TasksCollection  ResolveGRRealDataTaskFromDB()
        {
            string FailMsg = "Fail list:\r\n";
            //TODO: ResolveGRRealDataTaskFromDB
            //
            // 2007.03.10 Modify not use client flag, use serverIP diff local or remote gprs module,
            //
            //            string sql = string.Format(
            //                "select * from v_gprs_gr_xg where client = {0}",
            //                XGConfig.Default.ClientAorB  );
            string sql = "select * from v_gprs_gr_xg";

            DataSet         ds    = XGDB.DbClient.Execute(sql);
            DataTable       tbl   = ds.Tables[0];
            TasksCollection tasks = new TasksCollection();

            foreach (DataRow r in tbl.Rows)
            {
                string name   = r["name"].ToString();
                int    grAddr = int.Parse(r["gr_address"].ToString());
                int    xgAddr = int.Parse(r["xg_address"].ToString());

                string ip       = r["ip"].ToString();
                string serverIP = r["serverIP"].ToString();
                string team     = r["team"].ToString().Trim();

                //GRStation grst = new GRStation(name, grAddr, ip);
                GRStation grst = CreateGrStation(name, grAddr, ip, team);
                grst.ServerIP = serverIP;

                if (grst != null)
                {
                    // 2007.03.07 Added grstation to singles.grstationsCollection
                    //
                    Singles.S.GRStsCollection.Add(grst);

                    // 2007.03.01 Added gtstation last grRealdata
                    //
                    if (Singles.S.GRStRds == null)
                    {
                        Singles.S.GRStRds = new GRStationLastRealDatasCollection();
                    }

                    // create and add a new grstation last read data object to Singles.GRStRds
                    //
                    GRStationLastRealData grstLastRd = new GRStationLastRealData(grst);

                    Singles.S.GRStRds.Add(grstLastRd);

                    // 2007.03.10 Added check grstation(gprsstation).serverIP is the localhost ip
                    //
                    if (serverIP == XGConfig.Default.ServerIP)
                    {
                        // create a new grrealdata task for grStation
                        //
                        GRRealDataCommand cmd      = new GRRealDataCommand(grst);
                        TimeSpan          timeSp   = new TimeSpan(0, 0, XGConfig.Default.GrRealDataCollCycle, 0, 0);
                        CycleTaskStrategy strategy = new CycleTaskStrategy(timeSp);
                        Task t = new Task(cmd, strategy);
                        tasks.Add(t);
                    }
                }
                else
                {
                    FailMsg += name + Environment.NewLine;
                }

                // 2007.03.12 Added xg data task
                //
                XGStation xgst = CreateXgStation(name, xgAddr, ip);
                //TODO: ? xgst.serverIP = serverip
                //
                xgst.ServerIP = serverIP;

                if (xgst != null)
                {
                    Singles.S.XGStsCollection.Add(xgst);
                    if (serverIP == XGConfig.Default.ServerIP)
                    {
                        ReadTotalCountCommand xgCountCmd = new ReadTotalCountCommand(xgst);
                        TimeSpan          ts             = new TimeSpan(0, 0, XGConfig.Default.XgReadCountCycle, 0, 0);
                        CycleTaskStrategy strategy       = new CycleTaskStrategy(ts);
                        Task t = new Task(xgCountCmd, strategy);
                        tasks.Add(t);
                        //                        t.AfterProcessReceived +=new EventHandler(t_AfterProcessReceived);
                    }
                }
                else
                {
                }
            }

            if (FailMsg.Length >= 13)
            {
                MsgBox.Show(FailMsg);
            }
            return(tasks);
        }