示例#1
0
        public async Task WriteZipsToCSVFileAsync(string path, IEnumerable <ZipFile> records)
        {
            try
            {
                if (String.IsNullOrWhiteSpace(path) || String.IsNullOrEmpty(path))
                {
                    throw new ArgumentException("Path is empty");
                }
            }

            catch (ArgumentException ex)
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry($@"Cannot find path: {path} . The Path could not be found. /n Stack trace {ex}", EventLogEntryType.FailureAudit, 101, 1);
                }
            }

            try
            {
                if (!path.ToLower().EndsWith(".csv"))
                {
                    throw new ArgumentException("Path is not a CSV");
                }
            }

            catch (ArgumentException ex)
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry($@"File is not a CSV. /n Stack trace {ex}", EventLogEntryType.FailureAudit, 101, 1);
                }
                throw ex;
            }

            if (!ioManager.FileExists(path))
            {
                ioManager.CreateFile(path);
            }
            try
            {
                if (records == null)
                {
                    throw new ArgumentNullException("Records was null");
                }
                if (!(records.Count() >= 1))
                {
                    throw new ArgumentException("No records");
                }
            }
            catch (ArgumentNullException ex)
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry($@"No records found. Records was null. /n Stack trace {ex}", EventLogEntryType.FailureAudit, 101, 1);
                }
                throw;
            }
            catch (ArgumentException ex)
            {
                using (EventLog eventLog = new EventLog("Application"))
                {
                    eventLog.Source = "Application";
                    eventLog.WriteEntry($@"No records found. /n Stack trace {ex}", EventLogEntryType.FailureAudit, 101, 1);
                }
                throw;
            }

            await csvRepository.WriteZipsToCSVFileAsync(path, records);
        }