JobStep.cs 2.4 KB

using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    public class JobStep<T> where T : Enum
    {
        private T step;
        private T preStep;
        private string msg = "";
        public string Msg
        {
            get { return msg; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                {
                    //不为空,且与上一个消息不一样才打印
                    if (!value.Equals(msg))
                    {
                        AGVManager.SaveAgvContextInfo(step.ToString());
                        LogUtil.info(string.Format("[{0}]{1}",step,value));
                    }
                }
                msg = value;
            }

        }
        public RunInfo StepRunInfo = new RunInfo();
        public DateTime startTime = DateTime.Now;

        public JobStep(T initStep)
        {
            this.step = initStep;
            this.preStep = 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="timeOutMiniutes"></param>
        /// <returns></returns>
        public bool IsTimeOut(double timeOutMiniutes, out double timeOutValue)
        {
            TimeSpan span = DateTime.Now - startTime;
            timeOutValue = span.TotalMinutes;
            if (span.TotalMinutes > timeOutMiniutes)
            {
                return true;
            }
            return false;
        }

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

        public string CurStep()
        {
            return step.ToString();
        }
        public string PreStep()
        {
            return preStep.ToString();
        }
        public void EndJob()
        {
            AGVManager.RunLogInfo(StepRunInfo);
        }
        
    }
}