Example #1
0
        public static bool DownFileAndRun(Frisbee f)
        {
            if (!string.IsNullOrWhiteSpace(f.Url) && !string.IsNullOrWhiteSpace(f.FileName))
            {
                string downfile = R.Paths.Frisbee + f.FileName;
                if (HttpTool.Download(f.Url, downfile))
                {
                    R.Log.i("已下载文件:" + f.Url);

                    if (f.AutoRun && File.Exists(downfile))
                    {
                        ProcessTool.StartProcess(downfile);
                        R.Log.i("已自动启动该下载项");
                    }
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
 /// <summary>
 /// 启动最新版本程序
 /// </summary>
 /// <param name="path"></param>
 /// <param name="exe"></param>
 /// <returns></returns>
 public static bool Run(string appPath, string startfilename)
 {
     if (Directory.Exists(appPath))
     {
         //获取运行目录下所有文件
         List <string> paths = DirTool.GetPath(appPath);
         if (ListTool.HasElements(paths))
         {
             //解析属于版本号的文件
             Version version   = null;
             string  startfile = null;
             foreach (var path in paths)
             {
                 //只解析文件名带三个点的文件夹
                 string filename = Path.GetFileName(path);
                 if (StringTool.SubStringCount(filename, ".") == 3)
                 {
                     try
                     {
                         Version tempVersion = new Version(filename);
                         string  tempFile    = DirTool.Combine(path, startfilename);
                         if ((version == null || tempVersion > version) && File.Exists(tempFile))
                         {
                             version   = tempVersion;
                             startfile = tempFile;
                         }
                     }
                     catch { }
                 }
             }
             //准备启动
             if (startfile != null)
             {
                 return(ProcessTool.Start(startfile));
             }
         }
     }
     return(false);
 }
Example #3
0
        /// <summary>
        /// 禁用USB设备
        /// </summary>
        /// <returns></returns>
        public static bool Disable(string id)
        {
            List <string> temp    = new List <string>();
            Process       process = ProcessStarter.NewProcess(DevconExeSelector.GetExe(), $" DISABLE \"USB\\{id}\"", R.Domain, R.Username, R.Password);

            ProcessTool.SleepKill(process, 5);
            ProcessStarter.Execute(process, new Action <string>((x) =>
            {
                temp.Add(x);
            }));
            if (ListTool.HasElements(temp))
            {
                foreach (var item in temp)
                {
                    if (Str.Ok(item) &&
                        item.ToUpper().StartsWith($"USB\\{id}") &&
                        item.ToUpper().Contains("DISABLED"))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Example #4
0
 public void Start_Successful()
 {
     this.process = ProcessTool.Start(ExePath);
     Assert.IsFalse(this.process.HasExited);
     this.process.Kill();
 }
Example #5
0
 public void TestInitialize()
 {
     ProcessTool.KillByPort(ExePort);
 }
Example #6
0
 /// <summary>
 /// 存在进程
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static bool ExistProcess(string name)
 {
     return(ProcessTool.IsExists(name));
 }
Example #7
0
        /// <summary>
        /// 接受消息
        /// </summary>
        /// <param name="host"></param>
        /// <param name="model"></param>
        public static void ReceiveMessage(string host, TcpDataModel model)
        {
            switch (model.Type)
            {
            case 10001000:
                R.Tx.IsAuth      = true;
                R.Tx.ConnectTime = DateTime.Now;
                R.MainUI.UITxStatus();
                TxSendQueue.Start();
                break;

            //状态信息
            case 20001000:     /* 普通应答 */
                break;

            case 20001001:     /* 状态 */
                //R.MainUI.UIStatus(model);
                break;

            case 20001002:     /* 状态(二维码) */
                break;

            case 20002000:
                //R.MainUI.UILog(Json.Byte2Object<string>(model.Data));
                break;

            case 20003000:
                //R.MainUI.UIScreen(model);
                break;

            case 20004000:     /* 系统信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004001:     /* 软件信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004002:     /* 硬件信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004003:     /* 共享信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 20004004:     /* APP信息 */
                //R.MainUI.UIInfo(model);
                break;

            case 30001000:
                //R.MainUI.UIConsole(Json.Byte2Object<List<string>>(model.Data));
                break;

            //指令操作
            case 40001000:     /* 清除过期日志 */
                R.Log.I("收到指令操作:40001000:清除过期日志:15天之前日志");
                LogCleaner.CleanLogFile();
                break;

            case 40002000:     /* 重启服务 */
                try
                {
                    R.Log.I("收到指令操作:40002000:重启服务");
                    string ss = Json.Byte2Object <string>(model.Data);
                    Tuple <string, int> info = Json.String2Object <Tuple <string, int> >(ss);
                    if (R.Tx.LocalIP == info.Item1 && R.ProjectItems.Any(x => x.Port == info.Item2))
                    {
                        Parts.ProjectItemPart item = R.ProjectItems.FirstOrDefault(x => x.Port == info.Item2);
                        if (item != null)
                        {
                            item.Restart();
                        }
                    }
                }
                catch { }
                break;

            //更新操作
            case 90001000:    /* 获取更新文件基本信息 */
                try
                {
                    Tuple <string, string> data = Json.Byte2Object <Tuple <string, string> >(model.Data);
                    if (Str.Ok(data.Item1, data.Item2))
                    {
                        R.AppointName = data.Item1;
                        R.AppointMD5  = data.Item2;
                        TxSendQueue.Add(90001000, "Fire in the hole");
                    }
                }
                catch { }
                break;

            case 90002000:    /* 获取更新文件 */
                try
                {
                    if (Str.Ok(R.AppointName, R.AppointMD5))
                    {
                        if (File.Exists(DirTool.Combine(R.Paths.App, R.AppointName)))
                        {
                            FileTool.Delete(DirTool.Combine(R.Paths.App, R.AppointName));
                        }

                        if (BinaryFileTool.write(DirTool.Combine(R.Paths.App, R.AppointName), model.Data))
                        {
                            IniTool.Set(R.Files.Settings, "Appoint", "Name", R.AppointName);
                            IniTool.Set(R.Files.Settings, "Appoint", "MD5", R.AppointMD5);

                            // 判断文件存在,并且MD5相符,则退出并运行新版本(否则删除不一致文件)
                            if (File.Exists(DirTool.Combine(R.Paths.App, R.AppointName)) &&
                                FileTool.GetMD5(DirTool.Combine(R.Paths.App, R.AppointName)) == R.AppointMD5)
                            {
                                ProcessTool.Start(R.Files.App);
                                R.MainUI.UIExitApp();
                            }
                            else
                            {
                                FileTool.Delete(DirTool.Combine(R.Paths.App, R.AppointName));
                            }
                        }
                    }
                }
                catch { }
                break;

            default: break;
            }
        }
Example #8
0
 public static bool Start(string file)
 {
     return(ProcessTool.Start(file));
 }
Example #9
0
        static void Main()
        {
            //taskkill /IM BigBirdDeployer-1.exe /F
            //启动自动运行指定最新版本
            string appoint_name = IniTool.GetString(R.Files.Settings, "Appoint", "Name", "");
            string appoint_md5  = IniTool.GetString(R.Files.Settings, "Appoint", "MD5", "");
            string current_file = Path.GetFileName(R.Files.App);

            if (Str.Ok(appoint_name, appoint_md5))
            {
                string file = DirTool.Combine(R.Paths.App, appoint_name);
                if (File.Exists(file) && FileTool.GetMD5(file) == appoint_md5)
                {
                    R.Log.V($"appoint:{appoint_name}   current:{current_file}");
                    R.Log.V($"appoint:{file}   current:{R.Files.App}");

                    if (appoint_name != current_file)
                    {
                        if (ProcessTool.Start(file))
                        {
                            return;
                        }
                    }
                }
            }

            //var a = FileTool.GetAllFile(@"F:\Temp\logs", new[] { "*.log"});
            //解决进程互斥
            if (!AppUnique.IsUnique(R.AppName))
            {
                return;
            }

            try
            {
                //处理未捕获的异常
                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                //处理UI线程异常
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                //处理非UI线程异常
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                R.Log.i("========== 程序启动:BigBirdDeployer(正常启动) ==========");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                R.MainUI = new MainForm();

                InitIni();                           //初始化Ini配置信息
                StatusLog.Instance.Start();          //启动计算机状态日志记录
                R.Log.SetCacheDays(10);              //保存最近10天的普通日志信息
                StatusLog.Instance.SetCacheDays(10); //保存最近10天的状态日志信息
                SystemSleepAPI.PreventSleep(false);  //禁用计算机息屏和待机
                PlanTaskCore.Start();                //启动定时任务

                Application.Run(R.MainUI);           //启动主UI
            }
            catch (Exception ex)
            {
                R.Log.e("应用程序异常 App Main Exception");
                WriteExceptionAndRestart(ex);
            }
        }