private async void AddToProject() { try { this.IsBusy = true; this.AddToProjectCommand.RaiseCanExecuteChanged(); var project = Project.GetActiveProject(); var icons = this.Densities.Count == 0 ? new List <IProjectIcon>() { this.Icon.Provider.CreateProjectIcon(this.Icon, this.Color, this.Size, null) } : this.Densities.Where(x => x.IsSelected).Select(density => { return(this.Icon.Provider.CreateProjectIcon(this.Icon, this.Color, this.Size, density.Item)); }); foreach (var icon in icons) { await this._projectManager.AddIcon(project, icon, this.Name); } } catch (System.Exception ex) { OutputPane.Output(ex.Message); OutputPane.Output(ex.StackTrace); OutputPane.Activate(); } finally { this.IsBusy = false; this.AddToProjectCommand.RaiseCanExecuteChanged(); } }
private async void AddToProject() { try { this.IsBusy = true; this.AddToProjectCommand.RaiseCanExecuteChanged(); StatusBar.DisplayMessage("Downloading icons ..."); var project = VS.Project.GetActiveProject(); var projectDir = VS.Project.GetProjectDirectory(project); var selectedTypes = new List <Type>(); if (this.Mdpi.IsSelected) { selectedTypes.Add(this.Mdpi.Item); } if (this.Hdpi.IsSelected) { selectedTypes.Add(this.Hdpi.Item); } if (this.XHdpi.IsSelected) { selectedTypes.Add(this.XHdpi.Item); } if (this.XXHdpi.IsSelected) { selectedTypes.Add(this.XXHdpi.Item); } if (this.XXXHdpi.IsSelected) { selectedTypes.Add(this.XXXHdpi.Item); } foreach (var type in selectedTypes) { var color = (this.Color.IsKnown) ? this.Color : Pallete.Black; var iconUrl = this.GenerateUrl(this.Icon.Group.Id, this.Icon.Id, type.Folder, color.Name, this.Size.Value); byte[] icon; using (var client = new HttpClient()) icon = await client.GetByteArrayAsync(iconUrl); if (!this.Color.IsKnown) { icon = ColorUtils.ReplaceColor(icon, this.Color.Color); } var filepath = type.Destination(projectDir, this.Name); FileUtils.WriteAllBytes(icon, filepath); // add to project VS.Project.AddFileToProject(project, filepath, "AndroidResource"); } project.Save(); } catch (System.Exception ex) { OutputPane.Output(ex.Message); OutputPane.Output(ex.StackTrace); OutputPane.Activate(); } finally { StatusBar.Clear(); this.IsBusy = false; this.AddToProjectCommand.RaiseCanExecuteChanged(); } }