Exemplo n.º 1
0
        public void ApplyTo(BrowserEngine engine)
        {
            foreach (Fixup fixup in Fixups)
            {
                Page targetPage, argument;
                engine.PagesByName.TryGetValue(new Pair <Namespace, string>(fixup.TargetNamespace, fixup.TargetTitle), out targetPage);
                engine.PagesByName.TryGetValue(new Pair <Namespace, string>(fixup.ArgumentNamespace, fixup.ArgumentTitle), out argument);

                switch (fixup.Operation)
                {
                case FixupOperation.RemoveCategory:
                    if (targetPage == null)
                    {
                        throw new InvalidOperationException("Unknown title: " + fixup.TargetPage);
                    }
                    if (argument == null)
                    {
                        throw new InvalidOperationException("Unknown title: " + fixup.OperationArgument);
                    }
                    if (argument.Namespace != Namespace.Category)
                    {
                        throw new InvalidOperationException("Argument must be category: " + fixup.OperationArgument);
                    }

                    Category cat = (Category)argument;
                    if (!targetPage.Categories.Contains(cat))
                    {
                        throw new InvalidOperationException(String.Format("Page {0} is not a member of {1}", fixup.TargetPage, fixup.OperationArgument));
                    }

                    targetPage.Categories.Remove(cat);

                    Category targetCat = targetPage as Category;
                    if (targetCat != null)
                    {
                        cat.Subcategories.Remove(targetCat);
                    }
                    else
                    {
                        cat.Articles.Remove(targetPage);
                    }
                    break;
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Get the base page
 /// </summary>
 /// <param name="engine">Browser engine to be used for the page load</param>
 /// <returns>The page specified by <see cref="Namespace"/>.<see cref="Name"/> from <paramref name="engine"/></returns>
 internal Page GetPage(BrowserEngine engine)
 {
     return(engine.PagesByName[new Pair <Namespace, string>(Namespace, Name)]);
 }