bool run(ServiceInfo data) { DogAction action = getAction(data.RunName, out EnumAction enumAction); if (action != null) { logger.Info($"run {data.Name} begin"); switch (enumAction) { case EnumAction.e启动进程: //改用命令行呼起 //new Thread(new ThreadStart(() => ProcessHelper.StartUseCmd(data.Name, data.RunData, (s, ex) => logger.Info(s, ex)))).Start(); Task.Factory.StartNew(async() => { await ProcessHelper.StartByAgent(jobDataMap.GetString("serviceAgent"), data.Name, data.RunData, (s, ex) => logger.Info(s, ex)); }); break; case EnumAction.e启动服务: new QCommon.Service.ServiceHelper(data.RunData).Start(); break; } logger.Info($"run {data.Name} end "); return(true); } else { logger.Warn($"未知的停止方法:{data.StopName}"); return(false); } }
bool stop(ServiceInfo data) { //Stop KillProcess sc stop redis //目前都是命令,后续可能是代码 DogAction action = getAction(data.StopName, out EnumAction enumAction); bool flag = false; if (action != null) { logger.Info($"stop {data.Name} begin"); switch (enumAction) { case EnumAction.e终止进程: flag = ProcessHelper.Kill(data.StopData); break; case EnumAction.e停止服务: flag = new QCommon.Service.ServiceHelper(data.StopData).Stop(); break; default: flag = false; break; } logger.Info($"stop {data.Name} end,{flag}"); return(flag); } else { logger.Warn($"未知的停止方法:{data.StopName}"); return(false); } }
public override void StartAction() { actionTimer = actionDelay; isDone = false; currentAction = new GoStraightToPosition(dog, target, 1 - 5f); currentAction.StartAction(); isWaiting = false; }
public override void UpdateAction() { if (!isDone) { if (currentAction.IsDone()) { currentAction = new GotoPosition(dog, GetRandomTarget(), 0.5f); } currentAction.UpdateAction(); } }
public Call(Dog d, Transform player, bool staticPlayer = false) : base(d) { this.player = player; importance = Importance.LOW; if (!staticPlayer) { currentAction = new FollowTarget(dog, player, Vector3.zero, true, 3f); } else { currentAction = new GotoStaticPosition(dog, player.position, player.forward); } }
IEnumerator blabla(Dog dog, DogAI dogai, DogAction dogaction) { bool dogready = false; while (!dogready) { dogready = dogai.gameObject.GetComponent <Dog>().IsIdle(); yield return(null); } dogai.StartAction(dogaction); StartCoroutine(blabla(dog, dogai, new Rest(dog, -1))); }
void NextAction() { if (actionCount < actions.Count) { currentAction = actions[actionCount]; currentAction.StartAction(); actionCount++; } else { isDone = true; } }
bool check(ServiceInfo data) { DogAction action = getAction(data.CheckName, out EnumAction enumAction); if (action != null) { switch (enumAction) { case EnumAction.e打开网页: try { return(new HttpClient().GetAsync(data.CheckData).GetAwaiter().GetResult().StatusCode == HttpStatusCode.OK); } catch (Exception ex) { return(false); } case EnumAction.e检测服务状态: return(new QCommon.Service.ServiceHelper(data.CheckData).Status == System.ServiceProcess.ServiceControllerStatus.Running); case EnumAction.e检测端口: return(NetHelper.Telnet(IPEndPoint.Parse(data.CheckData))); case EnumAction.e检测IP: var ping = NetHelper.Ping(data.CheckData, (s, ex) => logger.Warn(s, ex)); if (ping == System.Net.NetworkInformation.IPStatus.Success) { return(true); } else { return(false); } case EnumAction.e查找进程: return(ProcessHelper.Exists(data.CheckData)); default: //CommandHelper.execute($"{action.Command} {data.CheckData}", out info, out error); break; } return(false); } else { logger.Warn($"未知的检测方法:{data.CheckName}"); return(false); } }
public void Fetch(Transform stick = null) { isSniffing = false; if (currentAction != null && currentAction.GetImportance() == DogAction.Importance.HIGH) { savedAction = currentAction; } if (stick != null) { ai.StartAction(new Fetch(this, player, stick)); } else { ai.StartAction(new Fetch(this, player)); } }
public override void UpdateAction() { if (!isDone) { currentAction.UpdateAction(); if (Vector2.Distance(new Vector2(dog.transform.position.x, dog.transform.position.z), new Vector2(target.x, target.z)) < width) { if (waitForPlayerAtTarget) { if (Vector2.Distance(new Vector2(player.position.x, player.position.z), new Vector2(target.x, target.z)) < 5f) { isDone = true; } } else { isDone = true; } } if (!ShouldWait()) { if (isWaiting) { if (currentAction.IsDone()) { currentAction.EndAction(); currentAction = new GoStraightToPosition(dog, target, 1.5f); currentAction.StartAction(); isWaiting = false; } } } else { if (!isWaiting) { currentAction.EndAction(); currentAction = new WaitForPlayer(dog, player, target, maxDistance / 2); currentAction.StartAction(); isWaiting = true; } } } }
public void Call() { isSniffing = false; if (currentAction != null && currentAction.GetImportance() == DogAction.Importance.HIGH) { savedAction = currentAction; } else if (currentAction != null && currentAction.ToString() == "Sit") { animator.SetTrigger("StandUp"); } if (characterMovement.CutsceneLock) { ai.StartAction(new Call(this, player, true)); } else { ai.StartAction(new Call(this, player)); } }
public void SetAction(DogAction action) { CurrentAction = action; switch (action) { case DogAction.Eating: performEating(); break; case DogAction.Sleeping: performSleeping(); break; case DogAction.Tablet: performTablet(); break; default: performIdling(); break; } }
void Update() { if (savedAction != null) { Debug.Log("saved action " + savedAction.ToString()); } Debug.DrawLine(transform.position, transform.position + transform.forward * 3, Color.yellow); if (itemHand != null && itemHand.GetItemInHand() != null && itemHand.GetItemInHand().name == "Stick") { if (currentAction != null && currentAction.GetImportance() == DogAction.Importance.HIGH) { savedAction = currentAction; } if (Vector3.Distance(transform.position, player.position) < 3) { if (!isWaitingForFetch) { ai.StartAction(new WaitForFetch(this, player)); } } else { ai.StartAction(new FollowPlayer(this, player)); } } if (currentAction != null) { currentAction.UpdateAction(); } else if (savedAction != null) { currentAction = savedAction; currentAction.StartAction(); savedAction = null; } }
public override void StartAction() { isDone = false; actionTimer = actionDelay; currentAction = new GotoPosition(dog, GetRandomTarget(), 0.5f); }
public void SetAction(DogAction action, Vector3 targetPosition) { //transform.position = targetPosition; //this is causing weird teleportation SetAction(action); }
public void StartAction(DogAction action) { EndAction(); dog.currentAction = action; dog.currentAction.StartAction(); }
public void CreateAndInitData(string clientName) { lock (lck) { Console.WriteLine("CreateAndInitData"); if (_created) { return; } _created = true; #if DEBUG //Database.EnsureDeleted(); if (!Database.EnsureCreated()) { return; } #else Database.EnsureCreated(); #endif if (!User.Any()) { User.Add(new Q.DevExtreme.Tpl.Models.User() { Id = Guid.NewGuid(), UserNo = "admin", Password = Extension.makePassword("123456"), UserName = "******", Role = "管理员" }); SaveChanges(); } if (!DogAction.Any()) { DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "sc query", Name = Enums.EnumAction.e检测服务状态.ToString().Substring(1), Type = "Check" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "sc stop {0}", Name = Enums.EnumAction.e停止服务.ToString().Substring(1), Type = "Stop" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "sc start {0}", Name = Enums.EnumAction.e启动服务.ToString().Substring(1), Type = "Run" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "Telent", Name = Enums.EnumAction.e检测端口.ToString().Substring(1), Type = "Check" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "/c ping {0} -4 -n 2", Name = Enums.EnumAction.e检测IP.ToString().Substring(1), Type = "Check" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "/c tasklist|findstr /i", Name = Enums.EnumAction.e查找进程.ToString().Substring(1), Type = "Check" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "", Name = Enums.EnumAction.e启动进程.ToString().Substring(1), Type = "Run" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "/c TASKKILL /F /IM {0}", Name = Enums.EnumAction.e终止进程.ToString().Substring(1), Type = "Stop" }); DogAction.Add(new DogAction() { Id = Guid.NewGuid(), Command = "Get", Name = Enums.EnumAction.e打开网页.ToString().Substring(1), Type = "Check" }); SaveChanges(); } #region 初始化模板 if (!ServiceTpl.Any()) { ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "进程检测", Name = "Process", CheckName = Enums.EnumAction.e查找进程.ToString().Substring(1), CheckData = "Notepad", RunName = Enums.EnumAction.e启动进程.ToString().Substring(1), RunData = new { FileName = @"c:\windows\system32\notepad.exe" }.SerializeObject(), StopName = Enums.EnumAction.e终止进程.ToString().Substring(1), StopData = "notepad", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(30), Client = "通用模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "Url检测", Name = "Url", CheckName = Enums.EnumAction.e打开网页.ToString().Substring(1), CheckData = "http://192.168.10.37:8080", RunName = Enums.EnumAction.e启动进程.ToString().Substring(1), RunData = new { FileName = @"c:\windows\system32\notepad.exe" }.SerializeObject(), StopName = Enums.EnumAction.e终止进程.ToString().Substring(1), StopData = "notepad", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(30), Client = "通用模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "端口检测", Name = "Port", CheckName = Enums.EnumAction.e检测端口.ToString().Substring(1), CheckData = "127.0.0.1:1433", RunName = Enums.EnumAction.e启动服务.ToString().Substring(1), RunData = @"MSSQL$SQL2014", StopName = Enums.EnumAction.e停止服务.ToString().Substring(1), StopData = "MSSQL$SQL2014", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(30), Client = "通用模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "服务检测", Name = "Service", CheckName = Enums.EnumAction.e检测服务状态.ToString().Substring(1), CheckData = "redis", RunName = Enums.EnumAction.e启动服务.ToString().Substring(1), RunData = @"redis", StopName = Enums.EnumAction.e停止服务.ToString().Substring(1), StopData = "redis", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(1), RestartTime = TimeSpan.FromMinutes(3), Client = "通用模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "IP检测", Name = "Ping", CheckName = Enums.EnumAction.e检测IP.ToString().Substring(1), CheckData = "192.168.255.1", RunName = Enums.EnumAction.e启动进程.ToString().Substring(1), RunData = new { FileName = @"C:\Program Files\OpenVPN\bin\openvpn.exe", Para = @"""d:\data\openvpn\config\aliyun.ovpn""", WorkingPath = @"d:\data\openvpn\config" }.SerializeObject(), StopName = Enums.EnumAction.e终止进程.ToString().Substring(1), StopData = "openvpn*", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(1), RestartTime = TimeSpan.FromMinutes(5), Client = "通用模板", IsEnable = true }); #region 产品模板 //常用产品:门禁、消费、考勤、数据备份、手环、IIS 等 ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "门禁服务", Name = "AC", CheckName = Enums.EnumAction.e检测端口.ToString().Substring(1), CheckData = "127.0.0.1:5000", RunName = Enums.EnumAction.e启动服务.ToString().Substring(1), RunData = "ZY.Cloud.Front.ACService.exe", StopName = Enums.EnumAction.e停止服务.ToString().Substring(1), StopData = "ZY.Cloud.Front.ACService.exe", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(7), Client = "产品模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "微信服务", Name = "WeChat", CheckName = Enums.EnumAction.e检测端口.ToString().Substring(1), CheckData = "127.0.0.1:5005", RunName = Enums.EnumAction.e启动服务.ToString().Substring(1), RunData = "ZY.Wechat.Service.exe", StopName = Enums.EnumAction.e停止服务.ToString().Substring(1), StopData = "ZY.Wechat.Service.exe", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(7), Client = "产品模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "消费服务", Name = "Pos", CheckName = Enums.EnumAction.e检测端口.ToString().Substring(1), CheckData = "127.0.0.1:8888", RunName = Enums.EnumAction.e启动服务.ToString().Substring(1), RunData = "PosService", StopName = Enums.EnumAction.e停止服务.ToString().Substring(1), StopData = "PosService", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(7), Client = "产品模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "青果教务对接", Name = "QGAPI", CheckName = Enums.EnumAction.e检测服务状态.ToString().Substring(1), CheckData = "TAYCApiService", RunName = Enums.EnumAction.e启动服务.ToString().Substring(1), RunData = "TAYCApiService", StopName = Enums.EnumAction.e停止服务.ToString().Substring(1), StopData = "TAYCApiService", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(7), Client = "产品模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "数据库备份上传服务", Name = "QBackup2", CheckName = Enums.EnumAction.e检测服务状态.ToString().Substring(1), CheckData = "QBackup2", RunName = Enums.EnumAction.e启动服务.ToString().Substring(1), RunData = "QBackup2", StopName = Enums.EnumAction.e停止服务.ToString().Substring(1), StopData = "QBackup2", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(7), Client = "产品模板", IsEnable = true }); ServiceTpl.Add(new ServiceTpl() { Id = Guid.NewGuid(), Desc = "手环服务", Name = "Band", CheckName = Enums.EnumAction.e打开网页.ToString().Substring(1), CheckData = "http://127.0.0.1:8080/band", RunName = Enums.EnumAction.e启动进程.ToString().Substring(1), RunData = "dotnet.exe", StopName = Enums.EnumAction.e终止进程.ToString().Substring(1), StopData = "dotnet.exe", LastAliveTime = DateTime.Now, LastStopTime = DateTime.Now, IdleTime = TimeSpan.FromMinutes(5), RestartTime = TimeSpan.FromDays(7), Client = "产品模板", IsEnable = true }); #endregion SaveChanges(); } #endregion if (!EventSubscriber.Any()) { EventSubscriber.Add(new EventSubscriber() { Id = Guid.NewGuid(), Name = "张文相", WXName = "ZhangWenXiang", EMail = "*****@*****.**", IsEnable = true }); EventSubscriber.Add(new EventSubscriber() { Id = Guid.NewGuid(), Name = "牛家隆", WXName = "NiuJiaLong", EMail = "*****@*****.**", IsEnable = true }); EventSubscriber.Add(new EventSubscriber() { Id = Guid.NewGuid(), Name = "马健", WXName = "MaJian", EMail = "*****@*****.**", IsEnable = false }); EventSubscriber.Add(new EventSubscriber() { Id = Guid.NewGuid(), Name = "于中涛", WXName = "YuZhongTao", EMail = "*****@*****.**", IsEnable = false }); EventSubscriber.Add(new EventSubscriber() { Id = Guid.NewGuid(), Name = "董梓莘", WXName = "DongZiShen", EMail = "*****@*****.**", IsEnable = false }); SaveChanges(); } if (!ClientEventSubscriber.Any()) { EventSubscriber.Where(r => r.IsEnable).ToList().ToList().ForEach(r => ClientEventSubscriber.Add( new ClientEventSubscriber() { Id = Guid.NewGuid(), Subscriber = r.Id, Client = "TEST" })); SaveChanges(); } if (!Sender.Any()) { Sender.Add(new Sender() { Id = Guid.NewGuid(), Name = "同安企业微信", TypeName = Enums.EnumSender.e企业微信.ToString().Substring(1), IsEnable = true, Para = new { agentid = 1000045, url = "http://work.jstayc.com/WechatWebService.asmx" }.SerializeObject() }); Sender.Add(new Sender() { Id = Guid.NewGuid(), Name = "中云企业微信", TypeName = Enums.EnumSender.e企业微信.ToString().Substring(1), IsEnable = false, Para = new { agentid = 1000002, url = "http://qywx.bjzycx.net/WechatWebService.asmx" }.SerializeObject() }); Sender.Add(new Sender() { Id = Guid.NewGuid(), Name = "126邮箱", TypeName = Enums.EnumSender.e邮箱.ToString().Substring(1), IsEnable = true, Para = new { account = "*****@*****.**", password = "******", smtp = "smtp.qq.com", port = 465, cc = new string[0] }.SerializeObject() }); SaveChanges(); } //更新本地标志 } }