Пример #1
0
		/// <summary>
		/// Create a namespace provider for the description and then give it a chance to create its namespace(s)
		/// </summary>
		/// <param name="def"></param>
		void LoadNamespacesFromProviderDefinition(NamespaceProviderDefinition def)
		{
			// We need to create it
			Type providerType = def.ProviderType;
			if (providerType == null)
				throw new Exception("Unrecognized type (" + def.Type + ") in assembly (" + (def.AssemblyName == null ? "[default]" : def.AssemblyName) + ")");
			object c = Activator.CreateInstance(providerType);
			INamespaceProvider provider = c as INamespaceProvider;
			if (provider == null)
				throw new Exception("Illegal type (" + def.Type + ") in assembly (" + (def.AssemblyName == null ? "[default]" : def.AssemblyName) + ").  Type must implement INamespaceProvider.");
			def.SetParametersInProvider(provider);
			provider.LoadNamespaces(this);
		}
Пример #2
0
		void ShowTypeDetailsForm(string providerID)
		{
			bool isCreate = providerID == null;
			INamespaceProvider provider = null;

			// If we're creating, fill default values, else fill values from the specified instance (or form field if the user already submitted)
			NamespaceProviderDefinition def = null;
			if (providerID == null)
			{
				// We're creating one
				provider = (INamespaceProvider)(Activator.CreateInstance(ProviderType));
			}
			else
			{
				foreach (NamespaceProviderDefinition each in TheFederation.CurrentConfiguration.NamespaceMappings)
				{
					if (each.Id == providerID)
					{
						def = each;
						break;
					}
				}
				if (def != null)
					provider = (INamespaceProvider)(Activator.CreateInstance(def.ProviderType));
				else
				{
					UIResponse.WritePara("Error: unknown namespace provider - " + UIResponse.Escape(providerID));
					return;
				}
			}


			// Decide if we're trying to save and have everything set
			IList errors = null;
			if (IsSave)
			{
				bool err = false;
				foreach (NamespaceProviderParameterDescriptor each in provider.ParameterDescriptors)
				{
					if (!isCreate && !each.IsPersistent)
						continue;	// skip create only parms for non-create scenario
					if (provider.ValidateParameter(TheFederation, each.ID, GetParm(each.ID), isCreate) != null)
					{
						err = true;
						break;
					}
				}

				if (!err)
				{
					errors = provider.ValidateAggregate(TheFederation, isCreate);
					if (errors == null)
					{
						// Great!  All's OK.  Create/modify the provider
						if (def == null)
						{
							def = new NamespaceProviderDefinition(AssemblyNamePart, TypeNamePart, Guid.NewGuid().ToString());
						}
						foreach (NamespaceProviderParameterDescriptor each in provider.ParameterDescriptors)
						{
							provider.SetParameter(each.ID, GetParm(each.ID));
							provider.SavePersistentParametersToDefinition(def);
						}
						IList namespaces = null;
						if (isCreate)
						{
							TheFederation.CurrentConfiguration.NamespaceMappings.Add(def);
							namespaces = provider.CreateNamespaces(TheFederation);
						}
						else
						{
							// If we're editing, we will have modified the definition in place, but we'll need to rescind and recreate
							// the namespaces
							provider.UpdateNamespaces(TheFederation);
						}

						TheFederation.CurrentConfiguration.WriteToFile(TheFederation.CurrentConfiguration.FederationNamespaceMapFilename);
						if (isCreate)
						{
							UIResponse.WritePara("The provider has been created.");
							if (provider.OwnerMailingAddress != null)
								NotifyOwnerOfCreation(provider.OwnerMailingAddress, namespaces);
							UIResponse.WritePara("Namespaces created:");
							UIResponse.WriteStartUnorderedList();
							foreach (string ns in namespaces)
							{
								string url = TheLinkMaker.LinkToTopic(TheFederation.ContentBaseForNamespace(ns).HomePageTopicName);
								UIResponse.WriteListItem("<a href='" + url + "'>" + HTMLWriter.Escape(ns) + "</a>");
							}
							UIResponse.WriteEndUnorderedList();
						}
						else
						{
							UIResponse.WritePara("The provider has been updated.");
						}
						UIResponse.WritePara(UIResponse.Link("providers.aspx", "View provider list"));
						return;
					}
				}
			}

			UIResponse.WriteStartForm("EditProvider.aspx");
			UIResponse.WriteStartFields();
  
			if (errors != null)
			{
				foreach (string s in errors)
				{
					UIResponse.WriteFieldError(UIResponse.Escape(s));
				}
			}

			foreach (NamespaceProviderParameterDescriptor each in provider.ParameterDescriptors)
			{
				if (!isCreate && !each.IsPersistent)
					continue;	// skip create only parms for non-create scenario
				string val = null;
				if (IsSave)
					val = GetParm(each.ID);
				else
				{
					if (isCreate)
					{
						string fromQuery = GetParm(each.ID);
						val = fromQuery == null ? each.DefaultValue : fromQuery;
					}
					else
						val = (string)(def.ParametersAsHash[each.ID]);
				}
				bool readOnly = !isCreate && !provider.CanParameterBeEdited(each.ID);
				UIResponse.WriteInputField(each.ID, each.Title, each.Description, val, readOnly);
				string error = provider.ValidateParameter(TheFederation, each.ID, val, isCreate);
				if (error != null)
					UIResponse.WriteFieldError(UIResponse.Escape(error));
			}
			UIResponse.WriteHiddenField(ParmNameSaveNow, "yup");
			UIResponse.WriteHiddenField(ParmNameTypeName, TypeNameParm);
			if (!isCreate)
				UIResponse.WriteHiddenField(ParmNameProviderID, providerID);

			UIResponse.WriteEndFields();

			UIResponse.WriteStartButtons();
			UIResponse.WriteSubmitButton("next2", (isCreate ? "Create >>" : "Save >>"));
			UIResponse.WriteEndButtons();

			UIResponse.WriteEndForm();				

		}
Пример #3
0
		public void SavePersistentParametersToDefinition(NamespaceProviderDefinition def)
		{
			def.SetParameter("Year", "" + Year);
		}
 public void SavePersistentParametersToDefinition(NamespaceProviderDefinition def)
 {
     def.SetParameter(c_namespace, Namespace);
     def.SetParameter(c_root, DefaultedRoot);
 }
Пример #5
0
        private string ExampleConfig()
        {
            HtmlStringWriter w = new HtmlStringWriter();
            w.Write("<blockquote><pre>");
            FlexWikiWebApplicationConfiguration appConfig = new FlexWikiWebApplicationConfiguration();
            appConfig.FederationConfiguration = new FederationConfiguration();
            appConfig.FederationConfiguration.AboutWikiString = "Text about the wiki here";
            appConfig.FederationConfiguration.AuthorizationRules.Add(
                new WikiAuthorizationRule(
                    new AuthorizationRule(
                        new AuthorizationRuleWho(AuthorizationRuleWhoType.GenericAll),
                        AuthorizationRulePolarity.Allow,
                        AuthorizationRuleScope.Wiki,
                        SecurableAction.Edit,
                        0)
                )
            );
            appConfig.FederationConfiguration.AuthorizationRules.Add(
                new WikiAuthorizationRule(
                    new AuthorizationRule(
                        new AuthorizationRuleWho(AuthorizationRuleWhoType.GenericAuthenticated),
                        AuthorizationRulePolarity.Allow,
                        AuthorizationRuleScope.Wiki,
                        SecurableAction.ManageNamespace,
                        1)
                )
            );
            appConfig.FederationConfiguration.DefaultNamespace = "SampleNamespaceOne";

            NamespaceProviderDefinition sampleNamespaceOne = new NamespaceProviderDefinition(
                typeof(FileSystemNamespaceProvider).Assembly.FullName,
                typeof(FileSystemNamespaceProvider).FullName,
                string.Empty);
            sampleNamespaceOne.Parameters.Add(new NamespaceProviderParameter("Root", @".\SampleNamespaceOne"));

            appConfig.FederationConfiguration.NamespaceMappings.Add(sampleNamespaceOne);

            appConfig.FederationConfiguration.WikiTalkVersion = 1;

            XmlSerializer serializer = new XmlSerializer(typeof(FlexWikiWebApplicationConfiguration));
            XmlWriterSettings writerSettings = new XmlWriterSettings();
            writerSettings.Indent = true;
            writerSettings.IndentChars = "  ";
            StringWriter stringWriter = new StringWriter();
            XmlWriter xmlWriter = XmlWriter.Create(stringWriter, writerSettings);

            serializer.Serialize(xmlWriter, appConfig);

            xmlWriter.Close();

            w.Write(HtmlStringWriter.Escape(stringWriter.ToString()));
            w.Write("</pre></blockquote>");
            return w.ToString();
        }
Пример #6
0
 /// <summary>
 /// Method responsible to write the namespace config information to the  
 /// NamespaceMapFile.
 /// </summary>
 /// <param name="def"></param>
 public void SavePersistentParametersToDefinition(NamespaceProviderDefinition def)
 {
     def.SetParameter(ConfigurationParameterNames.Namespace, Namespace);
     def.SetParameter(ConfigurationParameterNames.ConnectionString, ConnectionString);
 }