Beispiel #1
0
        public static IEnumerable <WeatherObservation> ReadAllWithoutYeild(TextReader text, Action <string> errorHandler = null)
        {
            string line = null;
            var    list = new List <WeatherObservation>();

            while ((line = text.ReadLine()) != null)
            {
                if (WeatherObservation.TryParse(line, out WeatherObservation wo))
                {
                    list.Add(wo);
                }
                else
                {
                    try
                    {
                        errorHandler?.Invoke(line);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
            return(list);
        }
Beispiel #2
0
        public static IEnumerable <WeatherObservation> ReadAll(TextReader text, Action <string> errorHandler = null)
        {
            string line = null;

            while ((line = text.ReadLine()) != null)
            {
                if (WeatherObservation.TryParse(line, out WeatherObservation wo))
                {
                    yield return(wo);
                }
                else
                {
                    try
                    {
                        errorHandler?.Invoke(line);
                    } catch { }
                }
            }
        }
        public static IEnumerable <WeatherObservation> ReadAll(TextReader text, Action <string> errorHandler)
        {
            // Using the yield return keyword allows us to return the data as it becomes available and not wait for the whole file to be processed
            string line = null;

            while ((line = text.ReadLine()) != null)
            {
                if (WeatherObservation.TryParse(line, out WeatherObservation wo))
                {
                    yield return(wo);
                }
                else
                {
                    try
                    {
                        errorHandler?.Invoke(line);
                    }
                    catch
                    {
                        //We'll leave this empty, but you can add handling here
                    }
                }
            }
        }