public MockWikiApplication(FederationConfiguration configuration, LinkMaker linkMaker, OutputFormat outputFormat, ITimeProvider timeProvider) { _configuration = configuration; _linkMaker = linkMaker; _ouputFormat = outputFormat; _timeProvider = timeProvider; }
/// <summary> /// Load the Federation up with all of the configuration information in the given FederationConfiguration. /// Directories listed in each NamespaceToRoot are made relative to the given relativeDirectoryBase. /// If relativeDirectoryBase is null and a relative reference is used, an Exception will be throw /// </summary> /// <param name="config"></param> public void LoadFromConfiguration(FederationConfiguration config) { try { _CurrentConfiguration = config; UpdateGenerator.Push(); FederationNamespaceMapFilename = config.FederationNamespaceMapFilename; _NamespaceToContentBaseMap = new Hashtable(); foreach (NamespaceProviderDefinition def in config.NamespaceMappings) { LoadNamespacesFromProviderDefinition(def); } _DefaultNamespace = config.DefaultNamespace; Borders = config.Borders; AboutWikiString = config.AboutWikiString; WikiTalkVersion = config.WikiTalkVersion; NoFollowExternalHyperlinks = config.NoFollowExternalHyperlinks != 0; foreach (string link in config.BlacklistedExternalLinks) { AddBlacklistedExternalLinkPrefix(link); } DefaultDirectoryForNewNamespaces = config.DefaultDirectoryForNewNamespaces; _FederationNamespaceMapLastRead = config.FederationNamespaceMapLastRead; UpdateGenerator.RecordNamespaceListChanged(); UpdateGenerator.RecordFederationPropertiesChanged(); } finally { UpdateGenerator.Pop(); } }
private void CheckProviders(FederationConfiguration config) { ArrayList uniqueProviders = new ArrayList(); // Now make sure each provider is well-defined foreach (NamespaceProviderDefinition provider in config.NamespaceMappings) { if (provider.Id == null || (provider.Id != null && provider.Id.Length == 0)) { Result r = new Result("Missing Id attribute in <Namespace> element", Level.Error); r.Writer.Write(@"<p>You did not specify the a unique Id for the NamespaceProvider in the in the <Namespaces> section of the configuration file. <p>Here is an example of a valid federation configuration file:"); r.Writer.Write(ExampleConfig()); AddResult(r); } if (provider.Id != null) { if (uniqueProviders.Contains(provider.Id)) { Result r = new Result("Id attribute value in <Namespace> element must be unique", Level.Error); r.Writer.Write(@"<p>You specified a non-unique Id:"" + provider.Id + @"" for the NamespaceProvider in the in the <Namespaces> section of the configuration file. <p>Here is an example of a valid federation configuration file:"); r.Writer.Write(ExampleConfig()); AddResult(r); } else { uniqueProviders.Add(provider.Id); } } if (provider.Type == null) { Result r = new Result("Missing Type attribute in <Namespace> element", Level.Error); r.Writer.Write(@"<p>You did not specify the Type of a NamespaceProvider in the in the <Namespaces> section of the configuration file. <p>Here is an example of a valid federation configuration file:"); r.Writer.Write(ExampleConfig()); AddResult(r); } // If an assembly is specified, make sure it can be found if (provider.AssemblyName != null) { try { System.Reflection.Assembly.Load(provider.AssemblyName); OK("Successfully loaded assembly " + HtmlWriter.Escape(provider.AssemblyName)); } catch (Exception e) { Result r = new Result("Error loading namespace provider assembly", Level.Error); r.Writer.Write(@"<p>The assembly <b>" + HtmlWriter.Escape(provider.AssemblyName) + @"</b> you specified could not be loaded. The following error occurred: <p>" + HtmlWriter.Escape(e.ToString(), true)); AddResult(r); } } // Make sure the type is a valid type and can be created if (provider.Type != null) { try { Type x = provider.ProviderType; // see if it'll resolve, but catch exceptions if (x == null) throw new Exception("Unable to find type."); OK("Successfully loaded type " + HtmlWriter.Escape(provider.Type)); } catch (Exception e) { Result r = new Result("Error loading namespace provider type", Level.Error); r.Writer.Write(@"<p>The type <b>" + HtmlWriter.Escape(provider.Type) + @"</b> you specified could not be loaded."); if (provider.AssemblyName == null) r.Writer.Write(@"The assembly used was the base FlexWiki engine."); else r.Writer.Write(@"The assembly used was: " + HtmlWriter.Escape(provider.AssemblyName)); r.Writer.Write("<p>The following error occurred: <p>" + HtmlWriter.Escape(e.Message, true)); AddResult(r); } } // TODO: Check for per-provider parms } }
public void SetUp() { string author = "tester-joebob"; _lm = new LinkMaker("http://bogusville"); FederationConfiguration configuration = new FederationConfiguration(); AuthorizationRule rule = new AuthorizationRule(new AuthorizationRuleWho(AuthorizationRuleWhoType.GenericAll, null), AuthorizationRulePolarity.Allow, AuthorizationRuleScope.Wiki, SecurableAction.ManageNamespace, 0); configuration.AuthorizationRules.Add(new WikiAuthorizationRule(rule)); MockWikiApplication application = new MockWikiApplication( configuration, _lm, OutputFormat.HTML, new MockTimeProvider(TimeSpan.FromSeconds(1))); Federation = new Federation(application); _versions = new ArrayList(); _storeManager = WikiTestUtilities.CreateMockStore(Federation, "FlexWiki.Base"); WikiTestUtilities.WriteTestTopicAndNewVersion(_storeManager, "TopicOne", @"1 2 3 4 5 6 7 8 9", author); WikiTestUtilities.WriteTestTopicAndNewVersion(_storeManager, "TopicOne", @"1 2 a b c 3 4 5 6 7 8 9", author); WikiTestUtilities.WriteTestTopicAndNewVersion(_storeManager, "TopicOne", @"1 2 a b 6 7 8 9", author); foreach (TopicChange change in _storeManager.AllChangesForTopic("TopicOne")) { _versions.Add(change.Version); } }