private void EnableControlsFromField(Sfm2Xml.LexImportField field) { // see if the abbr controls should be enabled or not bool enable = false; if (field != null) enable = field.IsAbbrField; lblAbbr.Enabled = enable; rbAbbrName.Enabled = enable; rbAbbrAbbr.Enabled = enable; // see if the function controls should be enabled if (field != null) enable = field.IsRef; lblFunction.Enabled = enable; cbFunction.Enabled = enable; if (lblFunction.Enabled == false) lblFunction.Text = "Not An Active Field :"; }
public bool IsValidCustomField(Sfm2Xml.ClsFieldDescription mapField) { // get the field description info from the map file for this marker if (mapField is Sfm2Xml.ClsCustomFieldDescription) { // first make sure if it's a custom field, that the field exists in the database if (m_LexFields.ContainsCustomField((mapField as Sfm2Xml.ClsCustomFieldDescription).CustomKey)) return true; } return false; }
/// <summary> /// Output each sfm and the sfm that followed it with the number of occurances in the input file. /// Each sfm should be listed, except for the case where the last sfm in the file is only used once. /// </summary> /// <param name="sfmSorted"></param> /// <param name="w"></param> /// <param name="reader"></param> static void OutputFollowedByInfo(System.Collections.ArrayList sfmSorted, BinaryWriter w, Sfm2Xml.SfmFileReaderEx reader) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}{1}{2}{3}{4}", nl, "SFM Followed by Info:", nl, "--------------------------------------", nl); sb.AppendFormat("{0}({1}){2}", reader.FileName, reader.Count, nl); w.Write(MakeBytes(sb.ToString())); byte[] a = new byte[] { (byte)' ', (byte)'-', (byte)' ' }; byte[] b = new byte[] { (byte)'\t', (byte)'=', (byte)' ' }; Dictionary<string, Dictionary<string, int>> fbInfo = reader.GetFollowedByInfo(); foreach (string sfm in sfmSorted) { if (fbInfo.ContainsKey(sfm) == false) // case where sfm is only used once and is last marker continue; Dictionary<string, int> kvp = fbInfo[sfm]; System.Collections.ArrayList sfm2 = new System.Collections.ArrayList(kvp.Keys); sfm2.Sort(); foreach (string sfmNext in sfm2) { w.Write(MakeBytes(sfm)); w.Write(a); w.Write(MakeBytes(sfmNext)); w.Write(b); w.Write(MakeBytes((kvp[sfmNext]).ToString("N0"))); w.Write(m_NL); } } }
public ContentMapping(string marker, string desc, string className, string fwDest, string ws, string langDescriptor, int count, int order, Sfm2Xml.ClsFieldDescription fdesc, bool isCustom) { m_marker = marker; m_description = desc; m_FWDestination = fwDest; m_writingSystem = ws; m_langDescriptor = langDescriptor; m_count = count; m_srcOrder = order; //m_excluded = false; m_destinationClass = className; m_clsFieldDescription = fdesc; // saved for now, used at end for producing map file m_LexImportField = null; if (m_clsFieldDescription == null) { if (!isCustom) m_clsFieldDescription = ClsFieldDescription; else { int shouldNotBeHere = 0; shouldNotBeHere++; m_clsFieldDescription = new Sfm2Xml.ClsCustomFieldDescription("", "", /*System.Guid.NewGuid(),*/ 0, false, 0, m_marker, " ", "string", this.m_langDescriptor, this.IsAbbrvField, this.m_FWDestination); } } m_isBeginMarker = false; }
public CFChanges TESTTESTTEST(Sfm2Xml.LexImportCustomField oldlexCustomField) { bool containsKEY = m_LexFields.ContainsCustomField(oldlexCustomField.CustomKey); if (!containsKEY) { return CFChanges.DoesntExist; } else { Sfm2Xml.ILexImportCustomField curICF = m_LexFields.GetCustomField(oldlexCustomField); if (curICF.CRC == oldlexCustomField.CRC) { return CFChanges.NoChanges; } else { return CFChanges.ASD; } } }
public void Initialize(FdoCache cache, IHelpTopicProvider helpTopicProvider, IApp app, NotebookImportWiz.RnSfMarker rsf, Sfm2Xml.SfmFile sfmFile, Dictionary<int, string> mapFlidName, IVwStylesheet stylesheet, Mediator mediator) { m_cache = cache; m_helpTopicProvider = helpTopicProvider; m_app = app; m_rsfm = rsf; m_sfmFile = sfmFile; m_stylesheet = stylesheet; m_mdc = cache.ServiceLocator.GetInstance<IFwMetaDataCacheManaged>(); m_mediator = mediator; m_mapFlidName = mapFlidName; FillInFieldList(); FillInContentsPane(rsf, sfmFile); SetSubControl(); }
//private bool m_excluded; //private string m_fwID; public void AddLexImportCustomField(Sfm2Xml.ILexImportField field, string uiClass) { AddLexImportField(field); (m_LexImportField as Sfm2Xml.ILexImportCustomField).UIClass = uiClass; Sfm2Xml.ClsFieldDescription xyz = LexImportField.ClsFieldDescriptionWith(ClsFieldDescription); m_clsFieldDescription = xyz; }
/// <summary> /// Store the data for a multi-paragraph text field. /// </summary> private void SetTextContent(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { // REVIEW: SHOULD WE WORRY ABOUT EMBEDDED CHAR MAPPINGS THAT CHANGE THE WRITING SYSTEM // WHEN IT COMES TO ENCODING CONVERSION??? ReconvertEncodedDataIfNeeded(field, rsf.m_txo.m_wsId); List<string> rgsParas = SplitIntoParagraphs(rsf, field); if (rgsParas.Count == 0) return; if (m_factStText == null) m_factStText = m_cache.ServiceLocator.GetInstance<IStTextFactory>(); switch (rsf.m_flid) { case RnGenericRecTags.kflidConclusions: if (rec.ConclusionsOA == null) rec.ConclusionsOA = m_factStText.Create(); StoreTextData(rec.ConclusionsOA, rsf, rgsParas); break; case RnGenericRecTags.kflidDescription: if (rec.DescriptionOA == null) rec.DescriptionOA = m_factStText.Create(); StoreTextData(rec.DescriptionOA, rsf, rgsParas); break; case RnGenericRecTags.kflidDiscussion: if (rec.DiscussionOA == null) rec.DiscussionOA = m_factStText.Create(); StoreTextData(rec.DiscussionOA, rsf, rgsParas); break; case RnGenericRecTags.kflidExternalMaterials: if (rec.ExternalMaterialsOA == null) rec.ExternalMaterialsOA = m_factStText.Create(); StoreTextData(rec.ExternalMaterialsOA, rsf, rgsParas); break; case RnGenericRecTags.kflidFurtherQuestions: if (rec.FurtherQuestionsOA == null) rec.FurtherQuestionsOA = m_factStText.Create(); StoreTextData(rec.FurtherQuestionsOA, rsf, rgsParas); break; case RnGenericRecTags.kflidHypothesis: if (rec.HypothesisOA == null) rec.HypothesisOA = m_factStText.Create(); StoreTextData(rec.HypothesisOA, rsf, rgsParas); break; case RnGenericRecTags.kflidPersonalNotes: if (rec.PersonalNotesOA == null) rec.PersonalNotesOA = m_factStText.Create(); StoreTextData(rec.PersonalNotesOA, rsf, rgsParas); break; case RnGenericRecTags.kflidResearchPlan: if (rec.ResearchPlanOA == null) rec.ResearchPlanOA = m_factStText.Create(); StoreTextData(rec.ResearchPlanOA, rsf, rgsParas); break; case RnGenericRecTags.kflidVersionHistory: if (rec.VersionHistoryOA == null) rec.VersionHistoryOA = m_factStText.Create(); StoreTextData(rec.VersionHistoryOA, rsf, rgsParas); break; default: // Handle custom field (don't think any can exist yet, but...) Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); IStText text; int hvo = m_cache.DomainDataByFlid.get_ObjectProp(rec.Hvo, rsf.m_flid); if (hvo == 0) { text = m_factStText.Create(); m_cache.DomainDataByFlid.SetObjProp(rec.Hvo, rsf.m_flid, text.Hvo); } else { if (m_repoStText == null) m_repoStText = m_cache.ServiceLocator.GetInstance<IStTextRepository>(); text = m_repoStText.GetObject(hvo); } StoreTextData(text, rsf, rgsParas); break; } }
private List<string> SplitIntoParagraphs(RnSfMarker rsf, Sfm2Xml.SfmField field) { List<string> rgsParas = new List<string>(); List<string> rgsLines = SplitIntoLines(field.Data); StringBuilder sbPara = new StringBuilder(); for (int i = 0; i < rgsLines.Count; ++i) { bool fIndented = false; string sLine = rgsLines[i]; if (sLine.Length > 0) fIndented = Char.IsWhiteSpace(sLine[0]); sLine = sLine.TrimStart(); if (rsf.m_txo.m_fStartParaNewLine) { if (sLine.Length > 0) rgsParas.Add(sLine); continue; } if (sLine.Length == 0) { if (sbPara.Length > 0 && (rsf.m_txo.m_fStartParaBlankLine || rsf.m_txo.m_fStartParaShortLine)) { rgsParas.Add(sbPara.ToString()); sbPara.Remove(0, sbPara.Length); } continue; } if (rsf.m_txo.m_fStartParaIndented && fIndented) { if (rsf.m_txo.m_fStartParaBlankLine && sbPara.Length > 0) { rgsParas.Add(sbPara.ToString()); sbPara.Remove(0, sbPara.Length); } sbPara.Append(sLine); continue; } if (rsf.m_txo.m_fStartParaShortLine && sLine.Length < rsf.m_txo.m_cchShortLim) { if (sbPara.Length > 0) sbPara.Append(" "); sbPara.Append(sLine); rgsParas.Add(sbPara.ToString()); sbPara.Remove(0, sbPara.Length); continue; } if (sbPara.Length > 0) sbPara.Append(" "); sbPara.Append(sLine); } if (sbPara.Length > 0) { rgsParas.Add(sbPara.ToString()); sbPara.Remove(0, sbPara.Length); } return rgsParas; }
public void UpdateLexFieldsWithCustomFields(Sfm2Xml.ILexImportFields customFields) { m_LexFields = customFields as Sfm2Xml.LexImportFields; string sRootDir = m_rootDir; // SIL.Utils.FwDirectoryFinder.CodeDirectory; if (!sRootDir.EndsWith(Path.DirectorySeparatorChar.ToString())) sRootDir += Path.DirectorySeparatorChar; string sImportFields = sRootDir + String.Format("Language Explorer{0}Import{0}ImportFields.xml", Path.DirectorySeparatorChar); m_LexFields.ReadLexImportFields(sImportFields); }
private void InitWithIFM( Sfm2Xml.ClsInFieldMarker ifm) { HideOKBtn(); // see if it needs to be visible or not m_inlineMarker = ifm; }
public bool AddInLineMarker(Sfm2Xml.ClsInFieldMarker marker, bool makeSelected) { CheckDisposed(); // now put the info into the list view string[] columns = new string[] {marker.Begin, marker.EndListToString(), marker.Language, marker.Style}; ListViewItem lvItem = new ListViewItem(columns); //marker.OptionsString()}); lvItem.Tag = marker; lvItem.Selected = makeSelected; lvItem.Focused = makeSelected; if (listViewCharMappings.Items.Contains(lvItem) == false) { listViewCharMappings.Items.Add(lvItem); if (marker.Ignore) // this is ignored { // lvItem.UseItemStyleForSubItems = false; // lvItem.SubItems[1].ForeColor = Color.Blue; lvItem.ForeColor = Color.Blue; // show as ignored } } else { Debug.WriteLine("Found a matching IFM entry, not adding again. (" + marker.ElementName + ")"); } return true; }
/// Step 7 is where the Feasability check is preformed. This is the /// finial step before letting the whole import process run it's course. #region Step 7 event handlers and routines // private void AddSectionComment(string comment, ref System.Text.StringBuilder XMLText) // { // string nl = System.Environment.NewLine; // string dashes = "====================================================================="; // XMLText.Append(nl + "<!--" + dashes + nl); // XMLText.Append(comment + nl); // XMLText.Append(dashes + " -->" + nl); // } /// <summary> /// This method will check for changes to the data due to a differnt version: for example /// 4.5.1 relase to 6.0 relase. /// This should be improved in the future to pass in the previous version so more concrete /// decisions can be made. /// </summary> /// <param name="data"></param> private void CheckForMapFileVersionChanges(Sfm2Xml.FieldHierarchyInfo data) { int topAnalysisWs = m_cache.DefaultAnalWs; string topAnalysis = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(topAnalysisWs); if (Sfm2Xml.STATICS.MapFileVersion == "6.0") { // LT-9936 // For old lexical relation and cross reference fields - use top analysis ws for the // funcWS instead of letting it default to "". switch (data.FwDestID) { case "lxrel": // Lexical relation case "cref": // Cross reference fields case "funold": // Old lexical function field if (data.RefFuncWS == string.Empty) data.RefFuncWS = topAnalysis; // dont let it be blank for old map files break; case "subd": // Subentry (Derivation) case "subc": // Subentry (Compound) case "subi": // Subentry (Idiom) case "subk": // Subentry (Keyterm Phrase) case "subpd": // Subentry (Phrasal Verb) case "subs": // Subentry (Saying) data.FwDestID_Changed = "sub"; // new value data.RefFuncWS = topAnalysis; break; case "vard": // Variant (Dialectal) case "varf": // Variant (Free) case "vari": // Variant (Inflectional) case "vars": // Variant (Spelling) //case "varc": // Variant (Comment) data.FwDestID_Changed = "var"; // new value data.RefFuncWS = topAnalysis; break; } // if (data.FwDestID == "lxrel" || data.FwDestID == "cref") // { // if (data.RefFuncWS == string.Empty) // data.RefFuncWS = topAnalysis; // dont let it be blank for old map files // } } // data.RefFuncWS = info.RefFieldWS; // data.RefFunc = info.RefField; }
private void FillLexicalRefTypesCombo(Sfm2Xml.LexImportField field) { if (m_LastSelectedField == field) return; // don't change m_LastSelectedField = field; // fill the combo box with current values in the DB cbFunction.Items.Clear(); m_htNameToAbbr.Clear(); if (field.IsRef) { lblFunction.Text = LexTextControls.ksLexicalRelationType; int pos = -1; //string abbr, name, reverseAbbr, reverseName; rbAbbrAbbr.Checked = true; rbAbbrName.Checked = false; if (field.ID == "cref" || field.ID == "scref") { // Fill the comboBox with the names (and where appropriate, reverse names) of the // LexRefType objects which map to entries. foreach (ILexRefType lrt in m_cache.LanguageProject.LexDbOA.ReferencesOA.PossibilitiesOS) { switch (lrt.MappingType) { case (int)MappingTypes.kmtEntryCollection: case (int)MappingTypes.kmtEntryPair: case (int)MappingTypes.kmtEntrySequence: case (int)MappingTypes.kmtEntryOrSenseCollection: case (int)MappingTypes.kmtEntryOrSensePair: case (int)MappingTypes.kmtEntryOrSenseSequence: //abbr = lrt.Abbreviation.AnalysisDefaultWritingSystem.Text; //name = lrt.Name.AnalysisDefaultWritingSystem.Text; //AddAbbrAndNameInfo(abbr, name, "en", null, null, null); AddAbbrAndNameInfo(lrt.Abbreviation, lrt.Name, null, null); break; case (int)MappingTypes.kmtEntryAsymmetricPair: case (int)MappingTypes.kmtEntryTree: case (int)MappingTypes.kmtEntryOrSenseAsymmetricPair: case (int)MappingTypes.kmtEntryOrSenseTree: //abbr = lrt.Abbreviation.AnalysisDefaultWritingSystem.Text; //name = lrt.Name.AnalysisDefaultWritingSystem.Text; //reverseAbbr = lrt.ReverseAbbreviation.AnalysisDefaultWritingSystem.Text; //reverseName = lrt.ReverseName.AnalysisDefaultWritingSystem.Text; //AddAbbrAndNameInfo(abbr, name, "en", reverseAbbr, reverseName, "en"); AddAbbrAndNameInfo(lrt.Abbreviation, lrt.Name, lrt.ReverseAbbreviation, lrt.ReverseName); break; } } } else if (field.ID == "lxrel") { // Fill the comboBox with the names (and where appropriate, reverse names) of the // LexRefType objects which map to senses. foreach (ILexRefType lrt in m_cache.LanguageProject.LexDbOA.ReferencesOA.PossibilitiesOS) { switch (lrt.MappingType) { case (int)MappingTypes.kmtSenseCollection: case (int)MappingTypes.kmtSensePair: case (int)MappingTypes.kmtSenseSequence: case (int)MappingTypes.kmtEntryOrSenseCollection: case (int)MappingTypes.kmtEntryOrSensePair: case (int)MappingTypes.kmtEntryOrSenseSequence: //abbr = lrt.Abbreviation.AnalysisDefaultWritingSystem.Text; //name = lrt.Name.AnalysisDefaultWritingSystem.Text; //AddAbbrAndNameInfo(abbr, name, "en", null, null, null); AddAbbrAndNameInfo(lrt.Abbreviation, lrt.Name, null, null); break; case (int)MappingTypes.kmtSenseAsymmetricPair: case (int)MappingTypes.kmtSenseTree: case (int)MappingTypes.kmtEntryOrSenseAsymmetricPair: case (int)MappingTypes.kmtEntryOrSenseTree: //abbr = lrt.Abbreviation.AnalysisDefaultWritingSystem.Text; //name = lrt.Name.AnalysisDefaultWritingSystem.Text; //reverseAbbr = lrt.ReverseAbbreviation.AnalysisDefaultWritingSystem.Text; //reverseName = lrt.ReverseName.AnalysisDefaultWritingSystem.Text; //AddAbbrAndNameInfo(abbr, name, "en", reverseAbbr, reverseName, "en"); AddAbbrAndNameInfo(lrt.Abbreviation, lrt.Name, lrt.ReverseAbbreviation, lrt.ReverseName); break; } } } else if (field.ID == "var") { lblFunction.Text = LexTextControls.ksVariantType; // fill the comboBox with the names of the Variant objects foreach (var let in m_cache.LangProject.LexDbOA.VariantEntryTypesOA.ReallyReallyAllPossibilities) { AddAbbrAndNameInfo(let.Abbreviation, let.Name, null, null); //int wsActual; //ITsString tssAnal = let.Name. GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsActual); //name = tssAnal.Text; //string ws = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsActual); //AddAbbrAndNameInfo(null, name, ws, null, null, null); } } else if (field.ID == "sub") { lblFunction.Text = LexTextControls.ksComplexFormType; // fill the comboBox with the names of the Variant objects foreach (var let in m_cache.LangProject.LexDbOA.ComplexEntryTypesOA.ReallyReallyAllPossibilities) { AddAbbrAndNameInfo(let.Abbreviation, let.Name, null, null); //int wsActual; //ITsString tssAnal = let.Name.GetAlternativeOrBestTss(m_cache.DefaultAnalWs, out wsActual); //name = tssAnal.Text; //string ws = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsActual); //AddAbbrAndNameInfo(null, name, ws, null, null, null); } } // now select the one with the correct abbreviation pos = -1; if (m_refFuncString.Length > 0) pos = cbFunction.FindString(m_refFuncString); if (pos >= 0) { cbFunction.SelectedIndex = pos; cbFunction.Text = cbFunction.SelectedItem as string; } } // The radio buttons for abbr and Name are set when initialized - so don't reset them }
public void Init(Sfm2Xml.ClsInFieldMarker ifm, Hashtable uiLangsHT, FdoCache cache) { CheckDisposed(); if (ifm == null) ifm = new Sfm2Xml.ClsInFieldMarker(); m_inlineMarker = ifm; m_uiLangs = uiLangsHT; m_cache = cache; // ==================================================================== // Set the language descriptor combo box. This is a DropList so that // the entered text can't be different from the contents of the list. // If the user wants a new language descriptor they have to add one. cbLangDesc.Items.Add(NoChange); cbLangDesc.SelectedItem = NoChange; foreach (DictionaryEntry lang in m_uiLangs) { Sfm2Xml.LanguageInfoUI langInfo = lang.Value as Sfm2Xml.LanguageInfoUI; // make sure there is only one entry for each writing system (especially 'ignore') if (cbLangDesc.FindStringExact(langInfo.ToString()) < 0) { cbLangDesc.Items.Add(langInfo); if (langInfo.FwName == m_inlineMarker.Language) cbLangDesc.SelectedItem = langInfo; } } InitializeStylesComboBox(); HideOKBtn(); // see if it needs to be visible or not }
/// <summary> /// Store a value for either a simple formatted string or a multilingual string. /// </summary> private void SetStringValue(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field, CellarPropertyType cpt) { // REVIEW: SHOULD WE WORRY ABOUT EMBEDDED CHAR MAPPINGS THAT CHANGE THE WRITING SYSTEM // WHEN IT COMES TO ENCODING CONVERSION??? ReconvertEncodedDataIfNeeded(field, rsf.m_sto.m_wsId); ITsString tss = MakeTsString(field.Data, rsf.m_sto.m_ws.Handle); switch (rsf.m_flid) { case RnGenericRecTags.kflidTitle: rec.Title = tss; break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); switch (cpt) { case CellarPropertyType.MultiString: case CellarPropertyType.MultiUnicode: m_cache.DomainDataByFlid.SetMultiStringAlt(rec.Hvo, rsf.m_flid, rsf.m_sto.m_ws.Handle, tss); break; case CellarPropertyType.String: m_cache.DomainDataByFlid.SetString(rec.Hvo, rsf.m_flid, tss); break; } break; } }
/// <summary> /// read the passed in list of additional fields (should be custom ones) /// and add them to the list of fields. /// </summary> /// <param name="customFields"></param> /// <returns></returns> public bool AddCustomImportFields(Sfm2Xml.ILexImportFields customFields) { //foreach (LexImportField field in customFields) //{ //} return true; }
private void ReconvertEncodedDataIfNeeded(Sfm2Xml.SfmField field, string sWs) { if (String.IsNullOrEmpty(sWs)) sWs = m_cache.WritingSystemFactory.GetStrFromWs(m_cache.DefaultAnalWs); if (!String.IsNullOrEmpty(sWs)) { EncConverterChoice ecc; if (m_mapWsEncConv.TryGetValue(sWs, out ecc)) { if (ecc.Converter != null) field.Data = ecc.Converter.ConvertToUnicode(field.RawData); } } if (field.ErrorConvertingData) { LogMessage( String.Format(LexTextControls.ksEncodingConversionProblem, field.Marker), field.LineNumber); } }
private void FillInContentsPane(NotebookImportWiz.RnSfMarker rsf, Sfm2Xml.SfmFile sfmFile) { m_groupContents.Text = String.Format(m_sContentsGroupFmt, rsf.m_sMkr); m_lvContents.Items.Clear(); Set<string> setContents = new Set<string>(); foreach (Sfm2Xml.SfmField field in m_sfmFile.Lines) { if (field.Marker == rsf.m_sMkr) { if (!setContents.Contains(field.Data)) { setContents.Add(field.Data); ListViewItem lvi = new ListViewItem(String.Format("\\{0} {1}", field.Marker, String.IsNullOrEmpty(field.Data) ? String.Empty : field.Data)); m_lvContents.Items.Add(lvi); } } } m_lblContents.Text = String.Format(m_sContentsLabelFmt, rsf.m_sMkr, sfmFile.GetSFMCount(rsf.m_sMkr), m_lvContents.Items.Count); }
/// <summary> /// Store a value with a "kcptGenDate" type value. Try to handle incomplete data if /// possible, since this value is typed by hand. The user may have substituted /// question marks for the date, and may even the month. /// </summary> private void SetGenDateValue(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { string sData = field.Data.Trim(); if (sData.Length == 0) return; // nothing we can do without data! GenDate gdt; if (!TryParseGenDate(sData, rsf.m_dto.m_rgsFmt, out gdt)) { LogMessage(String.Format(LexTextControls.ksCannotParseGenericDate, sData, field.Marker), field.LineNumber); return; } switch (rsf.m_flid) { case RnGenericRecTags.kflidDateOfEvent: rec.DateOfEvent = gdt; break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); // There's no way to pass a GenDate item into a custom field! break; } }
public void AddLexImportField(Sfm2Xml.ILexImportField field) { m_LexImportField = field as Sfm2Xml.LexImportField; if (field != null) m_clsFieldDescription.Type = field.DataType; else m_clsFieldDescription.Type = "string"; //if (m_LexImportField != null) // m_clsFieldDescription = LexImportField.ClsFieldDescriptionWith(ClsFieldDescription); //m_clsFieldDescription = xyz; // m_clsFieldDescription = null; // force recreation with new data // m_clsFieldDescription = ClsFieldDescription; // need to use lex field data type }
/// <summary> /// Store a value with a "kcptTime" type value. These are less forgiving than those with /// "kcptGenDate" values, because they are generally created by a computer program instead /// of typed by a user. /// </summary> private void SetDateTimeValue(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { string sData = field.Data.Trim(); if (sData.Length == 0) return; // nothing we can do without data! DateTime dt; if (!DateTime.TryParseExact(sData, rsf.m_dto.m_rgsFmt.ToArray(), null, DateTimeStyles.None, out dt)) { LogMessage(String.Format(LexTextControls.ksCannotParseDateTime, field.Data, field.Marker), field.LineNumber); return; } switch (rsf.m_flid) { case RnGenericRecTags.kflidDateCreated: rec.DateCreated = dt; break; case RnGenericRecTags.kflidDateModified: rec.DateModified = dt; break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); SilTime.SetTimeProperty(m_cache.DomainDataByFlid, rec.Hvo, rsf.m_flid, dt); break; } }
public void UpdateLexFieldsWithCustomFields(Sfm2Xml.ILexImportFields customFields) { m_LexFields = customFields as Sfm2Xml.LexImportFields; string sRootDir = m_rootDir; // SIL.FieldWorks.Common.Utils.DirectoryFinder.FWCodeDirectory; if (!sRootDir.EndsWith("\\")) sRootDir += "\\"; string sImportFields = sRootDir + "Language Explorer\\Import\\ImportFields.xml"; m_LexFields.ReadLexImportFields(sImportFields); }
/// <summary> /// Store the information needed to make any cross reference links after all the records /// have been created. /// </summary> private void StoreLinkData(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { if (String.IsNullOrEmpty(field.Data)) return; var pend = new PendingLink { Marker = rsf, Field = field, Record = rec }; m_pendingLinks.Add(pend); }
public bool IsValidCustomField(Sfm2Xml.LexImportCustomField lexCustomField) { // first make sure if it's a custom field, that the field exists in the database if (m_LexFields.ContainsCustomField(lexCustomField.CustomKey)) return true; return false; }
/// <summary> /// Store the data for a field that contains one or more references to a possibility /// list. /// </summary> private void SetListReference(IRnGenericRec rec, RnSfMarker rsf, Sfm2Xml.SfmField field) { ReconvertEncodedDataIfNeeded(field, rsf.m_tlo.m_wsId); string sData = field.Data; if (sData == null) sData = String.Empty; sData = ApplyChanges(rsf, sData); sData = sData.Trim(); List<string> rgsData = null; if (sData.Length > 0) { if (rsf.m_tlo.m_fHaveMulti) { rgsData = SplitString(sData, rsf.m_tlo.m_rgsDelimMulti); rgsData = PruneEmptyStrings(rgsData); } else { rgsData = new List<string> {sData}; } } if ((rgsData == null || rgsData.Count == 0) && rsf.m_tlo.m_default == null) { return; } if (rgsData == null) rgsData = new List<string>(); rgsData = ApplyBeforeAndBetween(rsf, rgsData); if (rgsData.Count == 0) rgsData.Add(String.Empty); foreach (var sItem in rgsData) { switch (rsf.m_flid) { case RnGenericRecTags.kflidAnthroCodes: if (!StoreAnthroCode(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidConfidence: if (!StoreConfidence(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidLocations: if (!StoreLocation(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidPhraseTags: if (!StorePhraseTag(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidResearchers: if (!StoreResearcher(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidRestrictions: if (!StoreRestriction(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidSources: if (!StoreSource(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidStatus: if (!StoreStatus(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidTimeOfEvent: if (!StoreTimeOfEvent(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidType: if (!StoreRecType(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; case RnGenericRecTags.kflidParticipants: if (!StoreParticipant(rec, rsf, sItem)) LogCannotFindListItem(sItem, field); break; default: // must be a custom field. Debug.Assert(rsf.m_flid >= (RnGenericRecTags.kClassId * 1000) + 500); Guid guidList = m_mdc.GetFieldListRoot(rsf.m_flid); if (guidList != Guid.Empty) { if (m_repoList == null) m_repoList = m_cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>(); ICmPossibilityList list = m_repoList.GetObject(guidList); if (list != null) { if (!StoreCustomListRefItem(rec, rsf, sItem, list)) LogCannotFindListItem(sItem, field); break; } } LogMessage( String.Format(LexTextControls.ksCannotFindPossibilityList, field.Marker), field.LineNumber); return; } } }
/// <summary> /// Output a count for each sfm in the input file, sorted by sfm. /// </summary> /// <param name="sfmSorted"></param> /// <param name="w"></param> /// <param name="reader"></param> static void OutputSfmInfo(System.Collections.ArrayList sfmSorted, BinaryWriter w, Sfm2Xml.SfmFileReaderEx reader) { StringBuilder sb = new StringBuilder(); sb.Append(nl); sb.AppendFormat("{0}{1}{2,5}{3,9}{4}{5}{6}", "SfmCount info:", nl, "SFM", "count", nl, "--------------", nl); w.Write(MakeBytes(sb.ToString())); byte[] a = new byte[] { (byte)'\t', (byte)'=', (byte)' ' }; foreach (string sfm in sfmSorted) { w.Write(MakeBytes(sfm)); w.Write(a); w.Write(MakeBytes((reader.GetSFMCount(sfm)).ToString("N0"))); w.Write(m_NL); } }
private void LogCannotFindListItem(string sItem, Sfm2Xml.SfmField field) { LogMessage( String.Format(LexTextControls.ksCannotFindMatchingListItem, sItem, field.Marker), field.LineNumber); }
/// <summary> /// Remove the byte counts of the SFMs from the bytecount array. That way the bytecount info /// will be from the data only. /// </summary> /// <param name="byteCounts">int counts for each byte index</param> /// <param name="sfms">list of sfms</param> /// <param name="reader">actual reader object</param> static void RemoveSFMsFromByteCount(ref int[] byteCounts, System.Collections.ArrayList sfms, Sfm2Xml.SfmFileReaderEx reader) { foreach (string sfm in sfms) { int count = reader.GetSFMCount(sfm); byteCounts[(byte)'\\'] -= count; byte[] bytes = MakeBytes(sfm); foreach (byte b in bytes) { byteCounts[b] -= count; } } }
public LexImportWizardMarker(Sfm2Xml.ILexImportFields fwFields) { // // Required for Windows Form Designer support // InitializeComponent(); AccessibleName = GetType().Name; InitBottomPanel(); tvDestination.BeginUpdate(); tvDestination.Nodes.Clear(); foreach(string className in fwFields.Classes) { TreeNode tnode = new TreeNode( String.Format("({0})", className)); // tnode.Tag = className; foreach (Sfm2Xml.LexImportField field in fwFields.FieldsForClass(className)) { TreeNode cnode = new TreeNode(field.UIName); cnode.Tag = field; tnode.Nodes.Add(cnode); } tvDestination.Nodes.Add(tnode); } tvDestination.ExpandAll(); tvDestination.EndUpdate(); helpProvider = new HelpProvider(); }