コード例 #1
0
        private async Task AddNewLocation(AddLocationMessage locationMessage)
        {
            if (Locations.Contains(new WeatherSummaryViewModel(locationMessage.Id)))
            {
                return;
            }

            LocationAnalytics.AddedALocation();
            var orderedSummary = new WeatherSummaryViewModel(locationMessage.Id, locationMessage.Name, Locations.Count);

            Locations.Add(orderedSummary);
            var summary = await openWeatherClient.GetWeatherSummariesFor(locationMessage.Id);

            if (summary.Any())
            {
                orderedSummary.UpdateWeather(summary.Single());
            }

            await localStorage.Save(Locations);
        }
コード例 #2
0
        public async Task <IEnumerable <WeatherSummary> > GetWeatherSummariesFor(params long[] locationIds)
        {
            try
            {
                LocationAnalytics.HasNLocations(locationIds.Length);
                var graphQLRequest = new GraphQLRequest
                {
                    Query         = "query WeatherSummaries($location_ids: [Long]!) { summaries(location_ids: $location_ids)  { location temperature openWeatherIcon id date timezone } }",
                    OperationName = "WeatherSummaries",
                    Variables     = new { location_ids = locationIds.ToArray() }
                };

                var response = await AttemptAndRetry(() => graphQLHttpClient.SendQueryAsync(graphQLRequest)).ConfigureAwait(false);

                var forecasts = response.GetDataFieldAs <IEnumerable <WeatherSummary> >("summaries");
                return(forecasts);
            }
            catch (Exception exception)
            {
                Crashes.TrackError(exception);
                return(new WeatherSummary[0]);
            }
        }