Exemplo n.º 1
0
 private void InitialTileSetup()
 {
     if (App.ViewModel != null && App.ViewModel.Item != null)
     {
         LiveTile.UpdateLiveTile("Trivia Buff", App.ViewModel.Item.Title);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            try
            {
                var model = new MainViewModel();
                model.OnLoaded += () =>
                {
                    if (model.Item == null)
                    {
                        return;
                    }
                    if (model.Items == null || model.Items.Count < 3)
                    {
                        return;
                    }

                    int randomIndex = new Random().Next(3);
                    var item        = model.Items[randomIndex];

                    string title       = "Trivia Buff";
                    string description = item.Title;

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        try
                        {
                            LiveTile.UpdateLiveTile(title, description);
                            Debug.WriteLine("Current memory - updated: {0}", DeviceStatus.ApplicationCurrentMemoryUsage);
                        }
                        catch
                        {
                            // TODO: log error
                        }

                        NotifyComplete();
                    });
                };
                model.OnError += exception =>
                {
                    // TODO: log error
                    NotifyComplete();
                };
                model.LoadData();
            }
            catch (Exception e)
            {
                NotifyComplete();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            Debug.WriteLine("Memory limit: {0}", DeviceStatus.ApplicationMemoryUsageLimit);
            Debug.WriteLine("Current memory - initial: {0}", DeviceStatus.ApplicationCurrentMemoryUsage);

            DataManager.Current.Load <DayViewModel>(
                CurrentDateForWiki,
                vm =>
            {
                Debug.WriteLine("Current memory - loaded: {0}", DeviceStatus.ApplicationCurrentMemoryUsage);
                try
                {
                    if (vm.Highlights.Count == 0)
                    {
                        return;
                    }

                    int index   = new Random().Next(vm.Highlights.Count);
                    Entry entry = vm.Highlights[index];

                    string title   = entry.Year;
                    string content = entry.Description;

                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    LiveTile.UpdateLiveTile(title, content);
                    Debug.WriteLine("Current memory - updated: {0}", DeviceStatus.ApplicationCurrentMemoryUsage);
                }
                finally
                {
                    NotifyComplete();
                }
            },
                ex =>
            {
                // TODO: report error using bugsense
                NotifyComplete();
            });
        }