/// <summary> /// Retrieves the matadata type for the given tactical data type (e.g: Area2D, Area3D and so on..) /// </summary> /// <param name="pParentTypePathAsString">The type parent type string path.</param> /// <param name="pTypeAsString">The type as string.</param> /// <returns>The found type, null otherwise.</returns> public MetadataSetType GetType(string pParentTypePathAsString, string pTypeAsString) { MetadataSetType lParentType = null; TargetKey lTargetKey; TypeKey lTypeKey; // Going threw the parents. List <string> lParentTypesAsString = null; this.ParseParentTypePath(pParentTypePathAsString, out lParentTypesAsString); foreach (string lParentTypeAsString in lParentTypesAsString) { if (this.ParseTypeAsString(lParentTypeAsString, out lTargetKey, out lTypeKey)) { lParentType = this.GetType(lParentType, lTargetKey, lTypeKey); } else { return(null); } } // Getting the final nested type. if (this.ParseTypeAsString(pTypeAsString, out lTargetKey, out lTypeKey)) { return(this.GetType(lParentType, lTargetKey, lTypeKey)); } return(null); }
/// <summary> /// Loads the Xml containing customization of tactical data. /// </summary> public void Load() { FileInfo lFileInfo = null; // PathManager.Instance.GetFile("Resources", @"Xml\UserTacticalDatas.xml"); if (lFileInfo.Exists) { XElement lRoot = XElement.Load(lFileInfo.FullName); foreach (XElement lXTacticalMetadataType in lRoot.Descendants(cMetadataTypeTag)) { XAttribute lXTargetType = lXTacticalMetadataType.Attribute(cMetadataTargetTypeTag); XAttribute lXuserType = lXTacticalMetadataType.Attribute(cMetadataUserTypeTag); if (lXTargetType == null || lXuserType == null) { continue; } string lTargetType = lXTargetType.Value; // If the target if (sTacticalMetadataTypes.ContainsKey(lTargetType) == false) { // Invalid tactical data type name... continue; } string lUserTypeName = lXuserType.Value; MetadataSetType lNewType = new MetadataSetType(lUserTypeName); lNewType.TargetType = lTargetType; foreach (XElement lXMetadata in lXTacticalMetadataType.Elements(cMetadataTag)) { XAttribute lXType = lXMetadata.Attribute(cTypeTag); if (lXType == null) { continue; } AMetadataReader lReader; if (sReaders.TryGetValue(lXType.Value, out lReader)) { lReader.Read(ref lNewType, lXMetadata); } } // Checks for nested types. foreach (XElement lXNestedType in lXTacticalMetadataType.Elements(cMetadataTypeTag)) { sTypeReader.Read(ref lNewType, lXNestedType); } this.RegisterUserType(lNewType); } } else { // Log an error. } }
/// <summary> /// Reads a new metadata element. /// </summary> /// <param name="pMetadataType">The metadata type to fill.</param> /// <param name="pElement">The XML element the metadata is extracted from.</param> /// <returns>True if successful, false otherwise.</returns> public bool Read(ref MetadataSetType pMetadataType, XElement pElement) { IMetadata lMetadata = null; this.Read(out lMetadata, pElement); pMetadataType.AddMetadata(lMetadata); return(true); }
/// <summary> /// Registers a new user type /// </summary> /// <param name="pType">The new user type to register.</param> public void RegisterUserType(MetadataSetType pType) { if (pType == null) { return; } string lTargetType = pType.TargetType; Dictionary <string, MetadataSetType> lTypesById; if (sTacticalMetadataTypes.TryGetValue(lTargetType, out lTypesById)) { lTypesById[pType.Id] = pType; } }
/// <summary> /// Unregisters a user type. /// </summary> /// <param name="pType">The user type to unregister</param> /// <returns>True if successful, false otherwise.</returns> public bool UnregisterUserType(MetadataSetType pType) { if (pType == null) { return(false); } string lTargetType = pType.TargetType; Dictionary <string, MetadataSetType> lTypesById; if (sTacticalMetadataTypes.TryGetValue(lTargetType, out lTypesById)) { return(lTypesById.Remove(pType.Id)); } return(false); }
/// <summary> /// Reads a new metadata element. /// </summary> /// <param name="pMetadataType">The metadata type to fill.</param> /// <param name="pElement">The XML element the metadata is extracted from.</param> /// <returns>True if successful, false otherwise.</returns> public bool Read(ref MetadataSetType pMetadataType, XElement pElement) { XAttribute lXNestedPropertyName = pElement.Attribute(MetadataManager.cMetadataPropertyNameTag); XAttribute lXNestedTypeId = pElement.Attribute(MetadataManager.cMetadataIdTag); if (lXNestedPropertyName == null || lXNestedTypeId == null) { return(false); } string lNestedTargetType = lXNestedPropertyName.Value; string lNestedTypeId = lXNestedTypeId.Value; MetadataSetType lNestedType = new MetadataSetType(lNestedTypeId); lNestedType.TargetType = lNestedTargetType; foreach (XElement lXMetadata in pElement.Elements(MetadataManager.cMetadataTag)) { XAttribute lXType = lXMetadata.Attribute(MetadataManager.cTypeTag); if (lXType == null) { continue; } AMetadataReader lReader = MetadataManager.Instance.GetReader(lXType.Value); if (lReader != null) { lReader.Read(ref lNestedType, lXMetadata); } } // Check for nested types too. foreach (XElement lXNestedType in pElement.Elements(MetadataManager.cMetadataTypeTag)) { MetadataTypeReader lNestedReader = new MetadataTypeReader(); lNestedReader.Read(ref lNestedType, lXNestedType); } pMetadataType.AddNestedType(lNestedType); return(true); }
/// <summary> /// Builds a tactical metadata type string. /// </summary> /// <param name="pType">The user type.</param> /// <returns>The type as string.</returns> public string BuildParentTypeAsString(MetadataSetType pType) { string lPath = string.Empty; IMetadataSetType lParent = pType.ParentType; while (lParent != null) { if (string.IsNullOrEmpty(lPath)) { lPath = lParent.GetTypeAsString(); } else { lPath = lParent.GetTypeAsString() + MetadataManager.PARENT_TYPE_AS_STRING_SEP + lPath; } lParent = lParent.ParentType; } return(lPath); }
/// <summary> /// Retrieves the matadata type for the given tactical data type (e.g: Area2D, Area3D and so on..) /// </summary> /// <param name="pParentType">The parent metadata type.</param> /// <param name="pTarget">The target tactical data type.</param> /// <param name="pType">The user type.</param> /// <returns>The found type, null otherwise.</returns> public MetadataSetType GetType(MetadataSetType pParentType, TargetKey pTarget, TypeKey pType) { if (pParentType == null) { Dictionary <string, MetadataSetType> lTypes; if (sTacticalMetadataTypes.TryGetValue(pTarget, out lTypes)) { MetadataSetType lType; if (lTypes.TryGetValue(pType, out lType)) { return(lType); } } } if (pParentType != null) { return(pParentType.NestedTypes.FirstOrDefault(pNestedType => pNestedType.GetTypeAsString() == this.BuildTypeAsString(pTarget, pType)) as MetadataSetType); } return(null); }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM V2.1 SCHEMA ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="MetadataSetObjectCore"/> class. /// </summary> /// <param name="parent"> /// The parent. /// </param> /// <param name="createdFrom"> /// The created from. /// </param> /// /// /// <exception cref="ArgumentNullException"> /// Throws ArgumentNullException. /// </exception> public MetadataSetObjectCore(IMetadata parent, MetadataSetType createdFrom) : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.MetadataSet), null) { if (createdFrom == null) { throw new ArgumentNullException("createdFrom"); } this.setId = createdFrom.setID; foreach (IDatasetStructureReference structurereference in parent.Header.Structures) { if (structurereference.Id.Equals(createdFrom.structureRef)) { this.structureRef = new CrossReferenceImpl(this, structurereference.StructureReference); break; } } if (createdFrom.Name != null) { this.names = TextTypeUtil.WrapTextTypeV21(createdFrom.Name, this); } var reportingDate = createdFrom.reportingBeginDate as DateTime?; if (reportingDate != null) { this.reportingBeginDate = new SdmxDateCore(reportingDate, TimeFormatEnumType.DateTime); } reportingDate = createdFrom.reportingEndDate as DateTime?; if (reportingDate != null) { this.reportingEndDate = new SdmxDateCore(reportingDate, TimeFormatEnumType.DateTime); } if (createdFrom.publicationYear != null) { this.publicationYear = new SdmxDateCore(createdFrom.publicationYear, TimeFormatEnumType.DateTime); } if (createdFrom.validFromDate != null) { this.validFromDate = new SdmxDateCore(createdFrom.validFromDate, TimeFormatEnumType.DateTime); } if (createdFrom.validToDate != null) { this.validToDate = new SdmxDateCore(createdFrom.validToDate, TimeFormatEnumType.DateTime); } // FUNC Publication Period this.publicationPeriod = createdFrom.publicationPeriod; if (createdFrom.DataProvider != null) { this.dataProviderReference = RefUtil.CreateReference(this, createdFrom.DataProvider); } if (ObjectUtil.ValidCollection(createdFrom.Report)) { foreach (ReportType currentReport in createdFrom.Report) { this.reports.Add(new MetadataReportObjectCore(this, currentReport)); } } this.Validate(); }
/// <summary> /// Recursive fonction to decorate metadatable with metadata type(s). /// </summary> /// <param name="pToDecorate"></param> /// <param name="pType"></param> private void Decorate(IMetadatable pToDecorate, MetadataSetType pType) { // Cleaning metadata. pToDecorate.Metadata = null; // Cleaning the old type. MetadataSetType lOldType = pToDecorate.Type as MetadataSetType; if (lOldType != null) { foreach (MetadataSetType lNestedType in lOldType.NestedTypes) { object lPropertyValue = pToDecorate.GetPropertyValue(lNestedType.TargetType); if (lPropertyValue == null) { continue; } if (lPropertyValue is IEnumerable) // List of metadatable?? { IEnumerable lList = lPropertyValue as IEnumerable; foreach (object lItem in lList) { IMetadatable lMetadatable = lItem as IMetadatable; if (lMetadatable != null) { this.Decorate(lMetadatable, null); } } } else if (lPropertyValue is IMetadatable) // Metadatable. { IMetadatable lMetadatable = lPropertyValue as IMetadatable; this.Decorate(lMetadatable, null); } } } pToDecorate.Type = pType; // Applying the new type. if (pType != null) { foreach (MetadataSetType lNestedType in pType.NestedTypes) { object lPropertyValue = pToDecorate.GetPropertyValue(lNestedType.TargetType); if (lPropertyValue == null) { continue; } if (lPropertyValue is IEnumerable) // List of metadatable?? { IEnumerable lList = lPropertyValue as IEnumerable; foreach (object lItem in lList) { IMetadatable lMetadatable = lItem as IMetadatable; if (lMetadatable != null) { // Recurse for sub nested. this.Decorate(lMetadatable, lNestedType); } } } else if (lPropertyValue is IMetadatable) // Metadatable. { IMetadatable lMetadatable = lPropertyValue as IMetadatable; // Recurse for sub nested. this.Decorate(lMetadatable, lNestedType); } } } }
/// <summary> /// Builds a tactical metadata type string. /// </summary> /// <param name="pType">The user type.</param> /// <returns>The type as string.</returns> public string BuildTypeAsString(MetadataSetType pType) { return(this.BuildTypeAsString(new TargetKey(pType.TargetType), new TypeKey(pType.Id))); }