Esempio n. 1
0
        /// <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());
        }
Esempio n. 2
0
        /// <summary>
        /// EXE로부터 전달받은 메세지를 처리
        /// </summary>
        /// <param name="receiveData"></param>
        /// <param name="token"></param>
        public static void Receive(WinMessage_ClientToServer receiveData, HY_AjaxAgent.TokenData token)
        {
            AJAX_Response sendData;

            switch (receiveData.RESULT_COMMAND)
            {
            case "workComplete":
                sendData = new AJAX_Response(receiveData.PARAM);

                HY_AjaxAgent.sendToWEB(sendData, token);
                break;

            case "startSuccess":
                exeLogging(receiveData.PROCESS_KIND.ToString() + "프로그램 실행 완료 메세지 받음");
                break;

            case "closeProcess":
                exeLogging(receiveData.PROCESS_KIND.ToString() + "프로그램 종료 메세지");
                sendData = new AJAX_Response(new Response_Error("exe close...", "508", "user click exe close before workcomplete."));

                HY_AjaxAgent.sendToWEB(sendData, token);
                break;

            default:
                exeLogging("알 수 없는 EXE Command 받음 : " + receiveData.RESULT_COMMAND);
                break;
            }
        }
Esempio n. 3
0
 private static void webLogging(string logMsg, bool isError = false)
 {
     HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.WEB, logMsg);
     if (isError)
     {
         Log.Instance.Error(logMsg);
     }
     else
     {
         Log.Instance.Info(logMsg);
     }
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        /// <summary>
        /// WEB으로 결과값 전달
        /// </summary>
        /// <param name="sendData"></param>
        /// <param name="token"></param>
        public static void Send(AJAX_Response sendData, HY_AjaxAgent.TokenData token)
        {
            //PARAM, PATH 처리
            string responseString = Json.ToString(sendData);

            //jsonp 처리 hychoi
            if (token.jsonpCheck.isJsonp)
            {
                responseString = string.Format("{0}({1});", token.jsonpCheck.callback, responseString);
            }

            HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.WEB, "보내는 데이터 : " + responseString);

            writeResponse(responseString, token.response);
        }
Esempio n. 6
0
 private static void exeLogging(string logMsg)
 {
     HY_AjaxAgent.AddText(HY_AjaxAgent.MSGVIEW.Process, "");
 }
Esempio n. 7
0
        /// <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;
            }
        }