Ejemplo n.º 1
0
        /// <summary>
        /// 下载方法
        /// 暂时不用
        /// </summary>
        /// <param name="startAppType"></param>
        private void DownLoadFunc(StartAppType startAppType)
        {
            AppInfo sigAppInfo = startAppType.AppInfo;
            string  url        = String.Empty;

            if (sigAppInfo.AppName.ToLower() == "chrome")
            {
                url = $"{chromdown}/{sigAppInfo.Version}/chromedriver_win32.zip";
            }
            if (sigAppInfo.AppName.ToLower() == "firefox")
            {
                url = $"{firefoxdown}/v{sigAppInfo.Version}/geckodriver-v{sigAppInfo.Version}-win32.zip";
            }
            if (sigAppInfo.AppName.ToLower() == "internetexplorer" && sigAppInfo.AppName.ToLower() == "ie")
            {
                //ie比较特殊,例如3.5.1是归属3.5中,所以这个地方要不定期修改
                url = $"{iedown}/{sigAppInfo.Version.Substring(0, 3).ToString()}/IEDriverServer_Win32_{sigAppInfo.Version}.zip";
            }
            //1.通过webclient进行下载
            WebClient webClient = new WebClient();

            webClient.DownloadFile(url, temppath);

            //2.解压文件
            string zippath = String.Empty;
            //设置路径
            ZipFile zip = new ZipFile(zippath);

            //解压
            zip.ExtractAll(sigAppInfo.ExecuePath);
            Thread.Sleep(1500); //静默1.5秒

            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// StartApp节点处理
        /// </summary>
        /// <param name="startXElement"></param>
        public StartAppNodes(XElement startXElement)
        {
            //1.转为对象
            StartAppType startAppType = new StartAppType
            {
                AppInfo = new AppInfo()
            };

            XElement appinfoEle = startXElement.Element(XName.Get("AppInfo", ComArgs.RosStr));

            AppInfo appInfo = new AppInfo
            {
                ExecuePath      = appinfoEle?.Element(XName.Get("ExecuePath", ComArgs.RosStr))?.Value,
                BaseWindowsBits = appinfoEle?.Element(XName.Get("BaseWindowsBits", ComArgs.RosStr))?.Attribute(XName.Get("Bits", ComArgs.RosStr))?.Value != "32Bits",
                Version         = appinfoEle?.Element(XName.Get("Version", ComArgs.RosStr))?.Value,
                Parameters      = new List <string>(),
                AppName         = appinfoEle?.Attribute(XName.Get("AppName", ComArgs.RosStr))?.Value
            };
            //需要验证是否有追加的参数
            XElement temps = appinfoEle?.Element(XName.Get("Parameters", ComArgs.RosStr));

            if (temps != null && !temps.Elements().Any())
            {
                foreach (XElement variable in temps.Elements(XName.Get("Parameter", ComArgs.RosStr)))
                {
                    appInfo.Parameters.Add(variable.Value);
                }
            }

            //2.根据实际情况进行解压
            startAppType.AppInfo = appInfo;
            StartApp_Info        = startAppType;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 开始APP的信息
        /// <para>Version 1.5 版本开始,StartApp的事件将直接进行下载</para>
        /// <para>但支持资源模式</para>
        /// </summary>
        /// <param name="startAppType">单个startApp的信息</param>
        public StartAppEvents(StartAppType startAppType)
        {
            try
            {
                AppInfo sigAppInfo   = startAppType.AppInfo;
                string  brodriverzip = $"{temppath}/BroDriver.zip";
                if (Directory.Exists($"{temppath}/BroDriver"))
                {
                    Directory.Delete($"{temppath}/BroDriver", true); //删除文件夹
                }
                File.Delete(brodriverzip);                           //删除总ZIP包


                //资源解压,通过资源重新释放
                File.WriteAllBytes(brodriverzip, Resources.DriverRes.BroDriver);
                //设置路径
                ZipFile zip = new ZipFile(brodriverzip);
                //解压得到总文件
                zip.ExtractAll(temppath, ExtractExistingFileAction.OverwriteSilently); //存在则更新
                zip.Dispose();

                //将需要的文件解压至对应文件夹内
                DirectoryInfo directoryInfo = new DirectoryInfo($"{temppath}/BroDriver");
                foreach (FileInfo sigFile in directoryInfo.GetFiles())
                {
                    if (sigFile.Name.ToLower().Contains(sigAppInfo.AppName.ToLower()))
                    {
                        string usebropath = sigFile.FullName;
                        //设置路径
                        ZipFile brozip = new ZipFile(usebropath);
                        //解压得到总文件
                        brozip.ExtractAll(sigAppInfo.ExecuePath, ExtractExistingFileAction.OverwriteSilently); //存在则更新
                        brozip.Dispose();
                    }
                }

                Thread.Sleep(3000);                              //冻结3秒
                //再次删除包
                Directory.Delete($"{temppath}/BroDriver", true); //删除文件夹
                File.Delete(brodriverzip);                       //删除总ZIP包

                //写入环境变量
                //SetEnvPathValue.SetPathA(sigAppInfo.ExecuePath);
            }
            catch (Exception e)
            {
                //添加输出
                ComArgs.RoLog.WriteLog(LogStatus.LExpt, "StartAppEvents发生异常", e.ToString());
            }
        }