コード例 #1
0
        private void LoadSettings()
        {
            BlogRunnerCommandLineOptions options = new BlogRunnerCommandLineOptions();

            options.Parse(Environment.GetCommandLineArgs(), false);
            fileBlogProviders.Path = (string)options.GetValue(BlogRunnerCommandLineOptions.OPTION_PROVIDERS, "");
            fileConfig.Path        = (string)options.GetValue(BlogRunnerCommandLineOptions.OPTION_CONFIG, "");
            fileOutput.Path        = (string)options.GetValue(BlogRunnerCommandLineOptions.OPTION_OUTPUT, "");
            chkVerbose.Checked     = options.GetFlagValue(BlogRunnerCommandLineOptions.OPTION_VERBOSE, false);
            SetSelectedProviderIds(options.UnnamedArgs);
        }
コード例 #2
0
        static int Main(string[] args)
        {
            try
            {
                ChangeErrorColors(ConsoleColor.Red);

                BlogRunnerCommandLineOptions options = new BlogRunnerCommandLineOptions();
                options.Parse(args, true);

                try
                {
                    if (options.GetFlagValue(BlogRunnerCommandLineOptions.OPTION_VERBOSE, false))
                    {
                        Debug.Listeners.Add(new ConsoleTraceListener(true));
                    }

                    string        providersPath = Path.GetFullPath((string)options.GetValue(BlogRunnerCommandLineOptions.OPTION_PROVIDERS, null));
                    string        configPath    = Path.GetFullPath((string)options.GetValue(BlogRunnerCommandLineOptions.OPTION_CONFIG, null));
                    string        outputPath    = Path.GetFullPath((string)options.GetValue(BlogRunnerCommandLineOptions.OPTION_OUTPUT, providersPath));
                    List <string> providerIds   = new List <string>(options.UnnamedArgs);
                    string        errorLogPath  = (string)options.GetValue(BlogRunnerCommandLineOptions.OPTION_ERRORLOG, null);
                    if (errorLogPath != null)
                    {
                        errorLogPath = Path.GetFullPath(errorLogPath);
                        Console.SetError(new CompositeTextWriter(
                                             Console.Error,
                                             File.CreateText(errorLogPath)));
                    }

                    ApplicationEnvironment.Initialize(Assembly.GetExecutingAssembly(),
                                                      Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"\Windows Live\Writer\"));
                    ApplicationDiagnostics.VerboseLogging = true;

                    var config    = Config.Load(configPath, providersPath);
                    var providers = new XmlDocument();
                    providers.Load(providersPath);


                    foreach (XmlElement provider in providers.SelectNodes("/providers/provider"))
                    {
                        string providerId = provider.SelectSingleNode("id/text()").Value;
                        string clientType = provider.SelectSingleNode("clientType/text()").Value;

                        if (providerIds.Count > 0 && !providerIds.Contains(providerId))
                        {
                            continue;
                        }

                        Provider p = config.GetProviderById(providerId);
                        if (p == null)
                        {
                            continue;
                        }

                        p.ClientType = clientType;

                        TestResultImpl results = new TestResultImpl();

                        Blog b = p.Blog;
                        if (b != null)
                        {
                            Console.Write(provider.SelectSingleNode("name/text()").Value);
                            Console.Write(" (");
                            Console.Write(b.HomepageUrl);
                            Console.WriteLine(")");

                            List <Test> tests = new List <Test>();
                            AddTests(tests);
                            TestRunner tr = new TestRunner(tests);
                            tr.RunTests(p, b, provider);
                        }
                    }

                    using (XmlTextWriter xw = new XmlTextWriter(outputPath, Encoding.UTF8))
                    {
                        xw.Formatting  = Formatting.Indented;
                        xw.Indentation = 1;
                        xw.IndentChar  = '\t';
                        providers.WriteTo(xw);
                    }
                    return(0);
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.ToString());
                    return(1);
                }
                finally
                {
                    if (options.GetFlagValue(BlogRunnerCommandLineOptions.OPTION_PAUSE, false))
                    {
                        Console.WriteLine();
                        Console.WriteLine();
                        Console.Write("Press any key to continue...");
                        Console.ReadKey(true);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(1);
            }
        }