/// <summary> /// /// </summary> /// <param name="output"></param> /// <param name="labelName"></param> /// <param name="fieldName"></param> /// <param name="customFieldId"></param> /// <param name="className"></param> protected void ReplaceParamsInAttributes(XmlNode output, string labelName, string fieldName, int customFieldId, string className) { SetupWsParams(output, customFieldId); ReplaceSubstringInAttr visitorFn = new ReplaceSubstringInAttr("$fieldName", fieldName); XmlUtils.VisitAttributes(output, visitorFn); AppendClassAttribute(output, fieldName, className); ReplaceSubstringInAttr visitorLab = new ReplaceSubstringInAttr("$label", labelName); XmlUtils.VisitAttributes(output, visitorLab); if (customFieldId != 0 && m_mdc is IFwMetaDataCacheManaged) { IFwMetaDataCacheManaged mdc = m_mdc as IFwMetaDataCacheManaged; if (mdc.IsCustom(customFieldId) && mdc.GetDstClsId(customFieldId) != 0) { Guid guidList = (m_mdc as IFwMetaDataCacheManaged).GetFieldListRoot(customFieldId); if (guidList != Guid.Empty) { string targetList; ICmPossibilityList list = m_cache.ServiceLocator.GetInstance <ICmPossibilityListRepository>().GetObject(guidList); if (list.Owner != null) { targetList = String.Format("{0}.{1}", list.Owner.ClassName, mdc.GetFieldName(list.OwningFlid)); } else { targetList = String.Format("unowned.{0}", guidList.ToString()); } ReplaceSubstringInAttr visitorTarg = new ReplaceSubstringInAttr("$targetList", targetList); XmlUtils.VisitAttributes(output, visitorTarg); } } } }
/// <summary> /// Gets the "Id" of the destination class that corresponds to this field. This is the "Id" /// of the class that is either owned or referred to by another class. ///</summary> /// <param name='luFlid'>Field identification number. In the database, this corresponds to the "Id" /// column in the Field$ table. </param> /// <returns>Points to the output "Id" of the class that contains the field. In /// the database, this corresponds to the DstCls column in the Field$ table. If it is NULL, /// (ULONG)1 is returned, which indicates the field holds a basic value instead of an /// object.</returns> public virtual int GetDstClsId(int luFlid) { return(m_metaDataCache.GetDstClsId(luFlid)); }
private void SetSubControl() { m_groupOptions.Controls.Clear(); if (m_rsfm.m_flid == 0) { m_groupOptions.Text = LexTextControls.ksDiscardedField; m_groupOptions.Controls.Add(m_discardOpt); m_discardOpt.Location = m_locSubCtrl; return; } CellarPropertyType cpt = (CellarPropertyType)m_mdc.GetFieldType(m_rsfm.m_flid); int clidDst = -1; switch (cpt) { case CellarPropertyType.ReferenceAtomic: case CellarPropertyType.ReferenceCollection: case CellarPropertyType.ReferenceSequence: clidDst = m_mdc.GetDstClsId(m_rsfm.m_flid); switch (clidDst) { case RnGenericRecTags.kClassId: m_groupOptions.Text = LexTextControls.ksRnLinkFieldOptions; m_groupOptions.Controls.Add(m_linkOpt); m_linkOpt.Location = m_locSubCtrl; break; case CrossReferenceTags.kClassId: case ReminderTags.kClassId: throw new NotImplementedException(LexTextControls.ksUnimplementedField); default: int clidBase = clidDst; while (clidBase != 0 && clidBase != CmPossibilityTags.kClassId) { clidBase = m_mdc.GetBaseClsId(clidBase); } if (clidBase == CmPossibilityTags.kClassId) { m_groupOptions.Text = LexTextControls.ksListRefImportOptions; m_groupOptions.Controls.Add(m_listOpt); m_listOpt.Location = m_locSubCtrl; m_listOpt.Initialize(m_cache, m_helpTopicProvider, m_app, m_stylesheet, m_rsfm, cpt); break; } throw new ArgumentException(LexTextControls.ksInvalidField); } break; case CellarPropertyType.OwningAtomic: case CellarPropertyType.OwningCollection: case CellarPropertyType.OwningSequence: clidDst = m_mdc.GetDstClsId(m_rsfm.m_flid); switch (clidDst) { case StTextTags.kClassId: Debug.Assert(cpt == CellarPropertyType.OwningAtomic); m_groupOptions.Text = LexTextControls.ksTextImportOptions; m_groupOptions.Controls.Add(m_textOpt); m_textOpt.Location = m_locSubCtrl; m_textOpt.Initialize(m_cache, m_helpTopicProvider, m_app, m_stylesheet, m_rsfm); break; case RnRoledParticTags.kClassId: m_groupOptions.Text = LexTextControls.ksListRefImportOptions; m_groupOptions.Controls.Add(m_listOpt); m_listOpt.Location = m_locSubCtrl; m_listOpt.Initialize(m_cache, m_helpTopicProvider, m_app, m_stylesheet, m_rsfm, cpt); break; case RnGenericRecTags.kClassId: throw new NotImplementedException(LexTextControls.ksUnimplementedField); default: throw new ArgumentException(LexTextControls.ksInvalidField); } break; case CellarPropertyType.MultiString: case CellarPropertyType.MultiUnicode: m_groupOptions.Text = LexTextControls.ksMultiStringImportOptions; m_groupOptions.Controls.Add(m_stringOpt); m_stringOpt.Location = m_locSubCtrl; m_stringOpt.Initialize(m_cache, m_helpTopicProvider, m_app, m_stylesheet, m_rsfm); break; case CellarPropertyType.String: m_groupOptions.Text = LexTextControls.ksStringImportOptions; m_groupOptions.Controls.Add(m_stringOpt); m_stringOpt.Location = m_locSubCtrl; m_stringOpt.Initialize(m_cache, m_helpTopicProvider, m_app, m_stylesheet, m_rsfm); break; case CellarPropertyType.GenDate: m_groupOptions.Text = LexTextControls.ksGenDateImportOptions; m_groupOptions.Controls.Add(m_dateOpt); m_dateOpt.Location = m_locSubCtrl; m_dateOpt.Initialize(m_cache, m_helpTopicProvider, m_rsfm, true); break; case CellarPropertyType.Time: m_groupOptions.Text = LexTextControls.ksDateTimeImportOptions; m_groupOptions.Controls.Add(m_dateOpt); m_dateOpt.Location = m_locSubCtrl; m_dateOpt.Initialize(m_cache, m_helpTopicProvider, m_rsfm, false); break; case CellarPropertyType.Unicode: case CellarPropertyType.Binary: case CellarPropertyType.Image: case CellarPropertyType.Boolean: case CellarPropertyType.Float: case CellarPropertyType.Guid: case CellarPropertyType.Integer: case CellarPropertyType.Numeric: throw new ArgumentException(LexTextControls.ksInvalidField); } }
private void ExportCustomFields(TextWriter writer, IRnGenericRec record) { ISilDataAccessManaged sda = m_cache.DomainDataByFlid as ISilDataAccessManaged; Debug.Assert(sda != null); foreach (int flid in m_customFlids) { string fieldName = m_mdc.GetFieldName(flid); bool fHandled = false; ITsString tss; string s; CellarPropertyType cpt = (CellarPropertyType)m_mdc.GetFieldType(flid); switch (cpt) { case CellarPropertyType.Boolean: break; case CellarPropertyType.Integer: break; case CellarPropertyType.Numeric: break; case CellarPropertyType.Float: break; case CellarPropertyType.Time: break; case CellarPropertyType.Guid: break; case CellarPropertyType.Image: case CellarPropertyType.Binary: break; case CellarPropertyType.GenDate: break; case CellarPropertyType.String: tss = sda.get_StringProp(record.Hvo, flid); if (tss != null && tss.Text != null) { ExportString(writer, tss, fieldName); } fHandled = true; break; case CellarPropertyType.MultiString: case CellarPropertyType.MultiUnicode: ITsMultiString tms = sda.get_MultiStringProp(record.Hvo, flid); int cch = 0; for (int i = 0; i < tms.StringCount; ++i) { int ws; tss = tms.GetStringFromIndex(i, out ws); cch += tss.Length; if (cch > 0) { break; } } if (cch > 0) { writer.WriteLine("<Field name=\"{0}\" type=\"MultiString\">", fieldName); for (int i = 0; i < tms.StringCount; ++i) { int ws; tss = tms.GetStringFromIndex(i, out ws); if (tss != null && tss.Length > 0) { if (cpt == CellarPropertyType.MultiString) { writer.WriteLine(TsStringUtils.GetXmlRep(tss, m_cache.WritingSystemFactory, ws, true)); } else { writer.WriteLine("<AUni ws=\"{0}\">{1}</AUni>", m_cache.WritingSystemFactory.GetStrFromWs(ws), XmlUtils.MakeSafeXml(tss.Text)); } } } writer.WriteLine("</Field>"); } fHandled = true; break; case CellarPropertyType.Unicode: break; case CellarPropertyType.ReferenceAtomic: case CellarPropertyType.ReferenceCollection: case CellarPropertyType.ReferenceSequence: { int destClid = m_mdc.GetDstClsId(flid); List <int> rghvoDest = new List <int>(); if (cpt == CellarPropertyType.ReferenceAtomic) { int hvo = sda.get_ObjectProp(record.Hvo, flid); if (hvo != 0) { if (destClid == CmPossibilityTags.kClassId) { ICmPossibility poss = PossibilityRepository.GetObject(hvo); ExportAtomicReference(writer, poss, fieldName, "CmPossibility"); fHandled = true; } else { rghvoDest.Add(hvo); } } else { fHandled = true; } } else { int[] hvos = sda.VecProp(record.Hvo, flid); if (hvos.Length > 0) { if (destClid == CmPossibilityTags.kClassId) { List <ICmPossibility> collection = new List <ICmPossibility>(); foreach (int hvo in hvos) { collection.Add(PossibilityRepository.GetObject(hvo)); } ExportReferenceList(writer, collection, fieldName, "CmPossibility", cpt); fHandled = true; } else { rghvoDest.AddRange(hvos); } } else { fHandled = true; } } if (rghvoDest.Count > 0) { } } break; case CellarPropertyType.OwningAtomic: case CellarPropertyType.OwningCollection: case CellarPropertyType.OwningSequence: { int destClid = m_mdc.GetDstClsId(flid); List <int> rghvoDest = new List <int>(); if (cpt == CellarPropertyType.OwningAtomic) { int hvo = sda.get_ObjectProp(record.Hvo, flid); if (hvo != 0) { if (destClid == StTextTags.kClassId) { IStText text = StTextRepository.GetObject(hvo); ExportStText(writer, text, fieldName); fHandled = true; } else { rghvoDest.Add(hvo); } } else { fHandled = true; } } else { } } break; } if (!fHandled) { } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Refresh the lv (list view) control based on the tv (tree view) control. /// </summary> /// ------------------------------------------------------------------------------------ public void AfterSelectMethod() { string holdType = "", holdSig = ""; int clid = (int)m_tvModel.SelectedNode.Tag; // Get flids. int[] uFlids = m_mdc.GetFields(clid, true, (int)CellarPropertyTypeFilter.All); List <ListViewItem> list = new List <ListViewItem>(); for (int i = uFlids.Length - 1; i >= 0; --i) { int flid = uFlids[i]; if (flid == 0) { continue; // Keep looking for suitable flids lower in the array. } else { if (FDOBrowserForm.m_virtualFlag == false && (flid >= 20000000 && flid < 30000000)) { continue; } else { string className = m_mdc.GetOwnClsName(flid); ListViewItem lvi = new ListViewItem(className); list.Add(lvi); // flid lvi.SubItems.Add(flid.ToString()); // field name string fieldname = m_mdc.GetFieldName(flid); lvi.SubItems.Add(fieldname); int flidType = m_mdc.GetFieldType(flid); string type = "Not recognized"; string signature = "Not recognized"; int dstClid; switch (flidType) { // Basic data types. case (int)CellarPropertyType.Boolean: type = "Basic"; signature = "Boolean"; break; case (int)CellarPropertyType.Integer: type = "Basic"; signature = "Integer"; break; case (int)CellarPropertyType.Numeric: type = "Basic"; signature = "Numeric"; break; case (int)CellarPropertyType.Float: type = "Basic"; signature = "Float"; break; case (int)CellarPropertyType.Time: type = "Basic"; signature = "Time"; break; case (int)CellarPropertyType.Guid: type = "Basic"; signature = "Guid"; break; case (int)CellarPropertyType.Image: type = "Basic"; signature = "Image"; break; case (int)CellarPropertyType.GenDate: type = "Basic"; signature = "GenDate"; break; case (int)CellarPropertyType.Binary: type = "Basic"; signature = "Binary"; break; case (int)CellarPropertyType.String: type = "Basic"; signature = "String"; break; case (int)CellarPropertyType.MultiString: type = "Basic"; signature = "MultiString"; break; case (int)CellarPropertyType.Unicode: type = "Basic"; signature = "Unicode"; break; case (int)CellarPropertyType.MultiUnicode: type = "Basic"; signature = "MultiUnicode"; break; // CmObjects. case (int)CellarPropertyType.OwningAtomic: type = "OA"; dstClid = m_mdc.GetDstClsId(flid); signature = m_mdc.GetClassName(dstClid); break; case (int)CellarPropertyType.ReferenceAtomic: type = "RA"; dstClid = m_mdc.GetDstClsId(flid); signature = m_mdc.GetClassName(dstClid); break; case (int)CellarPropertyType.OwningCollection: type = "OC"; dstClid = m_mdc.GetDstClsId(flid); signature = m_mdc.GetClassName(dstClid); break; case (int)CellarPropertyType.ReferenceCollection: type = "RC"; dstClid = m_mdc.GetDstClsId(flid); signature = m_mdc.GetClassName(dstClid); break; case (int)CellarPropertyType.OwningSequence: type = "OS"; dstClid = m_mdc.GetDstClsId(flid); signature = m_mdc.GetClassName(dstClid); break; case (int)CellarPropertyType.ReferenceSequence: type = "RS"; dstClid = m_mdc.GetDstClsId(flid); signature = m_mdc.GetClassName(dstClid); break; } if (flid >= 20000000 && flid < 30000000) { type += " (Virt)"; } else if (flid > 10000000) { type += " (BackRef)"; } lvi.SubItems.Add(type); lvi.SubItems.Add(signature); } } } // Add custom fields if (FDOBrowserForm.CFields != null && FDOBrowserForm.CFields.Count > 0) { foreach (CustomFields cf in FDOBrowserForm.CFields) { if (clid == cf.ClassID) { string clasName = m_mdc.GetClassName(cf.ClassID); ListViewItem lv = new ListViewItem(clasName); list.Add(lv); // classname //lv.SubItems.Add(clasName); // flid lv.SubItems.Add(cf.FieldID.ToString()); // field name lv.SubItems.Add(cf.Name); // Type switch (cf.Type) { case "ICmPossibility": holdType = "Custom - RA"; break; case "FdoReferenceCollection<ICmPossibility>": holdType = "Custom - RC"; break; case "IStText": holdType = "Custom - OA"; break; default: holdType = "Custom"; break; } lv.SubItems.Add(holdType); // Signature switch (cf.Type) { case "ITsString": holdSig = "String"; break; case "System.Int32": holdSig = "Integer"; break; case "SIL.FieldWorks.Common.FwUtils.GenDate": holdSig = "GenDate"; break; case "ICmPossibility": holdSig = "CmPossibility"; break; case "FdoReferenceCollection<ICmPossibility>": holdSig = "CmPossibility"; break; case "IStText": holdSig = "StText"; break; default: MessageBox.Show(String.Format("Type not recognized for signature for custom model fields. Type: {0}", cf.Type)); break; } lv.SubItems.Add(holdSig); } } } LoadListView(list); }