/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM MUTABLE OBJECT ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <see cref="AnnotableCore" /> class. /// </summary> /// <param name="mutableObject"> The mutable object. </param> /// <param name="parent"> The parent. </param> protected internal AnnotableCore(IAnnotableMutableObject mutableObject, ISdmxStructure parent) : base(mutableObject, parent) { this.annotations = new List<IAnnotation>(); if (mutableObject != null && mutableObject.Annotations != null) { foreach (IAnnotationMutableObject currentAnnotation in mutableObject.Annotations) { this.annotations.Add(new AnnotationObjectCore(currentAnnotation, this)); } } }
/// <summary> /// Retrieve annotations for the specified SDMX <paramref name="annotable"/> object /// </summary> /// <param name="sysId">The artefact primary key value.</param> /// <param name="annotable">The SDMX object.</param> public void RetrieveAnnotations(long sysId, IAnnotableMutableObject annotable) { using (var command = this._annotationCommandBuilder.Build(new PrimaryKeySqlQuery(this._annotationSqlQueryInfo, sysId))) using (var dataReader = this._mappingStoreDb.ExecuteReader(command)) { int annIdIdx = dataReader.GetOrdinal("ANN_ID"); int idIdx = dataReader.GetOrdinal("ID"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); int titleIdx = dataReader.GetOrdinal("TITLE"); int urlIdx = dataReader.GetOrdinal("URL"); IDictionary <long, IAnnotationMutableObject> annotationMap = new Dictionary <long, IAnnotationMutableObject>(); while (dataReader.Read()) { var annId = dataReader.GetInt64(annIdIdx); IAnnotationMutableObject annotation; if (!annotationMap.TryGetValue(annId, out annotation)) { annotation = new AnnotationMutableCore { Id = DataReaderHelper.GetString(dataReader, idIdx), Title = DataReaderHelper.GetString(dataReader, titleIdx), Type = DataReaderHelper.GetString(dataReader, typeIdx) }; var url = DataReaderHelper.GetString(dataReader, urlIdx); Uri uri; if (!string.IsNullOrWhiteSpace(url) && Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri)) { annotation.Uri = uri; } annotable.AddAnnotation(annotation); } var text = DataReaderHelper.GetString(dataReader, txtIdx); if (!string.IsNullOrWhiteSpace(text)) { annotation.AddText(DataReaderHelper.GetString(dataReader, langIdx), text); } } } }
/// <summary> /// Retrieve annotations for the specified SDMX <paramref name="annotable"/> object /// </summary> /// <param name="sysId">The artefact primary key value.</param> /// <param name="annotable">The SDMX object.</param> public void RetrieveAnnotations(long sysId, IAnnotableMutableObject annotable) { using (var command = this._annotationCommandBuilder.Build(new PrimaryKeySqlQuery(this._annotationSqlQueryInfo, sysId))) using (var dataReader = this._mappingStoreDb.ExecuteReader(command)) { int annIdIdx = dataReader.GetOrdinal("ANN_ID"); int idIdx = dataReader.GetOrdinal("ID"); int txtIdx = dataReader.GetOrdinal("TEXT"); int langIdx = dataReader.GetOrdinal("LANGUAGE"); int typeIdx = dataReader.GetOrdinal("TYPE"); int titleIdx = dataReader.GetOrdinal("TITLE"); int urlIdx = dataReader.GetOrdinal("URL"); IDictionary<long, IAnnotationMutableObject> annotationMap = new Dictionary<long, IAnnotationMutableObject>(); while (dataReader.Read()) { var annId = dataReader.GetInt64(annIdIdx); IAnnotationMutableObject annotation; if (!annotationMap.TryGetValue(annId, out annotation)) { annotation = new AnnotationMutableCore { Id = DataReaderHelper.GetString(dataReader, idIdx), Title = DataReaderHelper.GetString(dataReader, titleIdx), Type = DataReaderHelper.GetString(dataReader, typeIdx) }; var url = DataReaderHelper.GetString(dataReader, urlIdx); Uri uri; if (!string.IsNullOrWhiteSpace(url) && Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri)) { annotation.Uri = uri; } annotable.AddAnnotation(annotation); } var text = DataReaderHelper.GetString(dataReader, txtIdx); if (!string.IsNullOrWhiteSpace(text)) { annotation.AddText(DataReaderHelper.GetString(dataReader, langIdx), text); } } } }
private void FillAnnotationID(IAnnotableMutableObject AnnotableObject) { int AnnotationCounter = 0; int MatchingAnnotationCounter = 0; List<String> lIDS = new List<string>(); foreach (IAnnotationMutableObject ann in AnnotableObject.Annotations) { if ((ann.Id == null || ann.Id.Trim() == String.Empty) && ann.Type != "@ORDER@") { ++AnnotationCounter; ann.Id = "@" + AnnotationCounter.ToString() + "@"; } else { if (lIDS.Contains(ann.Id)) { ++MatchingAnnotationCounter; ann.Id = ann.Id + "_" + MatchingAnnotationCounter.ToString(); } } lIDS.Add(ann.Id); } }