static void Main(string[] args) { Logger.WriteToLogFile("Starting DealSheelRunner", Constants.FTPSERVER_LOGS, null); //Get all the directory from the current folder String[] dirs = Directory.GetDirectories(".", Constants.FTPSERVER_INPUT_FOLDER + "*"); if (dirs.Length == 0) { return; } foreach (string dir in dirs) { //get the timestamp from the directory name string timestamp = dir.Split('-').Last(); string outputFodler = Constants.FTPSERVER_OUTPUT_FOLDER + "-" + timestamp; try { //Checking for input file if (!System.IO.File.Exists(dir + "\\" + Constants.FTPSERVER_INPUT_FILE)) { continue; } if (System.IO.Directory.Exists(Constants.ImageFolder)) { System.IO.Directory.Delete(Constants.ImageFolder, true); } //outfolder if (Directory.Exists(outputFodler)) { Directory.Delete(outputFodler, true); } //create output and initialize logs Logger.InitializeLogs(outputFodler, Constants.FTPSERVER_TEMP_OUTPUT_FILE); Logger.WriteToLogFile("Starting DealSheelInserter ....."); CXMLNode m_xmlNode = XMLController.PopulateXMLObject(Constants.DealSheelConfigFile); if (m_xmlNode == null) { throw new Exception("Unable to parse xml file"); } Logger.WriteToLogFile("Initialize Neo4j"); Neo4jController.InitializeController(m_xmlNode.DatabaseServer.Server, Convert.ToInt32(m_xmlNode.DatabaseServer.Port)); Neo4jController.connect(); Adder objAdder = new Adder(m_xmlNode); List <string> lfiles = Utilities.GetFileList(dir + "//" + Constants.FTPSERVER_INPUT_FILE); lfiles.RemoveAt(lfiles.Count() - 1); objAdder.RunAllExcel(lfiles, dir, outputFodler); } catch (Exception ex) { Logger.WriteToLogFile(ex.Message, Constants.FTPSERVER_OUTPUT_ERROR_LOGS, outputFodler); } //work done //Rename the file to output file to let us know that the process has finished System.IO.File.Move(outputFodler + "//" + Constants.FTPSERVER_TEMP_OUTPUT_FILE, outputFodler + "//" + Constants.FTPSERVER_OUTPUT_FILE); //Remove input folder now if (System.IO.Directory.Exists(dir)) { System.IO.Directory.Delete(dir, true); } } Logger.WriteToLogFile("Finished DealSheelRunner", Constants.FTPSERVER_LOGS, null); }
static void Main(string[] args) { try { if (System.IO.File.Exists(Constants.FTPClient_Logs)) { System.IO.File.Delete(Constants.FTPClient_Logs); } //delete all input and output folder //Get all the directory from the current folder String[] Inputdirs = Directory.GetDirectories(".", Constants.FTPSERVER_INPUT_FOLDER + "*"); String[] Outputdirs = Directory.GetDirectories(".", Constants.FTPSERVER_OUTPUT_FOLDER + "*"); foreach (string dir in Inputdirs) { Directory.Delete(dir, true); } foreach (string dir in Outputdirs) { Directory.Delete(dir, true); } Logger.WriteToLogFile("Starting FTP Runner ....", Constants.FTPClient_Logs, null); m_xmlNode = XMLController.PopulateXMLObject(Constants.DealSheelConfigFile); //Get the current timestamp m_timestamp = Utilities.GetDateTimeInUnixTimeStamp().ToString(); //Delete the iput folder //Logger.WriteToLogFile("Delete the input folder", Constants.FTPClient_Logs, null); //create input folder m_InputFolder = Constants.FTPSERVER_INPUT_FOLDER + "-" + m_timestamp; System.IO.Directory.CreateDirectory(m_InputFolder); //Get ftp interactor FTPInteractor objftpInteractor = FTPInteractor.getInstance(m_xmlNode.FTPServer.Server, m_xmlNode.FTPServer.UserName, m_xmlNode.FTPServer.Password); //Copy FTP files from this machine to the ftp machine List <string> lFileList = Utilities.GetFileList(Constants.FTPSERVER_INPUT_EXCELFILES); //Copy the files to the input folder lFileList = Utilities.CopyFiles(lFileList, m_InputFolder); //add the input file to the list lFileList.Add(Constants.FTPSERVER_INPUT_FILE); objftpInteractor.WriteToInputFTPFile(lFileList, Constants.FTPSERVER_INPUT_FILE, m_InputFolder); Logger.WriteToLogFile("Uploading files on the server", Constants.FTPClient_Logs, null); objftpInteractor.UploadFilesToFTP(lFileList, m_InputFolder, m_InputFolder); //Wait till the output is not written Logger.WriteToLogFile("Checking for program completion on server machine", Constants.FTPClient_Logs, null); m_OutputFolder = Constants.FTPSERVER_OUTPUT_FOLDER + "-" + m_timestamp; while (!objftpInteractor.CheckforFTPfileExists(Constants.FTPSERVER_OUTPUT_FILE, m_OutputFolder)) { System.Threading.Thread.Sleep(60 * 1000); } System.IO.Directory.CreateDirectory(m_OutputFolder); //Download file from the server Logger.WriteToLogFile("Download files from the server", Constants.FTPClient_Logs, null); objftpInteractor.DownloadFolderFromFTPServer(m_OutputFolder); //Delete the folder from the server Logger.WriteToLogFile("Delete output folder from the server", Constants.FTPClient_Logs, null); objftpInteractor.DeleteFolderFromServer(m_OutputFolder); } catch (Exception ex) { Logger.WriteToLogFile(ex.Message, Constants.FTPClient_Logs, null); } }