JobStep.cs 2.2 KB
using AGVControl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGVControl
{
    public class JobStep<T> where T : Enum
    {
        private T step;
        private string msg = "";
        public string Msg
        {
            get { return msg; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    value = step.ToString() + ":" + value;
                    //不为空,且与上一个消息不一样才打印
                    if (!value.Equals(msg))
                    {
                       // Common.LogInfo(value);
                    }
                }
                msg = value;
            }

        }
        private DateTime startTime = DateTime.Now;

        public JobStep(T initStep)
        {
            this.step = initStep;
            this.msg = "";
        }


        /// <summary>
        /// 当前步骤是否是某个步骤
        /// </summary>
        /// <param name="step"></param>
        /// <returns></returns>
        public bool IsStep(T step)
        {
            return this.step.Equals(step);
        }

        /// <summary>
        /// 是否超时
        /// </summary>
        /// <param name="timeOutMilliseconds"></param>
        /// <returns></returns>
        public bool IsTimeOut(int timeOutMilliseconds,out TimeSpan timeOutValue)
        {
            TimeSpan span = DateTime.Now - startTime;
            timeOutValue = span;
            if (span.TotalMilliseconds > timeOutMilliseconds)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 进入下一个步骤
        /// </summary>
        /// <param name="nextStep"></param>
        public void ToNextStep(T nextStep)
        {
            step = nextStep;
            startTime = DateTime.Now;
        }

        public string CurStep()
        {
            return step.ToString();
        }


        public void RecordRunLog(Agv_Info agv, string JobName, string runInfo, string targetPlace)
        {
            Common.RunLogInfo(new RunInfo(agv.Name.PadLeft(4, '0'), JobName, targetPlace, CurStep(), runInfo, startTime));
        }
    }
}