ToXmlString() public method

public ToXmlString ( ) : string
return string
Beispiel #1
0
		/// <summary>
		/// This is the common method for building a map file.  The map file is a key part of the import
		/// process: used for generating all the output files.
		/// </summary>
		/// <param name="uiLangs">list of language information</param>
		/// <param name="ILexFields"></param>
		/// <param name="sfmInfo"></param>
		/// <param name="listInFieldMarkers"></param>
		/// <param name="m_SaveAsFileName"></param>
		static public void NewMapFileBuilder(
			Hashtable uiLangs,
			ILexImportFields ILexFields,
			ILexImportFields ICustomFields,
			List<FieldHierarchyInfo> sfmInfo,
			List<Sfm2Xml.ClsInFieldMarker> listInFieldMarkers,	// was lvInFieldMarkers
			string saveAsFileName
			)
		{
			string nl = System.Environment.NewLine;
			//string mapFileVersion = "6.0";	// this maps to FW release 6.0, prev release was 5.4.1
			System.Text.StringBuilder XMLText = new System.Text.StringBuilder(8192);

			AddSectionComment("Created via the Lexical Import process: " + System.DateTime.Now.ToString(), ref XMLText);
			XMLText.Append("<sfmMapping version=\""+MapFileVersion+"\">" + nl);			// Start of the map file
			AddSectionComment("Global Settings", ref XMLText);
			// Global Settings section of XML map file
			XMLText.Append("<settings>" + nl);
			XMLText.Append("<meaning app=\"fw.sil.org\"/>" + nl);
			XMLText.Append("</settings>" + nl);
			// ====================================================================
			// Languages section of XML map file
			// ====================================================================
			AddSectionComment("Language Definitions", ref XMLText);
			XMLText.Append("<languages>" + nl);
			foreach (DictionaryEntry item in uiLangs)
			{
				LanguageInfoUI lang = item.Value as LanguageInfoUI;
				Sfm2Xml.ClsLanguage langObj = lang.ClsLanguage;
				if (lang.FwName == STATICS.Ignore)
				{
					langObj.XmlLang = lang.FwName;	// use 'ignore' for the xml:lang value
				}
				string xmlOutput = langObj.ToXmlString();
				XMLText.Append(xmlOutput + nl);
			}
			XMLText.Append("</languages>" + nl);
			// ====================================================================
			// Level Hierarchy section of XML map file
			// ====================================================================
			AddSectionComment("Level Hierarchy", ref XMLText);
			XMLText.Append("<hierarchy>" + nl);

			// now use the list of FieldHierarchyInfo and ILexFields to put out the two sections in the map file
			Dictionary<string, Sfm2Xml.ClsHierarchyEntry> hierarchyItems = new Dictionary<string, Sfm2Xml.ClsHierarchyEntry>();
			foreach (string className in ILexFields.Classes)
			{
				string partOf = ILexFields.HierarchForClass(className);
				hierarchyItems.Add(className, new Sfm2Xml.ClsHierarchyEntry(className, partOf, "", "", "", ""));
			}
			// now walk the list of FieldHierarchyInfo
			foreach (FieldHierarchyInfo fieldInfo in sfmInfo)
			{
				if (fieldInfo.IsAuto)
					continue;	// skip it for the Hierarchy list -- no change there
				// get the class for the destination field : ASSUMPTION EACH FWDESTID IS UNIQUE AND NOT DUPLICATED AMONG CLASSES
				string className;
				ILexImportField lfield = ILexFields.GetField(fieldInfo.FwDestID, out className);
				if (lfield == null)
				{
					className = fieldInfo.FwDestClass;	// currently only set for custom fields (7/08)
					lfield = ICustomFields.GetField(className, fieldInfo.FwDestID);
					// handle custom fields SOMEWHERE....?
					//if (lfield != null)
					//    continue;
				}
				System.Diagnostics.Debug.Assert(lfield != null, "Error in the data assumptions: fwDestID=<" + fieldInfo.FwDestID + ">");

				Sfm2Xml.ClsHierarchyEntry activeOne = hierarchyItems[className];
				if (fieldInfo.IsBegin)
					activeOne.AddBeginField(fieldInfo.SFM);	// if it's a begin, don't add to addtl and multi
				else
				{
					activeOne.AddAdditionalField(fieldInfo.SFM);	// not a begin then has to be additional
					if (lfield.IsMulti)
						activeOne.AddMultiField(fieldInfo.SFM);		// can also be a multi field
				}
				if (lfield.IsUnique)
					activeOne.AddUniqueField(fieldInfo.SFM);
			}
			// can now put out the hierarchy items
			foreach (Sfm2Xml.ClsHierarchyEntry hierarchyItem in hierarchyItems.Values)
			{
				if (hierarchyItem.BeginFields.Count == 0)
					hierarchyItem.AddBeginField(Ignore);
				string xmlOutput = hierarchyItem.ToXmlString();
				XMLText.Append(xmlOutput + nl);
			}

			XMLText.Append("</hierarchy>" + nl);
			// ====================================================================
			// Field Descriptions of XML map file
			// ====================================================================
			AddSectionComment("Field Descriptions", ref XMLText);
			XMLText.Append("<fieldDescriptions>" + nl);

			// now put out each Field Description
			foreach (FieldHierarchyInfo fieldInfo in sfmInfo)
			{
				ClsFieldDescriptionWrapper tmp;
				if (fieldInfo.IsAuto)
				{
					tmp = new ClsFieldDescriptionWrapper(fieldInfo.SFM, " ", "string", fieldInfo.Lang, false, "");
					tmp.IsAutoImportField = true;
				}
				else
				{
					// get the class for the destination field : ASSUMPTION EACH FWDESTID IS UNIQUE AND NOT DUPLICATED AMONG CLASSES
					string className;
					ILexImportField lfield = ILexFields.GetField(fieldInfo.FwDestID, out className);
					if (lfield == null)
					{
						className = fieldInfo.FwDestClass;	// currently only set for custom fields (7/08)
						lfield = ICustomFields.GetField(className, fieldInfo.FwDestID);
						if (lfield != null)
							continue;
					}
					System.Diagnostics.Debug.Assert(lfield != null, "Error in the data assumptions: fwDestID=<" + fieldInfo.FwDestID + ">");

					tmp = new ClsFieldDescriptionWrapper(fieldInfo.SFM, lfield.UIName, lfield.DataType, fieldInfo.Lang, lfield.IsAbbrField, fieldInfo.FwDestID);
				}
				tmp.RefFunc = fieldInfo.RefFunc;
				tmp.RefFuncWS = fieldInfo.RefFuncWS;
				tmp.IsExcluded = fieldInfo.IsExcluded;
				if (fieldInfo.IsAbbrvField)			// if it's an abbreviation field then
					tmp.IsAbbr = fieldInfo.IsAbbr;	//  set the value for it.

				string xmlOutput = tmp.ToXmlString();
				//string xmlOutputNew = fieldInfo.ClsFieldDescription.ToXmlString();
				//if (xmlOutput != xmlOutputNew)
				//    System.Diagnostics.Debug.WriteLine("xml string are different.");

				XMLText.Append(xmlOutput + nl);
			}
			XMLText.Append("</fieldDescriptions>" + nl);

			// ====================================================================
			// InField markers of XML map file
			// ====================================================================
			AddSectionComment("In Field Markers", ref XMLText);
			XMLText.Append("<inFieldMarkers>" + nl);

			foreach (Sfm2Xml.ClsInFieldMarker marker in listInFieldMarkers)
			{
				if (marker == null)
					continue;
				XMLText.Append(marker.ToXmlString() + nl);
			}
			XMLText.Append("</inFieldMarkers>" + nl);

			// ====================================================================
			// Custom Field Descriptions of XML map file
			// ====================================================================
			AddSectionComment("Custom Field Descriptions", ref XMLText);
			XMLText.Append("<CustomFieldDescriptions>" + nl);

			// now put out each Field Description
			foreach (FieldHierarchyInfo fieldInfo in sfmInfo)
			{
				//// ClsFieldDescriptionWrapper tmp;
				if (fieldInfo.IsAuto)	continue;	// skip if not a custom field

				// get the class for the destination field : ASSUMPTION EACH FWDESTID IS UNIQUE AND NOT DUPLICATED AMONG CLASSES
				string className = fieldInfo.FwDestClass;	// currently only set for custom fields (7/08)
				ILexImportCustomField lfield = ICustomFields.GetField(className, fieldInfo.FwDestID) as ILexImportCustomField;

//				ILexImportCustomField lfield = ICustomFields.GetField(fieldInfo.FwDestID, out className) as ILexImportCustomField;
				if (lfield == null)	continue;
				//// tmp = new ClsFieldDescriptionWrapper(fieldInfo.SFM, lfield.UIName, lfield.DataType, fieldInfo.Lang, lfield.IsAbbrField, fieldInfo.FwDestID);
				ClsCustomFieldDescription tmp = new ClsCustomFieldDescription(lfield.Class, className, /*lfield.CustomFieldID,*/ lfield.FLID, lfield.Big, lfield.WsSelector,
					fieldInfo.SFM, lfield.UIName, lfield.Signature/*DataType*/, fieldInfo.Lang, lfield.IsAbbrField, fieldInfo.FwDestID);

				tmp.RefFunc = fieldInfo.RefFunc;
				tmp.RefFuncWS = fieldInfo.RefFuncWS;
				tmp.IsExcluded = fieldInfo.IsExcluded;
				if (fieldInfo.IsAbbrvField)			// if it's an abbreviation field then
					tmp.IsAbbr = fieldInfo.IsAbbr;	//  set the value for it.

				string xmlOutput = tmp.ToXmlString();
				XMLText.Append(xmlOutput + nl);
			}
			XMLText.Append("</CustomFieldDescriptions>" + nl);


			// ====================================================================
			// now close out the map file
			// ====================================================================
			XMLText.Append("</sfmMapping>" + nl);

			try
			{
				using (System.IO.StreamWriter outMapFile = new System.IO.StreamWriter(saveAsFileName, false))
				{
					outMapFile.Write(XMLText);
					outMapFile.Close();
					//				m_dirtySenseLastSave = false;
				}
			}
			catch (System.Exception ex)
			{
				throw (ex);
			//    System.Diagnostics.Debug.WriteLine("Error: " + ex.Message);
			//    MessageBox.Show(this, "Problem saving settings: " + ex.Message, "Cannot Save Settings",
			//        MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
		}
Beispiel #2
0
        /// <summary>
        /// This is the common method for building a map file.  The map file is a key part of the import
        /// process: used for generating all the output files.
        /// </summary>
        /// <param name="uiLangs">list of language information</param>
        /// <param name="ILexFields"></param>
        /// <param name="ICustomFields"></param>
        /// <param name="sfmInfo"></param>
        /// <param name="listInFieldMarkers"></param>
        /// <param name="saveAsFileName"></param>
        /// <param name="listOptions">records checkbox values</param>
        static public void NewMapFileBuilder(
            Hashtable uiLangs,
            ILexImportFields ILexFields,
            ILexImportFields ICustomFields,
            List <FieldHierarchyInfo> sfmInfo,
            List <ClsInFieldMarker> listInFieldMarkers,           // was lvInFieldMarkers
            string saveAsFileName,
            List <ILexImportOption> listOptions = null            // list of import options
            )
        {
            string nl = System.Environment.NewLine;

            System.Text.StringBuilder XMLText = new System.Text.StringBuilder(8192);

            AddSectionComment("Created via the Lexical Import process: " + System.DateTime.Now.ToString(), ref XMLText);
            XMLText.Append("<sfmMapping version=\"" + MapFileVersion + "\">" + nl);                             // Start of the map file
            // ====================================================================
            // Global Settings section of XML map file
            // ====================================================================
            AddSectionComment("Global Settings", ref XMLText);
            XMLText.Append("<settings>" + nl);
            XMLText.Append("<meaning app=\"fw.sil.org\"/>" + nl);
            XMLText.Append("</settings>" + nl);
            // ====================================================================
            // Import Options section of XML map file
            // ====================================================================
            AddSectionComment("Import Options", ref XMLText);
            XMLText.Append("<options>" + nl);
            if (listOptions == null)
            {
                listOptions = new List <ILexImportOption>();
            }
            foreach (var importOption in listOptions)
            {
                switch (importOption.Type)
                {
                case "Checkbox":
                    XMLText.Append(importOption.ToXmlString() + nl);
                    break;

                default:
                    Debug.Fail("Unknown LexImportOption Type: " + importOption.Type);
                    continue;
                }
            }
            XMLText.Append("</options>" + nl);
            // ====================================================================
            // Languages section of XML map file
            // ====================================================================
            AddSectionComment("Language Definitions", ref XMLText);
            XMLText.Append("<languages>" + nl);
            foreach (DictionaryEntry item in uiLangs)
            {
                LanguageInfoUI      lang    = item.Value as LanguageInfoUI;
                Sfm2Xml.ClsLanguage langObj = lang.ClsLanguage;
                if (lang.FwName == STATICS.Ignore)
                {
                    langObj.XmlLang = lang.FwName;                      // use 'ignore' for the xml:lang value
                }
                string xmlOutput = langObj.ToXmlString();
                XMLText.Append(xmlOutput + nl);
            }
            XMLText.Append("</languages>" + nl);
            // ====================================================================
            // Level Hierarchy section of XML map file
            // ====================================================================
            AddSectionComment("Level Hierarchy", ref XMLText);
            XMLText.Append("<hierarchy>" + nl);

            // now use the list of FieldHierarchyInfo and ILexFields to put out the two sections in the map file
            Dictionary <string, Sfm2Xml.ClsHierarchyEntry> hierarchyItems = new Dictionary <string, Sfm2Xml.ClsHierarchyEntry>();

            foreach (string className in ILexFields.Classes)
            {
                string partOf = ILexFields.HierarchForClass(className);
                hierarchyItems.Add(className, new Sfm2Xml.ClsHierarchyEntry(className, partOf, "", "", "", ""));
            }
            // now walk the list of FieldHierarchyInfo
            foreach (FieldHierarchyInfo fieldInfo in sfmInfo)
            {
                if (fieldInfo.IsAuto)
                {
                    continue;                           // skip it for the Hierarchy list -- no change there
                }
                // get the class for the destination field : ASSUMPTION EACH FWDESTID IS UNIQUE AND NOT DUPLICATED AMONG CLASSES
                string          className;
                ILexImportField lfield = ILexFields.GetField(fieldInfo.FwDestID, out className);
                if (lfield == null)
                {
                    className = fieldInfo.FwDestClass;                          // currently only set for custom fields (7/08)
                    lfield    = ICustomFields.GetField(className, fieldInfo.FwDestID);
                    // handle custom fields SOMEWHERE....?
                    //if (lfield != null)
                    //    continue;
                }
                System.Diagnostics.Debug.Assert(lfield != null, "Error in the data assumptions: fwDestID=<" + fieldInfo.FwDestID + ">");

                Sfm2Xml.ClsHierarchyEntry activeOne = hierarchyItems[className];
                if (fieldInfo.IsBegin)
                {
                    activeOne.AddBeginField(fieldInfo.SFM);                     // if it's a begin, don't add to addtl and multi
                }
                else
                {
                    activeOne.AddAdditionalField(fieldInfo.SFM);                        // not a begin then has to be additional
                    if (lfield.IsMulti)
                    {
                        activeOne.AddMultiField(fieldInfo.SFM);                                 // can also be a multi field
                    }
                }
                if (lfield.IsUnique)
                {
                    activeOne.AddUniqueField(fieldInfo.SFM);
                }
            }
            // can now put out the hierarchy items
            foreach (Sfm2Xml.ClsHierarchyEntry hierarchyItem in hierarchyItems.Values)
            {
                if (hierarchyItem.BeginFields.Count == 0)
                {
                    hierarchyItem.AddBeginField(Ignore);
                }
                string xmlOutput = hierarchyItem.ToXmlString();
                XMLText.Append(xmlOutput + nl);
            }

            XMLText.Append("</hierarchy>" + nl);
            // ====================================================================
            // Field Descriptions of XML map file
            // ====================================================================
            AddSectionComment("Field Descriptions", ref XMLText);
            XMLText.Append("<fieldDescriptions>" + nl);

            // now put out each Field Description
            foreach (FieldHierarchyInfo fieldInfo in sfmInfo)
            {
                ClsFieldDescriptionWrapper tmp;
                if (fieldInfo.IsAuto)
                {
                    tmp = new ClsFieldDescriptionWrapper(fieldInfo.SFM, " ", "string", fieldInfo.Lang, false, "");
                    tmp.IsAutoImportField = true;
                }
                else
                {
                    // get the class for the destination field : ASSUMPTION EACH FWDESTID IS UNIQUE AND NOT DUPLICATED AMONG CLASSES
                    string          className;
                    ILexImportField lfield = ILexFields.GetField(fieldInfo.FwDestID, out className);
                    if (lfield == null)
                    {
                        className = fieldInfo.FwDestClass;                              // currently only set for custom fields (7/08)
                        lfield    = ICustomFields.GetField(className, fieldInfo.FwDestID);
                        if (lfield != null)
                        {
                            continue;
                        }
                    }
                    System.Diagnostics.Debug.Assert(lfield != null, "Error in the data assumptions: fwDestID=<" + fieldInfo.FwDestID + ">");

                    tmp = new ClsFieldDescriptionWrapper(fieldInfo.SFM, lfield.UIName, lfield.DataType, fieldInfo.Lang, lfield.IsAbbrField, fieldInfo.FwDestID);
                }
                tmp.RefFunc    = fieldInfo.RefFunc;
                tmp.RefFuncWS  = fieldInfo.RefFuncWS;
                tmp.IsExcluded = fieldInfo.IsExcluded;
                if (fieldInfo.IsAbbrvField)                             // if it's an abbreviation field then
                {
                    tmp.IsAbbr = fieldInfo.IsAbbr;                      //  set the value for it.
                }
                string xmlOutput = tmp.ToXmlString();
                //string xmlOutputNew = fieldInfo.ClsFieldDescription.ToXmlString();
                //if (xmlOutput != xmlOutputNew)
                //    System.Diagnostics.Debug.WriteLine("xml string are different.");

                XMLText.Append(xmlOutput + nl);
            }
            XMLText.Append("</fieldDescriptions>" + nl);

            // ====================================================================
            // InField markers of XML map file
            // ====================================================================
            AddSectionComment("In Field Markers", ref XMLText);
            XMLText.Append("<inFieldMarkers>" + nl);

            foreach (Sfm2Xml.ClsInFieldMarker marker in listInFieldMarkers)
            {
                if (marker == null)
                {
                    continue;
                }
                XMLText.Append(marker.ToXmlString() + nl);
            }
            XMLText.Append("</inFieldMarkers>" + nl);

            // ====================================================================
            // Custom Field Descriptions of XML map file
            // ====================================================================
            AddSectionComment("Custom Field Descriptions", ref XMLText);
            XMLText.Append("<CustomFieldDescriptions>" + nl);

            // now put out each Field Description
            foreach (FieldHierarchyInfo fieldInfo in sfmInfo)
            {
                //// ClsFieldDescriptionWrapper tmp;
                if (fieldInfo.IsAuto)
                {
                    continue;                                           // skip if not a custom field
                }
                // get the class for the destination field : ASSUMPTION EACH FWDESTID IS UNIQUE AND NOT DUPLICATED AMONG CLASSES
                string className             = fieldInfo.FwDestClass;           // currently only set for custom fields (7/08)
                ILexImportCustomField lfield = ICustomFields.GetField(className, fieldInfo.FwDestID) as ILexImportCustomField;

//				ILexImportCustomField lfield = ICustomFields.GetField(fieldInfo.FwDestID, out className) as ILexImportCustomField;
                if (lfield == null)
                {
                    continue;
                }
                //// tmp = new ClsFieldDescriptionWrapper(fieldInfo.SFM, lfield.UIName, lfield.DataType, fieldInfo.Lang, lfield.IsAbbrField, fieldInfo.FwDestID);
                ClsCustomFieldDescription tmp = new ClsCustomFieldDescription(lfield.Class, className, /*lfield.CustomFieldID,*/ lfield.FLID, lfield.Big, lfield.WsSelector,
                                                                              fieldInfo.SFM, lfield.UIName, lfield.Signature /*DataType*/, fieldInfo.Lang, lfield.IsAbbrField, fieldInfo.FwDestID);

                tmp.RefFunc    = fieldInfo.RefFunc;
                tmp.RefFuncWS  = fieldInfo.RefFuncWS;
                tmp.IsExcluded = fieldInfo.IsExcluded;
                if (fieldInfo.IsAbbrvField)                             // if it's an abbreviation field then
                {
                    tmp.IsAbbr = fieldInfo.IsAbbr;                      //  set the value for it.
                }
                string xmlOutput = tmp.ToXmlString();
                XMLText.Append(xmlOutput + nl);
            }
            XMLText.Append("</CustomFieldDescriptions>" + nl);


            // ====================================================================
            // now close out the map file
            // ====================================================================
            XMLText.Append("</sfmMapping>" + nl);

            try
            {
                using (System.IO.StreamWriter outMapFile = new System.IO.StreamWriter(saveAsFileName, false))
                {
                    outMapFile.Write(XMLText);
                    outMapFile.Close();
                    //				m_dirtySenseLastSave = false;
                }
            }
            catch (System.Exception ex)
            {
                throw (ex);
                //    System.Diagnostics.Debug.WriteLine("Error: " + ex.Message);
                //    MessageBox.Show(this, "Problem saving settings: " + ex.Message, "Cannot Save Settings",
                //        MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }