public static ITaskItem[] GetPackagingOutput(this BaseLoadTask baseTask, ClientConfigDto clientConfigDto) { baseTask.LogDebug("Generating Packaging TaskItems"); var output = new List <ITaskItem>(); foreach (var field in clientConfigDto.Packaging.Fields) { var itemMetadata = new Dictionary <string, string>(); itemMetadata.Add("Value", field.Value); output.Add(new TaskItem(field.FieldId.ToString(), itemMetadata)); } baseTask.LogInformation("Generated {0} Packaging TaskItems", output.Count); return(output.ToArray()); }
public static ITaskItem GetAssetCatalogueName(this BaseLoadTask baseTask, ClientConfigDto clientConfigDto, string TargetFrameworkIdentifier) { if (TargetFrameworkIdentifier == "Xamarin.iOS") { var field = clientConfigDto.Packaging.Fields.FirstOrDefault(x => x.FieldId == FieldType.PackagingIosAssetCatalogueName.Value); if (field == null || String.IsNullOrEmpty(field.Value)) { baseTask.Log.LogError("Asset catalogue undefined"); } baseTask.LogInformation("AssetCatalogue name {0}", field.Value.ApplyXcAssetsExt()); var taskItem = new TaskItem(field.Value.ApplyXcAssetsExt()); var fieldType = FieldType.GetAll().FirstOrDefault(x => x.Value == field.FieldId); taskItem.SetDisabledMetadata(baseTask, field.Disabled, fieldType.DisplayName); return(taskItem); } else { return(null); } }
public static ITaskItem[] GetMediaFieldOutput <TFieldClientDto>(this BaseLoadTask baseTask , IList <TFieldClientDto> fieldsDto , ITaskItem assetCatalogueName , ClientConfigDto clientConfigDto , ITaskItem holder) where TFieldClientDto : BaseFieldClientDto <string> { baseTask.LogDebug("Generating Media Field TaskItems"); var output = new List <ITaskItem>(); foreach (var field in fieldsDto) { var itemMetadata = new Dictionary <string, string>(); var fieldType = FieldType.GetAll().FirstOrDefault(x => x.Value == field.FieldId); if (fieldType == null) { throw new Exception($"Missing field type {field.FieldId}"); } itemMetadata.Add(MetadataType.FieldHolderDisabled, holder.GetMetadata(MetadataType.Disabled)); if (fieldType.ProjectType == ProjectType.Droid) { StringFieldClientDto droidNameField = null; if (fieldType is AppIconFieldType) { droidNameField = clientConfigDto.Packaging.Fields.FirstOrDefault(x => x.FieldId == FieldType.PackagingDroidAppIconName.Value); } else if (fieldType is SplashFieldType) { droidNameField = clientConfigDto.Packaging.Fields.FirstOrDefault(x => x.FieldId == FieldType.PackagingDroidSplashName.Value); } if (droidNameField == null || String.IsNullOrEmpty(droidNameField.Value)) { baseTask.Log.LogError("Droid field name undefined"); } //these ones are required for both itemMetadata.Add(MetadataType.LogicalName, droidNameField.Value.ApplyPngExt()); itemMetadata.Add(MetadataType.TapAssetPath, Path.Combine(Consts.DroidTapAssets, fieldType.GetMetadata(MetadataType.Folder))); itemMetadata.Add(MetadataType.ProjectAssetPath, Path.Combine(Consts.DroidResources, fieldType.GetMetadata(MetadataType.Folder))); itemMetadata.Add(MetadataType.MediaName, droidNameField.Value.ApplyFieldId(field)); itemMetadata.Add(MetadataType.MSBuildItemType, MSBuildItemName.TapAsset); } else if (fieldType.ProjectType == ProjectType.Ios) { //do iTunesArtWork if (String.IsNullOrEmpty(fieldType.GetMetadata(MetadataType.Idiom))) { itemMetadata.Add(MetadataType.TapAssetPath, Consts.iTunesArtworkDir); itemMetadata.Add(MetadataType.ProjectAssetPath, Consts.iTunesArtworkDir); itemMetadata.Add(MetadataType.MediaName, fieldType.GetMetadata(MetadataType.FileName).RemovePngExt().ApplyFieldId(field)); itemMetadata.Add(MetadataType.LogicalName, fieldType.GetMetadata(MetadataType.FileName).RemovePngExt()); itemMetadata.Add(MetadataType.MSBuildItemType, MSBuildItemName.ITunesArtwork); } else //do asset catalogue { //need to seperate out image catalogues here, for launchsets and string catalogueSetName = null; if (fieldType is AppIconFieldType) { var catalogueSetField = clientConfigDto.Packaging.Fields.FirstOrDefault(x => x.FieldId == FieldType.PackagingIosAppIconXcAssetsName.Value); catalogueSetName = catalogueSetField.Value.ApplyAppiconsetExt(); } else if (fieldType is SplashFieldType) { var catalogueSetField = clientConfigDto.Packaging.Fields.FirstOrDefault(x => x.FieldId == FieldType.PackagingIosLaunchImageXcAssetsName.Value); catalogueSetName = catalogueSetField.Value.ApplyLaunchimageExt(); } if (!String.IsNullOrEmpty(fieldType.GetMetadata(MetadataType.CataloguePackagingFieldId))) { var catalogueSetField = clientConfigDto.Packaging.Fields.FirstOrDefault(x => x.FieldId == fieldType.GetMetadata(MetadataType.CataloguePackagingFieldId)); catalogueSetName = catalogueSetField.Value.ApplyImageSetExt(); } if (String.IsNullOrEmpty(catalogueSetName)) { baseTask.Log.LogError("Catalogue set name undefined"); } itemMetadata.Add(MetadataType.TapAssetPath, Path.Combine(assetCatalogueName.ItemSpec, catalogueSetName)); itemMetadata.Add(MetadataType.ProjectAssetPath, Path.Combine(assetCatalogueName.ItemSpec, catalogueSetName)); itemMetadata.Add(MetadataType.LogicalName, fieldType.GetMetadata(MetadataType.FileName)); itemMetadata.Add(MetadataType.MediaName, fieldType.GetMetadata(MetadataType.FileName).RemovePngExt().ApplyFieldId(field)); itemMetadata.Add(MetadataType.MSBuildItemType, MSBuildItemName.ImageAsset); itemMetadata.Add(MetadataType.Size, fieldType.GetMetadata(MetadataType.Size)); itemMetadata.Add(MetadataType.Idiom, fieldType.GetMetadata(MetadataType.Idiom)); itemMetadata.Add(MetadataType.Idiom2, fieldType.GetMetadata(MetadataType.Idiom2)); itemMetadata.Add(MetadataType.Scale, fieldType.GetMetadata(MetadataType.Scale)); itemMetadata.Add(MetadataType.Subtype, fieldType.GetMetadata(MetadataType.Subtype)); itemMetadata.Add(MetadataType.Extent, fieldType.GetMetadata(MetadataType.Extent)); itemMetadata.Add(MetadataType.MinimumSystemVersion, fieldType.GetMetadata(MetadataType.MinimumSystemVersion)); itemMetadata.Add(MetadataType.Orientation, fieldType.GetMetadata(MetadataType.Orientation)); itemMetadata.Add(MetadataType.ContentsFileName, fieldType.GetMetadata(MetadataType.FileName)); //we can use this to build a list to operate on as such itemMetadata.Add(MetadataType.CatalogueSetName, catalogueSetName); } } itemMetadata.Add(MetadataType.MediaFileId, field.Value); itemMetadata.Add(MetadataType.FieldDescription, fieldType.DisplayName); var taskItem = new TaskItem(field.FieldId.ToString(), itemMetadata); taskItem.SetDisabledMetadata(baseTask, field.Disabled, fieldType.DisplayName); baseTask.LogDebug(GetDebugStringFromTaskItem(taskItem, itemMetadata)); output.Add(taskItem); } baseTask.LogInformation("Generated {0} Media Field TaskItems", output.Count); return(output.ToArray()); }
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); }