public static bool TryParse(string text, out WeatherObservation wo)
        {
            wo = new WeatherObservation()
            {
                Barometric_Pressure = float.NaN, TimeStamp = DateTime.MinValue
            };

            var data = text.Split('\t');

            if (data.Length != 8)
            {
                return(false);
            }

            if (!DateTime.TryParse(ReplaceUnderScoreToDash(data[(int)WeatherObservationMetrics.Date_Time]), out DateTime dateTime))
            {
                return(false);
            }

            if (!float.TryParse(ReplaceUnderScoreToDash(data[(int)WeatherObservationMetrics.Barometric_Pressure]), out float pressure))
            {
                return(false);
            }

            wo = new WeatherObservation()
            {
                Barometric_Pressure = pressure, TimeStamp = dateTime
            };
            return(true);
        }
Exemple #2
0
        public static bool TryParse(string text, out WeatherObservation wo)
        {
            wo = new WeatherObservation()
            {
                TimeStamp           = DateTime.MinValue,
                Barometric_Pressure = float.NaN
            };

            var data = text.Split('\t');

            if (data.Length != 8)
            {
                return(false);
            }

            if (!DateTime.TryParse(data[(int)WeatherObservationMetrics.Date_Time].Replace("_", "-"), out DateTime timestamp))
            {
                return(false);
            }

            if (!float.TryParse(data[(int)WeatherObservationMetrics.Barometric_Pressure], out float pressure))
            {
                return(false);
            }

            wo = new WeatherObservation()
            {
                TimeStamp             = timestamp
                , Barometric_Pressure = pressure
            };
            return(true);
        }
Exemple #3
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);
        }
Exemple #4
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 { }
                }
            }
        }
Exemple #5
0
        public static bool TryParse(string text, out WeatherObservation wo)
        {
            // changee format to en-US : for the dateTime and the float delimiter

            wo = new WeatherObservation()
            {
                TimeStamp           = DateTime.MinValue,
                Barometric_Pressure = float.NaN
            };

            // changee format to en-US : for the dateTime and the float delimiter
            IFormatProvider culture = new CultureInfo("en-US");

            var data = text.Split('\t');

            if (data.Length != 8)
            {
                return(false);
            }

            if (!DateTime.TryParse(data[(int)WeatherObservationMetrics.Date_Time].Replace("_", "-"), culture, DateTimeStyles.AssumeLocal, out DateTime timestamp))
            {
                return(false);
            }

            if (!float.TryParse(data[(int)WeatherObservationMetrics.Barometric_Pressure], NumberStyles.Float, culture, out float pressure))
            {
                return(false);
            }

            wo = new WeatherObservation()
            {
                TimeStamp           = timestamp,
                Barometric_Pressure = pressure
            };
            return(true);
        }
        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
                    }
                }
            }
        }
Exemple #7
0
 public static bool TryParse(string text, out WeatherObservation wo)
 {
     throw new NotImplementedException();
 }