コード例 #1
0
        private static void LoadOperationArguments(OperationArguments operationArguments)
        {
            Debug.Assert(operationArguments != null, "The operationsArguments parameter is null.");

            Trace.WriteLine("Program::LoadOperationArguments");

            Configuration config = new Configuration();
            Configuration.Entry entry;

            if (config.TryGetEntry(ConfigPrefix, operationArguments.TargetUri, ConfigAuthortyKey, out entry))
            {
                Trace.WriteLine("   " + ConfigAuthortyKey + " = " + entry.Value);

                if (String.Equals(entry.Value, "MSA", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(entry.Value, "Microsoft", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(entry.Value, "MicrosoftAccount", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(entry.Value, "Live", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(entry.Value, "LiveConnect", StringComparison.OrdinalIgnoreCase)
                    || String.Equals(entry.Value, "LiveID", StringComparison.OrdinalIgnoreCase))
                {
                    operationArguments.Authority = AuthorityType.MicrosoftAccount;
                }
                else if (String.Equals(entry.Value, "AAD", StringComparison.OrdinalIgnoreCase)
                         || String.Equals(entry.Value, "Azure", StringComparison.OrdinalIgnoreCase)
                         || String.Equals(entry.Value, "AzureDirectory", StringComparison.OrdinalIgnoreCase))
                {
                    operationArguments.Authority = AuthorityType.AzureDirectory;
                }
                else if (String.Equals(entry.Value, "Integrated", StringComparison.OrdinalIgnoreCase)
                         || String.Equals(entry.Value, "NTLM", StringComparison.OrdinalIgnoreCase)
                         || String.Equals(entry.Value, "Kerberos", StringComparison.OrdinalIgnoreCase)
                         || String.Equals(entry.Value, "SSO", StringComparison.OrdinalIgnoreCase))
                {
                    operationArguments.Authority = AuthorityType.Integrated;
                }
                else
                {
                    operationArguments.Authority = AuthorityType.Basic;
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.TargetUri, ConfigInteractiveKey, out entry))
            {
                Trace.WriteLine("   " + ConfigInteractiveKey + " = " + entry.Value);

                if (String.Equals("always", entry.Value, StringComparison.OrdinalIgnoreCase)
                    || String.Equals("true", entry.Value, StringComparison.OrdinalIgnoreCase)
                    || String.Equals("force", entry.Value, StringComparison.OrdinalIgnoreCase))
                {
                    operationArguments.Interactivity = Interactivity.Always;
                }
                else if (String.Equals("never", entry.Value, StringComparison.OrdinalIgnoreCase)
                         || String.Equals("false", entry.Value, StringComparison.OrdinalIgnoreCase))
                {
                    operationArguments.Interactivity = Interactivity.Never;
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.TargetUri, ConfigValidateKey, out entry))
            {
                Trace.WriteLine("   " + ConfigValidateKey + " = " + entry.Value);

                bool validate = operationArguments.ValidateCredentials;
                if (Boolean.TryParse(entry.Value, out validate))
                {
                    operationArguments.ValidateCredentials = validate;
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.TargetUri, ConfigWritelogKey, out entry))
            {
                Trace.WriteLine("   " + ConfigWritelogKey + " = " + entry.Value);

                bool writelog = operationArguments.WriteLog;
                if (Boolean.TryParse(entry.Value, out writelog))
                {
                    operationArguments.WriteLog = writelog;
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.TargetUri, ConfigUseModalUi, out entry))
            {
                Trace.WriteLine("   " + ConfigUseModalUi + " = " + entry.Value);

                bool usemodel = operationArguments.WriteLog;
                if (Boolean.TryParse(entry.Value, out usemodel))
                {
                    operationArguments.UseModalUi = usemodel;
                }
            }
        }
コード例 #2
0
        public bool SetGitConfig(List<GitInstallation> installations, GitConfigAction action, Configuration.Type type, out Configuration.Type updated)
        {
            Trace.WriteLine("Installer::SetGitConfig");
            Trace.WriteLine("   action = " + action + ".");

            updated = Configuration.Type.None;

            if ((installations == null || installations.Count == 0) && !Where.FindGitInstallations(out installations))
            {
                Trace.WriteLine("   No Git installations detected to update.");
                return false;
            }

            if ((type & Configuration.Type.Global) == Configuration.Type.Global)
            {
                // the 0 entry in the installations list is the "preferred" instance of Git
                string gitCmdPath = installations[0].Git;
                string globalCmd = action == GitConfigAction.Set
                    ? "config --global credential.helper manager"
                    : "config --global --unset credential.helper";

                if (ExecuteGit(gitCmdPath, globalCmd, 0, 5))
                {
                    Trace.WriteLine("   updating ~/.gitconfig succeeded.");

                    updated |= Configuration.Type.Global;
                }
                else
                {
                    Trace.WriteLine("   updating ~/.gitconfig failed.");

                    Console.Out.WriteLine();
                    Console.Error.WriteLine("Fatal: Unable to update ~/.gitconfig.");
                    Pause();
                    return false;
                }
            }

            if ((type & Configuration.Type.System) == Configuration.Type.System)
            {
                string systemCmd = action == GitConfigAction.Set
                    ? "config --system credential.helper manager"
                    : "config --system --unset credential.helper";

                int successCount = 0;

                foreach (var installation in installations)
                {
                    if (ExecuteGit(installation.Git, systemCmd, 0, 5))
                    {
                        Trace.WriteLine("   updating /etc/gitconfig succeeded.");

                        successCount++;
                    }
                    else
                    {
                        Trace.WriteLine("   updating ~/.gitconfig failed.");
                    }
                }

                if (successCount == installations.Count)
                {
                    updated |= Configuration.Type.System;
                }
                else
                {
                    return false;
                }
            }

            return true;
        }
コード例 #3
0
        private static void LoadOperationArguments(OperationArguments operationArguments)
        {
            Debug.Assert(operationArguments != null, "The operationsArguments parameter is null.");

            Trace.WriteLine("Program::LoadOperationArguments");

            if (operationArguments.TargetUri == null)
            {
                Console.Error.WriteLine("fatal: no host information, unable to continue.");
                Environment.Exit(-1);
            }

            Configuration config = new Configuration();
            Configuration.Entry entry;

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigAuthortyKey, out entry))
            {
                Trace.WriteLine("   " + ConfigAuthortyKey + " = " + entry.Value);

                if (ConfigStringComparer.Equals(entry.Value, "MSA")
                    || ConfigStringComparer.Equals(entry.Value, "Microsoft")
                    || ConfigStringComparer.Equals(entry.Value, "MicrosoftAccount")
                    || ConfigStringComparer.Equals(entry.Value, "Live")
                    || ConfigStringComparer.Equals(entry.Value, "LiveConnect")
                    || ConfigStringComparer.Equals(entry.Value, "LiveID"))
                {
                    operationArguments.Authority = AuthorityType.MicrosoftAccount;
                }
                else if (ConfigStringComparer.Equals(entry.Value, "AAD")
                         || ConfigStringComparer.Equals(entry.Value, "Azure")
                         || ConfigStringComparer.Equals(entry.Value, "AzureDirectory"))
                {
                    operationArguments.Authority = AuthorityType.AzureDirectory;
                }
                else if (ConfigStringComparer.Equals(entry.Value, "Integrated")
                         || ConfigStringComparer.Equals(entry.Value, "NTLM")
                         || ConfigStringComparer.Equals(entry.Value, "Kerberos")
                         || ConfigStringComparer.Equals(entry.Value, "SSO"))
                {
                    operationArguments.Authority = AuthorityType.Integrated;
                }
                else
                {
                    operationArguments.Authority = AuthorityType.Basic;
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigInteractiveKey, out entry))
            {
                Trace.WriteLine("   " + ConfigInteractiveKey + " = " + entry.Value);

                if (ConfigStringComparer.Equals(entry.Value, "always")
                    || ConfigStringComparer.Equals(entry.Value, "true")
                    || ConfigStringComparer.Equals(entry.Value, "force"))
                {
                    operationArguments.Interactivity = Interactivity.Always;
                }
                else if (ConfigStringComparer.Equals(entry.Value, "never")
                         || ConfigStringComparer.Equals(entry.Value, "false"))
                {
                    operationArguments.Interactivity = Interactivity.Never;
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigValidateKey, out entry))
            {
                Trace.WriteLine("   " + ConfigValidateKey + " = " + entry.Value);

                bool validate = operationArguments.ValidateCredentials;
                if (Boolean.TryParse(entry.Value, out validate))
                {
                    operationArguments.ValidateCredentials = validate;
                }
                else
                {
                    if (ConfigStringComparer.Equals(validate, "no"))
                    {
                        operationArguments.ValidateCredentials = false;
                    }
                    else if (ConfigStringComparer.Equals(validate, "yes"))
                    {
                        operationArguments.ValidateCredentials = true;
                    }
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigWritelogKey, out entry))
            {
                Trace.WriteLine("   " + ConfigWritelogKey + " = " + entry.Value);

                bool writelog = operationArguments.WriteLog;
                if (Boolean.TryParse(entry.Value, out writelog))
                {
                    operationArguments.WriteLog = writelog;
                }
                else
                {
                    if (ConfigStringComparer.Equals(writelog, "no"))
                    {
                        operationArguments.WriteLog = false;
                    }
                    else if (ConfigStringComparer.Equals(writelog, "yes"))
                    {
                        operationArguments.WriteLog = true;
                    }
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigUseModalPromptKey, out entry))
            {
                Trace.WriteLine("   " + ConfigUseModalPromptKey + " = " + entry.Value);

                bool usemodel = operationArguments.UseModalUi;
                if (Boolean.TryParse(entry.Value, out usemodel))
                {
                    operationArguments.UseModalUi = usemodel;
                }
                else
                {
                    if (ConfigStringComparer.Equals(usemodel, "no"))
                    {
                        operationArguments.UseModalUi = false;
                    }
                    else if (ConfigStringComparer.Equals(usemodel, "yes"))
                    {
                        operationArguments.UseModalUi = true;
                    }
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigPreserveCredentialsKey, out entry))
            {
                Trace.WriteLine("   " + ConfigPreserveCredentialsKey + " = " + entry.Value);

                bool preserveCredentials = operationArguments.UseModalUi;
                if (Boolean.TryParse(entry.Value, out preserveCredentials))
                {
                    operationArguments.PreserveCredentials = preserveCredentials;
                }
                else
                {
                    if (ConfigStringComparer.Equals(preserveCredentials, "no"))
                    {
                        operationArguments.PreserveCredentials = false;
                    }
                    else if (ConfigStringComparer.Equals(preserveCredentials, "yes"))
                    {
                        operationArguments.PreserveCredentials = true;
                    }
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigUseHttpPathKey, out entry))
            {
                Trace.WriteLine("   " + ConfigUseHttpPathKey + " = " + entry.Value);

                bool useHttPath = operationArguments.UseHttpPath;
                if (Boolean.TryParse(entry.Value, out useHttPath))
                {
                    operationArguments.UseHttpPath = true;
                }
            }

            if (config.TryGetEntry(ConfigPrefix, operationArguments.QueryUri, ConfigHttpProxyKey, out entry)
                || config.TryGetEntry("http", operationArguments.QueryUri, "proxy", out entry))
            {
                Trace.WriteLine("   " + ConfigHttpProxyKey + " = " + entry.Value);

                operationArguments.SetProxy(entry.Value);
            }
        }