Пример #1
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                goto usage;
            }
            var program = new Program();
            var tracer = new Tracer();
            program.Tracer = tracer;

            for (int i = 0; i < args.Length; i++)
            {
                string personalAccessToken = null;
                Uri uri;
                switch (args[i])
                {
                    case "--microsoft-symbol-server":
                        Uri.TryCreate("http://msdl.microsoft.com/download/symbols/", UriKind.Absolute, out uri);
                        program.SymbolServers.Add(new ServerInfo {Uri = uri, PersonalAccessToken = null});
                        break;

                    case "--internal-server":
                        Uri.TryCreate("http://symweb.corp.microsoft.com/", UriKind.Absolute, out uri);
                        program.SymbolServers.Add(new ServerInfo {Uri = uri, PersonalAccessToken = null, InternalSymwebServer = true});
                        break;

                    case "--authenticated-server-path":
                        if (++i < args.Length)
                            personalAccessToken = args[i];
                        else
                            goto usage;

                        if (string.IsNullOrEmpty(personalAccessToken))
                        {
                            tracer.Error("No personal access token option");
                            goto usage;
                        }
                        goto case "--server-path";

                    case "--server-path":
                        if (++i < args.Length)
                        {
                            // Make sure the server Uri ends with "/"
                            string serverPath = args[i].TrimEnd('/') + '/';
                            if (!Uri.TryCreate(serverPath, UriKind.Absolute, out uri) || uri.IsFile)
                            {
                                tracer.Error(Resources.InvalidServerPath, args[i]);
                                goto usage;
                            }
                            Uri.TryCreate(serverPath, UriKind.Absolute, out uri);
                            program.SymbolServers.Add(new ServerInfo {Uri = uri, PersonalAccessToken = personalAccessToken});
                        }
                        else
                            goto usage;
                        break;

                    case "-o":
                    case "--output":
                        if (++i < args.Length)
                            program.OutputDirectory = args[i];
                        else
                            goto usage;
                        break;

                    case "--cache-directory":
                        if (++i < args.Length)
                            program.CacheDirectories.Add(args[i]);
                        else
                            goto usage;
                        break;

                    case "--recurse-subdirectories":
                        program.Subdirectories = true;
                        break;

                    case "--modules":
                        program.Modules = true;
                        break;

                    case "--symbols":
                        program.Symbols = true;
                        break;

                    case "--debugging":
                        program.Debugging = true;
                        break;

                    case "--windows-pdbs":
                        program.ForceWindowsPdbs = true;
                        break;

                    case "--host-only":
                        program.HostOnly = true;
                        break;

                    case "-d":
                    case "--diagnostics":
                        tracer.Enabled = true;
                        tracer.EnabledVerbose = true;
                        break;

                    case "-h":
                    case "-?":
                    case "--help":
                        goto usage;

                    default:
                        string inputFile = args[i];
                        if (inputFile.StartsWith("-") || inputFile.StartsWith("--"))
                        {
                            tracer.Error(Resources.InvalidCommandLineOption, inputFile);
                            goto usage;
                        }
                        program.InputFilePaths.Add(inputFile);
                        break;
                }
            }
            // Default to public Microsoft symbol server
            if (program.SymbolServers.Count == 0)
            {
                Uri.TryCreate("http://msdl.microsoft.com/download/symbols/", UriKind.Absolute, out Uri uri);
                program.SymbolServers.Add(new ServerInfo {Uri = uri, PersonalAccessToken = null});
            }
            foreach (ServerInfo server in program.SymbolServers)
            {
                tracer.WriteLine(Resources.DownloadFromUri, server.Uri);
            }
            if (program.OutputDirectory != null)
            {
                Directory.CreateDirectory(program.OutputDirectory);
                tracer.WriteLine(Resources.WritingFilesToOutput, program.OutputDirectory);
            }
            try
            {
                program.DownloadFiles().GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                tracer.Error("{0}{1}", ex.Message, ex.InnerException != null ? " -> " + ex.InnerException.Message : "");
            }
            return;

        usage:
            PrintUsage();
        }