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
        /// <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);
                    }
                }
            }
        }
        public void ReadRecordCommand_Verify_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            ReadRecordCommand       command
                = new ReadRecordCommand(connection);

            Assert.IsFalse(command.Verify(false));
        }
        public void ReadRecordCommand_Construciton_1()
        {
            Mock <IIrbisConnection> mock       = GetConnectionMock();
            IIrbisConnection        connection = mock.Object;
            ReadRecordCommand       command
                = new ReadRecordCommand(connection);

            Assert.AreSame(connection, command.Connection);
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        private void ProcessReadRecordCmd(ReadRecordCommand cmd)
        {
            XGData xgData = cmd.XGData;

            if (xgData != null)
            {
//                XGDB.InsertXGData ( cmd.XGData );
//                XGTask[] matchedXgTasks = Singles.S.XGScheduler.Tasks.MatchXGData( cmd.XGData );
//                foreach ( XGTask t in matchedXgTasks )
//                {
//                    t.IsComplete = true;
                // ?TODO: save complete task to db
                //
                XGDB.InsertXGData(cmd.Station.DestinationIP, xgData);
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        private void ProcessReadRecordCmd(ReadRecordCommand cmd)
        {
            if (cmd.XGData != null)
            {
                // 2007.03.11 Modify
                //
                //XGDB.InsertXGData ( cmd.XGData );
                XGDB.InsertXGData(cmd.Station.DestinationIP, cmd.XGData);

                XGTask[] matchedXgTasks = Singles.S.XGScheduler.Tasks.MatchXGData(cmd.XGData);
                foreach (XGTask t in matchedXgTasks)
                {
                    t.IsComplete = true;
                }
            }
        }
Example #7
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 #8
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 #9
0
        static public string GetCommCmdText(CommCmdBase cmd)
        {
            string r      = string.Empty;
            string stName = cmd.Station.StationName;
            string ip     = cmd.Station.DestinationIP;

            if (!Singles.S.CommPortProxyCollection.IsConnected(ip))
            {
                r = string.Format("同 {0}({1}) 尚未建立连接!", stName, ip);
            }
            else
            {
                if (cmd is GRRealDataCommand)
                {
                    r = string.Format("正在采集 {0}({1}) 供热实时数据...", stName, ip);
                }
                else if (cmd is ReadTotalCountCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 巡更记录总数...", stName, ip);
                }
                else if (cmd is ReadRecordCommand)
                {
                    ReadRecordCommand c = (ReadRecordCommand)cmd;
                    r = string.Format("正在读取 {0}({1}) 第{2}条巡更记录...", stName, ip, c.RecordIndex);
                }
                else if (cmd is AutoReportCommand)
                {
                    r = string.Format("正在清除 {0}({1}) 最新巡更数据...", stName, ip);
                }
                else if (cmd is GRReadPressAlarmSetCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 压力报警设定...", stName, ip);
                }
                else if (cmd is GRWritePressAlarmSetCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 压力报警设定...", stName, ip);
                }
                else if (cmd is GRReadTempWLAlarmSetCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 温度报警设定...", stName, ip);
                }
                else if (cmd is GRWriteTempWLAlarmSetCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 温度报警设定...", stName, ip);
                }
                else if (cmd is GRCyclePumpOpCmd)
                {
                    GRCyclePumpOpCmd tc = cmd as GRCyclePumpOpCmd;
                    string           s;
                    if (tc.OP == PumpOP.Stop)
                    {
                        s = "正在停止";
                    }
                    else
                    {
                        s = "正在启动";
                    }
                    r = string.Format(s + " {0}({1}) 循环泵...", stName, ip);
                }
                else if (cmd is GRRePumpOpCmd)
                {
                    GRRePumpOpCmd tc = cmd as GRRePumpOpCmd;
                    string        s;
                    if (tc.OP == PumpOP.Stop)
                    {
                        s = "正在停止";
                    }
                    else
                    {
                        s = "正在启动";
                    }

                    r = string.Format(s + " {0}({1}) 补水泵...", stName, ip);
                }
                else if (cmd is GRReadTLCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 温度控制曲线...", stName, ip);
                }
                else if (cmd is GRSetOutSideTempCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 室外温度...", stName, ip);
                }
                else if (cmd is GRSetOutSideTempModeCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 室外温度模式...", stName, ip);
                }
                else if (cmd is ReadDateCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 巡更控制器日期...", stName, ip);
                }
                else if (cmd is ReadTimeCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 巡更控制器时间...", stName, ip);
                }
                else if (cmd is ModifyDateCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 巡更控制器日期...", stName, ip);
                }
                else if (cmd is ModifyTimeCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 巡更控制器时间...", stName, ip);
                }
                else if (cmd is RemoveAllCommand)
                {
                    r = string.Format("正在删除 {0}({1}) 巡更控制器记录...", stName, ip);
                }
                //		public override string ToString()
                else if (cmd is GRWriteOTGT2Line)
                {
                    r = string.Format("正在设置 {0}({1}) 温度控制曲线...", stName, ip);
                }
                else if (cmd is GRWriteTimeTempLine)
                {
                    r = string.Format("正在设置 {0}({1}) 分时供热曲线...", stName, ip);
                }
                else if (cmd is GRReadTwoPressChaCommand)
                {
                    r = string.Format("正在读取 {0}({1}) 循环泵参数...", stName, ip);
                }
                else if (cmd is GRWriteTwoPressChaCommand)
                {
                    r = string.Format("正在设置 {0}({1}) 循环泵参数...", stName, ip);
                }
                else if (cmd is GRReadRepumpPressSettings)
                {
                    r = string.Format("正在读取 {0}({1}) 补水泵参数...", stName, ip);
                }
                else if (cmd is GRWriteRepumpPressSettings)
                {
                    r = string.Format("正在设置 {0}({1}) 补水泵参数...", stName, ip);
                }
                else
                {
                    r = string.Format("正在执行 {0}({1}) {2}...", stName, ip, cmd.ToString());
                }
            }

            return(r);
        }
Example #10
0
        /// <summary>
        /// 处理执行完毕的命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TaskScheduler_Executed(object sender, EventArgs e)
        {
            TaskScheduler sch = sender as TaskScheduler;

            if (sch == null)
            {
                Debug.Fail("TaskScheduler_Executed(), sender == null");
            }
            AddLog("TC: " + sch.Tasks.Count);
            Task   at = sch.ActiveTask;
            string s  = string.Format("send: {0}, {1}\r\nrece: {2}, {3}",
                                      at.LastSendDateTime, CT.BytesToString(at.LastSendDatas),
                                      at.LastReceivedDateTime, CT.BytesToString(at.LastReceived));

            AddLog(s);
            s = at.LastCommResultState.ToString();
            AddLog(s);
            CommCmdBase cmd = sch.ActiveTask.CommCmd;

            // read total count cmd
            //
            if (cmd is ReadTotalCountCommand)
            {
                ReadTotalCountCommand c = cmd as ReadTotalCountCommand;

                AddLog("LocalTotalCount: " + c.TotalCount);
                AddLog(c.Station.StationName + c.Station.Address);

                // need read all record and clear xg ctrler data
                //
                if (at.Tag != null)
                {//&&
                    // (string)at.Tag == TagType.OP_ReadAndClearXgData.ToString() )
                    //{
                    object[] tags    = (object[])at.Tag;
                    TagType  tagType = (TagType)tags[0];
                    XGTask   xgtask  = (XGTask)tags[1];

                    RemoveAllCommand clearCmd  = new RemoveAllCommand(c.Station as XGStation);
                    Task             clearTask = new Task(clearCmd, new ImmediateTaskStrategy());
                    Singles.S.TaskScheduler.Tasks.Add(clearTask);

                    for (int i = 0; i < c.TotalCount; i++)
                    {
                        ReadRecordCommand rdcmd = new ReadRecordCommand(c.Station as XGStation, i + 1);
                        Task t = new Task(rdcmd, new ImmediateTaskStrategy());
                        Singles.S.TaskScheduler.Tasks.Add(t);
                    }

                    // ???
                    //
                    //RemoveAllCommand rac = new RemoveAllCommand( c.Station as XGStation );
                    //Task trac = new Task( "rdall", rac, new ImmediateTaskStrategy() );
                    //trac.Tag = xgtask;
                    //trac.BeforeExecuteTask +=new EventHandler(trac_BeforeExecuteTask);
                    //Singles.S.TaskScheduler.Tasks.Add( trac );
                }
            }

            // read record cmd
            //
            if (cmd is ReadRecordCommand)
            {
                ReadRecordCommand rdcmd = cmd as ReadRecordCommand;
                AddLog("record index: " + rdcmd.RecordIndex);

                if (rdcmd.XGData != null)
                {
                    // 2007.03.11 Modify
                    //
                    //XGDB.InsertXGData( rdcmd.XGData );
                    XGDB.InsertXGData(cmd.Station.DestinationIP, rdcmd.XGData);
                }

                XGTask[] tasks = Singles.S.XGScheduler.Tasks.MatchXGData(rdcmd.XGData);
                foreach (XGTask task in tasks)
                {
                    task.IsComplete = true;
                }
            }
        }