/// <summary> /// Reads given AIM XML documents into memory /// </summary> /// <param name="aimVersion">Version of AIM given files are expected to be</param> /// <param name="filePaths">List of AIM XML documents on disk</param> /// <returns>Returns a dictionary of AIM file names mapped to the AIM XML document content</returns> public Dictionary <string, string> ReadXmlAnnotationsToMemory(AimVersion aimVersion, List <string> filePaths) { var uidToAnnotationDictionary = new Dictionary <string, string>(); if (filePaths.IsNullOrEmpty()) { return(uidToAnnotationDictionary); } switch (aimVersion) { case AimVersion.AimVersion3: { using (var aim3NativeHelper = new Aim3.Aim3NativeXmlHelper()) { foreach (var filePath in filePaths) { var annotations = aim3NativeHelper.ReadAnnotationsFromFile(filePath); if (annotations != null) { Debug.Assert(annotations.Count < 2, "AIM 3 XML Annotation document cannot have more than one annotation"); foreach (var annotation in annotations.Where(ann => ann != null)) { var strAnnotation = aim3NativeHelper.WriteXmlAnnotationToString(annotation); if (!String.IsNullOrEmpty(strAnnotation)) { uidToAnnotationDictionary.Add(filePath, strAnnotation); } } } } } } break; case AimVersion.AimVersion4: { using (var aim4NativeHelper = new Aim4.Aim4NativeXmlHelper()) { foreach (var filePath in filePaths) { var annotation = aim4NativeHelper.ReadAnnotationFromFile(filePath); if (annotation != null) { var strAnnotation = aim4NativeHelper.WriteXmlAnnotationToString(annotation); if (!String.IsNullOrEmpty(strAnnotation)) { uidToAnnotationDictionary.Add(filePath, strAnnotation); } } } } } break; default: Debug.Assert(false, "AimManager.ReadXmlAnnotationsToMemory: Unexpected AIM version"); break; } return(uidToAnnotationDictionary); }
public Dictionary <string, string> WriteXmlAnnotationsToString(List <IAimObjectReference> aimAnnotationReferences) { Platform.CheckForNullReference(aimAnnotationReferences, "aimAnnotationReferences"); var writtenAnnotations = new Dictionary <string, string>(); var aim3Annotations = (from aimInstance in aimAnnotationReferences where aimInstance != null && aimInstance.AimVersion == AimVersion.AimVersion3 select((Aim3.Aim3ObjectReference)aimInstance).AimAnnotation).ToList(); if (aim3Annotations.Any()) { using (var aim3NativeHelper = new Aim3.Aim3NativeXmlHelper()) { foreach (var annotation in aim3Annotations) { writtenAnnotations.Add(annotation.UniqueIdentifier, aim3NativeHelper.WriteXmlAnnotationToString(annotation)); } } } var aim4Annotations = (from aimInstance in aimAnnotationReferences where aimInstance != null && aimInstance.AimVersion == AimVersion.AimVersion4 select((Aim4.Aim4ObjectReference)aimInstance).AnnotationCollection).ToList(); if (aim4Annotations.Any()) { using (var aim4NativeHelper = new Aim4.Aim4NativeXmlHelper()) { foreach (var annotation in aim4Annotations) { writtenAnnotations.Add((annotation.UniqueIdentifier ?? Aim4.AimNativeConverter.NewUid).Uid, aim4NativeHelper.WriteXmlAnnotationToString(annotation)); } } } var unknownAimVersion = aimAnnotationReferences.Where(aimInstance => aimInstance != null && aimInstance.AimVersion != AimVersion.AimVersion3 && aimInstance.AimVersion != AimVersion.AimVersion4).ToList(); if (unknownAimVersion.Any()) { Platform.Log(LogLevel.Error, "AimManager.WriteXmlAnnotationsToString: not all annotations can be saved to XML string [" + unknownAimVersion.Count + "]."); throw new NotImplementedException("Cannot save some of the annotations to XML string [" + unknownAimVersion.Count + "]. Unknown version of AIM was encountered?"); } return(writtenAnnotations); }