/// <summary> /// Server로부터 Process를 종료시킨다. /// </summary> /// <param name="exeKind">EXE 종류</param> /// <param name="token">서버에서 가지고 있을 TokenData</param> public static string Stop_Process(EXEKIND exeKind, TokenData token) { AddText(MSGVIEW.Process, string.Format("EXE 종료... 종류 : {0}", exeKind.ToString())); Log.Instance.Info("## Process Stop ##..." + exeKind.ToString()); string retMsg; //Process를 실행시킨 후 핸들값을 받아온다. bool bRet = ProcessControl.closeEXE(exeKind, out retMsg); if (bRet) { if (WEB_EXE_TranseTokens.ContainsKey(exeKind)) { Log.Instance.Warn(string.Format("## {0} Token삭제 ##", exeKind.ToString())); WEB_EXE_TranseTokens.Remove(exeKind); } Log.Instance.Info("## Process Stop Success ##"); return(null); } else { AddText(MSGVIEW.Process, string.Format("{0}", retMsg)); Log.Instance.Error(">>" + retMsg + "<<"); Log.Instance.Error("## Process Stop Faild ##"); return(retMsg); } }
/// <summary> /// 프로세스(EXE)를 실행시킨다. /// </summary> /// <param name="exeKind">EXE 종류</param> /// <param name="arguments">실행인자</param> /// <param name="serverHandle">실행인자 첫번째로 넘어가게 될 서버 핸들</param> /// <param name="errorMsg"></param> /// <returns></returns> public static string executeEXE(EXEKIND exeKind, string arguments, IntPtr serverHandle, out string errorMsg) { string exeFilepath = getEXEFilePath(exeKind); errorMsg = string.Empty; if (!File.Exists(exeFilepath)) { HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe file dosen't exist... {0}", exeKind.ToString())); HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe file path : {0}", exeFilepath)); Log.Instance.Error(string.Format("exe file dosen't exist... {0}", exeKind.ToString())); Log.Instance.Error(string.Format("exe file path : {0}", exeFilepath)); errorMsg = string.Format("exe file dosen't exist... {0}", exeKind.ToString()); return(null); } if (processRunningCheck(exeKind)) { HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe is already started... {0}", exeKind.ToString())); HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe file path : {0}", exeFilepath)); Log.Instance.Error(string.Format("exe is already started... {0}", exeKind.ToString())); Log.Instance.Error(string.Format("exe file path : {0}", exeFilepath)); errorMsg = string.Format("exe is already started... {0}", exeKind.ToString()); return(null); } arguments = serverHandle.ToString() + " " + arguments; Process process = Process.Start(exeFilepath, arguments); return(process.Handle.ToString()); }
public static bool closeEXE(EXEKIND exeKind, out string errorMsg) { string exeFilepath = getEXEFilePath(exeKind); errorMsg = string.Empty; if (!File.Exists(exeFilepath)) { HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe file dosen't exist... {0}", exeKind.ToString())); HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe file path : {0}", exeFilepath)); Log.Instance.Error(string.Format("exe file dosen't exist... {0}", exeKind.ToString())); Log.Instance.Error(string.Format("exe file path : {0}", exeFilepath)); errorMsg = string.Format("exe file dosen't exist... {0}", exeKind.ToString()); return(false); } if (!processRunningCheck(exeKind)) { HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe is not running... {0}", exeKind.ToString())); HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, string.Format("exe file path : {0}", exeFilepath)); Log.Instance.Error(string.Format("exe is not running...... {0}", exeKind.ToString())); Log.Instance.Error(string.Format("exe file path : {0}", exeFilepath)); errorMsg = string.Format("exe is not running...... {0}", exeKind.ToString()); return(false); } try { Process[] runningProcess = Process.GetProcesses(); foreach (Process process in runningProcess) { try { if (string.Compare(process.MainModule.FileName, exeFilepath) == 0) { process.Kill(); } } catch { } } } catch (Exception error) { errorMsg = error.Message; return(false); } return(true); }
/// <summary> /// Server로부터 Process를 실행시킨다. /// </summary> /// <param name="exeKind">EXE 종류</param> /// <param name="param">Start COMMAND로 받은 PARAM 값(String)</param> /// <param name="token">서버에서 가지고 있을 TokenData</param> /// <param name="serverHandle">서버핸들값</param> public static string Start_Process(EXEKIND exeKind, string param, TokenData token, IntPtr serverHandle) { AddText(MSGVIEW.Process, string.Format("EXE 실행... 종류 : {0}", exeKind.ToString())); AddText(MSGVIEW.Process, string.Format("서버핸들 값 : {0}", serverHandle.ToString())); Log.Instance.Info("## Process Start ##"); Log.Instance.Info(string.Format("EXE : {0}, SERVER_HANDLE : {1}", exeKind.ToString(), serverHandle)); // Token이 이미 있을 때 재전송 할것인가? //if (WEB_EXE_TranseTokens.ContainsKey(exeKind)) //{ // Log.Instance.Error(string.Format("## {0} EXE가 이미 실행되어 있음. ##", exeKind.ToString())); // WEB_EXE_TranseTokens[exeKind] = token; //} string retMsg = string.Empty; //Process를 실행시킨 후 핸들값을 받아온다. string executedProcessHandle = ProcessControl.executeEXE(exeKind, param, serverHandle, out retMsg); if (executedProcessHandle != null) { if (WEB_EXE_TranseTokens.ContainsKey(exeKind)) { Log.Instance.Warn(string.Format("## {0} Token이 이미 존재. 새로 받은 token으로 교체 ##", exeKind.ToString())); WEB_EXE_TranseTokens[exeKind] = token; } else { WEB_EXE_TranseTokens.Add(exeKind, token); } AddText(MSGVIEW.Process, string.Format("실행 EXE 종류 : {0}, 실행 EXE 핸들 값 : {1}", exeKind.ToString(), executedProcessHandle)); Log.Instance.Info("## Process Start Success ##"); } else { AddText(MSGVIEW.Process, string.Format("{0}", retMsg)); Log.Instance.Error(">>" + retMsg + "<<"); Log.Instance.Error("## Process Start Faild ##"); } return(retMsg); }
/// <summary> /// WEB으로부터 전달받은 req, res 객체를 처리 /// </summary> /// <param name="request">req객체</param> /// <param name="response">res객체</param> /// <param name="server">server 객체</param> public static void Receive(HttpListenerRequest request, HttpListenerResponse response, HY_AjaxAgent server) { Log.Instance.Info("Receive...!"); string data_text = new StreamReader(request.InputStream, request.ContentEncoding).ReadToEnd(); string cleaned_data = System.Web.HttpUtility.UrlDecode(data_text); //jsonp 처리 hychoi bool isJsonp = false; Log.Instance.Info("Check post method or jsonp by checking cleaned_data(post) and querystring callback"); string callback = request.QueryString["callback"]; //jsonp 처리 hychoi if (string.IsNullOrEmpty(cleaned_data) && !string.IsNullOrEmpty(callback)) { //jsonp //2020-09-25 jsonp server check 추가. if (callback == "jsonCallback" || callback == "successServerCheckCallback") { cleaned_data = request.QueryString[1]; } if (string.IsNullOrEmpty(cleaned_data) && string.IsNullOrEmpty(callback) && request.QueryString.Count > 1) { cleaned_data = request.QueryString[1]; } cleaned_data = System.Web.HttpUtility.UrlDecode(cleaned_data); webLogging("jsonp 연결 확인 : "); response.ContentType = "application/json"; isJsonp = true; } webLogging("받은 데이터: " + cleaned_data); AJAX_Request receiveData; Json.ToObject <AJAX_Request>(cleaned_data, out receiveData); HY_AjaxAgent.TokenData token = new HY_AjaxAgent.TokenData(receiveData, response, new HY_AjaxAgent.TokenData.JsonPCheck(isJsonp, callback)); if (receiveData == null) { // ToDo. null처리 webLogging(">> Request 요청은 받았으나, 전달받은 데이터가 없거나 정해진 Interface 가 지켜지지 않았습니다. <<", true); Send(new AJAX_Response(new Response_Error("No Interface", "507", "you send data unruled Interface")), token); } //################################################################################################### EXEKIND exeKind = (EXEKIND)receiveData.EXEKIND; string command = receiveData.COMMAND; string param = Json.ToString(receiveData.PARAM); string errorMsg = string.Empty; switch (command) { case "start": //ToDo. process 실행 확인 param = param.Replace("\"", "\"\"\""); errorMsg = HY_AjaxAgent.Start_Process(exeKind, param, token, server.Handle); //error발생 if (!string.IsNullOrEmpty(errorMsg)) { Send(new AJAX_Response(new Response_Error(exeKind.ToString(), "500", errorMsg)), token); } break; case "close": errorMsg = HY_AjaxAgent.Stop_Process(exeKind, token); //error발생 if (!string.IsNullOrEmpty(errorMsg)) { Send(new AJAX_Response(new Response_Error(exeKind.ToString(), "500", errorMsg)), token); } else { Send(new AJAX_Response(new Response(exeKind.ToString(), command, "success")), token); } break; //2020-09-25 jsonp server check 추가. case "server_check": Send(new AJAX_Response(new Response(exeKind.ToString(), command, "success")), token); break; } }