IPCameraHelper.cs 2.1 KB
using OnlineStore.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    public class IPCameraHelper
    {
        //"E:\\Codes\\CSharp-Workspace\\MyProject\\WindowsService\\IPCamService\\bin\\Debug\\IPCamService.exe"
        static string baseDir = ConfigHelper.Config.Get("IPCamService_HttpServer", "http://localhost:8088");
        public static void StartIPCamService()
        {
            string appFilePath = ConfigHelper.Config.Get("IPCamService_FilePath", @"D:\IPCamera");
            if (Directory.Exists(appFilePath))
            {
                var exe = "IPCamera.exe";
                try
                {
                    Process process = new Process();
                    process.StartInfo = new ProcessStartInfo();
                    process.StartInfo.FileName = exe;
                    process.StartInfo.WorkingDirectory = appFilePath;
                    process.Start();
                    LogUtil.info($"启动软件:{appFilePath}\\{exe}");
                }
                catch (Exception ex)
                {
                    LogUtil.error($"启动软件失败:{appFilePath}\\{exe}",ex);
                }
            }

        }
        public static void StartRecord(string camName, string fileName = "")
        {
            Task.Factory.StartNew(delegate
            {
                string url = $"{baseDir}/cam/startRecord?camName={camName}&filename={fileName}";
                string res = HttpHelper.Get(url);
                LogUtil.info($"开始记录视频:{fileName},{res}");
            });

        }
        public static void StopRecord(string camName)
        {
            Task.Factory.StartNew(delegate
            {
                string url = $"{baseDir}/cam/stopRecord?camName={camName}";
                string res = HttpHelper.Get(url);
                LogUtil.info($"停止记录视频:{res}");
            });

        }
    }
}