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); }
public void OneItemInCollectionRemains() { var collData = new XElement("CollectionProperty", BaseDomainServices.CreateObjSurElement("c1ecf889-e382-11de-8a39-0800200c9a66")); DataSortingService.SortCollectionProperties(collData); Assert.AreEqual("CollectionProperty", collData.Name.LocalName); Assert.AreEqual(1, collData.Elements().Count()); Assert.AreEqual("c1ecf889-e382-11de-8a39-0800200c9a66", collData.Element(SharedConstants.Objsur).Attribute(SharedConstants.GuidStr).Value); }
public void OneItemInMultiRemains() { var multiSomethingData = new XElement("MultiSomething", new XElement("AStr", new XAttribute("ws", "en"))); DataSortingService.SortMultiSomethingProperty(multiSomethingData); Assert.AreEqual("MultiSomething", multiSomethingData.Name.LocalName); Assert.AreEqual(1, multiSomethingData.Elements().Count()); Assert.AreEqual("en", multiSomethingData.Element("AStr").Attribute("ws").Value); }
public void OneItemInCollectionRemains() { var collData = new XElement("CollectionProperty", new XElement("objsur", new XAttribute("guid", "c1ecf889-e382-11de-8a39-0800200c9a66"))); DataSortingService.SortCollectionProperties(collData); Assert.AreEqual("CollectionProperty", collData.Name.LocalName); Assert.AreEqual(1, collData.Elements().Count()); Assert.AreEqual("c1ecf889-e382-11de-8a39-0800200c9a66", collData.Element("objsur").Attribute("guid").Value); }
public void MultiSomethingPropertyIsSorted() { var multiSomethingData = new XElement("MultiSomething", new XElement("AStr", new XAttribute("ws", "es")), new XElement("AStr", new XAttribute("ws", "en"))); DataSortingService.SortMultiSomethingProperty(multiSomethingData); Assert.AreEqual("MultiSomething", multiSomethingData.Name.LocalName); Assert.AreEqual(2, multiSomethingData.Elements().Count()); Assert.AreEqual("en", multiSomethingData.Elements().ElementAt(0).Attribute("ws").Value); Assert.AreEqual("es", multiSomethingData.Elements().ElementAt(1).Attribute("ws").Value); }
public void CollectionPropertyIsSorted() { var collData = new XElement("CollectionProperty", new XElement("objsur", new XAttribute("guid", "c1ecf88b-e382-11de-8a39-0800200c9a66")), new XElement("objsur", new XAttribute("guid", "c1ecf88a-e382-11de-8a39-0800200c9a66"))); DataSortingService.SortCollectionProperties(collData); Assert.AreEqual("CollectionProperty", collData.Name.LocalName); Assert.AreEqual(2, collData.Elements().Count()); Assert.AreEqual("c1ecf88a-e382-11de-8a39-0800200c9a66", collData.Elements().ElementAt(0).Attribute("guid").Value); Assert.AreEqual("c1ecf88b-e382-11de-8a39-0800200c9a66", collData.Elements().ElementAt(1).Attribute("guid").Value); }
public void CollectionPropertyIsSorted() { var collData = new XElement("CollectionProperty", BaseDomainServices.CreateObjSurElement("c1ecf88b-e382-11de-8a39-0800200c9a66"), BaseDomainServices.CreateObjSurElement("c1ecf88a-e382-11de-8a39-0800200c9a66")); DataSortingService.SortCollectionProperties(collData); Assert.AreEqual("CollectionProperty", collData.Name.LocalName); Assert.AreEqual(2, collData.Elements().Count()); Assert.AreEqual("c1ecf88a-e382-11de-8a39-0800200c9a66", collData.Elements().ElementAt(0).Attribute(SharedConstants.GuidStr).Value); Assert.AreEqual("c1ecf88b-e382-11de-8a39-0800200c9a66", collData.Elements().ElementAt(1).Attribute(SharedConstants.GuidStr).Value); }
public void AttributesAreSorted() { var root = new XElement("outer", new XAttribute("outerB", "outerBData"), new XAttribute("outera", "outerAData"), new XElement("inner", new XAttribute("innerB", "innerBData"), new XAttribute("innerA", "innerAData"))); DataSortingService.SortAttributes(root); Assert.AreEqual("outer", root.Name.LocalName); Assert.AreEqual(1, root.Elements().Count()); Assert.AreEqual("outerAData", root.Attributes().ElementAt(0).Value); Assert.AreEqual("outerBData", root.Attributes().ElementAt(1).Value); Assert.AreEqual("innerAData", root.Element("inner").Attributes().ElementAt(0).Value); Assert.AreEqual("innerBData", root.Element("inner").Attributes().ElementAt(1).Value); }
public void SortMainElement() { // Possibilities is an owning seq prop of CmPossibilityList. const string rt = @"<rt ownerguid='fe832a87-4846-4895-9c7e-98c5da0c84ba' class='CmPossibilityList' guid='fb5e83e5-6576-455d-aba0-0b7a722b9b5d'> <Possibilities> <objsur guid='d3c9c406-3ed6-4529-8807-db0864d2df07' t='o' /> <objsur guid='595daad3-9b65-43dc-b60c-705544921559' t='o' /> </Possibilities> <Custom name='CustomProp' /> <DateCreated val='1995-1-25 13:22:29.0' /> <Abbreviation> <AUni ws='es'>Categorías Gramáticas</AUni> <AUni ws='en'>Parts Of Speech</AUni> </Abbreviation> </rt>"; var pl = new Dictionary <string, HashSet <string> >(); var hs = new HashSet <string> { "Possibilities" }; pl.Add("Collections", hs); hs = new HashSet <string> { "Abbreviation" }; pl.Add("MultiAlt", hs); var rtElement = DataSortingService.TestingSortMainElement(rt); Assert.AreEqual(SharedConstants.Class, rtElement.Attributes().ElementAt(0).Name.LocalName); Assert.AreEqual(SharedConstants.GuidStr, rtElement.Attributes().ElementAt(1).Name.LocalName); Assert.AreEqual(SharedConstants.OwnerGuid, rtElement.Attributes().ElementAt(2).Name.LocalName); Assert.AreEqual(4, rtElement.Elements().Count()); var sortedProp = rtElement.Elements().ElementAt(0); Assert.AreEqual("en", sortedProp.Element("AUni").Attribute("ws").Value); // Make sure SortMainRtElement called mutli sorter. Assert.AreEqual("Abbreviation", sortedProp.Name.LocalName); Assert.AreEqual(SharedConstants.Custom, rtElement.Elements().ElementAt(1).Name.LocalName); Assert.AreEqual("DateCreated", rtElement.Elements().ElementAt(2).Name.LocalName); sortedProp = rtElement.Elements().ElementAt(3); //Assert.AreEqual("595daad3-9b65-43dc-b60c-705544921559", sortedProp.Element(SharedConstants.Objsur).Attribute(SharedConstants.GuidStr).Value); // Make sure SortMainRtElement called coll sorter. Assert.AreEqual("Possibilities", sortedProp.Name.LocalName); }
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); }
public void SortEntireFile() { const string rt = @"<?xml version='1.0' encoding='utf-8'?> <languageproject version='7000037'> <AdditionalFields> <CustomField class='WfiWordform' name='Certified' type='Boolean' /> <CustomField class='LexEntry' destclass='7' listRoot='53241fd4-72ae-4082-af55-6b659657083c' name='Tone' type='RC' /> </AdditionalFields> <rt guid='c1ecf88d-e382-11de-8a39-0800200c9a66' class='WfiWordform' /> <rt guid='c1ecf88c-e382-11de-8a39-0800200c9a66' class='LexEntry' /> </languageproject>"; var tempInputPathname = Path.GetTempFileName(); var tempOutputPathname = Path.GetTempFileName(); File.WriteAllText(tempInputPathname, rt); try { using (var writer = XmlWriter.Create(tempOutputPathname)) { writer.WriteStartElement("languageproject"); DataSortingService.SortEntireFile(((IFwMetaDataCacheManagedInternal)m_mdc).GetSortableProperties(), writer, tempInputPathname); writer.WriteEndElement(); writer.Flush(); writer.Close(); } var doc = XDocument.Load(tempOutputPathname); var rtElement = doc.Root; Assert.AreEqual(3, rtElement.Elements().Count()); var sortedProp = rtElement.Elements().ElementAt(0); Assert.AreEqual("LexEntry", sortedProp.Element("CustomField").Attribute("class").Value); // Make sure SortCustomPropertiesRecord was called. sortedProp = rtElement.Elements().ElementAt(1); Assert.AreEqual("c1ecf88c-e382-11de-8a39-0800200c9a66", sortedProp.Attribute("guid").Value); // Make sure SortMainElement was called. } finally { File.Delete(tempInputPathname); File.Delete(tempOutputPathname); } }
public void CustomPropertiesAreSorted() { const string sortedCustomData = @"<AdditionalFields> <CustomField type='Boolean' name='Certified' class='WfiWordform' /> <CustomField destclass='7' listRoot='53241fd4-72ae-4082-af55-6b659657083c' name='Tone' type='RC' class='LexEntry' /> <CustomField wsSelector='-2' type='String' name='Paradigm' class='LexEntry' /> </AdditionalFields>"; var sortedCustomDataElement = DataSortingService.SortCustomPropertiesRecord(sortedCustomData); Assert.AreEqual("AdditionalFields", sortedCustomDataElement.Name.LocalName); Assert.AreEqual(3, sortedCustomDataElement.Elements().Count()); var customData = sortedCustomDataElement.Elements().ElementAt(0); CheckAttributes(customData, new List <string> { "class", "name", "type", "wsSelector" }, new List <string> { "LexEntry", "Paradigm", "String", "-2" }); customData = sortedCustomDataElement.Elements().ElementAt(1); CheckAttributes(customData, new List <string> { "class", "destclass", "listRoot", "name", "type" }, new List <string> { "LexEntry", "7", "53241fd4-72ae-4082-af55-6b659657083c", "Tone", "RC" }); customData = sortedCustomDataElement.Elements().ElementAt(2); CheckAttributes(customData, new List <string> { "class", "name", "type" }, new List <string> { "WfiWordform", "Certified", "Boolean" }); }
public Menu() { linqService = new DataSortingService(); }
public void SortMainElement() { const string rt = @"<rt ownerguid='fe832a87-4846-4895-9c7e-98c5da0c84ba' class='CmPossibilityList' guid='fb5e83e5-6576-455d-aba0-0b7a722b9b5d'> <Possibilities> <objsur guid='d3c9c406-3ed6-4529-8807-db0864d2df07' t='o' /> <objsur guid='595daad3-9b65-43dc-b60c-705544921559' t='o' /> </Possibilities> <Custom name='CustomProp' /> <DateCreated val='1995-1-25 13:22:29.0' /> <Abbreviation> <AUni ws='es'>Categorías Gramáticas</AUni> <AUni ws='en'>Parts Of Speech</AUni> </Abbreviation> </rt>"; var sortableProperties = new Dictionary <string, Dictionary <string, HashSet <string> > >(); var pl = new Dictionary <string, HashSet <string> >(); sortableProperties.Add("CmPossibilityList", pl); var hs = new HashSet <string> { "Possibilities" }; pl.Add("Collections", hs); hs = new HashSet <string> { "Abbreviation" }; pl.Add("MultiAlt", hs); //var tempInputPathname = Path.GetTempFileName(); //var tempOutputPathname = Path.GetTempFileName(); //File.WriteAllText(tempInputPathname, rt); //try //{ // using (var writer = XmlWriter.Create(tempOutputPathname)) // { var rtElement = DataSortingService.SortMainElement(sortableProperties, rt); // writer.Flush(); // writer.Close(); // } // var doc = XDocument.Load(tempOutputPathname); Assert.AreEqual("class", rtElement.Attributes().ElementAt(0).Name.LocalName); Assert.AreEqual("guid", rtElement.Attributes().ElementAt(1).Name.LocalName); Assert.AreEqual("ownerguid", rtElement.Attributes().ElementAt(2).Name.LocalName); Assert.AreEqual(4, rtElement.Elements().Count()); var sortedProp = rtElement.Elements().ElementAt(0); Assert.AreEqual("en", sortedProp.Element("AUni").Attribute("ws").Value); // Make sure SortMainElement called mutli sorter. Assert.AreEqual("Abbreviation", sortedProp.Name.LocalName); Assert.AreEqual("Custom", rtElement.Elements().ElementAt(1).Name.LocalName); Assert.AreEqual("DateCreated", rtElement.Elements().ElementAt(2).Name.LocalName); sortedProp = rtElement.Elements().ElementAt(3); Assert.AreEqual("595daad3-9b65-43dc-b60c-705544921559", sortedProp.Element("objsur").Attribute("guid").Value); // Make sure SortMainElement called coll sorter. Assert.AreEqual("Possibilities", sortedProp.Name.LocalName); //} //finally //{ // //File.Delete(tempInputPathname); // File.Delete(tempOutputPathname); //} }
internal static void FlattenContext( SortedDictionary <string, XElement> highLevelData, SortedDictionary <string, XElement> sortedData, string scriptureBaseDir) { if (!Directory.Exists(scriptureBaseDir)) { return; } // scriptureBaseDir is root/Scripture. var pathname = Path.Combine(scriptureBaseDir, SharedConstants.ScriptureTransFilename); if (!File.Exists(pathname)) { return; // Nobody home. } var doc = XDocument.Load(pathname); var scrElement = doc.Element(SharedConstants.TranslatedScripture).Elements().First(); // Put the NoteCategories list back in the right place. pathname = Path.Combine(scriptureBaseDir, SharedConstants.NoteCategoriesListFilename); if (File.Exists(pathname)) { doc = XDocument.Load(pathname); BaseDomainServices.RestoreElement(pathname, sortedData, scrElement, SharedConstants.NoteCategories, doc.Root.Element(SharedConstants.CmPossibilityList)); } // Owned by LangProj in TranslatedScripture prop. var langProjElement = highLevelData[SharedConstants.LangProject]; CmObjectFlatteningService.FlattenOwnedObject( pathname, sortedData, scrElement, langProjElement.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant(), langProjElement, SharedConstants.TranslatedScripture); // Restore 'ownerguid' to scrElement. // Put the <objsur> elements back into BookAnnotations and ScriptureBooks property elements. // There will always be 66 ScrBookAnnotations instances and they need go in canonical book order. // There may (or may not) be ScrBook instances, but they all go in canonical book order in ScriptureBooks, if present. var booksDir = Path.Combine(scriptureBaseDir, SharedConstants.Books); var sortedFiles = new SortedList <int, string>(66); foreach (var pathnameForAnn in Directory.GetFiles(booksDir, "*." + SharedConstants.bookannotations)) { sortedFiles.Add(Int32.Parse(Path.GetFileNameWithoutExtension(pathnameForAnn)), pathnameForAnn); } var scrElementGuid = scrElement.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant(); var scriptureBooksProperty = scrElement.Element(SharedConstants.ScriptureBooks); foreach (var sortedPathnameKvp in sortedFiles) { var sortedDoc = XDocument.Load(sortedPathnameKvp.Value); var element = sortedDoc.Root.Element(SharedConstants.ScrBookAnnotations); CmObjectFlatteningService.FlattenOwnedObject( sortedPathnameKvp.Value, sortedData, element, scrElementGuid, scrElement, SharedConstants.BookAnnotations); // Restore 'ownerguid' to annotation. // Deal with optional ScrBook var bookPathname = sortedPathnameKvp.Value.Replace(SharedConstants.bookannotations, SharedConstants.book); if (!File.Exists(bookPathname)) { continue; } if (scriptureBooksProperty == null) { scriptureBooksProperty = new XElement(SharedConstants.ScriptureBooks); scrElement.Add(scriptureBooksProperty); // Make sure new property is sorted in correct place. DataSortingService.SortMainRtElement(scrElement); } // Add book <objsur> element to scrElement's ScriptureBooks element. sortedDoc = XDocument.Load(bookPathname); element = sortedDoc.Root.Element(SharedConstants.ScrBook); CmObjectFlatteningService.FlattenOwnedObject( bookPathname, sortedData, element, scrElementGuid, scrElement, SharedConstants.ScriptureBooks); // Restore 'ownerguid' to book. } highLevelData.Add(scrElement.Attribute(SharedConstants.Class).Value, scrElement); }