private void UpdatePrimaryTile( TileColoring coloring )
        {
            var xml = new XmlDocument();
            xml.LoadXml( string.Format( TileXmlFormat, PrimaryTilePaths[coloring] ) );

            // COMPAT: v2.5.0 (incorrectly) used a ScheduledTileNotification, so we must clear the queue
            TileUpdateManager.CreateTileUpdaterForApplication().Clear();

            var notification = new TileNotification( xml );
            notification.ExpirationTime = DateTimeOffset.MaxValue;
            TileUpdateManager.CreateTileUpdaterForApplication().Update( notification );
        }
 private async Task UpdateSecondaryTilesAsync( TileColoring coloring )
 {
     var existingTiles = await SecondaryTile.FindAllAsync();
     var tileProps = SecondaryTileProperties[coloring];
     foreach ( var plugin in _pluginLoader.GetPlugins() )
     {
         if ( existingTiles.Any( t => t.TileId == plugin.Id ) )
         {
             var tile = await GetTileAsync( plugin, coloring );
             await tile.UpdateAsync();
         }
     }
 }
 public async void SetTileColoring( TileColoring coloring )
 {
     UpdatePrimaryTile( coloring );
     await UpdateSecondaryTilesAsync( coloring );
 }
 public async void CreateTile( IPlugin plugin, TileColoring coloring )
 {
     var tile = await GetTileAsync( plugin, coloring );
     await tile.RequestCreateAsync();
 }
        private async Task<SecondaryTile> GetTileAsync( IPlugin plugin, TileColoring coloring )
        {
            var winPlugin = (IWindowsRuntimePlugin) plugin;

            var tileProps = SecondaryTileProperties[coloring];

            var icon = new Icon
            {
                Data = winPlugin.Icon,
                IconWidth = TilePixelSize,
                IconHeight = TilePixelSize,
                Foreground = tileProps.Foreground,
                Padding = new Thickness( TilePadding )
            };

            // HACK: To render the icon to a RenderTargetBitmap, the icon needs to be visible, i.e. in the visual tree, and not Collapsed.
            //       But we don't want to show it, so Opacity = 0 and Column/RowSpan = max to make sure it doesn't take up any space
            var tempContainer = new Border { Child = icon, Opacity = 0 };
            Grid.SetColumnSpan( tempContainer, int.MaxValue );
            Grid.SetRowSpan( tempContainer, int.MaxValue );
            var currentRoot = (Panel) ( (Page) ( (Frame) Window.Current.Content ).Content ).Content;
            currentRoot.Children.Add( tempContainer );

            var bitmap = new RenderTargetBitmap();
            await bitmap.RenderAsync( icon, TilePixelSize, TilePixelSize );

            currentRoot.Children.Remove( tempContainer );

            string fileName = plugin.Id + TileFileSuffix;
            var file = await ApplicationData.Current.LocalFolder.CreateFileAsync( fileName, CreationCollisionOption.ReplaceExisting );
            var fileUri = new Uri( "ms-appdata:///local/" + fileName, UriKind.Absolute );

            using ( var stream = await file.OpenAsync( FileAccessMode.ReadWrite ) )
            {
                double currentDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
                var encoder = await BitmapEncoder.CreateAsync( BitmapEncoder.PngEncoderId, stream );
                encoder.SetPixelData( BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
                                      (uint) bitmap.PixelWidth, (uint) bitmap.PixelHeight,
                                      currentDpi, currentDpi,
                                      ( await bitmap.GetPixelsAsync() ).ToArray() );
                await encoder.FlushAsync();
            }

            var tile = new SecondaryTile( plugin.Id, winPlugin.Name, plugin.Id, fileUri, TileSize.Square150x150 );
            tile.VisualElements.BackgroundColor = tileProps.Background;
            tile.VisualElements.ForegroundText = tileProps.ForegroundText;
            tile.VisualElements.ShowNameOnSquare150x150Logo = true;
            return tile;
        }
 public void SetTileColoring( TileColoring coloring ) { }
 public void CreateTile( IPlugin plugin, TileColoring coloring ) { }