private void ExtractAvalancheProblem(string problemName, StringBuilder sbHeader, StringBuilder sbBody)
        {
            var problem = AvalancheProblems.Where(p => p.ProblemName == problemName);

            if (problem.Count() == 1)
            {
                sbHeader.Append(problem.First().Header());
                sbBody.Append(problem.First().ToString());
            }
            else
            {
                var p = new AvalancheProblem()
                {
                    ProblemName = problemName,
                    Likelihood  = "no-data",
                    MaximumSize = "no-data",
                    MinimumSize = "no-data"
                };
                sbHeader.Append(p.Header());
                sbBody.Append(p.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses json response
        /// </summary>
        /// <param name="resultToParse">json repsonse from api</param>
        /// <returns>list of parsed responses one item in list per regional forecast</returns>
        private static List <AvalancheRegionForecast> ParseResponse(string resultToParse)
        {
            var parsedForecasts = new List <AvalancheRegionForecast>();
            //for each forecast
            dynamic file = JObject.Parse(resultToParse);

            if (file.objects.Count == 0)
            {
                return(null);
            }
            dynamic avyRegionForecasts = file.objects[0].avalanche_region_forecast;

            foreach (dynamic forecast in avyRegionForecasts)
            {
                foreach (dynamic zone in forecast.zones)
                {
                    var parsedForecast = new AvalancheRegionForecast
                    {
                        Zone                      = zone.name,
                        PublishDate               = forecast.publish_date,
                        ResourceUri               = forecast.resource_uri,
                        SpecialStatement          = forecast.special_statement,
                        Day1Date                  = forecast.day1_date,
                        BottomLineSummary         = forecast.bottom_line_summary,
                        Day1DangerElevationHigh   = forecast.day1_danger_elev_high,
                        Day1DangerElevationMiddle = forecast.day1_danger_elev_middle,
                        Day1DangerElevationLow    = forecast.day1_danger_elev_low,
                        Day1DetailedForecast      = forecast.day1_detailed_forecast,
                        Day1Trend                 = forecast.day1_trend,
                        Day1Warning               = forecast.day1_warning,
                        Day1WarningText           = forecast.day1_warning_text,
                        Day1WarningEnd            = forecast.day1_warning_end,
                        Day2DangerElevationHigh   = forecast.day2_danger_elev_high,
                        Day2DangerElevationMiddle = forecast.day2_danger_elev_middle,
                        Day2DangerElevationLow    = forecast.day2_danger_elev_low,
                        Day2DetailedForecast      = forecast.day2_detailed_forecast,
                        Day2Trend                 = forecast.day2_trend,
                        Day2Warning               = forecast.day2_warning,
                        Day2WarningText           = forecast.day2_warning_text,
                        Day2WarningEnd            = forecast.day2_warning_end,
                        AvalancheProblems         = new List <AvalancheProblem>()
                    };
                    foreach (dynamic problem in forecast.problems)
                    {
                        var parsedProblem = new AvalancheProblem
                        {
                            ProblemName = problem.problem_type.name,
                            Likelihood  = problem.likelihood,
                            MaximumSize = problem.maximum_size,
                            MinimumSize = problem.minimum_size,
                            OctagonAboveTreelineEast      = problem.octagon_high_east,
                            OctagonAboveTreelineNorth     = problem.octagon_high_north,
                            OctagonAboveTreelineNorthEast = problem.octagon_high_northeast,
                            OctagonAboveTreelineNorthWest = problem.octagon_high_northwest,
                            OctagonAboveTreelineSouth     = problem.octagon_high_south,
                            OctagonAboveTreelineSouthEast = problem.octagon_high_southeast,
                            OctagonAboveTreelineSouthWest = problem.octagon_high_southwest,
                            OctagonAboveTreelineWest      = problem.octagon_high_west,

                            OctagonBelowTreelineEast      = problem.octagon_low_east,
                            OctagonBelowTreelineNorth     = problem.octagon_low_north,
                            OctagonBelowTreelineNorthEast = problem.octagon_low_northeast,
                            OctagonBelowTreelineNorthWest = problem.octagon_low_northwest,
                            OctagonBelowTreelineSouth     = problem.octagon_low_south,
                            OctagonBelowTreelineSouthEast = problem.octagon_low_southeast,
                            OctagonBelowTreelineSouthWest = problem.octagon_low_southwest,
                            OctagonBelowTreelineWest      = problem.octagon_low_west,

                            OctagonNearTreelineEast      = problem.octagon_mid_east,
                            OctagonNearTreelineNorth     = problem.octagon_mid_north,
                            OctagonNearTreelineNorthEast = problem.octagon_mid_northeast,
                            OctagonNearTreelineNorthWest = problem.octagon_mid_northwest,
                            OctagonNearTreelineSouth     = problem.octagon_mid_south,
                            OctagonNearTreelineSouthEast = problem.octagon_mid_southeast,
                            OctagonNearTreelineSouthWest = problem.octagon_mid_southwest,
                            OctagonNearTreelineWest      = problem.octagon_mid_west
                        };
                        parsedForecast.AvalancheProblems.Add(parsedProblem);
                    }
                    parsedForecasts.Add(parsedForecast);
                }
            }
            return(parsedForecasts);
        }