internal static void NestContext(string linguisticsBaseDir, IDictionary <string, XElement> wellUsedElements, IDictionary <string, SortedDictionary <string, byte[]> > classData, Dictionary <string, string> guidToClassMapping) { var discourseDir = Path.Combine(linguisticsBaseDir, SharedConstants.DiscourseRootFolder); if (!Directory.Exists(discourseDir)) { Directory.CreateDirectory(discourseDir); } var sortedInstanceData = classData["DsDiscourseData"]; if (sortedInstanceData.Count == 0) { return; } // 'discourseElement' is owned by LangProj in DsDiscourseData prop (OA). var discourseElement = Utilities.CreateFromBytes(sortedInstanceData.Values.First()); // Nest the entire object, and then pull out the owned stuff, and relocate them, as needed. CmObjectNestingService.NestObject( false, discourseElement, classData, guidToClassMapping); var listElement = discourseElement.Element(SharedConstants.ConstChartTempl); if (listElement != null) { // NB: Write list file, but only if discourseElement has the list. FileWriterService.WriteNestedFile(Path.Combine(discourseDir, SharedConstants.ConstChartTemplFilename), listElement); listElement.RemoveNodes(); } listElement = discourseElement.Element(SharedConstants.ChartMarkers); if (listElement != null) { // NB: Write list file, but only if discourseElement has the list. FileWriterService.WriteNestedFile(Path.Combine(discourseDir, SharedConstants.ChartMarkersFilename), listElement); listElement.RemoveNodes(); } // <owning num="2" id="Charts" card="col" sig="DsChart"> [Abstract. Owns nothing special, but is subclass of CmMajorObject.] // Disposition: Write in main discourse file as the repeating series of objects, BUT use the abstract class for the repeating element, since Gordon sees new subclasses of it coming along. // NB: We will just let the normal nesting code work over discourseElement, // which will put in the actual subclass name as the element tag. // So, we'll just intercept them out of the owning prop elemtent (if any exist), and patch them up here. // NB: If there are no such charts, then do the usual of making one with the empty guid for its Id. var root = new XElement(SharedConstants.DiscourseRootFolder); var header = new XElement(SharedConstants.Header); root.Add(header); header.Add(discourseElement); // Remove child objsur node from owning LangProg var langProjElement = wellUsedElements[SharedConstants.LangProject]; langProjElement.Element("DiscourseData").RemoveNodes(); var chartElements = discourseElement.Element("Charts"); if (chartElements != null && chartElements.HasElements) { foreach (var chartElement in chartElements.Elements()) { BaseDomainServices.ReplaceElementNameWithAndAddClassAttribute(SharedConstants.DsChart, chartElement); // It is already nested. root.Add(chartElement); } chartElements.RemoveNodes(); } FileWriterService.WriteNestedFile(Path.Combine(discourseDir, SharedConstants.DiscourseChartFilename), root); }
internal static void NestContext(string generalBaseDir, IDictionary <string, XElement> wellUsedElements, IDictionary <string, SortedDictionary <string, byte[]> > classData, Dictionary <string, string> guidToClassMapping) { var langProjElement = wellUsedElements[SharedConstants.LangProject]; // LP AnnotationDefs (OA-CmPossibilityList). AnnotationDefs.list] FileWriterService.WriteNestedListFileIfItExists(classData, guidToClassMapping, langProjElement, SharedConstants.AnnotationDefs, Path.Combine(generalBaseDir, SharedConstants.AnnotationDefsListFilename)); // LP Styles (OC-StStyle) is used by everyone, but Scripture, so they go here. BaseDomainServices.NestStylesPropertyElement( classData, guidToClassMapping, langProjElement.Element(SharedConstants.Styles), Path.Combine(generalBaseDir, SharedConstants.FLExStylesFilename)); // LP Filters (OC) can go into one filters file here. (FLExFilters.filter: new ext) var owningPropElement = langProjElement.Element(SharedConstants.Filters); if (owningPropElement != null && owningPropElement.HasElements) { var root = new XElement(SharedConstants.Filters); foreach (var filterObjSurElement in owningPropElement.Elements().ToList()) { var filterGuid = filterObjSurElement.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant(); var className = guidToClassMapping[filterGuid]; var filterElement = Utilities.CreateFromBytes(classData[className][filterGuid]); CmObjectNestingService.NestObject(false, filterElement, classData, guidToClassMapping); root.Add(filterElement); } FileWriterService.WriteNestedFile(Path.Combine(generalBaseDir, SharedConstants.FLExFiltersFilename), root); owningPropElement.RemoveNodes(); } // LP Annotations (OC). Who still uses them? If all else fails, or they are used by several BCs, then store them in one file here. // [FLExAnnotations.annotation: new ext] // OJO! Sig is "CmAnnotation", which is abtract class, so handle like in Discourse-land. owningPropElement = langProjElement.Element(SharedConstants.Annotations); if (owningPropElement != null && owningPropElement.HasElements) { var root = new XElement(SharedConstants.Annotations); foreach (var annotationObjSurElement in owningPropElement.Elements().ToList()) { var annotationGuid = annotationObjSurElement.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant(); var className = guidToClassMapping[annotationGuid]; var annotationElement = Utilities.CreateFromBytes(classData[className][annotationGuid]); CmObjectNestingService.NestObject(false, annotationElement, classData, guidToClassMapping); BaseDomainServices.ReplaceElementNameWithAndAddClassAttribute(SharedConstants.CmAnnotation, annotationElement); root.Add(annotationElement); } FileWriterService.WriteNestedFile(Path.Combine(generalBaseDir, SharedConstants.FLExAnnotationsFilename), root); owningPropElement.RemoveNodes(); } // Some CmPicture instances may not be owned. var rootElement = new XElement(SharedConstants.Pictures); var unownedPictures = classData[SharedConstants.CmPicture].Values.Where(listElement => XmlUtils.GetAttributes(listElement, new HashSet <string> { SharedConstants.OwnerGuid })[SharedConstants.OwnerGuid] == null).ToList(); foreach (var unownedPictureBytes in unownedPictures) { var element = Utilities.CreateFromBytes(unownedPictureBytes); CmObjectNestingService.NestObject( false, element, classData, guidToClassMapping); rootElement.Add(element); } FileWriterService.WriteNestedFile(Path.Combine(generalBaseDir, SharedConstants.FLExUnownedPicturesFilename), rootElement); // No VirtualOrdering instances are owned. if (MetadataCache.MdCache.ModelVersion > MetadataCache.StartingModelVersion) { rootElement = new XElement(SharedConstants.VirtualOrderings); foreach (var element in classData[SharedConstants.VirtualOrdering].Values.ToArray().Select(virtualOrderingBytes => Utilities.CreateFromBytes(virtualOrderingBytes))) { CmObjectNestingService.NestObject( false, element, classData, guidToClassMapping); rootElement.Add(element); } FileWriterService.WriteNestedFile(Path.Combine(generalBaseDir, SharedConstants.FLExVirtualOrderingFilename), rootElement); } // Yippee!! Write LP here. :-) [LanguageProject.langproj; new ext] CmObjectNestingService.NestObject(false, langProjElement, classData, guidToClassMapping); FileWriterService.WriteNestedFile(Path.Combine(generalBaseDir, SharedConstants.LanguageProjectFilename), new XElement(SharedConstants.LanguageProject, langProjElement)); }