Beispiel #1
0
        /// <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);
                    }
                }
            }
        }
Beispiel #2
0
        private static Dictionary <string, List <PropertyInfo> > CacheBasicProperties(IFwMetaDataCacheManaged mdc)
        {
            var cachedBasicProperties = new Dictionary <string, List <PropertyInfo> >();

            foreach (var classId in mdc.GetClassIds())
            {
                var className = mdc.GetClassName(classId);
                List <PropertyInfo> basicProps;
                if (!cachedBasicProperties.TryGetValue(className, out basicProps))
                {
                    basicProps = new List <PropertyInfo>();
                    cachedBasicProperties.Add(className, basicProps);
                }
                basicProps.AddRange(mdc.GetFields(classId, className != "CmObject", (int)CellarPropertyTypeFilter.AllBasic).Select(propId => new PropertyInfo
                {
                    m_propertyName = mdc.GetFieldName(propId),
                    m_propertyType = (CellarPropertyType)mdc.GetFieldType(propId),
                    m_isCustom     = mdc.IsCustom(propId),
                    m_isVirtual    = mdc.get_IsVirtual(propId)
                }));
                if (basicProps.Count == 0)
                {
                    cachedBasicProperties.Remove(className);
                }
            }
            return(cachedBasicProperties);
        }
Beispiel #3
0
        private void m_btnAddCustom_Click(object sender, EventArgs e)
        {
            // What we'd like to do is the following bit of code, but we can't due to
            // circular dependencies that would be introduced.  We could possibly move
            // the dialog to another assembly/dll, but that would require reworking a
            // fair number of strings that have been converted to resources.
            //using (var dlg = new AddCustomFieldDlg(m_mediator, AddCustomFieldDlg.LocationType.Notebook))
            //    dlg.ShowDialog();
            System.Type typeFound;
            MethodInfo  mi = XmlUtils.GetStaticMethod("xWorks.dll",
                                                      "SIL.FieldWorks.XWorks.AddCustomFieldDlg",
                                                      "ShowNotebookCustomFieldDlg",
                                                      "AnthroFieldMappingDlg.m_btnAddCustom_Click()", out typeFound);

            if (mi != null)
            {
                var parameters = new object[2];
                parameters[0] = m_mediator;
                parameters[1] = m_propertyTable;
                mi.Invoke(typeFound,
                          System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public |
                          System.Reflection.BindingFlags.NonPublic, null, parameters, null);
                // Now, clean up our map of possible field targets and reload the field combo list.
                List <int> delFields = new List <int>();
                foreach (int key in m_mapFlidName.Keys)
                {
                    if (!m_mdc.FieldExists(key))
                    {
                        delFields.Add(key);
                    }
                }
                foreach (int flid in delFields)
                {
                    m_mapFlidName.Remove(flid);
                }
                foreach (int flid in m_mdc.GetFields(RnGenericRecTags.kClassId, false, (int)CellarPropertyTypeFilter.All))
                {
                    if (m_mapFlidName.ContainsKey(flid))
                    {
                        continue;
                    }
                    if (m_mdc.IsCustom(flid))
                    {
                        string name = m_mdc.GetFieldName(flid);
                        m_mapFlidName.Add(flid, name);
                    }
                }
                FillInFieldList();
            }
            else
            {
            }
        }
Beispiel #4
0
        private void ExportRecords(TextWriter writer, IProgress progress)
        {
            m_mdc = m_cache.ServiceLocator.GetInstance <IFwMetaDataCacheManaged>();
            foreach (int flid in m_mdc.GetFields(RnGenericRecTags.kClassId, true,
                                                 (int)CellarPropertyTypeFilter.All))
            {
                if (m_mdc.IsCustom(flid))
                {
                    m_customFlids.Add(flid);
                }
            }


            writer.WriteLine("<Entries docRightToLeft=\"{0}\">",
                             m_fRightToLeft ? "true" : "false");
            foreach (var record in m_cache.LangProject.ResearchNotebookOA.RecordsOC)
            {
                ExportRecord(writer, record, 0);
                progress.Step(1);
            }
            writer.WriteLine("</Entries>");
        }
Beispiel #5
0
        /// <summary>
        /// Get the field values as a dict, keyed by field ID, for any CmObject.
        /// </summary>
        /// <returns>A dictionary with integer field ID mapped to values.</returns>
        /// <param name="cache">LCM cache the object lives in.</param>
        /// <param name="obj">Object whose fields we're getting.</param>
        protected IDictionary <int, object> GetFieldValues(LcmCache cache, ICmObject obj)
        {
            IFwMetaDataCacheManaged mdc  = cache.ServiceLocator.MetaDataCache;
            ISilDataAccess          data = cache.DomainDataByFlid;

            int[] fieldIds    = mdc.GetFields(obj.ClassID, false, (int)CellarPropertyTypeFilter.All);
            var   fieldValues = new Dictionary <int, object>();

            foreach (int flid in fieldIds)
            {
                if (mdc.IsCustom(flid))
                {
                    continue;                     // Custom fields get processed differently
                }
                string fieldName = mdc.GetFieldNameOrNull(flid);
                if (String.IsNullOrEmpty(fieldName))
                {
                    continue;
                }
                object value = data.get_Prop(obj.Hvo, flid);
                fieldValues[flid] = value;
            }
            return(fieldValues);
        }
Beispiel #6
0
 public virtual bool IsCustom(int flid)
 {
     return(m_metaDataCache.IsCustom(flid));
 }
Beispiel #7
0
        protected IDictionary <string, Tuple <string, string> > GetLcmDifferences(
            LcmCache cache,
            IDictionary <int, object> fieldValuesBeforeTest,
            IDictionary <int, object> fieldValuesAfterTest
            )
        {
            IFwMetaDataCacheManaged mdc         = cache.ServiceLocator.MetaDataCache;
            var fieldNamesThatShouldBeDifferent = new string[] {
            };
            var fieldNamesToSkip  = new string[] {
                // These are ComObject or SIL.FieldWorks.LCM.DomainImpl.VirtualStringAccessor instances, which we can't compare
                //				"FullReferenceName",
                //				"HeadWord",
                //				"HeadWordRef",
                //				"HeadWordReversal",
                //				"LexSenseOutline",
                //				"MLHeadWord",
                //				"MLOwnerOutlineName",
                //				"ReversalEntriesBulkText",
                //				"ReversalName",
            };
            var differencesByName = new Dictionary <string, Tuple <string, string> >();          // Tuple of (before, after)

            foreach (int flid in fieldValuesBeforeTest.Keys)
            {
                if (mdc.IsCustom(flid))
                {
                    continue;
                }
                string fieldName = mdc.GetFieldNameOrNull(flid);
                if (String.IsNullOrEmpty(fieldName))
                {
                    continue;
                }
                object valueBeforeTest = fieldValuesBeforeTest[flid];
                object valueAfterTest  = fieldValuesAfterTest[flid];

                // Some fields, like DateModified, *should* be different
                if (fieldNamesThatShouldBeDifferent.Contains(fieldName) ||
                    fieldNamesToSkip.Contains(fieldName))
                {
                    continue;
                }

                if ((valueAfterTest == null && valueBeforeTest == null))
                {
                    continue;
                }
                if (mdc.GetFieldType(flid) == (int)CellarPropertyType.String)
                {
                    // Might not need this, see below
                }

                // Arrays need to be compared specially
                Type valueType = valueBeforeTest.GetType();
                if (valueType == typeof(int[]))
                {
                    int[] before = valueBeforeTest as int[];
                    int[] after  = valueAfterTest as int[];
                    if (before.SequenceEqual(after))
                    {
                        continue;
                    }
                }
                // So do TsString objects
                var tsStringBeforeTest = valueBeforeTest as ITsString;
                var tsStringAfterTest  = valueAfterTest as ITsString;
                if (tsStringBeforeTest != null && tsStringAfterTest != null)
                {
                    TsStringDiffInfo diffInfo = TsStringUtils.GetDiffsInTsStrings(tsStringBeforeTest, tsStringAfterTest);
                    if (diffInfo != null)
                    {
                        differencesByName[fieldName] = new Tuple <string, string>(
                            ConvertLcmToMongoTsStrings.TextFromTsString(tsStringBeforeTest, _cache.WritingSystemFactory),
                            ConvertLcmToMongoTsStrings.TextFromTsString(tsStringAfterTest, _cache.WritingSystemFactory)
                            );
                    }
                    continue;
                }
                // So do multistrings
                var multiStrBeforeTest = valueBeforeTest as IMultiAccessorBase;
                var multiStrAfterTest  = valueAfterTest as IMultiAccessorBase;
                if (multiStrBeforeTest != null && multiStrAfterTest != null)
                {
                    int[] wsIds;
                    try
                    {
                        wsIds = multiStrBeforeTest.AvailableWritingSystemIds;
                    }
                    catch (NotImplementedException)
                    {
                        // This is a VirtualStringAccessor, which we can't easily compare. Punt.
                        continue;
                    }
                    foreach (int wsId in wsIds)
                    {
                        string beforeStr = ConvertLcmToMongoTsStrings.TextFromTsString(multiStrBeforeTest.get_String(wsId), _cache.WritingSystemFactory);
                        string afterStr  = ConvertLcmToMongoTsStrings.TextFromTsString(multiStrAfterTest.get_String(wsId), _cache.WritingSystemFactory);
                        if (beforeStr != afterStr)
                        {
                            string wsStr = cache.WritingSystemFactory.GetStrFromWs(wsId);
                            differencesByName[fieldName + ":" + wsStr] = new Tuple <string, string>(beforeStr, afterStr);
                        }
                    }
                    continue;
                }
                if (valueBeforeTest.Equals(valueAfterTest))
                {
                    continue;
                }
                //				if (Repr(valueBeforeTest) == Repr(valueAfterTest))
                //					continue; // This should catch TsStrings
                // If we get this far, they're different
                var diff = new Tuple <string, string>(Repr(fieldValuesBeforeTest[flid]), Repr(fieldValuesAfterTest[flid]));
                differencesByName[fieldName] = diff;
            }
            return(differencesByName);
        }
		private static Dictionary<string, List<PropertyInfo>> CacheBasicProperties(IFwMetaDataCacheManaged mdc)
		{
			var cachedBasicProperties = new Dictionary<string, List<PropertyInfo>>();
			foreach (var classId in mdc.GetClassIds())
			{
				var className = mdc.GetClassName(classId);
				List<PropertyInfo> basicProps;
				if (!cachedBasicProperties.TryGetValue(className, out basicProps))
				{
					basicProps = new List<PropertyInfo>();
					cachedBasicProperties.Add(className, basicProps);
				}
				basicProps.AddRange(mdc.GetFields(classId, className != "CmObject", (int)CellarPropertyTypeFilter.AllBasic).Select(propId => new PropertyInfo
					{
						m_propertyName = mdc.GetFieldName(propId),
						m_propertyType = (CellarPropertyType)mdc.GetFieldType(propId),
						m_isCustom = mdc.IsCustom(propId),
						m_isVirtual = mdc.get_IsVirtual(propId)
					}));
				if (basicProps.Count == 0)
					cachedBasicProperties.Remove(className);
			}
			return cachedBasicProperties;
		}
Beispiel #9
0
		private void VerifyCmPossibilityCustomFields(ILexEntry entry)
		{
			m_mdc = Cache.MetaDataCacheAccessor as IFwMetaDataCacheManaged;
			var repo = Cache.ServiceLocator.GetInstance<ICmPossibilityListRepository>();

			//Store mapping between Possibility List names and their guids. This is used to verify that
			//the custom list has stored the correct guid for the list when imported.
			m_customListNamesAndGuids.Add(RangeNames.sSemanticDomainListOA, Cache.LanguageProject.SemanticDomainListOA.Guid);
			foreach (ICmPossibilityList list in repo.AllInstances())
			{
				if (list.OwningFlid == 0) //then it is a custom list
				{
					if (!m_customListNamesAndGuids.ContainsKey(list.Name.BestAnalysisVernacularAlternative.Text))
					{
						m_customListNamesAndGuids.Add(list.Name.BestAnalysisVernacularAlternative.Text, list.Guid);
					}
				}
			}

			//Verify each custom field
			foreach (var flid in m_mdc.GetFields(entry.ClassID, true, (int)CellarPropertyTypeFilter.All))
			{
				if (!m_mdc.IsCustom(flid))
					continue;
				var fieldName = m_mdc.GetFieldName(flid);

				if (fieldName == "CustomFld ListSingle")
				{
					VerifyCustomListToPossList(flid, CellarPropertyType.ReferenceAtomic, RangeNames.sSemanticDomainListOA);
				}
				else if (fieldName == "CustomFld ListMulti")
				{
					VerifyCustomListToPossList(flid, CellarPropertyType.ReferenceCollection, RangeNames.sSemanticDomainListOA);
				}
				else if (fieldName == "CustomFld CmPossibilityCustomList")
				{
					VerifyCustomListToPossList(flid, CellarPropertyType.ReferenceAtomic, "CustomCmPossibiltyList");
				}
				else if (fieldName == "CustomFld CustomList2")
				{
					VerifyCustomListToPossList(flid, CellarPropertyType.ReferenceAtomic, "CustomList Number2 ");
				}
			}
		}
        private void ExportRecords(TextWriter writer, IProgress progress)
        {
            m_mdc = m_cache.ServiceLocator.GetInstance<IFwMetaDataCacheManaged>();
            foreach (int flid in m_mdc.GetFields(RnGenericRecTags.kClassId, true,
                (int)CellarPropertyTypeFilter.All))
            {
                if (m_mdc.IsCustom(flid))
                    m_customFlids.Add(flid);
            }

            writer.WriteLine("<Entries docRightToLeft=\"{0}\">",
                m_fRightToLeft ? "true" : "false");
            foreach (var record in m_cache.LangProject.ResearchNotebookOA.RecordsOC)
            {
                ExportRecord(writer, record, 0);
                progress.Step(1);
            }
            writer.WriteLine("</Entries>");
        }