Beispiel #1
0
        /// <summary>
        /// 启动simlink模型
        /// </summary>
        /// <param name="arguments">启动参数,这是启动MATLAB的名称参数,在配置文件的属性中可以看到DEMO</param>
        /// <param name="row">PID记录在这里</param>
        private void MakeRun(string arguments, ref ManagerMessage row)
        {
            try
            {
                //string arguments = @"-nosplash -nodesktop -sd D:\MyWorkGGTest\one\MGtcp -r test";


                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(PublicClassRule.GetValues("root", "MATLAB_Process_FullPath"), arguments);

                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                System.Diagnostics.Process myprocess = new System.Diagnostics.Process();
                myprocess.StartInfo = startInfo;
                myprocess.StartInfo.UseShellExecute        = false;
                myprocess.StartInfo.CreateNoWindow         = true;
                myprocess.StartInfo.RedirectStandardOutput = true;

                myprocess.Start();


                row.PID = myprocess.Id;  //获取PID

                myprocess.WaitForExit(); //进程会一直处于等待退出状态。
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #2
0
 /// <summary>
 /// 异步操作文件夹复制
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 private async Task Copy(ManagerMessage row)
 {
     await Task.Run(() => {
         PublicClassTools.Copy(row.SourceModelPath, row.CopyModel_To_TargetPath);
         row.Status = ShiYanStatus.FilesCopyCompleted;
     });
 }
Beispiel #3
0
 private void Read_Exception(ref ManagerMessage r, Exception e)
 {
     if (e.Message == "无此试验模型配置")
     {
         r.Status = ShiYanStatus.Error_No_THIS_HR_ID;
     }
     else if (e.Message == "母文件夹无效")
     {
         r.Status = ShiYanStatus.Error_No_MotherPath;
     }
     else if (e.Message == "没找到原模型路径")
     {
         //没找到原模型路径
         r.Status = ShiYanStatus.Error_NoFind_SourcePath;
     }
     else if (e.Message == "没找到自己的试验模型数据路径")
     {
         //没找到自己的试验模型数据路径
         r.Status = ShiYanStatus.Error_NoFind_FuPanPath;
     }
     else if (e.Message == "复盘试验时:UID与Look_Other_UID不一致")
     {
         r.Status = ShiYanStatus.Error_UID_NOT_Equal_LookOtherUID;
     }
     else if (e.Message == "【motherPathName】文件夹名称无效")
     {
         //文件夹名称不合格
         r.Status = ShiYanStatus.Error_Write_MotherPathName;
     }
 }
Beispiel #4
0
        //// <summary>
        /// 创建新的试验
        /// 这里有几个关键步骤:创建管理连接、复制文件、启动文件、实现通讯
        /// </summary>
        /// <param name="uid">用户编号</param>
        /// <param name="type">试验类型</param>
        /// <param name="hrID">华人设定的模板模型编号</param>
        /// <param name="look_uid">如果看其他人的试验,这里写别人的uid,默认不写为0</param>
        /// <param name="motherPathName">被查看的用户路径名称  eg.55_20191206144001New</param>
        /// <returns></returns>
        public ManagerMessage CreateNew_ShiYan(int uid, ShiYanCreateType type, int hrID, string m_Setting_Arguments, int look_uid = 0, string motherPathName = "")
        {
            //
            ManagerMessage r = new ManagerMessage();

            r.ID                  = PublicClassRule.MakeMessageID(YingHeXinList, TCPConnectMax);//运算生成
            r.UID                 = uid;
            r.CreateType          = type;
            r.HR_Make_ID          = hrID;
            r.Status              = ShiYanStatus.New;
            r.Look_Other_UID      = look_uid;
            r.SourceModelPath     = motherPathName;
            r.M_Setting_Arguments = m_Setting_Arguments;

            #region 路径处理
            try
            {
                PublicClassRule.Self_Make_Path(ref r, motherPathName);//根据创建类型,分配相关路径
            }
            catch (Exception e)
            {
                Read_Exception(ref r, e);
            }
            #endregion



            YingHeXinList.Add(r);
            return(r);
        }
Beispiel #5
0
        public ManagerMessage GetMessageByID(int id)
        {
            ManagerMessage r = null;

            for (int i = 0; i < YingHeXinList.Count; i++)
            {
                if (YingHeXinList[i].ID == id)
                {
                    r = YingHeXinList[i];
                    YingHeXinList[i].Web_Heart++;//web心跳
                    break;
                }
            }
            return(r);
        }
Beispiel #6
0
        /// <summary>
        /// 启动simlink的过程
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        private async Task MakeSimlinkRun(ManagerMessage row)
        {
            await Task.Run(() => {
                //要运行的路径是row.CopyModel_To_TargetPath
                //文件夹里面的命令需要复制过来、你看看怎么能启动起来

                #region 将来不会用这里的代码 2019年12月9日09:40:17

                //System.Diagnostics.Process cmd_MakeRun = new System.Diagnostics.Process();
                //cmd_MakeRun.StartInfo.FileName = @"D:\uuu\UID44\44_20191209114531New\MGtcp\hello.bat";
                ////cmd_MakeRun.StartInfo.UserName = "******";
                //cmd_MakeRun.StartInfo.UseShellExecute = false;

                //cmd_MakeRun.Start();



                //row.PID = CMDClass.FindPID("MATLAB R2018a", @"C:\Program Files\MATLAB\R2018a\bin\win64\MATLAB.exe");

                ////row.PID = cmd_MakeRun.Id;//把程序启动起来的PID记录下来

                ////cmd_MakeRun.Kill();
                //CMDClass.KillProcess("QQ", cmd_MakeRun.StartInfo.FileName);//两种方式都能把!QQ干掉!!
                ////CMDClass.KillProcess(row.PID);
                #endregion


                string arguments = PublicClassRule.GetValues(row.HR_Make_ID.ToString(), "arguments");              //原始参数

                arguments = PublicClassRule.MakeArguments(arguments, row.HR_Make_ID, row.CopyModel_To_TargetPath); //结构化之后的最终使用参数

                //修改M文件中的  input 的ID  本段属于文件操作,修改.m文件内容
                string m_path = string.Format("{0}{1}", row.CopyModel_To_TargetPath, PublicClassRule.GetValues(row.HR_Make_ID.ToString(), "mFileName"));
                PublicClassRule.Edit_M_File(m_path, row.HR_Make_ID, row.ID, row.M_Setting_Arguments);

                MakeRun(arguments, ref row);
                //等待程序和服务TCP通讯,!!!注意,此时,这个进程不会停止,不会自动关闭。只能等待kill   PID  2019年12月9日14:40:17
            });
        }
Beispiel #7
0
        /// <summary>
        /// 通过自身初始化设置,根据创建类型,分配相关路径
        /// 【注意】文件夹规则设计
        /// UID1336/1336_20191212131356NEW   这是某个用户的新建试验   也可以用这个复盘
        /// UID1336/1336_20191212131356From1222_20191111111213New  这是1336号用户从1222号用户拿取11月11日创建的试验
        /// </summary>
        /// <param name="self">一条消息</param>
        /// <param name="motherPathName">被查看的目录名称</param>
        public static void Self_Make_Path(ref ManagerMessage self, string motherPathName)
        {
            switch (self.CreateType)
            {
            case ShiYanCreateType.New:
            {
                self.SourceModelPath = ini.ReadValue(self.HR_Make_ID.ToString(), "path");        //从配置文件中读取
                if (self.SourceModelPath == "")
                {
                    //读出来是空格,说明没找到这个配置。如果这里不报错,下面就会把我们所有的试验都复制过去给这个用户了。
                    throw new Exception("无此试验模型配置");
                }
                self.CopyModel_To_TargetPath = string.Format("UID{0}/{0}_{1}New/", self.UID, DateTime.Now.ToString("yyyyMMddHHmmss"));         //文件夹copy规则
                //补充完成:
                self.SourceModelPath         = ini.ReadValue("root", "ModelRootPath") + self.SourceModelPath;
                self.CopyModel_To_TargetPath = ini.ReadValue("root", "UserRootPath") + self.CopyModel_To_TargetPath;


                //只有需要复制文件时做这个判断
                if (!System.IO.Directory.Exists(self.SourceModelPath))
                {
                    throw new Exception("没找到原模型路径");
                }
            }
            break;

            case ShiYanCreateType.ReView:
            {
                if (self.UID == self.Look_Other_UID)
                {
                    //自己看自己
                    if (motherPathName == "" || motherPathName == null)
                    {
                        throw new Exception("母文件夹无效");
                    }
                    self.CopyModel_To_TargetPath = JieXiMuLu(motherPathName);        //解析目录
                    //补充完成:
                    self.CopyModel_To_TargetPath = ini.ReadValue("root", "UserRootPath") + self.CopyModel_To_TargetPath;
                }
                else
                {
                    //不是自己看自己
                    throw new Exception("复盘试验时:UID与Look_Other_UID不一致");
                }

                //不需要复制,但要看看自己的文件在不在
                if (!System.IO.Directory.Exists(self.CopyModel_To_TargetPath))
                {
                    throw new Exception("没找到自己的试验模型数据路径");
                }
            }
            break;

            case ShiYanCreateType.LookOthers:
            {
                if (self.SourceModelPath == "" || self.SourceModelPath == null)
                {
                    throw new Exception("母文件夹无效");
                }
                self.SourceModelPath         = JieXiMuLu(motherPathName);//解析目录
                self.CopyModel_To_TargetPath = string.Format(@"UID{0}/{0}_{1}_From_{2}/", self.UID, DateTime.Now.ToString("yyyyMMddHHmmss"), self.SourceModelPath.Split('/')[1]);
                //补充完成:
                self.SourceModelPath         = ini.ReadValue("root", "UserRootPath") + self.SourceModelPath;
                self.CopyModel_To_TargetPath = ini.ReadValue("root", "UserRootPath") + self.CopyModel_To_TargetPath;

                //只有需要复制文件时做这个判断
                if (!System.IO.Directory.Exists(self.SourceModelPath))
                {
                    throw new Exception("没找到原模型路径");
                }
            }
            break;

            default:
                break;
            }
        }
Beispiel #8
0
        /// <summary>
        /// 日志操作
        /// </summary>
        /// <param name="managerMessage"></param>
        internal static void MakeLog(ManagerMessage managerMessage)
        {
            //首先确定文件路径
            string sLogPath = managerMessage.CopyModel_To_TargetPath + GetValues("root", "tcpSendLogName");
            string rLogPath = managerMessage.CopyModel_To_TargetPath + GetValues("root", "tcpReceivedLogName");

            //CopyModel_To_TargetPath = "D:/uuu/UID0/0_20191211152935New/"

            //然后写入文件内容
            try
            {
                #region send日志

                if (File.Exists(sLogPath))
                {
                    //原本就存在,继续写数据,不再写标题
                    FileStream   fsc2             = new FileStream(sLogPath, FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter m_streamWriterc2 = new StreamWriter(fsc2, Encoding.Default);
                    m_streamWriterc2.BaseStream.Seek(0, SeekOrigin.End);

                    string b = string.Format("{0},{1}", managerMessage.TCP_GoOn_Time, managerMessage.SendData);
                    m_streamWriterc2.WriteLine(b);
                    m_streamWriterc2.Flush();
                    m_streamWriterc2.Close();
                    fsc2.Close();
                }
                else
                {
                    //不存在,创建
                    FileStream   fsc2             = new FileStream(sLogPath, FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter m_streamWriterc2 = new StreamWriter(fsc2, Encoding.Default);
                    m_streamWriterc2.BaseStream.Seek(0, SeekOrigin.End);

                    //这里写个标题
                    string title = GetValues(managerMessage.HR_Make_ID.ToString(), "tcpSendBytesNames");

                    string a = string.Format("{0},{1}", "时间", title);
                    string b = string.Format("{0},{1}", managerMessage.TCP_GoOn_Time, managerMessage.SendData);
                    m_streamWriterc2.WriteLine(a);
                    m_streamWriterc2.WriteLine(b);
                    m_streamWriterc2.Flush();
                    m_streamWriterc2.Close();
                    fsc2.Close();
                }
                #endregion

                #region received日志

                if (File.Exists(rLogPath))
                {
                    //原本就存在,继续写数据,不再写标题
                    FileStream   fsc2             = new FileStream(rLogPath, FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter m_streamWriterc2 = new StreamWriter(fsc2, Encoding.Default);
                    m_streamWriterc2.BaseStream.Seek(0, SeekOrigin.End);

                    string b = string.Format("{0},{1}", managerMessage.TCP_GoOn_Time, managerMessage.ReceivedData);
                    m_streamWriterc2.WriteLine(b);
                    m_streamWriterc2.Flush();
                    m_streamWriterc2.Close();
                    fsc2.Close();
                }
                else
                {
                    //不存在,创建
                    FileStream   fsc2             = new FileStream(rLogPath, FileMode.OpenOrCreate, FileAccess.Write);
                    StreamWriter m_streamWriterc2 = new StreamWriter(fsc2, Encoding.Default);
                    m_streamWriterc2.BaseStream.Seek(0, SeekOrigin.End);

                    //这里写个标题
                    string title = GetValues(managerMessage.HR_Make_ID.ToString(), "tcpReceiveBytesNames");

                    string a = string.Format("{0},{1}", "时间", title);
                    string b = string.Format("{0},{1}", managerMessage.TCP_GoOn_Time, managerMessage.ReceivedData);
                    m_streamWriterc2.WriteLine(a);
                    m_streamWriterc2.WriteLine(b);
                    m_streamWriterc2.Flush();
                    m_streamWriterc2.Close();
                    fsc2.Close();
                }
                #endregion
            }
            catch (Exception)
            {
                //咱们不用管出了什么错误。我估摸着就是咱们写文件时,这个文件被打开了
            }
        }
Beispiel #9
0
        /// <summary>
        /// 超时机制处理,之后根据配置文件处理超时问题。自动销毁试验管理
        /// </summary>
        /// <param name="managerMessage"></param>
        internal static void CheckTimeOut(ManagerMessage managerMessage)
        {
            //int lastTcp = managerMessage.Tcp_TimeOut_Test.LastNum;
            //int nowTcp = managerMessage.ReceivedTotalCount;
            #region simlink tcp超时测试

            if (managerMessage.Tcp_TimeOut_Test.LastNum == managerMessage.ReceivedTotalCount)//对比
            {
                //没变化,就记超时
                managerMessage.Tcp_TimeOut_Test.TimeOutCount++;
            }
            else
            {
                managerMessage.Tcp_TimeOut_Test.LastNum      = managerMessage.ReceivedTotalCount;
                managerMessage.Tcp_TimeOut_Test.TimeOutCount = 0;
            }
            if (System.Configuration.ConfigurationManager.AppSettings["tcpAllowTimeOut"] == "true")
            {
                //不予理睬
            }
            else
            {
                //验证次数
                if (managerMessage.Tcp_TimeOut_Test.TimeOutCount > Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["tcpAllowTimeOutMaxCount"]))
                {
                    //超时,退出
                    managerMessage.Status = ShiYanStatus.End;
                }
                else
                {
                    //未超时
                }
            }
            #endregion

            #region web端超时测试

            if (managerMessage.Web_TimeOut_Test.LastNum == managerMessage.Web_Heart)//对比
            {
                //没变化,就记超时
                managerMessage.Web_TimeOut_Test.TimeOutCount++;
            }
            else
            {
                managerMessage.Web_TimeOut_Test.LastNum      = managerMessage.Web_Heart;
                managerMessage.Web_TimeOut_Test.TimeOutCount = 0;
            }
            if (System.Configuration.ConfigurationManager.AppSettings["webAllowTimeOut"] == "true")
            {
                //不予理睬
            }
            else
            {
                //验证次数
                if (managerMessage.Web_TimeOut_Test.TimeOutCount > Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["webAllowTimeOutMaxCount"]))
                {
                    //超时,退出
                    managerMessage.Status = ShiYanStatus.End;
                }
                else
                {
                    //未超时
                }
            }
            #endregion
        }