Пример #1
0
        public void SetUp()
        {
            federation = WikiTestUtilities.SetupFederation("test://NamespaceManagerTests",
              TestContentSets.SingleEmptyNamespace);
            testApp = (IMockWikiApplication)federation.Application;

            NamespaceManager manager = federation.NamespaceManagerForNamespace("NamespaceOne");

            testApp.SetApplicationProperty("DisableNewParser", false);
            testApp.SetApplicationProperty("EnableNewParser", true);
            parser = new ParserEngine(federation);
        }
Пример #2
0
        public static QualifiedTopicRevision GetTopicRevision(Federation federation)
        {
            string topic;

            topic = HttpContext.Current.Request.PathInfo;
            if (topic.StartsWith("/"))
            {
                topic = topic.Substring(1);
            }

            // See if we're dealign with old style references or new ones
            // OLD: My.Name.Space.Topic
            // NEW: My.Name.Space/Topic.html
            bool isNewStyle = topic.IndexOf("/") != -1;	// if we have a slash, it's new

            // OK, we've got the namespace and the name now
            QualifiedTopicRevision revision;

            if (topic == null || topic.Length == 0)
            {
                if ((!String.IsNullOrEmpty(HttpContext.Current.Request.Form["Topic"])) && ((bool)federation.Application["EnableBordersAllPages"])
                            && (!String.IsNullOrEmpty(HttpContext.Current.Request.Form["Namespace"])))
                {
                    revision = new QualifiedTopicRevision(HttpContext.Current.Request.Form["Topic"], HttpContext.Current.Request.Form["Namespace"]);
                }
                else if ((!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["namespace"])) && ((bool)federation.Application["EnableBordersAllPages"]))
                {
                    if (HttpContext.Current.Request.QueryString["namespace"] != "[All]") //search All namespaces
                    {
                        NamespaceManager mgr = federation.NamespaceManagerForNamespace(HttpContext.Current.Request.QueryString["namespace"]);
                        revision = new QualifiedTopicRevision(mgr.HomePage, mgr.Namespace);
                    }
                    else
                    {
                        revision = new QualifiedTopicRevision(DefaultNamespaceManager(federation).HomePage,
                            DefaultNamespaceManager(federation).Namespace);
                    }

                }
                else if ((!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["topic"])) && ((bool)federation.Application["EnableBordersAllPages"]))
                {
                    string reqTopic = HttpContext.Current.Request.QueryString["topic"];
                    //NamespaceManager mgr = federation.NamespaceManagerForNamespace(reqTopic.Substring(0, reqTopic.IndexOf(".") - 1));
                    revision = new QualifiedTopicRevision(reqTopic.Substring(reqTopic.IndexOf(".") + 1), reqTopic.Substring(0, reqTopic.IndexOf(".")));
                }
                else
                {
                    revision = new QualifiedTopicRevision(DefaultNamespaceManager(federation).HomePage,
                        DefaultNamespaceManager(federation).Namespace);
                }
            }
            else
            {
                if (isNewStyle)
                {
                    string ns, top;
                    int slash = topic.IndexOf("/");
                    ns = topic.Substring(0, slash);
                    top = topic.Substring(slash + 1);

                    int tailDot = top.LastIndexOf(".");
                    if (tailDot != -1)
                        top = top.Substring(0, tailDot);	// trim of the extension (e.g., ".html")

                    revision = new QualifiedTopicRevision(ns + "." + top);
                }
                else
                {
                    revision = new QualifiedTopicRevision(topic);
                }
            }
            return revision;
        }
Пример #3
0
 public static NamespaceManager DefaultNamespaceManager(Federation federation)
 {
     return federation.NamespaceManagerForNamespace(federation.DefaultNamespace);
 }
Пример #4
0
        internal static Federation CreateFederation(string root, TestContent content)
        {
            string contentDir = Path.Combine(Path.GetFullPath(root), "WikiBases");
            if (Directory.Exists(contentDir))
            {
                Directory.Delete(contentDir, true);
            }

            Directory.CreateDirectory(contentDir);

            TestUtilities.SetDirectoryWebWritable(contentDir);

            FederationConfiguration configuration = new FederationConfiguration();

            FileSystemNamespaceProvider provider = new FileSystemNamespaceProvider();
            bool defaultNamespaceSpecified = false;
            foreach (TestNamespace ns in content.Namespaces)
            {
                provider.Root = Path.Combine(contentDir, ns.Name);
                provider.Namespace = ns.Name;
                NamespaceProviderDefinition definition = new NamespaceProviderDefinition();
                definition.Id = Guid.NewGuid().ToString();
                provider.SavePersistentParametersToDefinition(definition);
                definition.Type = provider.GetType().FullName;
                definition.AssemblyName = provider.GetType().Assembly.FullName;
                configuration.NamespaceMappings.Add(definition);

                // We always set the first namespace to be the default one
                if (defaultNamespaceSpecified == false)
                {
                    configuration.DefaultNamespace = ns.Name;
                    defaultNamespaceSpecified = true;
                }
            }

            string configFilePath = TestUtilities.ReadConfigFilePath();
            configuration.WriteToFile(configFilePath);

            FlexWiki.Web.FlexWikiWebApplication application =
                new FlexWiki.Web.FlexWikiWebApplication(configFilePath, new LinkMaker(TestUtilities.BaseUrl));
            Federation federation = new Federation(application);

            foreach (TestNamespace ns in content.Namespaces)
            {
                FlexWiki.NamespaceManager namespaceManager = federation.NamespaceManagerForNamespace(ns.Name);
                foreach (TestTopic topic in ns.Topics)
                {
                    foreach (string text in topic.ContentHistory)
                    {
                        namespaceManager.WriteTopicAndNewVersion(topic.Name, text, "BuildVerificationTests");
                        //CA We need to sleep a little while so we don't try to write two topics
                        //CA within the same time slice, or they get the same version name.
                        System.Threading.Thread.Sleep(30);
                    }
                }
            }

            RestartWebApplication();

            return federation;
        }