private bool Connect(ref string errStr) { #region 說明 /* * * 1. 寫入註冊表SOFTWARE\\Wow6432Node\\tri\\Printer * 2. 讀取註冊表SOFTWARE\\Wow6432Node\\tri\\Printer\\bShowRPCServer=1 : 顯示Console RPC viewer * 3. 開啟路徑 * 執行檔所在路徑\\RPC\\ (檔案交換路徑) * 執行檔所在路徑\\RPC\\server\\ (RPC通訊軟體開啟路徑) * */ #endregion bool IsConnected = false; Log4.PrinterLogger.InfoFormat("Ping to {0} .. ", _RPCPara.SideIP); if (NetTool.Ping(_RPCPara.SideIP) == false) { errStr = "@CANT_CONNECT_TO_PRINTER_IP".Translate() + ": " + _RPCPara.SideIP; Log4.PrinterLogger.ErrorFormat("Connect False: {0} .. ", errStr); return(false); } if (IsComputerNameDuplicated()) { errStr = "Computer Name Is Duplicated!"; Log4.PrinterLogger.ErrorFormat("IsComputerNameDuplicated: {0} .. ", errStr); return(false); } KillRpcProcess(); System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(_RPCPara.WorkingPath + "server\\RPCServer.exe"); string strCreateRPCFail = "@CANT_CREATE_SPI_RPC_SERVER_FROM".Translate() + ": " + _RPCPara.WorkingPath + "server\\RPCServer.exe"; Log4.PrinterLogger.InfoFormat("Process StartInfo ({0})", _RPCPara.WorkingPath + "server\\RPCServer.exe"); Log4.PrinterLogger.InfoFormat("_RPCPara.bShowRPCWindow = ({0})", _RPCPara.bShowRPCWindow); if (_RPCPara.bShowRPCWindow == true) { info.CreateNoWindow = true; info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; } else { info.CreateNoWindow = false; info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; } try { process = System.Diagnostics.Process.Start(info); errStr = (process == null) ? strCreateRPCFail : string.Empty; } catch (Exception e) { Log4.PrinterLogger.ErrorFormat("Start Process Exception = {0}", e.Message); errStr = strCreateRPCFail; } if (process == null || errStr != string.Empty) { return(false); } IsConnected = InquirePrinterStatus(); if (IsConnected == true) { SendSpiStatusToPrinter(eSpiExecutionStatus.Idle); } else { errStr = "@CANT_RECEIVE_PRINTER_STATUS".Translate(); } return(IsConnected); }