public static string GetAssetDir(this BaseTask baseTask)
        {
            baseTask.LogDebug("ProjectDir located at {0}", baseTask.ProjectDir);

            try
            {
                var tapAssetDir = Path.Combine(baseTask.ProjectDir, Consts.TapAssetsDir);
                if (!Directory.Exists(tapAssetDir))
                {
                    baseTask.LogDebug($"Created {Consts.TapAssetsDir} folder at {tapAssetDir}");
                    Directory.CreateDirectory(tapAssetDir);
                }
                else
                {
                    baseTask.LogDebug($"{Consts.TapAssetsDir} folder location {tapAssetDir}");
                }
                var directoryInfo = new DirectoryInfo(tapAssetDir);
                return(directoryInfo.FullName);
            }
            catch (Exception ex)
            {
                baseTask.Log.LogErrorFromException(ex);
            }
            return(null);
        }
        public static string GetBuildConfigurationAssetDir(this BaseTask baseTask, string buildConfiguration)
        {
            var tapAssetDir = baseTask.GetAssetDir();

            baseTask.LogDebug($"{Consts.TapAssetsDir} located at {tapAssetDir}", tapAssetDir);
            baseTask.LogDebug("BuildConfiguration {0}", buildConfiguration);

            try
            {
                var mediaAssetDir = Path.Combine(tapAssetDir, buildConfiguration);
                if (!Directory.Exists(mediaAssetDir))
                {
                    baseTask.LogDebug("Created asset folder at '{0}'", mediaAssetDir);
                    Directory.CreateDirectory(mediaAssetDir);
                }
                else
                {
                    baseTask.LogDebug("Asset folder location '{0}'", mediaAssetDir);
                }
                var directoryInfo = new DirectoryInfo(mediaAssetDir);
                return(directoryInfo.FullName);
            }
            catch (Exception ex)
            {
                baseTask.Log.LogErrorFromException(ex);
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// Login client, and return bearer token
        /// </summary>
        /// <returns>The login.</returns>
        /// <param name="baseTask">Base task.</param>
        public static ITaskItem Login(this BaseTask baseTask, TapSecurityJson tapSecurity)
        {
            LoginResponseDto token;

            //authenticate
            try
            {
                using (WebClient client = new WebClient())
                {
                    var tokenUrl = String.Concat(baseTask.TapSettings.GetMetadata(MetadataType.TapEndpoint), Consts.TokenEndpoint);
                    System.Collections.Specialized.NameValueCollection postData = null;

                    if (String.IsNullOrEmpty(tapSecurity.ServiceUserAccessKey))
                    {
                        postData = new System.Collections.Specialized.NameValueCollection()
                        {
                            { "username", tapSecurity.Username },
                            { "password", tapSecurity.Password },
                            { "grant_type", "password" },
                            { "scope", "openid email plantype profile offline_access roles" },
                            { "resource", "loadremotebuildconfig" }
                        };

                        baseTask.LogDebug("Using grant_type: password");
                    }
                    else
                    {
                        postData = new System.Collections.Specialized.NameValueCollection()
                        {
                            { "password", tapSecurity.ServiceUserAccessKey },
                            { "grant_type", "access_key" },
                            { "scope", "openid email plantype profile offline_access roles" },
                            { "resource", "loadremotebuildconfig" }
                        };
                        baseTask.LogDebug("Using grant_type: access_key");
                    }

                    var tokenResult = Encoding.UTF8.GetString(client.UploadValues(tokenUrl, postData));

                    token = JsonConvert.DeserializeObject <LoginResponseDto>(tokenResult);
                    //client.Credentials = new NetworkCredential(securityConfig.UserName, securityConfig.Password);
                    //var tokenResult = client.DownloadString(tokenUrl);
                    baseTask.LogDebug("Token result recieved <-- value removed from log -->");
                    return(new TaskItem(token.access_token));
                }
            }
            catch (Exception ex)
            {
                baseTask.Log.LogErrorFromException(ex);
                return(null);
            }
        }
        public static IEnumerable <string> GetExistingMediaFiles(this BaseTask baseTask, string buildConfiguration)
        {
            var buildConfigAssetDir = baseTask.GetBuildConfigurationAssetDir(buildConfiguration);

            try
            {
                var files = Directory.EnumerateFiles(buildConfigAssetDir, "*.png", SearchOption.AllDirectories);
                if (baseTask.IsVerbose())
                {
                    if (files.Any())
                    {
                        baseTask.LogVerbose("{0} png files found in resources folder {1}", files.Count(), buildConfigAssetDir);
                        foreach (var file in files)
                        {
                            baseTask.LogDebug("Media file found {0}", file);
                        }
                    }
                    else
                    {
                        baseTask.LogVerbose("No files found in resources folder {0}", buildConfigAssetDir);
                    }
                }
                return(files);
            }
            catch (Exception ex)
            {
                baseTask.Log.LogErrorFromException(ex);
            }
            return(null);
        }
Example #5
0
        public static bool IsTrue(this ITaskItem taskItem, BaseTask baseTask)
        {
            if (taskItem.GetMetadata("Value") == "1")
            {
                baseTask.LogDebug($"Value is true for boolean task item {taskItem.ItemSpec}");
                return(true);
            }

            return(false);
        }
Example #6
0
 public static void SetDisabledMetadata(this ITaskItem taskItem, BaseTask baseTask, bool disabled, string description)
 {
     if (disabled)
     {
         baseTask.LogWarning($"{description} is disabled");
         taskItem.SetMetadata(MetadataType.Disabled, bool.TrueString);
     }
     else
     {
         baseTask.LogDebug($"{description} is enabled");
         taskItem.SetMetadata(MetadataType.Disabled, bool.FalseString);
     }
 }
Example #7
0
        public static TapSecurityJson GetSecurity(this BaseTask baseTask)
        {
            baseTask.LogDebug($"Loading {Consts.TapSecurityFile} file");

            try
            {
                var             tapSecurityPath = baseTask.FindTopFileInProjectDir(Consts.TapSecurityFile);
                TapSecurityJson tapSecurity     = null;
                if (String.IsNullOrEmpty(tapSecurityPath))
                {
                    baseTask.Log.LogError($"{Consts.TapSecurityFile} file not found");
                    return(null);
                }
                else
                {
                    var json = File.ReadAllText(tapSecurityPath);
                    tapSecurity = JsonConvert.DeserializeObject <TapSecurityJson>(json);

                    if ((String.IsNullOrEmpty(tapSecurity.Username) || String.IsNullOrEmpty(tapSecurity.Password)) &&
                        String.IsNullOrEmpty(tapSecurity.ServiceUserAccessKey))
                    {
                        baseTask.Log.LogError($"{Consts.TapSecurityFile} username, password, or service user access key is null, please complete username and password, or service user access key at {tapSecurityPath} and restart build process");
                        return(null);
                    }
                    else
                    {
                        baseTask.LogDebug($"{Consts.TapSecurityFile} file read from {tapSecurityPath}, Username {tapSecurity.Username}");
                        return(tapSecurity);
                    }
                }
            }
            catch (Exception ex)
            {
                baseTask.Log.LogErrorFromException(ex);
            }
            return(null);
        }
Example #8
0
        public static string FindTopFileInProjectDir(this BaseTask baseTask, string fileToFind)
        {
            string filePath = String.Empty;

            try
            {
                baseTask.LogVerbose($"Searching for config file {fileToFind}");
                var currentDirectoryInfo = new DirectoryInfo(baseTask.ProjectDir);
                if (currentDirectoryInfo == null)
                {
                    baseTask.Log.LogError($"Directory {baseTask.ProjectDir} is null");
                }
                do
                {
                    var fileExistenceToTest = Path.Combine(currentDirectoryInfo.FullName, fileToFind);
                    //baseTask.LogVerbose($"Testing for file {fileExistenceToTest}");
                    if (File.Exists(fileExistenceToTest))
                    {
                        //baseTask.LogVerbose($"File exists at {fileExistenceToTest}");
                        filePath = fileExistenceToTest;
                    }
                    if (currentDirectoryInfo.Parent == null)
                    {
                        break;
                    }
                    currentDirectoryInfo = currentDirectoryInfo.Parent;
                } while (currentDirectoryInfo != null);

                if (!String.IsNullOrEmpty(filePath))
                {
                    baseTask.LogInformation($"Selecting {fileToFind} from {filePath}");
                }
                else
                {
                    baseTask.LogDebug($"Did not find file {fileToFind} in path {baseTask.ProjectDir}");
                }
            } catch (Exception e) {
                baseTask.Log.LogError($"Exception reading files {e.Message}");
            }
            return(filePath);
        }