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

namespace RailMeterSystem
{
    /// <summary>
    /// 截图调用类
    /// </summary>
    public class CameraShotCls
    {
        public void Connection()
        {
            foreach (DhCameraShot shot in CarCache.cameraShots)
            {
                shot.Connection();
            }
        }

        public void Close()
        {
            foreach (DhCameraShot shot in CarCache.cameraShots)
            {
                shot.Close();
            }
        }

        /// <summary>
        /// 截图
        /// </summary>
        /// <param name="actualFirstNo">作业编号</param>
        public void CapPic(string actualFirstNo)
        {
            int iCnt = 1; //抓拍摄像头配置顺序必须是前面2个
            foreach (DhCameraShot shot in CarCache.cameraShots)
            {
                shot.CapPic(1, PbCache.path + string.Format("\\imgShort\\tempImg\\{0}_{1}_{2}.jpg", PbStaticRailwayCache.sportInfo.baseSpotNo, "R" + actualFirstNo, iCnt));
                iCnt++;
            }
        }

        /// <summary>
        /// 从硬盘录像机 进行截图
        /// </summary>
        /// <param name="actualFirstNo"></param>
        public void CapPicFromVideo(string actualFirstNo)
        {
            foreach (DhCameraShot shot in CarCache.cameraShots)
            {
                //放在tempImg文件夹下面就进行图片的压缩操作，否则不进行图片压缩
                //shot.CapPic(iCnt < 3 ? 0 : 1, PbCache.path + string.Format("\\imgShort\\tempImg\\{0}_{1}_{2}.jpg", PbCache.sportInfo.baseSpotNo, "C" + actualFirstNo, iCnt));
                shot.CapPicFromVedio(PbCache.path + string.Format("\\imgShort\\formalImg\\{0}_{1}_", PbStaticRailwayCache.sportInfo.baseSpotNo, "R" + actualFirstNo));
            }

        }

        /// <summary>
        /// 连接视频截图并关闭
        /// </summary>
        /// <param name="actualFirstNo">作业编号</param>
        public void CapMethod(string actualFirstNo)
        {
            Connection();
            CapPic(actualFirstNo);
            Close();
        }
        /// <summary>
        /// 连接视频截图并关闭；使用硬盘录像机
        /// </summary>
        /// <param name="actualFirstNo">作业编号</param>
        public void CapMethodFromVideo(string actualFirstNo)
        {
            Connection();
            CapPicFromVideo(actualFirstNo);
            Close();
        }
    }

    public class CarCache
    {
        /// <summary>
        /// 摄像头的开关类集合
        /// </summary>
        public static List<DhCameraShot> cameraShots { get; set; }
    }
}
