public string StartG2(string strUserName, string strPassword, int portNo) { LogMsg("StartG2: StartG2 called."); DSResponse response = new DSResponse(); string strErrMsg = ""; BSLUser objUser = GetUser(strUserName, strPassword, ref strErrMsg); if (objUser == null) { response.G2MgrResponse.AddG2MgrResponseRow("", strErrMsg, 1); return(response.GetXml()); } LogMsg("StartG2: Successfully retrieved user."); BSLCompany objCompany = objUser.GetCompany(); LogMsg("StartG2: Successfully retrieved user's company."); LogMsg("StartG2: About to call ShellG2."); if (!ShellG2(portNo, objCompany, ref strErrMsg)) { LogMsg("StartG2: " + strErrMsg + " occured in ShellG2."); response.G2MgrResponse.AddG2MgrResponseRow("", strErrMsg, 1); return(response.GetXml()); } LogMsg("StartG2: Successfully Shelled G2."); response.G2MgrResponse.AddG2MgrResponseRow("Started", "", 0); return(response.GetXml()); // XmlDocument xDoc = new XmlDocument(); // xDoc.LoadXml(response.GetXml()); // NameTable nt = new NameTable(); // XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); // nsmgr.AddNamespace("dsresponse", "http://tempuri.org/DSResponse.xsd"); // XmlNode nodeErrCode = xDoc.DocumentElement.SelectSingleNode("//dsresponse:errorCode", nsmgr); // if (nodeErrCode.InnerText.Equals("0")) // { // try // { // XmlNode nodeResults = xDoc.DocumentElement.SelectSingleNode("//dsresponse:results", nsmgr); // if (nodeResults != null) // { // string s = nodeResults.InnerText; // DSUser ds2 = new DSUser(); // System.Xml.XmlDataDocument xDataDoc = new XmlDataDocument(ds2); // xDataDoc.LoadXml(s); // if (ds2.TUsers.Count > 0) // s = ds2.TUsers[0].firstName; // } // } // catch(Exception ex) // { // } // } }
private void BindInputFileData(string strSortField) { try { if (m_objUser == null) { throw new Exception("Your session has expired."); } BSLCompany objCompany = m_objUser.GetCompany(); string strDataDirName = objCompany.TCompanies[0].rootDirName; string strInputDir = (string)Cache["G2_DATA_PATH"]; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + strDataDirName; string strOutputDir = strInputDir; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + "Input"; strOutputDir += (!strOutputDir.EndsWith("\\") ? "\\" : "") + "Output"; DirectoryInfo myDirInfo; FileInfo[] arrFileInfo; DataRow myDataRow; DataView myDataView; //Populate Input Grid DataTable tblInputFiles = new DataTable(); tblInputFiles.Columns.Add("fileName", Type.GetType("System.String")); tblInputFiles.Columns.Add("fileSize", Type.GetType("System.Int32")); tblInputFiles.Columns.Add("modifyDate", Type.GetType("System.DateTime")); tblInputFiles.Columns.Add("fileExt", Type.GetType("System.String")); myDirInfo = new DirectoryInfo(strInputDir); // You can easily filter results by name... I just want a list // of all the files, but you could filter here if you wanted. //arrFileInfo = myDirInfo.GetFiles("s*.*") arrFileInfo = myDirInfo.GetFiles(); // Loop through array of FileInfo objects placing the data we'll // be using into our DataTable for easy manipulation. for (int i = 0; i < arrFileInfo.Length; i++) { FileInfo myFileInfo = arrFileInfo[i]; myDataRow = tblInputFiles.NewRow(); myDataRow["fileName"] = myFileInfo.Name; myDataRow["fileSize"] = myFileInfo.Length; myDataRow["modifyDate"] = myFileInfo.LastWriteTime; myDataRow["fileExt"] = myFileInfo.Extension; tblInputFiles.Rows.Add(myDataRow); } // Create a new DataView and sort it. myDataView = tblInputFiles.DefaultView; myDataView.Sort = strSortField; dataGridInput.DataSource = myDataView; dataGridInput.DataBind(); } catch (System.Exception ex) { lblMsg.Visible = true; lblMsg.Text = ex.Message; } }
private void OnUpload(object sender, System.EventArgs e) { try { if (m_objUser == null) { throw new Exception("Your session has expired."); } System.Web.HttpFileCollection uploadedFiles = Request.Files; BSLCompany objCompany = m_objUser.GetCompany(); string strDataDirName = objCompany.TCompanies[0].rootDirName; string strInputDir = (string)Cache["G2_DATA_PATH"]; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + strDataDirName; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + "Input"; for (int i = 0; i < uploadedFiles.Count; i++) { System.Web.HttpPostedFile postedFile = uploadedFiles[i]; string strFileName = System.IO.Path.GetFileName(postedFile.FileName); postedFile.SaveAs(strInputDir + "\\" + strFileName); } string strScript = "<script for='window' event='onload' language='javascript'>alert('File(s) uploaded successfully.');</script>"; RegisterStartupScript("SuccessMsg", strScript); } catch (Exception ex) { lblMsg.Visible = true; lblMsg.Text = ex.Message; } }
public string StartG2(string strUserName, string strPassword, int portNo, int companyId) { DSResponse response = new DSResponse(); //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 strConnStr = (string)Context.Cache["CONN_STR"]; string strErrMsg = ""; BSLUser objUser = GetUser(strUserName, strPassword, ref strErrMsg); if (objUser == null) { response.G2MgrResponse.AddG2MgrResponseRow("", strErrMsg, 1); return(response.GetXml()); } if (!objUser.IsGensymAdmin) { response.G2MgrResponse.AddG2MgrResponseRow("", "Method reserved for internal use.", 1); return(response.GetXml()); } BSLCompany objCompany = new BSLCompany(strConnStr); try { objCompany.Fill(companyId); } catch (Exception ex) { response.G2MgrResponse.AddG2MgrResponseRow("", ex.Message, 1); LogMsg("StartG2: " + ex.Message); return(response.GetXml()); } try { if (!ShellG2(portNo, objCompany, ref strErrMsg)) { response.G2MgrResponse.AddG2MgrResponseRow("", strErrMsg, 1); return(response.GetXml()); } } catch (Exception ex) { response.G2MgrResponse.AddG2MgrResponseRow("", ex.Message, 1); LogMsg("Start G2: " + ex.Message); return(response.GetXml()); } response.G2MgrResponse.AddG2MgrResponseRow("Started", "", 0); return(response.GetXml()); }
private void BindOutputFileData(string strSortField) { try { if (m_objUser == null) { throw new Exception("Your session has expired."); } BSLCompany objCompany = m_objUser.GetCompany(); string strDataDirName = objCompany.TCompanies[0].rootDirName; string strInputDir = (string)Cache["G2_DATA_PATH"]; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + strDataDirName; string strOutputDir = strInputDir; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + "Input"; strOutputDir += (!strOutputDir.EndsWith("\\") ? "\\" : "") + "Output"; DirectoryInfo myDirInfo; FileInfo[] arrFileInfo; DataRow myDataRow; DataView myDataView; //Populate Ouptut Grid DataTable tblOutputFiles = new DataTable(); tblOutputFiles.Columns.Add("fileName", Type.GetType("System.String")); tblOutputFiles.Columns.Add("fileSize", Type.GetType("System.Int32")); tblOutputFiles.Columns.Add("modifyDate", Type.GetType("System.DateTime")); tblOutputFiles.Columns.Add("fileExt", Type.GetType("System.String")); myDirInfo = new DirectoryInfo(strOutputDir); arrFileInfo = myDirInfo.GetFiles(); for (int i = 0; i < arrFileInfo.Length; i++) { FileInfo myFileInfo = arrFileInfo[i]; myDataRow = tblOutputFiles.NewRow(); myDataRow["fileName"] = myFileInfo.Name; myDataRow["fileSize"] = myFileInfo.Length; myDataRow["modifyDate"] = myFileInfo.LastWriteTime; myDataRow["fileExt"] = myFileInfo.Extension; tblOutputFiles.Rows.Add(myDataRow); } // Create a new DataView and sort it based on the field passed in. myDataView = tblOutputFiles.DefaultView; myDataView.Sort = strSortField; dataGridOutput.DataSource = myDataView; dataGridOutput.DataBind(); } catch (System.Exception ex) { lblMsg.Visible = true; lblMsg.Text = ex.Message; } }
private void OnOutputItemCmd(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { try { if (m_objUser == null) { throw new Exception("Your session has expired."); } BSLCompany objCompany = m_objUser.GetCompany(); string strDataDirName = objCompany.TCompanies[0].rootDirName; string strInputDir = (string)Cache["G2_DATA_PATH"]; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + strDataDirName; string strOutputDir = strInputDir; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + "Input"; strOutputDir += (!strOutputDir.EndsWith("\\") ? "\\" : "") + "Output"; // added by pcp 8/15/05 to ensure the command is not executed when sorting the table for example if (!e.CommandName.ToLower().Equals("delete")) { return; } string strFileName = (string)e.CommandArgument; System.IO.File.Delete(strOutputDir + "\\" + strFileName); if (!System.IO.File.Exists(strOutputDir + "\\" + strFileName)) { // pcp modified this 8/15/05 to include the filename that was deleted string strScript = "<script for='window' event='onload' language='javascript'>alert('File " + strFileName + " deleted successfully.');</script>"; RegisterStartupScript("SuccessMsg", strScript); } else { throw new Exception("File was not deleted."); } BindOutputFileData("fileName"); } catch (Exception ex) { lblMsg.Visible = true; lblMsg.Text = "Error '" + ex.Message + "' occurred."; } }
private void Page_Load(object sender, System.EventArgs e) { BSLUser objUser = (BSLUser)Session["objUser"]; if ((objUser == null) || (objUser.TUsers[0].inactive)) { return; } string strDir = Request["d"]; if ((strDir == null) || (strDir.Length == 0)) { return; } string strFilename = Request["f"]; if ((strFilename == null) || (strFilename.Length == 0)) { return; } BSLCompany objCompany = objUser.GetCompany(); string strDataDirName = objCompany.TCompanies[0].rootDirName; string strInputDir = (string)Cache["G2_DATA_PATH"]; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + strDataDirName; string strOutputDir = strInputDir; strInputDir += (!strInputDir.EndsWith("\\") ? "\\" : "") + "Input"; strOutputDir += (!strOutputDir.EndsWith("\\") ? "\\" : "") + "Output"; string strSourceDir = ""; if (strDir.ToLower().Equals("i")) { strSourceDir = strInputDir; } else if (strDir.ToLower().Equals("o")) { strSourceDir = strOutputDir; } else { return; } Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=" + strFilename); Response.ContentType = "application/download"; //"application/octet-stream" string filename = strSourceDir + "\\" + strFilename; System.IO.FileStream downloadFile = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); byte[] byteArray = new byte[(int)downloadFile.Length]; downloadFile.Read(byteArray, 0, (int)downloadFile.Length); downloadFile.Close(); Response.BinaryWrite(byteArray); Response.Flush(); Response.End(); }
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); } }