public SearchCityPage() { InitializeComponent(); weatherBug = new WeatherBug(); weatherBug.FindLocationCompleted += weatherBug_FindLocationCompleted; weatherBug.RequestFailed += weatherBug_RequestFailed; }
private void MainPageWeather() { //앱바 생성 CreateWeatherAppBar(); weatherBug = new WeatherBug(); weatherBug.DefaultUnitType = (DisplayUnit)SettingHelper.Get(Constants.WEATHER_UNIT_TYPE); weatherBug.RequestFailed += weatherBug_RequestFailed; weatherBug.LiveWeatherBeforeLoad += weatherBug_LiveWeatherBeforeLoad; weatherBug.LiveWeatherCompletedLoad += weatherBug_LiveWeatherCompleted; }
/// <summary> /// 예약된 작업을 실행하는 에이전트입니다. /// </summary> /// <param name="task"> /// 호출한 작업입니다. /// </param> /// <remarks> /// 이 메서드는 정기적 작업 또는 리소스를 많이 사용하는 작업이 호출될 때 호출됩니다. /// </remarks> protected override void OnInvoke(ScheduledTask task) { bool isLiveTileTurn = true; scheduleSettings = MutexedIsoStorageFile.Read <ScheduleSettings>("ScheduleSettings", Constants.MUTEX_DATA); //스케쥴러는 30분마다 들어온다. //이번이 누구 차례인가를 생성해야 한다. //라이브타일과 락스크린은 각각의 인터벌이 있고, 그 인터벌은 어느 순간 중복될 수 있다. //중복되면 라이브타일에 우선권을 부여하여 실행하며, 락스크린은 그 이후 스케줄로 밀린다. //판별에 사용될 변수는 1.인터벌, 2.실행대상, 3.실행대상의 최종 실행시간 #if !DEBUG_AGENT { DateTime LastRunForLivetile, LastRunForLockscreen; IsolatedStorageSettings.ApplicationSettings.TryGetValue <DateTime>(Constants.LAST_RUN_LIVETILE, out LastRunForLivetile); IsolatedStorageSettings.ApplicationSettings.TryGetValue <DateTime>(Constants.LAST_RUN_LOCKSCREEN, out LastRunForLockscreen); bool useLockscreenRotator; IsolatedStorageSettings.ApplicationSettings.TryGetValue <bool>(Constants.LOCKSCREEN_USE_ROTATOR, out useLockscreenRotator); double lockscreenTerm = DateTime.Now.Subtract(LastRunForLockscreen).TotalMinutes - scheduleSettings.LockscreenUpdateInterval; //한번도 락스크린 스케쥴러를 실행한적이 없고 락스크린이 스케쥴에서 사용되지 않는 경우는 -1로 설정하여 락스크린으로 분기되지 않도록 처리 if (LastRunForLockscreen.Year == 1 && LastRunForLockscreen.Month == 1 && LastRunForLockscreen.Day == 1 && !useLockscreenRotator) { lockscreenTerm = -1; } if (DateTime.Now.Subtract(LastRunForLivetile).TotalMinutes < scheduleSettings.LivetileUpdateInterval && lockscreenTerm < 0) { System.Diagnostics.Debug.WriteLine("Too soon, stopping."); NotifyComplete(); return; } else if (lockscreenTerm >= 0) { isLiveTileTurn = false; } } #else isLiveTileTurn = false; #endif if (isLiveTileTurn) { Deployment.Current.Dispatcher.BeginInvoke(() => { System.Diagnostics.Debug.WriteLine("1 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage); LivetileData data = new LivetileData() { DayList = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true), }; try { System.Diagnostics.Debug.WriteLine("타일 전 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage); bool hasWeather = ShellTile.ActiveTiles.Any(x => x.NavigationUri.ToString().Contains("weather")); bool hasCalendar = ShellTile.ActiveTiles.Any(x => x.NavigationUri.ToString().Contains("calendar")); if (hasWeather) { //1. 날씨 타일이 핀되어 있다. WeatherCity city = SettingHelper.Get(Constants.WEATHER_MAIN_CITY) as WeatherCity; DisplayUnit unit = (DisplayUnit)SettingHelper.Get(Constants.WEATHER_UNIT_TYPE); WeatherBug weather = new WeatherBug(); weather.LiveWeatherCompletedLoad += (s, r, f) => { //조회된 데이터를 셋팅(없으면 저장된 날씨를 사용함) SetWeatherResult(data, r, f); //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); }; weather.RequestFailed += (s, r) => { //데이터를 얻는데 실패 한 경우 네트워크가 연결되지 않았다면, 이전 저장된 데이터를 사용 if (!DeviceNetworkInformation.IsNetworkAvailable) { data.LiveWeather = (LiveWeather)SettingHelper.Get(Constants.WEATHER_LIVE_RESULT); data.Forecasts = (Forecasts)SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT); } //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); }; if (city != null) { weather.LiveWeather(city, unit); } else { //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); } } else { //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }); } else { if (!LockScreenManager.IsProvidedByCurrentApplication) { System.Diagnostics.Debug.WriteLine("잠금화면 제공앱이 아니므로 변경할수 없음."); NotifyComplete(); return; } if (!IsolatedStorageSettings.ApplicationSettings.Contains(Constants.LOCKSCREEN_USE_ROTATOR) || !(bool)IsolatedStorageSettings.ApplicationSettings[Constants.LOCKSCREEN_USE_ROTATOR]) { System.Diagnostics.Debug.WriteLine("로테이터 사용안함."); NotifyComplete(); return; } Deployment.Current.Dispatcher.BeginInvoke(() => { System.Diagnostics.Debug.WriteLine("1 =>" + Microsoft.Phone.Info.DeviceStatus.ApplicationCurrentMemoryUsage); LockscreenData data = new LockscreenData(true) { DayList = VsCalendar.GetCalendarOfMonth(DateTime.Now, DateTime.Now, true, true), }; bool hasWeather = false; bool hasCalendar = false; LockscreenItemInfo[] items = data.Items; for (int i = 0; i < items.Length; i++) { switch (items[i].LockscreenItem) { case LiveItems.Weather: case LiveItems.NoForecast: hasWeather = true; break; case LiveItems.Calendar: hasCalendar = true; break; } } if (hasWeather) { WeatherBug weather = new WeatherBug(); WeatherCity city = SettingHelper.Get(Constants.WEATHER_MAIN_CITY) as WeatherCity; DisplayUnit unit = (DisplayUnit)SettingHelper.Get(Constants.WEATHER_UNIT_TYPE); weather.LiveWeatherCompletedLoad += (s, r, f) => { //조회된 데이터를 셋팅(없으면 저장된 날씨를 사용함) SetWeatherResult(data, r, f); //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); }; weather.RequestFailed += (s, r) => { if (!DeviceNetworkInformation.IsNetworkAvailable) { data.LiveWeather = (LiveWeather)SettingHelper.Get(Constants.WEATHER_LIVE_RESULT); data.Forecasts = (Forecasts)SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT); } //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); }; if (city != null) { weather.LiveWeather(city, unit); } else { //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); } } else { //달력 적용 또는 직접 렌더링 DelegateUpdateProcess(task, data, hasCalendar); } }); } }