public IAimObjectReference ReadXmlAnnotationFromString(AimVersion aimVersion, string xmlString)
        {
            IAimObjectReference aimObjectReference = null;

            switch (aimVersion)
            {
            case AimVersion.AimVersion3:
            {
                using (var aim3NativeHelper = new Aim3.Aim3NativeXmlHelper())
                {
                    aimObjectReference = aim3NativeHelper.ReadAnnotationFromString(xmlString);
                }
            }
            break;

            case AimVersion.AimVersion4:
            {
                using (var aim4NativeHelper = new Aim4.Aim4NativeXmlHelper())
                {
                    aimObjectReference = aim4NativeHelper.ReadAnnotationFromString(xmlString);
                }
            }
            break;

            default:
                Debug.Assert(false, "AimManager.ReadXmlAnnotationFromString: Unexpected AIM version");
                break;
            }

            return(aimObjectReference);
        }
        public static List <IDataProvider> GetDataProviders(IAimObjectReference aimObjectReference)
        {
            if (aimObjectReference == null)
            {
                return(null);
            }

            List <IDataProvider> dataProviders = null;

            switch (aimObjectReference.AimVersion)
            {
            case AimVersion.AimVersion3:
                return(new List <IDataProvider> {
                    new Aim3.DataProvider(((Aim3.Aim3ObjectReference)aimObjectReference).AimAnnotation)
                });

            case AimVersion.AimVersion4:
                var aim4AnnotationCollection      = ((Aim4.Aim4ObjectReference)aimObjectReference).AnnotationCollection;
                var aim4ImageAnnotationCollection = aim4AnnotationCollection as aim4_dotnet.ImageAnnotationCollection;
                if (aim4ImageAnnotationCollection != null)
                {
                    dataProviders = aim4ImageAnnotationCollection.ImageAnnotations.Select(
                        imageAnnotation => new Aim4.DataProvider(imageAnnotation, aim4ImageAnnotationCollection.Person, aim4ImageAnnotationCollection.User))
                                    .Cast <IDataProvider>().ToList();
                }
                else
                {
                    var aim4AnnotationOfAnnotationCollection = aim4AnnotationCollection as aim4_dotnet.AnnotationOfAnnotationCollection;
                    if (aim4AnnotationOfAnnotationCollection != null)
                    {
                        dataProviders = aim4AnnotationOfAnnotationCollection.AnnotationOfAnnotations.Select(
                            annOfAnnotation => new Aim4.DataProvider(annOfAnnotation, null, aim4AnnotationOfAnnotationCollection.User)).Cast <IDataProvider>().ToList();
                    }
                }
                break;

            default:
                Debug.Assert(false, "Cannot get converter for unknown annotation version: " + aimObjectReference.AimVersion);
                break;
            }

            return(dataProviders);
        }
        public string WriteAnnotationToTempFile(IAimObjectReference aimObjectReference)
        {
            Platform.CheckForNullReference(aimObjectReference, "aimObjectReference");

            if (aimObjectReference.AimVersion != AimVersion.AimVersion4)
            {
                return(null);
            }

            var aim4ObjectReference = aimObjectReference as Aim4ObjectReference;

            if (aim4ObjectReference == null)
            {
                throw new AimManagerException("AIM4 helper cannot operate on non-AIM4 objects");
            }

            string tempFileName = System.IO.Path.GetTempFileName();

            try
            {
                Model.WriteAnnotationCollectionToFile(aim4ObjectReference.AnnotationCollection, tempFileName);
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Error, "Failed to save annotation to temp file.", ex);
                try
                {
                    System.IO.File.Delete(tempFileName);
                }
                catch
                {
                }
                throw new AimManagerException("Failed to save annotation to a temp file", ex);
            }

            return(tempFileName);
        }
        public string WriteAnnotationToTempFile(IAimObjectReference aimObjectReference)
        {
            Platform.CheckForNullReference(aimObjectReference, "aimObjectReference");

            if (aimObjectReference.AimVersion != AimVersion.AimVersion3)
                return null;

            var aim3ObjectReference = aimObjectReference as Aim3ObjectReference;
            if (aim3ObjectReference == null)
                throw new AimManagerException("AIM3 helper cannot operate on non-AIM3 objects");

            string tempFileName = System.IO.Path.GetTempFileName();
            try
            {
                Model.WriteAnnotationToFile(aim3ObjectReference.AimAnnotation, tempFileName);
            }
            catch (Exception ex)
            {
                Platform.Log(LogLevel.Error, "Failed to save annotation to temp file.", ex);
                try
                {
                    System.IO.File.Delete(tempFileName);
                }
                catch
                {
                }
                throw new AimManagerException("Failed to save annotation to a temp file", ex);
            }

            return tempFileName;
        }