Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name">Task的名称</param>
        /// <param name="commCmd">执行的命令</param>
        /// <param name="taskStrategy">使用的策略</param>
        // 2006.12.13 move station parameters to commandBase
        //
        //// 2006.10.26
        ////
        ////public Task( Station station, CommCmdBase commCmd, TaskStrategy taskStrategy )
        ////public Task( string name, Station station, CommCmdBase commCmd, TaskStrategy taskStrategy )
        public Task(string name, CommCmdBase commCmd, TaskStrategy taskStrategy)
        {
            this.Name = name;
            // 2006.12.13
            //
            ////Debug.Assert (station != null,      "station can't is null.");
            //if ( station == null )
            //    throw new ArgumentNullException("station", SR.GetString("LE_StationNull"));

            //Debug.Assert (commCmd != null,      "commCmd can't is null.");
            if (commCmd == null)
            {
                throw new ArgumentNullException("commCmd", SR.GetString("LE_CommCmdNull"));
            }



            // 2006.12.13
            //
            //m_Station = station;

            m_CommCmd = commCmd;

            TaskStrategy = taskStrategy;
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="commPortProxy"></param>
        /// <param name="cmd"></param>
        // 2006.12.13
        //
        //virtual protected void OnExecute ( CommPortProxy commPortProxy, Station station, CommCmdBase cmd, object[] parameters )
        virtual protected void OnExecute(CommPortProxy commPortProxy, CommCmdBase cmd)
        {
            // 2006.12.13
            //
            //byte[] bytesCmd = cmd.MakeCommand ( station, parameters );
            byte[] bytesCmd = cmd.MakeCommand();
            //Debug.Assert (bytesCmd != null && bytesCmd.Length >0 , "bytesCmd can't is null and must length >0" );

            // 2006.12.15 Added, save last send command byte[].
            //
            this.m_LastSendDatas = bytesCmd;

            commPortProxy.Send(bytesCmd, cmd.LatencyTime);
        }
Example #3
0
        protected Task(SerializationInfo info, StreamingContext context)
        {
            foreach (SerializationEntry entry in info)
            {
                //if (entry.ObjectType == typeof (Station) ||
                //    entry.ObjectType.IsSubclassOf(typeof(Station)))
                //{
                //    this.m_Station = (Station) entry.Value;
                //}

                switch (entry.Name)
                {
                case "TaskStrategy":
                    //this.TaskStrategy = (TaskStrategy)entry.Value;
                    this.m_TaskStrategy = (TaskStrategy)entry.Value;
                    break;

                // 2006.12.13
                //
                //case "Station":
                //    this.m_Station  = (Station)entry.Value;
                //    break;

                case "CommCmd":
                    this.m_CommCmd = (CommCmdBase)entry.Value;
                    break;

                // 2006.12.13
                //
                //case "Parameters":
                //    this.m_Parameters = (object[])entry.Value;
                //    break;

                case "Key":
                    this.Key = (string)entry.Value;
                    break;

                case "Tag":
                    this.Tag = (object)entry.Value;
                    break;

                default:
                    throw new SerializationException(entry.Name + " " + entry.Value);
                }
            }
        }
        /// <summary>
        /// 查找需要执行的任务,并执行
        /// </summary>
        private void ScanExecute()
        {
            Task needExecTask = FindNeedExecuteTask();

            if (needExecTask != null)
            {
                if (Executing != null)
                {
                    EventHandler temp = Executing;
                    temp(this, EventArgs.Empty);
                }
                //{

                // 2007.02.23 modify
                //
                //needExecTask.Execute( m_CommPortProxy );
                CommCmdBase cmd = needExecTask.CommCmd;
                Debug.Assert(cmd != null);

                Station st = cmd.Station;
                Debug.Assert(st != null);

                // use ip
                //
                if (st.IsUseIP)
                {
                    string ip = st.DestinationIP;
                    // TODO: 2007-10-18 Search cpp use ip or simNumber
                    //
                    // search commPortProxy match ip
                    //
                    CommPortProxy cpp = SearchCPP(ip);
                    if (cpp != null)
                    {
                        needExecTask.Execute(cpp);
                    }
                    else
                    {
                        // not find match cpp
                        //
                        // TODO: raise not find cpp event
                        //
                        if (this.NotFindMatchCPPEvent != null)
                        {
                            EventHandler temp = NotFindMatchCPPEvent;
                            temp(this, EventArgs.Empty);
                        }
                        needExecTask.LastExecute = DateTime.Now;
                        Debug.Assert(m_ActiveTask != null, "at not find match ip cpp, m_activeTask == null");
                        m_ActiveTask = null;
                    }
                }
                // use commport
                //
                else
                {
                    //CommPortProxy cpp;
                    //needExecTask.Execute( cpp );
                    Debug.Fail("need use IP");
                }
                //}
            }
        }
Example #5
0
 public Task(CommCmdBase commCmd, TaskStrategy taskStrategy)
     : this(string.Empty, commCmd, taskStrategy)
 {
 }