Example #1
0
        private bool ShellG2(int portNo, BSLCompany objCompany, ref string strErrMsg)
        {
            LogMsg("ShellG2: ShellG2 called.");
            Hashtable sessionList = (Hashtable)Application["m_sessionList"];

            //Retrieve application constants
            string strG2Path     = (string)Context.Cache["G2_PATH"];
            string strOKPath     = (string)Context.Cache["OK_PATH"];
            string strLogPath    = (string)Context.Cache["LOG_PATH"];
            string strG2DataPath = (string)Context.Cache["G2_DATA_PATH"];
            string strG2KB       = (string)Context.Cache["G2_KB"];

            //string strConnStr = (string)Context.Cache["CONN_STR"];

            LogMsg("ShellG2: Retrieved application constants.");

            //Retrieve company-specific data from database.
            string strOKFileName  = objCompany.TCompanies[0].okFileName;
            string strLogFileName = objCompany.TCompanies[0].logFileName;
            string strDataDirName = objCompany.TCompanies[0].rootDirName;

            string strRootDir = strG2DataPath + (!strG2DataPath.EndsWith("\\") ? "\\" : "") +
                                strDataDirName;

            LogMsg("ShellG2: Read company-specific data.");

            //Build G2 command line arguments
            string strArgs = "-tcpport " + portNo + " -tcpipexact";

            //strArgs += " -ok \"" + strOKPath + (!strOKPath.EndsWith("\\") ? "\\" : "") + strOKFileName + "\"";
            strArgs += " -log \"" + strLogPath + (!strLogPath.EndsWith("\\") ? "\\" : "") + strLogFileName + "\"";
            strArgs += " -root-dir \"" + strRootDir + "\"";
            strArgs += " -kb \"" + strG2KB + "\"";
            strArgs += " -nowindow";

            try
            {
                ProcessStartInfo si = new ProcessStartInfo();
                si.FileName         = "\"" + strG2Path + (!strG2Path.EndsWith("\\") ? "\\" : "") + "g2.exe\"";         // "g2.exe\""; // "start-g2.bat\""
                si.WorkingDirectory = strG2Path;
                si.Arguments        = strArgs;

                LogMsg("ShellG2: Process command line: " + si.FileName);

                LogMsg("ShellG2: Process command line args: " + strArgs);

                LogMsg("ShellG2: Process Working Dir: " + si.WorkingDirectory);

                si.WindowStyle     = ProcessWindowStyle.Normal;
                si.UseShellExecute = false;
                si.EnvironmentVariables.Add("G2_OK", strOKPath + (!strOKPath.EndsWith("\\") ? "\\" : "") + strOKFileName);

                /*
                 * si.EnvironmentVariables.Add("G2_MODULE_SEARCH_PATH",
                 *      " '%SITE_%' '%G2IHOME_%\sites\Optegrity\kbs'
                 * '%G2IHOME_%\sites\e-SCOR\kbs' '%G2IHOME_%\sites\ReThink\kbs'
                 * '%G2IHOME_%\sites\DevSite\kbs' '%G2IHOME_%\kbs' '%G2HOME_%\g2\kbs\utils'
                 * '%G2HOME_%\activexlink' '%G2HOME_%\odbc' '%G2HOME_%\pi'
                 * '%G2HOME_%\opclink\kbs' '%G2HOME_%\protools\kbs' '%G2HOME_%\gw'
                 * '%G2HOME_%\corbalink\kbs' '%G2HOME_%\javalink\kbs' '%G2HOME_%\tw2\kbs' "
                 * set G2_MODULE_SEARCH_PATH=" '%G2IHOME_%\sites\Optegrity\kbs'
                 * '%G2IHOME_%\sites\e-SCOR\kbs' '%G2IHOME_%\sites\ReThink\kbs'
                 * '%G2IHOME_%\sites\DevSite\kbs' '%G2IHOME_%\kbs' 'C:\bt\kbs'
                 * '%G2HOME_%\activexlink\kbs' '%G2HOME_%\odbc\kbs' '%G2HOME_%\pi'
                 * '%G2HOME_%\opclink\kbs' '%G2HOME_%\jmail\kbs' '%G2HOME_%\jms\kbs'
                 * '%G2HOME_%\protools\kbs' '%G2HOME_%\gw' '%G2HOME_%\corbalink\kbs'
                 * '%G2HOME_%\javalink\kbs' '%G2HOME_%\tw2\kbs' '%G2HOME_%\g2\kbs\utils'
                 * '%G2HOME_%\g2\kbs\demos' " />
                 */

                G2Process p = new G2Process(objCompany.TCompanies[0].coId, portNo);
                p.StartInfo           = si;
                p.Exited             += new EventHandler(p_Exited);
                p.EnableRaisingEvents = true;
                //p.SynchronizingObject = this.Contain;

                LogMsg("ShellG2: Calling Start.");
                if (!p.Start())
                {
                    LogMsg("ShellG2: Process failed to start.");
                    strErrMsg = "Process failed to start.";
                    return(false);
                }

                LogMsg("ShellG2: Calling WaitForInputIdle.");
                p.WaitForInputIdle(20000);
                LogMsg("ShellG2: Adding process to list.");
                sessionList.Add(portNo, p);
                LogMsg("ShellG2: Saving list.");
                Application["m_sessionList"] = sessionList;
                LogMsg("ShellG2: Returning 'true'.");
                return(true);
            }
            catch (Exception ex)
            {
                strErrMsg = ex.Message;
                LogMsg("ShellG2: " + ex.Message);
                return(false);
            }
        }