コード例 #1
0
        //
        // The Run method is the entry point of a background task.
        //
        public async void Run(IBackgroundTaskInstance taskInstance)
        {

            //
            // Associate a cancellation handler with the background task.
            //
            taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);

            //
            // Get the deferral object from the task instance, and take a reference to the taskInstance;
            //
            _deferral = taskInstance.GetDeferral();

            TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true);
            // delete all previous notifications
            var notifier = Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication();
            var scheduled = notifier.GetScheduledTileNotifications();

            for (int i = 0, len = scheduled.Count; i < len; i++) 
            {
                    notifier.RemoveFromSchedule(scheduled[i]);
            }

            CalendarDataReader reader = new CalendarDataReader();
            String cityToken = Windows.Storage.ApplicationData.Current.LocalSettings.Values["CityName"] as String;
            DateTime today = DateTime.Today;
            await reader.ReadCalendarYearData(cityToken, today.Year);
            TileUpdateManager.CreateTileUpdaterForApplication().Clear();
            for (int i = 0; i < 31; i++)
            {
                if (i == 0)
                {
                    // to get an immediate update add a tile 3 minutes from now
                    UpdateTile(reader, DateTime.Now.AddMinutes(3));
                }
                else
                {
                    UpdateTile(reader, today.AddDays(i));
                }
            }
            _taskInstance = taskInstance;
            _deferral.Complete();
        }
コード例 #2
0
 // Find and load the calendar data into memory.
 public async Task GetCalendarYearData()
 {
     try
     {
         _calendarYearData.Clear();
         CalendarDataReader calendarReader;
         calendarReader = new CalendarDataReader();
         await calendarReader.ReadCalendarYearData(_cityToken, _startYear);
         _calendarYearData.Add(_startYear, calendarReader.CalendarYearData);
         await calendarReader.ReadCalendarYearData(_cityToken, _startYear + 1);
         _calendarYearData.Add(_startYear + 1, calendarReader.CalendarYearData);
         _group.PanchangDataForYear = _calendarYearData;
         _group.city = GetCityInformation(_cityToken);
     }
     catch (Exception e)
     {
         Debug.WriteLine("GetCalenderYearData: " + e.Message);
     }
 }