public override void OnCreate(HookHelper hook) { Name = "绘制多边形"; mMapCtrl = hook.MapControl as RgMapControl; mScreenDisplay = mMapCtrl.ScreenDisplay; mScreenDisplayDraw = mScreenDisplay as IScreenDisplayDraw; }
internal static void Load() { hookOnHeartCount = new Hook(typeof(HeartGemDoor).GetMethod("get_HeartGems"), typeof(MiniHeartDoor).GetMethod(nameof(getCollectedHeartGems), BindingFlags.NonPublic | BindingFlags.Static)); hookOnDoorRoutine = HookHelper.HookCoroutine("Celeste.HeartGemDoor", "Routine", modDoorRoutine); IL.Celeste.HeartGemDoor.DrawInterior += modDoorColor; }
private static void modStrawberrySound(ILContext il) { ILCursor cursor = new ILCursor(il); FieldReference refToThis = HookHelper.FindReferenceToThisInCoroutine(cursor); if (cursor.TryGotoNext(MoveType.After, instr => instr.MatchLdstr("event:/game/general/strawberry_get"))) { Logger.Log("CollabUtils2/StrawberryHooks", $"Modding golden sound at {cursor.Index} in IL for Strawberry.CollectRoutine"); // we want to replace the vanilla collect sound with the silver berry one if the current berry is a silver one. cursor.Emit(OpCodes.Ldarg_0); cursor.Emit(OpCodes.Ldfld, refToThis); cursor.EmitDelegate <Func <string, Strawberry, string> >((orig, self) => { if (self is SilverBerry) { return("event:/SC2020_silverBerry_get"); } if (self is RainbowBerry) { return("event:/SC2020_rainbowBerry_get"); } if (self is SpeedBerry) { return("event:/SC2020_timedBerry_get"); } return(orig); }); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { this.Text = String.Format(this.Text, targetWindowHandle.ToInt32()); int processId; int threadId = UnmanagedMethods.GetWindowThreadProcessId(targetWindowHandle, out processId); Type type = typeof(WindowPropertiesView); int panelHandle = propertyViewPanel.Handle.ToInt32(); int targetHandle = targetWindowHandle.ToInt32(); byte[] b1 = BitConverter.GetBytes(panelHandle); byte[] b2 = BitConverter.GetBytes(targetHandle); byte[] data = new byte[b1.Length + b2.Length]; Array.Copy(b1, data, b1.Length); Array.Copy(b2, 0, data, b1.Length, b2.Length); HookHelper.InstallIdleHandler(processId, threadId, type.Assembly.Location, type.FullName, data); UnmanagedMethods.SendMessage(targetWindowHandle, 0, IntPtr.Zero, IntPtr.Zero); } catch (Exception ex) { MessageBox.Show(ex.Message, "wfspy"); } }
private static void modDeathSound(ILContext il) { ILCursor cursor = new ILCursor(il); FieldReference refToThis = HookHelper.FindReferenceToThisInCoroutine(cursor); if (cursor.TryGotoNext(MoveType.After, instr => instr.MatchLdstr("event:/new_content/char/madeline/death_golden"))) { Logger.Log("CollabUtils2/StrawberryHooks", $"Modding golden death sound at {cursor.Index} in IL for PlayerDeadBody.DeathRoutine"); // we want to replace the vanilla death sound with the silver berry one if carrying a silver berry. cursor.Emit(OpCodes.Ldarg_0); cursor.Emit(OpCodes.Ldfld, refToThis); cursor.EmitDelegate <Func <string, PlayerDeadBody, string> >((orig, self) => { DynData <PlayerDeadBody> data = new DynData <PlayerDeadBody>(self); bool hasSilver = data.Get <bool>("hasSilver"); bool hasSpeedBerry = data.Get <bool>("hasSpeedBerry"); if (hasSilver && hasSpeedBerry) { return("event:/SC2020_silverTimedBerry_death"); } if (hasSilver) { return("event:/SC2020_silverBerry_death"); } if (hasSpeedBerry) { return("event:/SC2020_timedBerry_death"); } return(orig); }); } }
public void Install() { if (m_ThreadId != 0) { m_HookId = HookHelper.SetWindowsHookEx(m_HookType, m_HookProc, IntPtr.Zero, m_ThreadId); } else { if (m_ProcessId == IntPtr.Zero) { return; } m_HookId = HookHelper.SetWindowsHookEx(m_HookType, m_HookProc, m_ProcessId, 0); } if (m_HookId == 0) { return; } if (!m_Hooks.ContainsKey(m_HookId)) { m_Hooks.Add(m_HookId, this); } }
private void tspClear_Click(object sender, EventArgs e) { HookHelper mHook = HookHelper.Instance(); ICommand pCmd = new UnSelectCommand(); pCmd.OnCreate(mHook); pCmd.OnClick(); }
private void tspDrawPolygon_Click(object sender, EventArgs e) { HookHelper mHook = HookHelper.Instance(); ICommand pCmd = new DrawPolygonTool(); pCmd.OnCreate(mHook); mHook.MapControl.CurrentTool = pCmd as ITool; }
protected HookBase(int threadId, HookType hookType) : this(hookType) { m_ThreadId = threadId; if (m_ThreadId == 0) { m_ThreadId = HookHelper.GetCurrentThreadId(); } }
protected HookBase(IntPtr processId, HookType hookType) : this(hookType) { m_ProcessId = processId; if (m_ProcessId == IntPtr.Zero) { m_ProcessId = HookHelper.GetCurrentProcessId(); } }
private void btnPickUpPoint_Click(object sender, EventArgs e) { HookHelper mHook = HookHelper.Instance(); ICommand cmd = new PickUpPointTool(); pick = cmd as IPickUpPoint; pick.PickUpFinishedEventHandler += new PickUpFinished(pick_PickUpFinishedEventHandler); cmd.OnCreate(mHook); mMapCtrl.CurrentTool = cmd as ITool; }
internal static void Load() { IL.Celeste.Strawberry.Added += modStrawberrySprite; collectRoutineHook = HookHelper.HookCoroutine("Celeste.Strawberry", "CollectRoutine", modStrawberrySound); On.Celeste.Player.Die += onPlayerDie; playerDeathRoutineHook = HookHelper.HookCoroutine("Celeste.PlayerDeadBody", "DeathRoutine", modDeathSound); Everest.Events.Level.OnCreatePauseMenuButtons += onCreatePauseMenuButtons; On.Celeste.Player.Added += Player_Added; On.Celeste.SaveData.AddStrawberry_AreaKey_EntityID_bool += onSaveDataAddStrawberry; On.Celeste.Strawberry.CollectRoutine += onStrawberryCollectRoutine; On.Celeste.Level.End += onLevelEnd; }
public static void Apply() { List <int> addrs = HookHelper.searchAsm(new byte[] { 0x66, 0x89, 0x46, 0x02, 0x5e, 0xc3, 0xcc }); foreach (int addr in addrs) { IntPtr PortFixLoc = (IntPtr)addr + 1; uint dwOldProtection; Kernel32.VirtualProtect(PortFixLoc, 1, 0x40, out dwOldProtection); Marshal.WriteByte(PortFixLoc, 0x8B); Kernel32.VirtualProtect(PortFixLoc, 1, dwOldProtection, out dwOldProtection); } }
public FrmPartialRefresh() { InitializeComponent(); mMapControl = new UcMapControl(); mMapControl.Dock = DockStyle.Fill; mMapControl.SetCenter(new RPoint(0, 0, 0));//设置基准点 this.Controls.Add(mMapControl); HookHelper mHook = HookHelper.Instance(); mHook.MapControl = mMapControl; }
public static void Apply() { List <int> addrs = HookHelper.searchAsm(new byte[] { 0x32, 0x44, 0x0a, 0xff }); foreach (int addr in addrs) { IntPtr location = (IntPtr)addr; uint dwOldProtection; Kernel32.VirtualProtect(location, 1, 0x40, out dwOldProtection); Marshal.WriteByte(location, 0x8a); Kernel32.VirtualProtect(location, 1, dwOldProtection, out dwOldProtection); } }
public CaptureForm() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.Location = new Point(0, 0); this.Size = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); this.TopMost = true; this.ShowInTaskbar = false; m_MHook = new HookHelper(); this.FormClosing += (s, e) => { m_MHook.UnLoadMHook(); this.DelResource(); }; imageProcessBox1.MouseLeave += (s, e) => this.Cursor = Cursors.Default; //后期一些操作历史记录图层 m_layer = new List <Bitmap>(); }
public MainFrm() { InitializeComponent(); mMapControl = new RgMapControl(); mMapControl.Dock = DockStyle.Fill; mMapControl.SetCenter(new RgPoint(0, 0));//设置基准点 this.panel1.Controls.Add(mMapControl); HookHelper mHook = HookHelper.Instance(); mHook.MapControl = mMapControl as IMapControl; mTimer.Interval = 100; mTimer.Tick += new EventHandler(mTimer_Tick); mMapControl.MouseMove += new MouseEventHandler(mMapControl_MouseMove); mTimer.Start(); }
public void Uninstall() { if (m_HookId == 0) { return; } var flag = HookHelper.UnhookWindowsHookEx(m_HookId); if (flag) { if (m_Hooks.Remove(m_HookId)) { m_HookId = 0; } } }
private void tspNewLayer_Click(object sender, EventArgs e) { HookHelper mHook = HookHelper.Instance(); IMapControl2 mapCtrl = mHook.MapControl as IMapControl2; RGeos.Carto.IMap map = mapCtrl.Map; FrmNewFeatureClass newFeatCls = new FrmNewFeatureClass(); if (newFeatCls.ShowDialog() == DialogResult.OK) { RGeos.Carto.ILayer layer = new RGeos.Carto.FetureLayer(); layer.Name = newFeatCls.FeatureName; (layer as RGeos.Carto.FetureLayer).ShapeType = newFeatCls.ShapeType; map.AddLayer(layer); mapCtrl.Refresh(); } }
public RgMapControl() { mScreenDisplay = new RGeos.Display.ScreenDisplay(Handle); mScreenDisplay.DisplayTransformation.Zoom = 1.0f; InitializeComponent(); mMap = new RGeos.Carto.Map(); this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); this.MouseDown += new MouseEventHandler(mPanel_MouseDown); this.MouseMove += new MouseEventHandler(mPanel_MouseMove); this.MouseUp += new MouseEventHandler(mPanel_MouseUp); this.Resize += new System.EventHandler(this.UcMapControl_Resize); HookHelper mHook = HookHelper.Instance(); mHook.MapControl = this as IMapControl; timeTick.Interval = 500; timeTick.Tick += new EventHandler(timeTick_Tick); }
void DoHook(OperationType type, string msg) { // API进入要替换msg if (m_isTokenAccess) { msg = msg.Replace(_token, "xxx"); } // 替换数字为枚举值 var reg = new Regex(@"runtype=(\d+)"); var match = reg.Match(msg); if (match.Success) { var runtype = (RunType)int.Parse(match.Result("$1")); msg = reg.Replace(msg, "runtype=" + runtype); } HookHelper.DoHook(type, msg); }
private void tspNewLayer_Click(object sender, EventArgs e) { HookHelper mHook = HookHelper.Instance(); IMapControl2 mapCtrl = mHook.MapControl as IMapControl2; RGeos.Carto.IMap map = mapCtrl.Map; frmNewFeatureClass newFeatCls = new frmNewFeatureClass(); if (newFeatCls.ShowDialog() == DialogResult.OK) { RGeos.Carto.ILayer layer = new RGeos.Carto.FetureLayer(); layer.Name = newFeatCls.FeatureName; (layer as RGeos.Carto.FetureLayer).ShapeType = newFeatCls.ShapeType; map.AddLayer(layer); mapCtrl.Refresh(); } //RGeos.Carto.ILayer layer = new RGeos.Carto.FetureLayer(); //(layer as RGeos.Carto.FetureLayer).ShapeType = RgEnumShapeType.RgLineString; //LineString line = new LineString(); //RgPoint pt = new RgPoint(0, 0); //RgPoint pt1 = new RgPoint(10 / MillmeteresPerInch, 0); //line.Vertices.Add(pt); //line.Vertices.Add(pt1); //(layer as RGeos.Carto.FetureLayer).mGeometries.Add(line); //LineString line1 = new LineString(); //RgPoint pt11 = new RgPoint(0, 10 / MillmeteresPerInch); //RgPoint pt12 = new RgPoint(0, 0); //line1.Vertices.Add(pt11); //line1.Vertices.Add(pt12); //(layer as RGeos.Carto.FetureLayer).mGeometries.Add(line1); //map.AddLayer(layer); //RGeos.Carto.ILayer layerPolygon = new RGeos.Carto.FetureLayer(); //(layerPolygon as RGeos.Carto.FetureLayer).ShapeType = RgEnumShapeType.RgPolygon; //map.AddLayer(layerPolygon); //RGeos.Carto.ILayer layerPolygon = new RGeos.Carto.FetureLayer(); //(layerPolygon as RGeos.Carto.FetureLayer).ShapeType = RgEnumShapeType.RgPoint; //map.AddLayer(layerPolygon); //mapCtrl.Refresh(); }
public FormMain() { InitializeComponent(); //大漠插件免注册或注册 var r = Reg(); switch (r) { case 0: Console.WriteLine(@"reg注册成功"); break; case 1: MessageBox.Show(@"reg无法释放资源"); break; case 2: MessageBox.Show(@"reg免注册失败,请重启软件"); break; case 3: MessageBox.Show(@"加载dm.dll失败"); break; case 4: MessageBox.Show(@"dm调用失败"); break; default: MessageBox.Show(@"reg无法调用"); break; } dm = new dmsoft(); //实例化钩子 var kh = new HookHelper(); //挂载钩子按键事件 kh.KeyDownEvent += OnKeyDown; //注册钩子 kh.SetHook(); }
private void button1_Click(object sender, EventArgs e) { float dx, dy; Graphics g = this.CreateGraphics(); try { dx = g.DpiX; dy = g.DpiY; } finally { g.Dispose(); } MessageBox.Show(string.Format("{0}/{1}", dx, dy)); HookHelper mHook = HookHelper.Instance(); ICommand pCmd = new DrawPolylineTool(); pCmd.OnCreate(mHook); mHook.MapControl.CurrentTool = pCmd as ITool; }
protected override int HookProc(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode < 0) { return(HookHelper.CallNextHookEx(m_HookId, nCode, wParam, lParam)); } var mouseMsg = (MouseMessage)wParam.ToInt32(); var mouseHookStruct = lParam.ToStruct <MOUSEHOOKSTRUCT>(); var button = this.GetMouseButtons(mouseMsg); switch (mouseMsg) { case MouseMessage.WM_LBUTTONDOWN: case MouseMessage.WM_RBUTTONDOWN: case MouseMessage.WM_MBUTTONDOWN: return(this.OnRaiseMouseDown(button, 1, mouseHookStruct.pt.X, mouseHookStruct.pt.Y, mouseHookStruct.mouseData)); case MouseMessage.WM_LBUTTONUP: case MouseMessage.WM_MBUTTONUP: case MouseMessage.WM_RBUTTONUP: return(this.OnRaiseMouseUp(button, 1, mouseHookStruct.pt.X, mouseHookStruct.pt.Y, mouseHookStruct.mouseData)); case MouseMessage.WM_LBUTTONDBLCLK: case MouseMessage.WM_RBUTTONDBLCLK: case MouseMessage.WM_MBUTTONDBLCLK: return(this.OnRaiseMouseDoubleClick(button, 2, mouseHookStruct.pt.X, mouseHookStruct.pt.Y, mouseHookStruct.mouseData)); case MouseMessage.WM_MOUSEMOVE: return(this.OnRaiseMouseMove(MouseButtons.None, 0, mouseHookStruct.pt.X, mouseHookStruct.pt.Y, mouseHookStruct.mouseData)); default: return(HookHelper.CallNextHookEx(m_HookId, nCode, wParam, lParam)); } }
internal static void Main() { AppDomain.CurrentDomain.UnhandledException += (sender, args) => Debug.Error(args.ExceptionObject.ToString()); GuildWarsInterface.Debugging.Debug.ThrowException += exception => Debug.Error(exception.ToString()); HookHelper.Initialize(); Game.Initialize(); Linking.Initialize(); new Thread(() => { while (true) { if (Game.State == GameState.Playing) { Game.TimePassed(1000); } Thread.Sleep(1000); } }).Start(); //ToDo: Fix Method in Movement.cs L67-96 new Thread(Movement.Task).Start(); }
public override void OnCreate(HookHelper hook) { Name = "绘制多边形"; mMapCtrl = hook.MapControl as UcMapControl; mScreenDisplay = mMapCtrl.mScreenDisplay; }
public static bool runBySingleCC() { //!! 场次信息回传 // 更新execpath的值 string start = "2000-01-01T00:00"; string end = "2000-01-01T08:00"; string datnums = "95"; string yearmmddForID = "2000010100"; //! 遍历指定目录下的降雨数据 //! 设置计时器,当前场次时间 Stopwatch totalFolderDat = new Stopwatch(); totalFolderDat.Start(); if (!Directory.Exists(HookHelper.rainSRCDirectory)) { Console.WriteLine(string.Format("{0}台风场dat降雨目录不存在 ", HookHelper.rainSRCDirectory) + DateTime.Now); return(false); } FileInfo[] fInfo = GenRainTileByCSharp.GetRaindatList(); int datnum = fInfo.Length; for (int d = 0; d < datnum; ++d) { //每次计算当前台风前先删除当前节点下,所有单元的公共传递文件inputq.csv\rainfile.txt //! 当前dat文件全路径 //! 设置计时器,当前场次时间 Stopwatch oneDat = new Stopwatch(); oneDat.Start(); string curDatFullname = fInfo[d].FullName; Console.WriteLine(string.Format("****************************降雨目录下第{0}场*********A************", d + 1) + DateTime.Now); Console.WriteLine(string.Format("*****************************************************AAA***********") + DateTime.Now); Console.WriteLine(string.Format("*****************************{0}场次Start***********AAAAA**********", curDatFullname) + DateTime.Now); Console.WriteLine(string.Format("***************************************************AAAAAAA*********") + DateTime.Now); Console.WriteLine(string.Format("**************************************************AAAAAAAAA********") + DateTime.Now); //! 遍历每个流域的网格模型 //!执行python切片 //!1、执行切片,调用python执行 if (HookHelper.isgenraintile) { //CSVLog //CSVData.addRow(); //! 设置计时器,当前场次时间 Stopwatch perChangci = new Stopwatch(); perChangci.Start(); bool isGenTilesucess = GenRainTileByCSharp.CreateTileByWATAByCSharp(curDatFullname, ref start, ref end, ref datnums, ref yearmmddForID); perChangci.Stop(); TimeSpan perChangciTime = perChangci.Elapsed; if (!isGenTilesucess) { //Console.WriteLine(string.Format("{0}区域降雨切片执行失败 ", HookHelper.computerNode) + DateTime.Now); HookHelper.Log += string.Format("{0}区域降雨切片执行失败 ", HookHelper.computerNode) + DateTime.Now + ";\r\n"; continue; } else { Console.WriteLine(string.Format("网格{0}场次降雨切片执行耗时:{1}秒", curDatFullname, perChangciTime.TotalMilliseconds / 1000)); HookHelper.Log += string.Format("网格{0}场次降雨切片执行耗时:{1}秒", curDatFullname, perChangciTime.TotalMilliseconds / 1000) + DateTime.Now + ";\r\n"; Console.WriteLine(string.Format("{0}区域降雨切片执行成功 ", HookHelper.computerNode) + DateTime.Now); //CSVLog if (HookHelper.useCSVLOG.Equals("true")) { CSVData.addData(CSVData.GetRowNumber(), "切片时长", perChangciTime.TotalMilliseconds / 1000); } } } //! 启动bat前每场的时间不同,要更新写出execsingle.bat if (dbTableConfigs["china"].Count > 0) { int appnum = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows.Count; int appValidCount = 0; for (int a = 0; a < appnum; ++a) { //!当前路径 string apppath = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows[a]["AppPath"].ToString(); string ComputeUnit = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows[a]["ComputeUnit"].ToString(); string provinceName = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows[a]["province"].ToString(); //execbat路径 string execpath = apppath + "execsingle.bat"; if (apppath.EndsWith("/")) { execpath = apppath + "execsingle.bat"; } else { execpath = apppath + "\\" + "execsingle.bat"; } if (!dbValues.ContainsKey(provinceName)) { continue; } string outrainTilepath = dbValues[provinceName]["rainTileFolder"]; // 更新execpath的值 bool isUpExec = false; //!覆盖更新通过指定参数到execsingle.bat文件 string datPureName = System.IO.Path.GetFileNameWithoutExtension(curDatFullname); isUpExec = WriteExecBatFile.UpdateExecBatFileByTemplateExecsingle(execpath, ComputeUnit, start, end, datnums, datPureName, outrainTilepath, yearmmddForID); if (isUpExec) { appValidCount++; //Console.WriteLine(string.Format("{0}区域{1}文件execsingle.bat更新成功 ", "china", apppath) + DateTime.Now); } else { //Console.WriteLine(string.Format("{0}区域{1}文件execsingle.bat更新失败 ", "china", apppath) + DateTime.Now); } } Console.WriteLine(string.Format("{0}区域{1}个有效单元的execsingle.bat更新成功 ", "china", appValidCount) + DateTime.Now); //!判断appnum 是否超过了processnum,是则部分启动,等待 //!先根据个数分组,分组后,则循环,则可以等待了 int processGroup = (int)Math.Ceiling((float)appnum / (float)HookHelper.processnum); for (int g = 0; g < processGroup; ++g) { //!循环每个组,pid存在,则执行等待 int perGroupCount = 0; while (pids.Count > 0) { //! 执行等待,然后查询更新pids列表.等待1分钟 Console.WriteLine(string.Format("共{0}个分组", processGroup) + DateTime.Now); Console.WriteLine(string.Format("等待第{0}场{1}文件的第{2}进程组计算完成并关闭,pid进程查询更新等待中,等待时长15秒...", d + 1, curDatFullname, g) + DateTime.Now); System.Threading.Thread.Sleep(1000 * 15 * 1); //kill perGroupCount++; Console.WriteLine(string.Format("已经等待次数{0}次", perGroupCount) + DateTime.Now); if (perGroupCount >= HookHelper.waitcount) { //遍历强制关闭当前场次的所有pid程序 foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (isInProcess) { //curProcss.Kill(); HookHelper.KillProcessAndChildren(curPID); } } } //! 遍历pids,查询windows process中是否存在这个pid,不存在,则移除 int pidnum = pids.Count; foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (!isInProcess) { pids.Remove(item.Key); } else { Console.WriteLine(string.Format("单元{0}所在分组{1}计算进行中......需继续等待......", item.Value, g) + DateTime.Now); } } if (pids.Count == 0) { break; } } //当前分组的起始值,和end值 int startPROCESS = g * HookHelper.processnum; int endPROCESS = (g + 1) * HookHelper.processnum; if (g == processGroup - 1) { endPROCESS = appnum; } int validStartUnitModel = 0; for (int a = startPROCESS; a < endPROCESS; ++a) { //!当前路径 string apppath = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows[a]["AppPath"].ToString(); string ComputeUnit = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows[a]["ComputeUnit"].ToString(); string ComputeNode = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows[a]["ComputeNode"].ToString(); //execbat路径 string execpath = apppath + "execsingle.bat"; if (apppath.EndsWith("/")) { execpath = apppath + "execsingle.bat"; } else { execpath = apppath + "\\" + "execsingle.bat"; } //! 启动该exec.bat //! 单元信息 string appunitInfo = ComputeNode + "_" + ComputeUnit + "_" + apppath; bool isOneStart = StartOneByOneExecsingle(execpath, appunitInfo); if (isOneStart) { validStartUnitModel++; HookHelper.Log += string.Format("{0}节点{1}单元{2}路径执行成功 ", HookHelper.computerNode, ComputeUnit, execpath) + DateTime.Now + ";\r\n"; //Console.WriteLine(string.Format("{0}节点{1}单元{2}路径执行成功 ", HookHelper.computerNode, ComputeUnit, execpath) + DateTime.Now); } else { HookHelper.Log += string.Format("{0}节点{1}单元{2}路径执行失败 ", HookHelper.computerNode, ComputeUnit, execpath) + DateTime.Now + ";\r\n"; //Console.WriteLine(string.Format("{0}节点{1}单元{2}路径执行失败 ", HookHelper.computerNode, ComputeUnit, execpath) + DateTime.Now); } } Console.WriteLine(string.Format("{0}节点{1}个有效单元启动命令执行成功 ", HookHelper.computerNode, validStartUnitModel) + DateTime.Now); } } //!循环每个组,pid存在,则执行等待,直至继续运行到下一步,代表一个场次计算结束 int perWaitCount = 0; //如果等待超过1个小时,仍然无法计算,则跳过这个场次,并写出到log中 while (pids.Count > 0) { //! 执行等待,然后查询更新pids列表.等待1分钟 Console.WriteLine(string.Format("等待第{0}场{1}文件计算完成并关闭,pid进程查询更新等待中,等待时长15秒...", d + 1, curDatFullname) + DateTime.Now); System.Threading.Thread.Sleep(1000 * 15 * 1); perWaitCount++; Console.WriteLine(string.Format("已经等待次数{0}次", perWaitCount) + DateTime.Now); if (perWaitCount >= HookHelper.waitcount) { //遍历强制关闭当前场次的所有pid程序 //将该场次值写出到log文件中 string ignoreCCName = curDatFullname; WriteLog.AppendLogMethod(ignoreCCName, "datIgnore"); foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (isInProcess) { //curProcss.Kill(); HookHelper.KillProcessAndChildren(curPID); } else { Console.WriteLine(string.Format("最后一组单元{0}计算进行中......需继续等待......", item.Value) + DateTime.Now); } } } //! 遍历pids,查询windows process中是否存在这个pid,不存在,则移除 int pidnum = pids.Count; foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (!isInProcess) { pids.Remove(item.Key); } else { Console.WriteLine(string.Format("最后一组单元{0}计算进行中......需继续等待......", item.Value) + DateTime.Now); } } if (pids.Count == 0) { break; } } Console.WriteLine(string.Format("{0}台风场所有流域计算完成 ", curDatFullname) + DateTime.Now); HookHelper.Log += string.Format("{0}台风场所有流域计算完成 ", curDatFullname) + DateTime.Now + ";\r\n"; Console.WriteLine(string.Format("******************************************************A************") + DateTime.Now); Console.WriteLine(string.Format("*****************************************************AAA***********") + DateTime.Now); Console.WriteLine(string.Format("*****************************{0}场次END*************AAAAA**********", curDatFullname) + DateTime.Now); Console.WriteLine(string.Format("***************************************************AAAAAAA*********") + DateTime.Now); Console.WriteLine(string.Format("**************************************************AAAAAAAAA********") + DateTime.Now); Console.WriteLine(string.Format("****************************降雨目录下第{0}场结束******************", d + 1) + DateTime.Now); oneDat.Stop(); TimeSpan oneDatTime = oneDat.Elapsed; Console.WriteLine(string.Format("网格{0}场次降雨切片->bat信息更新->等待网格流域计算,单场次全流程耗时:{1}秒", curDatFullname, oneDatTime.TotalMilliseconds / 1000)); HookHelper.Log += string.Format("网格{0}场次降雨切片->bat信息更新->等待网格流域计算,单场次全流程耗时:{1}秒", curDatFullname, oneDatTime.TotalMilliseconds / 1000) + DateTime.Now + ";\r\n"; Console.WriteLine(string.Format("####################################################################") + DateTime.Now); Console.WriteLine(string.Format(" ") + DateTime.Now); Console.WriteLine(string.Format(" ") + DateTime.Now); Console.WriteLine(string.Format("####################################################################") + DateTime.Now); //CSVLog if (HookHelper.useCSVLOG.Equals("true")) { CSVData.addData(CSVData.GetRowNumber(), "单场台风时长", oneDatTime.TotalMilliseconds / 1000); CSVData.addData(CSVData.GetRowNumber(), "单场计算时长", oneDatTime.TotalMilliseconds / 1000 - (double)CSVData.LogDataTable.Rows[CSVData.GetRowNumber()]["切片时长"]); } } Console.WriteLine(string.Format("{0}场台风场次逐场次流域计算完成 ", datnum) + DateTime.Now); HookHelper.Log += string.Format("{0}场台风场次逐场次流域计算完成 ", datnum) + DateTime.Now + ";\r\n"; Console.WriteLine(string.Format("*********(-_-) **************{0}场台风场次逐场次流域计算完成*******..~^_^~..***********", datnum) + DateTime.Now); Console.WriteLine(string.Format("*********(-_-) ***************{0}场台风场次逐场次流域计算完成*******..~^_^~..**********", datnum) + DateTime.Now); Console.WriteLine(string.Format("*********(-_-) ***************{0}场台风场次逐场次流域计算完成*******..~^_^~..**********", datnum) + DateTime.Now); Console.WriteLine(string.Format("********(-_-) **************{0}场台风场次逐场次流域计算完成*******..~^_^~..**********", datnum) + DateTime.Now); Console.WriteLine(string.Format("********(-_-) ***************{0}场台风场次逐场次流域计算完成*******..~^_^~..*********", datnum) + DateTime.Now); Console.WriteLine(string.Format("********(-_-) ****************{0}场台风场次逐场次流域计算完成*******..~^_^~..**********", datnum) + DateTime.Now); totalFolderDat.Stop(); TimeSpan totalFolderDatTime = totalFolderDat.Elapsed; Console.WriteLine(string.Format("{0}降雨目录下{1}个降雨文件从降雨切片->bat信息更新->等待网格流域计算,总耗时:{2}秒", HookHelper.rainSRCDirectory, datnum, totalFolderDatTime.TotalMilliseconds / 1000)); HookHelper.Log += string.Format("{0}降雨目录下{1}个降雨文件从降雨切片->bat信息更新->等待网格流域计算,总耗时:{2}秒", HookHelper.rainSRCDirectory, datnum, totalFolderDatTime.TotalMilliseconds / 1000) + DateTime.Now + ";\r\n"; return(true); }
public static bool runBySingleCC() { // 更新execpath的值 string start = "2000-01-01T00:00"; string end = "2000-01-01T08:00"; string datnums = "95"; string yearmmddForID = "2000010100"; //! 设置计时器,当前场次时间 Stopwatch totalFolderDat = new Stopwatch(); totalFolderDat.Start(); //! 遍历指定目录下的降雨数据 if (!Directory.Exists(HookHelper.rainSRCDirectory)) { Console.WriteLine(string.Format("{0}台风场dat降雨目录不存在 ", HookHelper.rainSRCDirectory) + DateTime.Now); return(false); } FileInfo[] fInfo = GenRainTileByPython.GetRaindatList(); int datnum = fInfo.Length; for (int d = 0; d < datnum; ++d) { //! 当前dat文件全路径 string curDatFullname = fInfo[d].FullName; Console.WriteLine(string.Format("*****************************{0}场次Start**************************", curDatFullname) + DateTime.Now); //! 遍历每个省的网格模型 foreach (var curDB in dbValues) { //! key名称,省份的名称 string keyString = curDB.Key; if (!String.IsNullOrWhiteSpace(HookHelper.curProvince)) { if (!keyString.ToUpper().Equals(HookHelper.curProvince.ToUpper())) { continue; } } //! 每个省的切片目录,对每个省执行两步操作 //! 1、根据指定的src降雨目录,执行python切片,输出路径为tile指定的目录 //!2、根据数据库中配置的模型存放目录,写出批量启动bat命令,一次性启动当前省份的n个并行程序 foreach (var curTBType in curDB.Value) { //! 只有配置了raintile目录才执行计算 string keyTableType = curTBType.Key; string folderPath = curTBType.Value; HookHelper.rainTileDirectory = ""; if (keyTableType.ToUpper() == "RAINTILEFOLDER") { HookHelper.rainTileDirectory = folderPath; //!执行python切片 //!1、执行切片,调用python执行 if (HookHelper.isgenraintile) { //! 设置计时器,当前场次时间 Stopwatch perChangci = new Stopwatch(); perChangci.Start(); bool isGenTilesucess = GenRainTileByCSharp.CreateTileByWATAByCSharpFromProvince(keyString, curDatFullname, ref start, ref end, ref datnums, ref yearmmddForID); perChangci.Stop(); TimeSpan perChangciTime = perChangci.Elapsed; if (!isGenTilesucess) { //Console.WriteLine(string.Format("{0}区域降雨切片执行失败 ", HookHelper.computerNode) + DateTime.Now); continue; } else { Console.WriteLine(string.Format("网格{0}场次降雨切片执行耗时:{1}秒", curDatFullname, perChangciTime.TotalMilliseconds / 1000)); HookHelper.Log += string.Format("网格{0}场次降雨切片执行耗时:{1}秒", curDatFullname, perChangciTime.TotalMilliseconds / 1000) + DateTime.Now + ";\r\n"; Console.WriteLine(string.Format("{0}区域降雨切片执行成功 ", HookHelper.computerNode) + DateTime.Now); } } //! 启动bat前每场的时间不同,要更新写出execsingle.bat if (dbTableConfigs[keyString].Count > 0) { int appnum = dbTableConfigs[keyString]["HSFX_ComputeUnit"].Rows.Count; for (int a = 0; a < appnum; ++a) { //!当前路径 string apppath = dbTableConfigs[keyString]["HSFX_ComputeUnit"].Rows[a]["AppPath"].ToString(); string ComputeUnit = dbTableConfigs[keyString]["HSFX_ComputeUnit"].Rows[a]["ComputeUnit"].ToString(); //execbat路径 string execpath = apppath + "execsingle.bat"; if (apppath.EndsWith("/")) { execpath = apppath + "execsingle.bat"; } else { execpath = apppath + "\\" + "execsingle.bat"; } string outpath = HookHelper.rainTileDirectory; // 更新execpath的值 bool isUpExec = false; string datPureName = System.IO.Path.GetFileNameWithoutExtension(curDatFullname); isUpExec = WriteExecBatFile.UpdateExecBatFileByTemplateExecsingle(execpath, ComputeUnit, start, end, datnums, datPureName, HookHelper.rainTileDirectory, yearmmddForID); if (isUpExec) { Console.WriteLine(string.Format("{0}区域{1}文件exec.bat更新成功 ", keyString, apppath) + DateTime.Now); } } } //12、遍历一个个启动 if (dbTableConfigs[keyString].Count > 0) { //!每个省下的所有app int appnum = dbTableConfigs[keyString]["HSFX_ComputeUnit"].Rows.Count; //!判断appnum 是否超过了processnum,是则部分启动,等待 //!先根据个数分组,分组后,则循环,则可以等待了 int processGroup = (int)Math.Ceiling((float)appnum / (float)HookHelper.processnum); for (int g = 0; g < processGroup; ++g) { //!循环每个组,pid存在,则执行等待 int perGroupCount = 0; while (pids.Count > 0) { //! 执行等待,然后查询更新pids列表.等待1分钟 Console.WriteLine(string.Format("共{0}个分组", processGroup) + DateTime.Now); Console.WriteLine(string.Format("等待第{0}场{1}文件的第{2}进程组计算完成并关闭,pid进程查询更新等待中,等待时长15秒...", d + 1, curDatFullname, g) + DateTime.Now); System.Threading.Thread.Sleep(1000 * 15 * 1); //kill perGroupCount++; Console.WriteLine(string.Format("已经等待次数{0}次", perGroupCount) + DateTime.Now); if (perGroupCount >= HookHelper.waitcount) { //遍历强制关闭当前场次的所有pid程序 foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (isInProcess) { //curProcss.Kill(); HookHelper.KillProcessAndChildren(curPID); } } } //! 遍历pids,查询windows process中是否存在这个pid,不存在,则移除 int pidnum = pids.Count; foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (!isInProcess) { pids.Remove(item.Key); } else { Console.WriteLine(string.Format("单元{0}所在分组{1}计算进行中......需继续等待......", item.Value, g) + DateTime.Now); } } if (pids.Count == 0) { break; } } //当前分组的起始值,和end值 int startPROCESS = g * HookHelper.processnum; int endPROCESS = (g + 1) * HookHelper.processnum; if (g == processGroup - 1) { endPROCESS = appnum; } int validStartUnitModel = 0; for (int a = startPROCESS; a < endPROCESS; ++a) { //!当前路径 string apppath = dbTableConfigs[keyString]["HSFX_ComputeUnit"].Rows[a]["AppPath"].ToString(); string ComputeUnit = dbTableConfigs[keyString]["HSFX_ComputeUnit"].Rows[a]["ComputeUnit"].ToString(); string ComputeNode = dbTableConfigs["china"]["HSFX_ComputeUnit"].Rows[a]["ComputeNode"].ToString(); //execbat路径 string execpath = apppath + "execsingle.bat"; if (apppath.EndsWith("/")) { execpath = apppath + "execsingle.bat"; } else { execpath = apppath + "\\" + "execsingle.bat"; } //! 启动该exec.bat //! 单元信息 string appunitInfo = ComputeNode + "_" + ComputeUnit + "_" + apppath; bool isOneStart = StartOneByOneExecsingle(execpath, appunitInfo); if (isOneStart) { validStartUnitModel++; //Console.WriteLine(string.Format("{0}节点{1}单元{2}路径执行成功 ", HookHelper.computerNode, ComputeUnit, execpath) + DateTime.Now); } else { //Console.WriteLine(string.Format("{0}节点{1}单元{2}路径执行失败 ", HookHelper.computerNode, ComputeUnit, execpath) + DateTime.Now); } } Console.WriteLine(string.Format("{0}节点{1}个有效单元启动命令执行成功 ", HookHelper.computerNode, validStartUnitModel) + DateTime.Now); } //!循环每个组,pid存在,则执行等待,直至继续运行到下一步,代表一个场次计算结束 int perWaitCount = 0; //如果等待超过1个小时,仍然无法计算,则跳过这个场次,并写出到log中 while (pids.Count > 0) { //! 执行等待,然后查询更新pids列表.等待1分钟 Console.WriteLine(string.Format("等待第{0}场{1}文件计算完成并关闭,pid进程查询更新等待中,等待时长15秒...", d + 1, curDatFullname) + DateTime.Now); System.Threading.Thread.Sleep(1000 * 15 * 1); perWaitCount++; Console.WriteLine(string.Format("已经等待次数{0}次", perWaitCount) + DateTime.Now); if (perWaitCount >= HookHelper.waitcount) { //遍历强制关闭当前场次的所有pid程序 //将该场次值写出到log文件中 string ignoreCCName = curDatFullname; WriteLog.AppendLogMethod(ignoreCCName, "datIgnore"); foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (isInProcess) { //curProcss.Kill(); HookHelper.KillProcessAndChildren(curPID); } else { Console.WriteLine(string.Format("最后一组单元{0}计算进行中......需继续等待......", item.Value) + DateTime.Now); } } } //! 遍历pids,查询windows process中是否存在这个pid,不存在,则移除 int pidnum = pids.Count; foreach (var item in pids.ToList()) { int curPID = item.Key; Process curProcss = null; try { curProcss = Process.GetProcessById(curPID); } catch (Exception ex) { curProcss = null; } bool isInProcess = curProcss == null ? false : true; if (!isInProcess) { pids.Remove(item.Key); } else { Console.WriteLine(string.Format("最后一组单元{0}计算进行中......需继续等待......", item.Value) + DateTime.Now); } } if (pids.Count == 0) { break; } } } else { Console.WriteLine(string.Format("{0}区域所有单元执行bat启动失败 ", keyString) + DateTime.Now); } } } } Console.WriteLine(string.Format("{0}台风场所有省份计算完成 ", curDatFullname) + DateTime.Now); Console.WriteLine(string.Format("*****************************{0}场次END**************************", curDatFullname) + DateTime.Now); } totalFolderDat.Stop(); TimeSpan totalFolderDatTime = totalFolderDat.Elapsed; Console.WriteLine(string.Format("{0}降雨目录下{1}个降雨文件从降雨切片->bat信息更新->等待网格流域计算,总耗时:{2}秒", HookHelper.rainSRCDirectory, datnum, totalFolderDatTime.TotalMilliseconds / 1000)); HookHelper.Log += string.Format("{0}降雨目录下{1}个降雨文件从降雨切片->bat信息更新->等待网格流域计算,总耗时:{2}秒", HookHelper.rainSRCDirectory, datnum, totalFolderDatTime.TotalMilliseconds / 1000) + DateTime.Now + ";\r\n"; return(true); }
public void MyTestInitialize() { hookRepository = HookHelper.GetRepository <IHook>(); }