internal static void WriteCustomPropertyFile(MetadataCache mdc, string pathRoot, string record) { // Theory has it that the fwdata file is all sorted. var cpElement = DataSortingService.SortCustomPropertiesRecord(record); // Not this one, since it leaves out the temporary "key' attr. var cpElement = XElement.Parse(SharedConstants.Utf8.GetString(record)); // Add custom property info to MDC, since it may need to be sorted in the data files. var hasCustomProperties = false; foreach (var propElement in cpElement.Elements(SharedConstants.CustomField)) { hasCustomProperties = true; var className = propElement.Attribute(SharedConstants.Class).Value; var propName = propElement.Attribute(SharedConstants.Name).Value; var typeAttr = propElement.Attribute("type"); var adjustedTypeValue = MetadataCache.AdjustedPropertyType(typeAttr.Value); if (adjustedTypeValue != typeAttr.Value) { typeAttr.Value = adjustedTypeValue; } var customProp = new FdoPropertyInfo( propName, typeAttr.Value, true); mdc.AddCustomPropInfo( className, customProp); } if (hasCustomProperties) { mdc.ResetCaches(); } WriteCustomPropertyFile(Path.Combine(pathRoot, SharedConstants.CustomPropertiesFilename), cpElement); }
/// <summary> /// All callers merging FieldWorks data need to pass 'true', so the MDC will know about any custom properties for their classes. /// /// Non-object callers (currently only the merge of the custom property definitions themselves) shoudl pass 'false'. /// </summary> internal static void Do3WayMerge(MergeOrder mergeOrder, MetadataCache mdc, bool addcustomPropertyInformation) { // Skip doing this for the Custom property definiton file, since it has no real need for the custom prop definitions, // which are being merged (when 'false' is provided). if (addcustomPropertyInformation) mdc.AddCustomPropInfo(mergeOrder); // NB: Must be done before FieldWorksCommonMergeStrategy is created. since it used the MDC. var merger = FieldWorksMergeServices.CreateXmlMergerForFieldWorksData(mergeOrder, mdc); merger.EventListener = mergeOrder.EventListener; var mergeResults = merger.MergeFiles(mergeOrder.pathToOurs, mergeOrder.pathToTheirs, mergeOrder.pathToCommonAncestor); // Write out merged data. FileWriterService.WriteNestedFile(mergeOrder.pathToOurs, mergeResults.MergedNode); }
public void CanAddCustomProperty() { var wordformInfo = _mdc.GetClassInfo("WfiWordform"); Assert.IsNull((from propInfo in wordformInfo.AllProperties where propInfo.PropertyName == "Certified" select propInfo).FirstOrDefault()); _mdc.AddCustomPropInfo("WfiWordform", new FdoPropertyInfo("Certified", DataType.Boolean, true)); _mdc.ResetCaches(); Assert.IsNotNull((from propInfo in wordformInfo.AllProperties where propInfo.PropertyName == "Certified" select propInfo).FirstOrDefault()); }
/// <summary> /// All callers merging FieldWorks data need to pass 'true', so the MDC will know about any custom properties for their classes. /// /// Non-object callers (currently only the merge of the custom property definitions themselves) shoudl pass 'false'. /// </summary> internal static void Do3WayMerge(MergeOrder mergeOrder, MetadataCache mdc, bool addcustomPropertyInformation) { // Skip doing this for the Custom property definiton file, since it has no real need for the custom prop definitions, // which are being merged (when 'false' is provided). if (addcustomPropertyInformation) { mdc.AddCustomPropInfo(mergeOrder); // NB: Must be done before FieldWorksCommonMergeStrategy is created. since it used the MDC. } var merger = FieldWorksMergeServices.CreateXmlMergerForFieldWorksData(mergeOrder, mdc); merger.EventListener = mergeOrder.EventListener; var mergeResults = merger.MergeFiles(mergeOrder.pathToOurs, mergeOrder.pathToTheirs, mergeOrder.pathToCommonAncestor); // Write out merged data. FileWriterService.WriteNestedFile(mergeOrder.pathToOurs, mergeResults.MergedNode); }
private static void TokenizeFile(MetadataCache mdc, string srcFwdataPathname, Dictionary <string, SortedDictionary <string, byte[]> > unownedObjects, Dictionary <string, SortedDictionary <string, byte[]> > classData, Dictionary <string, string> guidToClassMapping) { using (var fastSplitter = new FastXmlElementSplitter(srcFwdataPathname)) { bool foundOptionalFirstElement; // NB: The main input file *does* have to deal with the optional first element. foreach (var record in fastSplitter.GetSecondLevelElementBytes(SharedConstants.AdditionalFieldsTag, SharedConstants.RtTag, out foundOptionalFirstElement)) { if (foundOptionalFirstElement) { // Cache custom prop file for later write. var cpElement = DataSortingService.SortCustomPropertiesRecord(SharedConstants.Utf8.GetString(record)); // Add custom property info to MDC, since it may need to be sorted in the data files. foreach (var propElement in cpElement.Elements(SharedConstants.CustomField)) { var className = propElement.Attribute(SharedConstants.Class).Value; var propName = propElement.Attribute(SharedConstants.Name).Value; var typeAttr = propElement.Attribute("type"); var adjustedTypeValue = MetadataCache.AdjustedPropertyType(typeAttr.Value); if (adjustedTypeValue != typeAttr.Value) { typeAttr.Value = adjustedTypeValue; } var customProp = new FdoPropertyInfo( propName, typeAttr.Value, true); mdc.AddCustomPropInfo( className, customProp); } mdc.ResetCaches(); //optionalFirstElement = Utf8.GetBytes(cpElement.ToString()); foundOptionalFirstElement = false; } else { CacheDataRecord(unownedObjects, classData, guidToClassMapping, record); } } } GC.Collect(2, GCCollectionMode.Forced); }
internal static void WriteCustomPropertyFile(MetadataCache mdc, string pathRoot, string record) { // Theory has it that the fwdata file is all sorted. var cpElement = DataSortingService.SortCustomPropertiesRecord(record); // Not this one, since it leaves out the temporary "key' attr. var cpElement = XElement.Parse(SharedConstants.Utf8.GetString(record)); // Add custom property info to MDC, since it may need to be sorted in the data files. var hasCustomProperties = false; foreach (var propElement in cpElement.Elements(SharedConstants.CustomField)) { hasCustomProperties = true; var className = propElement.Attribute(SharedConstants.Class).Value; var propName = propElement.Attribute(SharedConstants.Name).Value; var typeAttr = propElement.Attribute("type"); var adjustedTypeValue = MetadataCache.AdjustedPropertyType(typeAttr.Value); if (adjustedTypeValue != typeAttr.Value) typeAttr.Value = adjustedTypeValue; var customProp = new FdoPropertyInfo( propName, typeAttr.Value, true); mdc.AddCustomPropInfo( className, customProp); } if (hasCustomProperties) mdc.ResetCaches(); WriteCustomPropertyFile(Path.Combine(pathRoot, SharedConstants.CustomPropertiesFilename), cpElement); }