Exemplo n.º 1
0
        private static async void UpdateNewsTile(ArticlePageWorkMode mode)
        {
            var news = await new MalArticlesIndexQuery(mode).GetArticlesIndex();

            try
            {
                var updater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(mode == ArticlePageWorkMode.Articles ? ArticlesTileId : NewsTileId);
                updater.EnableNotificationQueue(true);
                updater.Clear();
                foreach (var malNewsUnitModel in news.Take(5))
                {
                    var tileContent = new TileContent
                    {
                        Visual = new TileVisual
                        {
                            TileMedium = GenerateTileBindingMedium(malNewsUnitModel),
                            TileWide   = GenerateTileBindingWide(malNewsUnitModel),
                        }
                    };
                    if (!ViewModelLocator.Mobile)
                    {
                        tileContent.Visual.TileLarge = GenerateTileBindingLarge(malNewsUnitModel);
                    }
                    updater.Update(new TileNotification(tileContent.GetXml()));
                }
            }
            catch (Exception)
            {
                //can carsh due to unknown reasons
            }
            _tileUpdateSemaphore?.Release();
            NotificationTaskManager.StartNotificationTask(BgTasks.Tiles, false);
        }
Exemplo n.º 2
0
        public static async Task UpdateNewsTilesAsync()
        {
            _tileUpdateSemaphore = new SemaphoreSlim(2);
            var tilesToUpdate = new List <ArticlePageWorkMode>();

            if (SecondaryTile.Exists(ArticlesTileId))
            {
                await _tileUpdateSemaphore.WaitAsync(1);

                tilesToUpdate.Add(ArticlePageWorkMode.Articles);
            }
            if (SecondaryTile.Exists(NewsTileId))
            {
                await _tileUpdateSemaphore.WaitAsync(1);

                tilesToUpdate.Add(ArticlePageWorkMode.News);
            }

            if (!tilesToUpdate.Any())
            {
                NotificationTaskManager.StopTask(BgTasks.Tiles);
            }
            else
            {
                tilesToUpdate.ForEach(UpdateNewsTile);
                for (int i = 0; i < tilesToUpdate.Count; i++)
                {
                    await _tileUpdateSemaphore.WaitAsync();
                }
            }
            _tileUpdateSemaphore = null;
        }