Пример #1
0
        /// <summary>
        /// Main method that handles the organization of downloading and saving the registrant information file from the 3rd party
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
#if DEBUG
            Serilog.Debugging.SelfLog.Enable(Console.Error);
#endif
            var localFileLocation = ConfigurationManager.AppSettings["LocalFileLocation"];
            var fileName          = "SampleFile.txt";

            using (var logger = LoggingInitializer.GetLogger())
            {
                // Download the file from the FTP site
                var ftp          = new SftpDownload();
                var messageToUse = ftp.DownloadFileUsingSftpClient(fileName, localFileLocation)
                    ? "\nFile retrieved."
                    : "\nFile not downloaded.";
                logger.Information(messageToUse, fileName, localFileLocation);

                // Parse the file from the local file path
                List <RegistrantInformation> registrants;
                var filePath = localFileLocation + fileName;

                if (File.Exists(filePath))
                {
                    var streamReader = new StreamReader(filePath);
                    var fileParser   = new FileParser(streamReader);

                    registrants = fileParser.ParseFile();
                }
                else
                {
                    // If the file does not exist, throw an exception
                    throw new FileNotFoundException($"File {fileName} does not exist in {localFileLocation}.", fileName);
                }

                // If the parser could not get any records, don't try to save to the database
                if (registrants.Any())
                {
                    // Write the records to the database
                    var writer = new WriteToDatabase();
                    writer.WriteDownloadRecords(registrants);
                }

#if DEBUG
                Console.WriteLine("\nPress any key to Continue...");
                Console.ReadKey();
#endif
            }
        }
Пример #2
0
 /// <summary>
 /// Constructor for the  SftpDownload
 /// </summary>
 public SftpDownload()
 {
     _logger = LoggingInitializer.GetLogger();
 }
 /// <summary>
 /// Constructor for the WriteToDatabase class
 /// </summary>
 public WriteToDatabase()
 {
     _logger   = LoggingInitializer.GetLogger();
     _database = new DCCKellyDatabase();
 }
 /// <summary>
 /// Constructor for the File Parser
 /// </summary>
 /// <param name="fileReader"><see cref="TextReader"/> of the file to parse</param>
 public FileParser(TextReader fileReader)
 {
     _logger     = LoggingInitializer.GetLogger();
     _fileReader = fileReader;
 }