コード例 #1
0
        public List <Dependency> MergeDependencies(CompileDependencies rawDependencies, CompileDependencies userDefinedDependencies, CompileDependencies userDefinedAuth)
        {
            Log($"{nameof(MergeDependencies)}: user-authentication specified: {! string.IsNullOrEmpty(userDefinedAuth.Username)}");
            Dependency userAuth = null;

            if (!string.IsNullOrEmpty(userDefinedAuth.Username))
            {
                if (!string.IsNullOrEmpty(userDefinedAuth.AuthenticationType))
                {
                    Authentication = userDefinedAuth.AuthenticationType;
                }

                userAuth = new Dependency
                {
                    Username = userDefinedAuth.Username,
                    Password = userDefinedAuth.Password,
                    Email    = userDefinedAuth.Email
                };
            }

            Log($"{nameof(MergeDependencies)}: raw dependencies count = {rawDependencies.Dependencies.Count}");
            IDictionary <string, Dependency> transformedRawDependencies = rawDependencies.Dependencies.Select(p =>
                                                                                                              new Dependency
            {
                Branch         = p.Branch,
                Commit         = p.Commit,
                DependencyName = p.DependencyName,
                TopFolder      = p.TopFolder,
                Remote         = p.Remote,
                Username       = (userAuth == null) ? rawDependencies.Username : userAuth.Username,
                Password       = (userAuth == null) ? rawDependencies.Password : userAuth.Password,
                Email          = (userAuth == null) ? rawDependencies.Email : userAuth.Email,
                LocalFolder    = p.LocalFolder
            }).ToDictionary(p => p.DependencyName);

            Log($"{nameof(MergeDependencies)}: user-defined dependencies specified: {userDefinedDependencies.Dependencies != null}");
            var transformedUserDefinedDependencies = userDefinedDependencies.Dependencies.Select(p =>
                                                                                                 new Dependency
            {
                Branch         = p.Branch,
                Commit         = p.Commit,
                DependencyName = p.DependencyName,
                TopFolder      = p.TopFolder,
                Remote         = string.Format(p.Remote, userDefinedDependencies.Username, userDefinedDependencies.Password),
                Username       = (userAuth == null) ? userDefinedDependencies.Username : userAuth.Username,
                Password       = (userAuth == null) ? userDefinedDependencies.Password : userAuth.Password,
                Email          = (userAuth == null) ? userDefinedDependencies.Email : userAuth.Email,
                LocalFolder    = p.LocalFolder
            }).ToDictionary(p => p.DependencyName);

            Log($"{nameof(MergeDependencies)}: performing...");
            foreach (var p in transformedUserDefinedDependencies)
            {
                transformedRawDependencies[p.Key] = p.Value;
            }

            Log($"{nameof(MergeDependencies)}: dependencies count = {transformedUserDefinedDependencies.Count}");
            return(transformedRawDependencies.Select(p => p.Value).ToList());
        }
コード例 #2
0
        private CompileDependencies readUserDefinedAuth()
        {
            CompileDependencies _userAuth = new CompileDependencies();

            if (File.Exists(DependencyFile))
            {
                try
                {
                    _userAuth = JsonConvert.DeserializeObject <CompileDependencies>(File.ReadAllText(UserAuthenticationFile));
                }
                catch (Exception ex)
                {
                    Warn($"Unable to read or deserialize '{UserAuthenticationFile}': {ex.Message}");
                }
            }

            return(_userAuth);
        }