/// <summary> /// Initializes a new instance of the <see cref="CachedRetrievalManager"/> class. /// </summary> /// <param name="maintainableMutableObjects"> /// The mutable objects. /// </param> /// <param name="retrievalManager"> /// The retrieval manager. /// </param> public CachedRetrievalManager( IEnumerable <IMaintainableMutableObject> maintainableMutableObjects, ISdmxMutableObjectRetrievalManager retrievalManager) { this._retrievalManager = retrievalManager; this._requestToLatestArtefacts = new Dictionary <IStructureReference, IMaintainableMutableObject>(); this._requestToArtefacts = new DictionaryOfSets <IStructureReference, IMaintainableMutableObject>(); if (maintainableMutableObjects != null) { foreach (IMaintainableMutableObject mutableObject in maintainableMutableObjects) { this._requestToArtefacts.Add(_fromMutable.Build(mutableObject), new HashSet <IMaintainableMutableObject> { mutableObject }); } } }
/// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefMutableCore"/> class. /// </summary> /// <param name="representationMapRef"> /// The iref. /// </param> public RepresentationMapRefMutableCore(IRepresentationMapRef representationMapRef) : base(representationMapRef) { this.valueMappings = new DictionaryOfSets<string, string>(); if (representationMapRef.CodelistMap != null) { this.codelistMap = representationMapRef.CodelistMap.CreateMutableInstance(); } if (representationMapRef.ToTextFormat != null) { this.toTextFormat = new TextFormatMutableCore(representationMapRef.ToTextFormat); } this.toValueType = representationMapRef.ToValueType; this.valueMappings = representationMapRef.ValueMappings; }
/// <summary> /// Resolve references. /// </summary> /// <param name="beans"> /// The beans. /// </param> /// <param name="numberLevelsDeep"> /// The number levels deep. /// </param> /// <param name="retrievalManager"> /// The retrieval manager. /// </param> /// <param name="missingReferences"> /// The missing references. /// </param> /// <returns> /// The <see cref="MaintainableDictionary{IMaintainableMutableObject}"/>. /// </returns> private MaintainableDictionary<IMaintainableMutableObject> ResolveReferencesInternal( IMutableObjects beans, int numberLevelsDeep, Func<IStructureReference, IMaintainableMutableObject> retrievalManager, IDictionaryOfSets<IMaintainableMutableObject, IStructureReference> missingReferences) { var returnMap = new MaintainableDictionary<IMaintainableMutableObject>(); var outerLevel = new Queue<IMaintainableMutableObject>(); foreach (IMaintainableMutableObject artefact in beans.AllMaintainables) { outerLevel.Enqueue(artefact); } int count = 0; do { var innerLevel = new Queue<IMaintainableMutableObject>(); while (outerLevel.Count > 0) { IMaintainableMutableObject parent = outerLevel.Dequeue(); var structureReferences = GetChildStructureReferences(retrievalManager, parent); foreach (IStructureReference structureReference in structureReferences) { if (structureReference == null) { string message = string.Format(CultureInfo.InvariantCulture, "Null reference for parent artefact : {0}+{1}+{2}", parent.AgencyId, parent.Id, parent.Version); _log.Error(message); throw new MappingStoreException(message); } if (this._structureTypeSet.HasStructure(structureReference.MaintainableStructureEnumType)) { IMaintainableMutableObject resolved = this.GetMutableObject(retrievalManager, structureReference); if (resolved != null) { returnMap.AddToSet(parent, resolved); if (numberLevelsDeep == 0 || numberLevelsDeep > count) { innerLevel.Enqueue(resolved); } } else if (missingReferences != null) { missingReferences.AddToSet(parent, structureReference); } } } } count++; outerLevel = innerLevel; } while (count < numberLevelsDeep); return returnMap; }
/// <summary> /// Initializes a new instance of the <see cref="MaintainableDictionary{TValue}"/> class. /// </summary> /// <param name="dictionary"> /// The <see cref="T:System.Collections.Generic.IDictionary`2"/> whose elements are copied to the new /// <see cref="T:System.Collections.Generic.Dictionary`2"/> /// . /// </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="dictionary"/> is null. /// </exception> /// <exception cref="T:System.ArgumentException"> /// <paramref name="dictionary"/> contains one or more duplicate keys. /// </exception> public MaintainableDictionary(IDictionaryOfSets <IMaintainableMutableObject, TValue> dictionary) : base(dictionary, MaintainableMutableComparer.Instance) { }
/// <summary> /// Resolve references. /// </summary> /// <param name="beans"> /// The beans. /// </param> /// <param name="numberLevelsDeep"> /// The number levels deep. /// </param> /// <param name="retrievalManager"> /// The retrieval manager. /// </param> /// <param name="missingReferences"> /// The missing references. /// </param> /// <returns> /// The <see cref="MaintainableDictionary{IMaintainableMutableObject}"/>. /// </returns> private MaintainableDictionary <IMaintainableMutableObject> ResolveReferencesInternal( IMutableObjects beans, int numberLevelsDeep, Func <IStructureReference, IMaintainableMutableObject> retrievalManager, IDictionaryOfSets <IMaintainableMutableObject, IStructureReference> missingReferences) { var returnMap = new MaintainableDictionary <IMaintainableMutableObject>(); var outerLevel = new Queue <IMaintainableMutableObject>(); foreach (IMaintainableMutableObject artefact in beans.AllMaintainables) { outerLevel.Enqueue(artefact); } int count = 0; do { var innerLevel = new Queue <IMaintainableMutableObject>(); while (outerLevel.Count > 0) { IMaintainableMutableObject parent = outerLevel.Dequeue(); var structureReferences = GetChildStructureReferences(retrievalManager, parent); foreach (IStructureReference structureReference in structureReferences) { if (structureReference == null) { string message = string.Format(CultureInfo.InvariantCulture, "Null reference for parent artefact : {0}+{1}+{2}", parent.AgencyId, parent.Id, parent.Version); _log.Error(message); throw new MappingStoreException(message); } if (this._structureTypeSet.HasStructure(structureReference.MaintainableStructureEnumType)) { IMaintainableMutableObject resolved = this.GetMutableObject(retrievalManager, structureReference); if (resolved != null) { returnMap.AddToSet(parent, resolved); if (numberLevelsDeep == 0 || numberLevelsDeep > count) { innerLevel.Enqueue(resolved); } } else if (missingReferences != null) { missingReferences.AddToSet(parent, structureReference); } } } } count++; outerLevel = innerLevel; }while (count < numberLevelsDeep); return(returnMap); }
/// <summary> /// Returns a set of <see cref="IMaintainableMutableObject"/> that the IMaintainableMutableObject cross references /// </summary> /// <param name="artefact"> /// The bean. /// </param> /// <param name="numberLevelsDeep"> /// references, an argument of 0 (zero) implies there is no limit, and the resolver engine will continue re-cursing until it has found every directly and indirectly referenced artifact. Note that there is no risk of infinite recursion in calling this. /// </param> /// <param name="retrievalManager"> /// - Used to resolve the structure references. Can be null, if supplied this is used to resolve any references that do not exist in the supplied beans /// </param> /// <exception cref="SdmxReferenceException"> /// - if any of the references could not be resolved /// </exception> /// <exception cref="ArgumentNullException"><paramref name="artefact"/> is null.</exception> /// <returns> /// a set of <see cref="IMaintainableMutableObject"/> that the IMaintainableMutableObject cross references /// </returns> public ISet <IMaintainableMutableObject> ResolveReferences(IMaintainableMutableObject artefact, int numberLevelsDeep, Func <IStructureReference, IMaintainableMutableObject> retrievalManager) { if (artefact == null) { throw new ArgumentNullException("artefact"); } IMutableObjects objects = new MutableObjectsImpl(); objects.AddIdentifiable(artefact); IDictionaryOfSets <IMaintainableMutableObject, IMaintainableMutableObject> dictionaryOfSets = this.ResolveReferences(objects, numberLevelsDeep, retrievalManager); ISet <IMaintainableMutableObject> set; if (!dictionaryOfSets.TryGetValue(artefact, out set)) { set = new HashSet <IMaintainableMutableObject>(); } return(set); }
/// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefMutableCore" /> class. /// </summary> public RepresentationMapRefMutableCore() : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.RepresentationMap)) { this.valueMappings = new DictionaryOfSets<string, string>(); }
/// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefCore"/> class. /// </summary> /// <param name="xref"> /// The xref. /// </param> /// <param name="parent"> /// The parent. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> protected internal RepresentationMapRefCore(IRepresentationMapRefMutableObject xref, ISdmxStructure parent) : base(xref, parent) { this.valueMappings = new DictionaryOfSets<string, string>(); if (xref.CodelistMap != null) { this.codelistMap = new CrossReferenceImpl(this, xref.CodelistMap); } if (xref.ToTextFormat != null) { this.toTextFormat = new TextFormatObjectCore(xref.ToTextFormat, this); } if (xref.ValueMappings != null) { this.valueMappings = new DictionaryOfSets<string, string>(xref.ValueMappings); } this.toValueType = xref.ToValueType; try { this.Validate(); } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this); } catch (Exception th) { throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this); } }
/// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefCore"/> class. /// </summary> /// <param name="representationMapRefType"> /// The iref. /// </param> /// <param name="parent"> /// The parent. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> public RepresentationMapRefCore(RepresentationMapRefType representationMapRefType, ISdmxStructure parent) : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.RepresentationMap), parent) { this.valueMappings = new DictionaryOfSets<string, string>(); this.codelistMap = new CrossReferenceImpl( this, representationMapRefType.RepresentationMapAgencyID, representationMapRefType.RepresentationMapID, MaintainableObject.DefaultVersion, SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList)); try { this.Validate(); } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this); } catch (Exception th) { throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this); } }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM V2 SCHEMA ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefCore"/> class. /// </summary> /// <param name="textFormatType"> /// The text format type. /// </param> /// <param name="toValueType"> /// The to value type. /// </param> /// <param name="parent"> /// The parent. /// </param> public RepresentationMapRefCore(TextFormatType textFormatType, string toValueType, ISdmxStructure parent) : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.RepresentationMap), parent) { this.valueMappings = new DictionaryOfSets<string, string>(); this.toTextFormat = new TextFormatObjectCore(textFormatType, this); if (toValueType != null) { switch (toValueType) { case Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ToValueTypeTypeConstants.Description: this.toValueType = ToValue.Description; break; case Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ToValueTypeTypeConstants.Name: this.toValueType = ToValue.Name; break; case Org.Sdmx.Resources.SdmxMl.Schemas.V20.structure.ToValueTypeTypeConstants.Value: this.toValueType = ToValue.Value; break; } } this.Validate(); }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM MUTABLE OBJECTS ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM V21 SCHEMA ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="RepresentationMapRefCore"/> class. /// </summary> /// <param name="representationMapType"> /// The iref. /// </param> /// <param name="parent"> /// The parent. /// </param> /// <exception cref="SdmxSemmanticException"> /// Throws Validate exception. /// </exception> public RepresentationMapRefCore(RepresentationMapType representationMapType, ISdmxStructure parent) : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.RepresentationMap), parent) { this.valueMappings = new DictionaryOfSets<string, string>(); if (representationMapType.CodelistMap != null) { // Local Reference string agencyId = this.MaintainableParent.AgencyId; string maintainableId = this.MaintainableParent.Id; string version = this.MaintainableParent.Version; this.codelistMap = new CrossReferenceImpl( this, agencyId, maintainableId, version, SdmxStructureEnumType.CodeListMap, representationMapType.CodelistMap.GetTypedRef<LocalCodelistMapRefType>().id); } if (representationMapType.ToTextFormat != null) { this.toTextFormat = new TextFormatObjectCore(representationMapType.ToTextFormat, this); } if (representationMapType.ToValueType != null) { switch (representationMapType.ToValueType) { case ToValueTypeTypeConstants.Description: this.toValueType = ToValue.Description; break; case ToValueTypeTypeConstants.Name: this.toValueType = ToValue.Name; break; case ToValueTypeTypeConstants.Value: this.toValueType = ToValue.Value; break; } } if (representationMapType.ValueMap != null) { foreach (ValueMappingType vmt in representationMapType.ValueMap.ValueMapping) { ISet<string> mappings = valueMappings[vmt.source]; if (mappings==null) { mappings = new HashSet<string>(); valueMappings.Add(vmt.source, mappings); } mappings.Add(vmt.target); } } try { this.Validate(); } catch (SdmxSemmanticException ex) { throw new SdmxSemmanticException(ex, ExceptionCode.ObjectStructureConstructionError, this); } catch (Exception th) { throw new SdmxException(th, ExceptionCode.ObjectStructureConstructionError, this); } }
/// <summary> /// Initializes a new instance of the <see cref="MaintainableReferenceDictionary"/> class. /// </summary> /// <param name="dictionary"> /// The dictionary. /// </param> public MaintainableReferenceDictionary(IDictionaryOfSets <IMaintainableMutableObject, IStructureReference> dictionary) : base(dictionary) { }
/// <summary> /// Initialize the instance. /// </summary> private void Init() { if (this._retrieveCrossRefefences) { ICrossReferenceResolverEngine crossRefResolver = new CrossReferenceResolverEngineCore(); this._crossReferencedObjects = crossRefResolver.ResolveReferences( this._sdmxObjects, this._retrieveAgencies, this._resolutionDepth, this._retrievalManager); } this._allSdmxObjects = new SdmxObjectsImpl(this._sdmxObjects); if (this._crossReferencedObjects != null) { /* foreach */ foreach (ISet<IIdentifiableObject> currentBeanSet in this._crossReferencedObjects.Values) { /* foreach */ foreach (IIdentifiableObject currentBean in currentBeanSet) { this._allSdmxObjects.AddIdentifiable(currentBean); } } } }
/// <summary> /// Initializes a new instance of the <see cref="StructureWorkspace"/> class. /// Creates a workspace /// </summary> /// <param name="sdmxObjects"> /// The SDMX Objects /// </param> /// <param name="crossReferencedBeans1"> /// The cross Referenced Objects . /// </param> private StructureWorkspace( ISdmxObjects sdmxObjects, IDictionaryOfSets<IIdentifiableObject, IIdentifiableObject> crossReferencedBeans1) { if (sdmxObjects == null) throw new ArgumentException("Cannot instantiate a StructureWorkspace with beans as a null reference."); this._sdmxObjects = sdmxObjects; this._crossReferencedObjects = crossReferencedBeans1; this.Init(); }
/// <summary> /// The reset maps. /// </summary> private void ResetMaps() { this._crossReferences = new DictionaryOfSets<IIdentifiableObject, IIdentifiableObject>(); //this._maintianables = new HashSet<IMaintainableObject>(); this._agencies = new Dictionary<string, IAgency>(); }
/// <summary> /// Initializes a new instance of the <see cref="CrossReferenceResolverEngineCore" /> class. /// </summary> /// <param name="structureRetrievalManager"> The structure retrieval manager. </param> public CrossReferenceResolverEngineCore(IIdentifiableRetrievalManager structureRetrievalManager, IMaintainableCrossReferenceRetrieverEngine maintainableCrossReferenceRetrieverEngine) { this._maintainableCrossReferenceRetrieverEngine = maintainableCrossReferenceRetrieverEngine; this._crossReferences = new DictionaryOfSets<IIdentifiableObject, IIdentifiableObject>(); this._agencies = new Dictionary<string, IAgency>(StringComparer.Ordinal); this._allIdentifiables = new Dictionary<Uri, IIdentifiableObject>(); }