private static void read_contactform_element(XmlReader readerXml, ContactForm_Configuration config, ContactForm_Configuration_Element_Type_Enum type) { // Create the element object ContactForm_Configuration_Element newElement = new ContactForm_Configuration_Element(type); // Read the attributes if (readerXml.MoveToAttribute("Name")) { newElement.Name = readerXml.Value.Trim(); if (String.IsNullOrEmpty(newElement.QueryText.DefaultValue)) { newElement.QueryText.DefaultValue = newElement.Name.Replace("_", " ") + ":"; } } if (readerXml.MoveToAttribute("CssClass")) { newElement.CssClass = readerXml.Value.Trim(); } if (readerXml.MoveToAttribute("Query")) { newElement.QueryText.DefaultValue = readerXml.Value.Trim(); } else if (readerXml.MoveToAttribute("Text")) { newElement.QueryText.DefaultValue = readerXml.Value.Trim(); } if (readerXml.MoveToAttribute("UserAttribute")) { string attr = readerXml.Value.Trim(); newElement.UserAttribute = User_Object_Attribute_Mapping_Enum_Converter.ToEnum(attr); } if (readerXml.MoveToAttribute("AlwaysShow")) { string alwaysShow = readerXml.Value.Trim(); switch (alwaysShow.ToLower()) { case "false": newElement.AlwaysShow = false; break; case "true": newElement.AlwaysShow = true; break; } } if (readerXml.MoveToAttribute("Required")) { string required = readerXml.Value.Trim(); switch (required.ToLower()) { case "false": newElement.Required = false; break; case "true": newElement.Required = true; break; } } readerXml.MoveToElement(); // Just step through the subtree of this XmlReader subTreeReader = readerXml.ReadSubtree(); while (subTreeReader.Read()) { if (subTreeReader.NodeType == XmlNodeType.Element) { switch (subTreeReader.Name.ToLower()) { case "option": if (!subTreeReader.IsEmptyElement) { subTreeReader.Read(); if (newElement.Options == null) { newElement.Options = new List <string>(); } newElement.Options.Add(subTreeReader.Value.Trim()); } break; case "language": if (!subTreeReader.IsEmptyElement) { if (subTreeReader.MoveToAttribute("Code")) { string language_code = subTreeReader.Value.Trim(); Web_Language_Enum enum_lang = Web_Language_Enum_Converter.Code_To_Enum(language_code); if (enum_lang != Web_Language_Enum.UNDEFINED) { subTreeReader.Read(); newElement.QueryText.Add_Translation(enum_lang, subTreeReader.Value.Trim()); } } } break; } } } config.Add_Element(newElement); }
/// <summary> Save this configuration to a XML config file </summary> /// <param name="FilePath"> File/path for the resulting XML config file </param> /// <returns> TRUE if successful, otherwise FALSE </returns> public bool Save_To_Config_File(string FilePath) { bool returnValue = true; StreamWriter writer = null; try { // Start the output file writer = new StreamWriter(FilePath, false, Encoding.UTF8); writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); writer.WriteLine("<SobekCM_Config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "); writer.WriteLine("\txmlns=\"http://sobekrepository.org/schemas/sobekcm_config\" "); writer.WriteLine("\txsi:schemaLocation=\"http://sobekrepository.org/schemas/sobekcm_config "); writer.WriteLine("\t\thttp://sobekrepository.org/schemas/sobekcm_config.xsd\">"); if (String.IsNullOrEmpty(Name)) { writer.WriteLine("\t<ContactForm>"); } else { writer.WriteLine("\t<ContactForm Name=\"" + Convert_String_To_XML_Safe(Name) + "\">"); } if (FormElements.Count > 0) { writer.WriteLine("\t\t<Elements>"); // Add the elements foreach (ContactForm_Configuration_Element thisElement in FormElements) { string elementName = String.Empty; switch (thisElement.Element_Type) { case ContactForm_Configuration_Element_Type_Enum.CheckBoxSet: elementName = "CheckBoxSet"; break; case ContactForm_Configuration_Element_Type_Enum.Email: elementName = "Email"; break; case ContactForm_Configuration_Element_Type_Enum.ExplanationText: elementName = "ExplanationText"; break; case ContactForm_Configuration_Element_Type_Enum.HiddenValue: elementName = "HiddenValue"; break; case ContactForm_Configuration_Element_Type_Enum.RadioSet: elementName = "RadioSet"; break; case ContactForm_Configuration_Element_Type_Enum.SelectBox: elementName = "SelectBox"; break; case ContactForm_Configuration_Element_Type_Enum.Subject: elementName = "Subject"; break; case ContactForm_Configuration_Element_Type_Enum.TextArea: elementName = "TextArea"; break; case ContactForm_Configuration_Element_Type_Enum.TextBox: elementName = "TextBox"; break; } writer.Write("\t\t\t<" + elementName); if (!String.IsNullOrEmpty(thisElement.Name)) { writer.Write(" Name=\"" + thisElement.Name + "\""); } if (!String.IsNullOrEmpty(thisElement.QueryText.DefaultValue)) { if (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText) { writer.Write(" Query=\"" + Convert_String_To_XML_Safe(thisElement.QueryText.DefaultValue) + "\""); } else { writer.Write(" Text=\"" + Convert_String_To_XML_Safe(thisElement.QueryText.DefaultValue) + "\""); } } if (!String.IsNullOrEmpty(thisElement.CssClass)) { writer.Write(" CssClass=\"" + thisElement.CssClass + "\""); } if (thisElement.UserAttribute != User_Object_Attribute_Mapping_Enum.NONE) { writer.Write(" UserAttribute=\"" + User_Object_Attribute_Mapping_Enum_Converter.ToString(thisElement.UserAttribute) + "\""); if ((thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText) && (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.HiddenValue)) { writer.Write(" AlwaysShow=\"" + thisElement.AlwaysShow.ToString().ToLower() + "\""); } } if ((thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.ExplanationText) && (thisElement.Element_Type != ContactForm_Configuration_Element_Type_Enum.HiddenValue)) { if (thisElement.Required) { writer.Write(" Required=\"true\""); } } if (((thisElement.Options == null) || (thisElement.Options.Count == 0)) && (thisElement.QueryText.Count <= 1)) { writer.WriteLine(" />"); } else { writer.WriteLine(">"); // Add the query in different languages List <Web_Language_Translation_Value> translations = thisElement.QueryText.Values; if (translations.Count > 0) { writer.WriteLine("\t\t\t\t<Translations>"); foreach (Web_Language_Translation_Value thisTranslation in translations) { writer.WriteLine("\t\t\t\t\t<Language Code=\"" + Web_Language_Enum_Converter.Enum_To_Code(thisTranslation.Language) + "\">" + Convert_String_To_XML_Safe(thisTranslation.Value) + "</Language>"); } writer.WriteLine("\t\t\t\t</Translations>"); } // Add the possible options if ((thisElement.Options != null) && (thisElement.Options.Count > 0)) { writer.WriteLine("\t\t\t\t<Options>"); foreach (string thisOption in thisElement.Options) { writer.WriteLine("\t\t\t\t\t<Option>" + Convert_String_To_XML_Safe(thisOption) + "</Option>"); } writer.WriteLine("\t\t\t\t</Options>"); } writer.WriteLine("\t\t\t</" + elementName + ">"); } } writer.WriteLine("\t\t</Elements>"); } writer.WriteLine("\t</ContactForm>"); writer.WriteLine("</SobekCM_Config>"); writer.Flush(); writer.Close(); } catch { returnValue = false; } finally { if (writer != null) { writer.Close(); } } return(returnValue); }
/// <summary> Save this quality control configuration to a XML config file </summary> /// <param name="FilePath"> File/path for the resulting XML config file </param> /// <returns> TRUE if successful, otherwise FALSE </returns> public bool Save_To_Config_File(string FilePath) { bool returnValue = true; StreamWriter writer = null; try { // Start the output file writer = new StreamWriter(FilePath, false, Encoding.UTF8); writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); writer.WriteLine("<SobekCM_Config xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "); writer.WriteLine("\txmlns=\"http://sobekrepository.org/schemas/sobekcm_config\" "); writer.WriteLine("\txsi:schemaLocation=\"http://sobekrepository.org/schemas/sobekcm_config "); writer.WriteLine("\t\thttp://sobekrepository.org/schemas/sobekcm_config.xsd\">"); writer.WriteLine("\t<Authentication>"); writer.Write("\t\t<Shibboleth"); if (!String.IsNullOrEmpty(UserIdentityAttribute)) { writer.Write(" UserIdentityAttribute=\"" + UserIdentityAttribute + "\""); } if (!String.IsNullOrEmpty(ShibbolethURL)) { writer.Write(" URL=\"" + ShibbolethURL + "\""); } if (!String.IsNullOrEmpty(Label)) { writer.Write(" Label=\"" + Label + "\""); } writer.Write(" Enabled=\"" + Enabled.ToString().ToLower() + "\""); if (Debug) { writer.Write(" Debug=\"true\""); } writer.WriteLine(">"); // Add the attribute matching if ((attributeMappingDictionary != null) && (attributeMappingDictionary.Count > 0)) { writer.WriteLine("\t\t\t<AttributeMatching>"); foreach (KeyValuePair <string, User_Object_Attribute_Mapping_Enum> thisMatch in attributeMappingDictionary) { writer.WriteLine("\t\t\t\t<Mapping ServerVariable=\"" + thisMatch.Key + "\" UserAttribute=\"" + User_Object_Attribute_Mapping_Enum_Converter.ToString(thisMatch.Value) + "\" />"); } writer.WriteLine("\t\t\t</AttributeMatching>"); } // Add the constants if ((Constants != null) && (Constants.Count > 0)) { writer.WriteLine("\t\t\t<Constants>"); foreach (Shibboleth_Configuration_Mapping thisConstant in Constants) { writer.WriteLine("\t\t\t\t<Constant UserAttribute=\"" + User_Object_Attribute_Mapping_Enum_Converter.ToString(thisConstant.Mapping) + "\">" + Convert_String_To_XML_Safe(thisConstant.Value) + "</Constant>"); } writer.WriteLine("\t\t\t</Constants>"); } // Add the logic portions if ((CanSubmitIndicators != null) && (CanSubmitIndicators.Count > 0)) { writer.WriteLine("\t\t\t<Logic>"); foreach (StringKeyValuePair canSubmitIndicator in CanSubmitIndicators) { writer.WriteLine("\t\t\t\t<CanSubmit ServerVariable=\"" + canSubmitIndicator.Key + "\" Value=\"" + canSubmitIndicator.Value + "\" />"); } writer.WriteLine("\t\t\t</Logic>"); } writer.WriteLine("\t\t</Shibboleth>"); writer.WriteLine("\t</Authentication>"); writer.WriteLine("</SobekCM_Config>"); writer.Flush(); writer.Close(); } catch { returnValue = false; } finally { if (writer != null) { writer.Close(); } } return(returnValue); }