Esempio n. 1
0
        private void OnRefresh()
        {
            try
            {
                var jobMethod = string.Format(JobUrlFormat, Id);
                var job       = _restClient.MakeRequest <Job>(BaseUrl, jobMethod, null, null);

                LastChecked         = DateTime.Now;
                CurrentBuild        = job.LastBuild.ToString();
                LastSuccessfulBuild = job.LastSuccessfulBuild == null ? string.Empty : job.LastSuccessfulBuild.ToString();
                LastCompletedBuild  = job.LastCompletedBuild.Number.ToString();

                if (job.LastSuccessfulBuild == null)
                {
                    if (job.LastCompletedBuild != null)
                    {
                        Pass = false;
                    }
                    else
                    {
                        Pass = null;
                    }
                }
                else
                {
                    Pass = job.LastCompletedBuild.Number == job.LastSuccessfulBuild.Number || WasLastActualBuildSuccess(job);
                }

                InProgress = job.LastBuild.Number != job.LastCompletedBuild.Number;

                var detailsMethod = string.Format(DetailsUrlFormat, Id, CurrentBuild);
                var details       = _restClient.MakeRequest <BuildDetails>(BaseUrl, detailsMethod, null, null);

                var durationTicks = (InProgress ? details.EstimatedDuration : details.Duration) * 10000;
                Duration  = new TimeSpan(durationTicks);
                TimeBuilt = TimeHelpers.TimeFromEpochTimestamp(details.Timestamp);
            }
            catch (Exception ex)
            {
                Log.TraceErr("JenkinsBuildJobViewModel.OnRefresh: Error retrieving results for '{0}'. {1}", Id, ex.ToString());
                LastChecked = null;
                Pass        = null;
            }
        }
Esempio n. 2
0
        private void OnRefresh()
        {
            if (!Initialized)
            {
                Initialize();
            }

            var restArgs = new Dictionary <string, string>
            {
                { "daily", "location" },
                { "q", _location },
                { "mode", "json" },
                { "cnt", "10" },
                { "units", Units == Units.Metric ? "metric" : "imperial" },
                { "appid", WebHelpers.OpenWeatherMapApiKey }
            };

            var response = _restClient.MakeRequest <WeatherResponse>(Url, "daily", null, restArgs);

            Title = response.City.Name;

            Dispatcher.Invoke(() =>
            {
                BackgroundImagePath = null;

                var newDailyWeathers = new Collection <DailyWeather>();

                for (var i = 0; i < response.List.Length; i++)
                {
                    var list = response.List[i];

                    var dailyWeather = new DailyWeather
                    {
                        Date    = TimeHelpers.TimeFromEpochTimestamp(list.Dt * 1000),
                        MaxTemp = (int)Math.Ceiling(list.Temp.Max),
                        MinTemp = (int)Math.Floor(list.Temp.Min)
                    };

                    var weather = list.Weather.FirstOrDefault();
                    if (weather != null)
                    {
                        dailyWeather.Icon             = weather.Icon;
                        dailyWeather.ShortDescription = weather.Main;
                        dailyWeather.LongDescription  = weather.Description;
                        dailyWeather.IconPath         = Path.Combine(_directory, weather.Day
                            ? WeatherIconHelper.GetDayFileName(weather.Icon)
                            : WeatherIconHelper.GetNightFileName(weather.Icon));

                        if (newDailyWeathers.Count == 0)
                        {
                            switch (weather.Icon)
                            {
                            case WeatherIcon.Clear:
                                BackgroundImagePath = @"..\..\Images\weather_clear.jpg";
                                break;

                            case WeatherIcon.FewClouds:
                                BackgroundImagePath = @"..\..\Images\weather_clouds.jpg";
                                break;

                            case WeatherIcon.ScatteredClouds:
                            case WeatherIcon.BrokenClouds:
                                BackgroundImagePath = @"..\..\Images\weather_overcast.jpg";
                                break;

                            case WeatherIcon.Showers:
                            case WeatherIcon.Rain:
                                BackgroundImagePath = @"..\..\Images\weather_rain.jpg";
                                break;

                            case WeatherIcon.Thunder:
                                BackgroundImagePath = @"..\..\Images\weather_thunder.jpg";
                                break;

                            case WeatherIcon.Snow:
                                BackgroundImagePath = @"..\..\Images\weather_snow.jpg";
                                break;

                            case WeatherIcon.Mist:
                                BackgroundImagePath = @"..\..\Images\weather_fog.jpg";
                                break;

                            default:
                                BackgroundImagePath = null;
                                break;
                            }
                        }
                    }

                    newDailyWeathers.Add(dailyWeather);
                }

                DailyWeathers.Clear();
                DailyWeathers.AddRange(newDailyWeathers);
            });
        }