/* ==============================================================================
 * 功能描述：RevitCmdExecutor  
 * 创 建 者：Garrett
 * 创建日期：2019/4/16 11:46:37
 * ==============================================================================*/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace Client.Start
{
    /// <summary>
    /// RevitCmdExecutor
    /// </summary>
    public class RevitCmdExecutor : IRevitCommandExcutor
    {
        public string ExecuteCmd(string revitCmd, string param, HashSet<string> filePathList)
        {
            //由revitCmd生成实体类
            //实体类传入参数、参考楼层列表
            //执行方法，返回执行结果 
            Console.WriteLine(DateTime.Now+" 准备执行命令:"+revitCmd);
            string fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StartVisionSelector.exe");
            Process process = new Process();//AppDomain.CurrentDomain.BaseDirectory +
            process.StartInfo.FileName = fullPath;//执行的exe路径
            process.StartInfo.UseShellExecute = false;//不显示shell
            process.StartInfo.CreateNoWindow = true;//不创建窗口
            process.StartInfo.RedirectStandardInput = true;//打开流输入
            process.StartInfo.RedirectStandardOutput = true;//打开流输出
            process.StartInfo.RedirectStandardError = true;//打开错误流
            process.StartInfo.Arguments = "" + revitCmd + " \"" + filePathList.First() + "\"";//输入参数，多个参数使用空间分割，如果一个参数包含空格，使用""包括此参数
            process.Start();//执行
            string msg = process.StandardOutput.ReadToEnd();//读取输出
            process.WaitForExit();//等待执行完成
            process.Close();//结束
            Console.WriteLine(DateTime.Now + " 命令执行完成:" + revitCmd);

            return msg;
        }
     
    }
}
