public override bool Execute() { var baseResult = base.Execute(); if (baseResult == false) { return(false); } TapAssetDir = this.GetAssetDir(); if (String.IsNullOrEmpty(TapAssetDir)) { Log.LogError($"{Consts.TapAssetsDir} folder not found, exiting"); return(false); } var securitySettings = this.GetSecurity(); if (securitySettings == null) { Log.LogError($"{Consts.TapSecurityFile} file not set, please see solution root and complete"); return(false); } TapAppId = new TaskItem(_tapSetting.TapAppId); var token = this.Login(securitySettings); if (token == null) { Log.LogError("Authentication failure"); return(false); } var unmodifedProjectName = ProjectName.Replace(Consts.ModifiedProjectNameExtra, String.Empty); var url = String.Concat(TapSettings.GetMetadata(MetadataType.TapEndpoint), Consts.TapClientEndpoint, "?", "tapAppId=", _tapSetting.TapAppId, "&projectName=", unmodifedProjectName, "&buildConfiguration=", BuildConfiguration); LogInformation("Loading tap build config from '{0}'", url); string jsonClientConfig = null; try { using (WebClient client = new WebClient()) { client.SetWebClientHeaders(token); jsonClientConfig = client.DownloadString(url); LogInformation("Successfully loaded tap build config from '{0}', recieved '{1}'", url, jsonClientConfig.Length); LogDebug("Json data recieved\n{0}", jsonClientConfig); //write to file //deserialise now (extension method) //return object } } catch (WebException ex) { var response = ex.Response as HttpWebResponse; if (response == null) { Log.LogError($"Unknown server api error {response.StatusCode.ToString()}, exiting"); //Log.LogErrorFromException(ex); return(false); } if (response.StatusCode == HttpStatusCode.NotFound) { Log.LogError($"Build configuration or Tap App Id not found on server, exiting"); TapShouldContinue = bool.FalseString; return(false); } //TODO load client config from projects if no web available and run anyway } catch (Exception ex) { Log.LogErrorFromException(ex); return(false); } ClientConfigDto clientConfigDto = this.GetClientConfig(jsonClientConfig); if (clientConfigDto == null) { return(false); } if (clientConfigDto.AppIcon.Succeeded == false || clientConfigDto.Splash.Succeeded == false) { foreach (var message in clientConfigDto.AppIcon.Messages.Where(x => x.MessageImportanceTypeValue == MessageImportanceType.Error.Value)) { Log.LogError(message.MessageBody); } foreach (var message in clientConfigDto.Splash.Messages.Where(x => x.MessageImportanceTypeValue == MessageImportanceType.Error.Value)) { Log.LogError(message.MessageBody); } return(false); } MediaAccessKey = new TaskItem(clientConfigDto.MediaAccessKey); //this is not quite identical in base var projectsConfig = this.GetProjectsConfig(); var projectConfig = projectsConfig.Projects.FirstOrDefault(x => x.BuildConfiguration == BuildConfiguration); if (projectConfig == null) { projectConfig = new ProjectJson(); projectsConfig.Projects.Add(projectConfig); } projectConfig.BuildConfiguration = BuildConfiguration; projectConfig.ClientConfig = clientConfigDto; if (!this.SaveProjects(projectsConfig)) { return(false); } //this is identical in base AssetCatalogueName = this.GetAssetCatalogueName(projectConfig.ClientConfig, TargetFrameworkIdentifier); BuildConfigHolderOutput = this.GetHolderOutput(projectConfig.ClientConfig.BuildConfig, "Build config"); PackagingHolderOutput = this.GetHolderOutput(projectConfig.ClientConfig.Packaging, "Packaging"); AppIconHolderOutput = this.GetHolderOutput(projectConfig.ClientConfig.AppIcon, "App icon"); SplashHolderOutput = this.GetHolderOutput(projectConfig.ClientConfig.Splash, "Splash"); FileExchangeHolderOutput = this.GetHolderOutput(projectConfig.ClientConfig.FileExchange, "FileExchange"); AppIconFieldOutput = this.GetMediaFieldOutput(projectConfig.ClientConfig.AppIcon.Fields, AssetCatalogueName, projectConfig.ClientConfig, AppIconHolderOutput); SplashFieldOutput = this.GetMediaFieldOutput(projectConfig.ClientConfig.Splash.Fields, AssetCatalogueName, projectConfig.ClientConfig, SplashHolderOutput); PackagingFieldOutput = this.GetStringFieldOutput(projectConfig.ClientConfig.Packaging.Fields, PackagingHolderOutput); FileExchangeFieldOutput = this.GetFileExchangeFieldOutput(projectConfig.ClientConfig.FileExchange.Fields, FileExchangeHolderOutput); return(true); }
public override bool Execute() { var baseResult = base.Execute(); LogInformation("Downloading media files"); LogDebug($"Media access key ${MediaAccessKey.ItemSpec}"); var allMediaFields = this.CombineMediaFields(AppIconFields, SplashFields); var existingFiles = this.GetExistingMediaFiles(BuildConfiguration).Select(x => new FileHolder(x)); LogInformation("{0} media files required, {1} media files already available", allMediaFields.Count(), existingFiles.Count()); var filesToDeleteFromProject = new List <ITaskItem>(); if (FilesToDeleteFromProject != null) { filesToDeleteFromProject.AddRange(FilesToDeleteFromProject); } var buildConfigurationAssetDir = this.GetBuildConfigurationAssetDir(BuildConfiguration); try { foreach (var field in allMediaFields) { var exists = existingFiles.Any(x => x.FileNoExt == field.GetMetadata(MetadataType.MediaName)); if (!exists) { if (field.IsDisabled() == true) { Log.LogMessage("Media field {0} is disabled, not downloading", field.GetMetadata(MetadataType.FieldDescription)); continue; } using (WebClient client = new WebClient()) { LogDebug("Media file exists, getting setup for download"); //do we need headers at all? //client.SetWebClientHeaders(Token); LogDebug("Generating url for mediaId {0}, {1}", field.GetMetadata(MetadataType.MediaFileId), TapAppId.ItemSpec); var url = String.Concat(TapSettings.GetMetadata(MetadataType.MediaEndpoint), "/", TapAppId.ItemSpec, "/", field.GetMetadata(MetadataType.MediaFileId), ".png", MediaAccessKey.ItemSpec); LogDebug($"url generated : {url}"); LogDebug("Finding directory"); var directory = Path.Combine(buildConfigurationAssetDir, field.GetMetadata(MetadataType.TapAssetPath)); LogDebug("Checking directory existance {0}", directory); if (!Directory.Exists(directory)) { LogDebug("Created folder {0}", directory); Directory.CreateDirectory(directory); } var fileName = Path.Combine(buildConfigurationAssetDir, field.GetMetadata(MetadataType.TapAssetPath), field.GetMetadata(MetadataType.MediaName).ApplyPngExt()); LogInformation("Downloading media file {0}, from url {1}", fileName, url); client.DownloadFile(url, fileName); } //doing this in deleteunusedfiles, so should be alright //} //else if (field.IsDisabled() == true) //{ ////Think this takes care of deleting. not sure about old files tho? //Log.LogMessage("Media file {0} exists, but is now disabled, deleting", field.GetMetadata(MetadataType.FieldDescription)); //var fileInfo = existingFiles.FirstOrDefault(x => x.FileNoExt == field.GetMetadata(MetadataType.MediaName)); //fileInfo.FileInfo.Delete(); //var fileToDelete = new TaskItem(field.GetMetadata(MetadataType.MSBuildItemType), new Dictionary<string, string>{ // { MetadataType.DeletePath, fileInfo.FileInfo.FullName } //}); //filesToDeleteFromProject.Add(fileToDelete); } else { LogInformation("Media file {0} exists, skipping", field.GetMetadata(MetadataType.LogicalName)); } } FilesToDeleteFromProject = filesToDeleteFromProject.ToArray(); } catch (Exception ex) { Log.LogErrorFromException(ex); return(false); } return(true); }