Пример #1
0
        public virtual void DoTest(Blog blog, IBlogClient blogClient, XmlElement providerEl)
        {
            TestResultImpl results = new TestResultImpl();
            DoTest(blog, blogClient, results);
            results.ForEach(delegate (string key, string value)
            {
                XmlElement optionsEl = (XmlElement)providerEl.SelectSingleNode("options");
                if (optionsEl == null)
                {
                    optionsEl = providerEl.OwnerDocument.CreateElement("options");
                    providerEl.AppendChild(optionsEl);
                }

                XmlElement el = (XmlElement)optionsEl.SelectSingleNode(key);
                if (el == null)
                {
                    el = providerEl.OwnerDocument.CreateElement(key);
                    optionsEl.AppendChild(el);
                }

                if (!el.HasAttribute("readonly", NAMESPACE_BLOGRUNNER))
                {
                    el.InnerText = value;
                }
            });
        }
Пример #2
0
        public virtual void DoTest(Blog blog, IBlogClient blogClient, XmlElement providerEl)
        {
            TestResultImpl results = new TestResultImpl();

            DoTest(blog, blogClient, results);
            results.ForEach(delegate(string key, string value) {
                XmlElement optionsEl = (XmlElement)providerEl.SelectSingleNode("options");
                if (optionsEl == null)
                {
                    optionsEl = providerEl.OwnerDocument.CreateElement("options");
                    providerEl.AppendChild(optionsEl);
                }

                XmlElement el = (XmlElement)optionsEl.SelectSingleNode(key);
                if (el == null)
                {
                    el = providerEl.OwnerDocument.CreateElement(key);
                    optionsEl.AppendChild(el);
                }

                if (!el.HasAttribute("readonly", NAMESPACE_BLOGRUNNER))
                {
                    el.InnerText = value;
                }
            });
        }
Пример #3
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;
            }
        }