Beispiel #1
0
        public CfgData Read()
        {
            var data = new CfgData();

            if (!File.Exists(_fileName))
            {
                return(data);
            }

            try
            {
                string?line;
                using var reader = File.OpenText(_fileName);
                while ((line = reader.ReadLine()) != null)
                {
                    data.AddRow(line);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Failed read file: {_fileName}");
            }
            return(data);
        }
Beispiel #2
0
        public async Task <CfgData> ReadAsync()
        {
            var data = new CfgData();

            if (!File.Exists(_fileName))
            {
                return(data);
            }

            try
            {
                using var reader = File.OpenText(_fileName);
                string line;
                while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
                {
                    data.AddRow(line);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Failed read file: {_fileName}");
            }
            return(data);
        }