public static void Create_Constraint_Artefact_For_Version_2_0_SDMLMLFile(string RegistrationId, string DbNId, string UserNId, string AgencyId, string FileURL) { string InsertQuery, OutputFolder; DIConnection DIConnection; XmlDocument SimpleDataFileXML; XmlNodeList ObjXmlNodeList; SDMXObjectModel.Message.StructureType ConstraintStructure; SDMXObjectModel.Structure.ContentConstraintType ContentConstraint; DataKeySetType DataKeySet; DataKeyValueType DataKeyValue; int KeyIndex; string SimpleDataFileUrl = string.Empty; string ConstraintFileName = string.Empty; string ConstraintFileLocation = string.Empty; InsertQuery = string.Empty; OutputFolder = Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, Constants.FolderName.Data + DbNId + "\\sdmx\\Constraints\\" + UserNId); ConstraintFileName = DevInfo.Lib.DI_LibSDMX.Constants.Constraint.Prefix + RegistrationId + ".xml"; ConstraintFileLocation = OutputFolder + "\\" + ConstraintFileName; DIConnection = null; try { DIConnection = new DIConnection(DIServerType.MsAccess, string.Empty, string.Empty, Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "stock//Database.mdb"), string.Empty, string.Empty); SimpleDataFileXML = new XmlDocument(); if (!String.IsNullOrEmpty(FileURL)) { SimpleDataFileXML.Load(FileURL); } ObjXmlNodeList = SimpleDataFileXML.GetElementsByTagName("sts:Series"); ConstraintStructure = new SDMXObjectModel.Message.StructureType(); ConstraintStructure.Structures = new StructuresType(); ConstraintStructure.Structures.Constraints = new List<ConstraintType>(); ContentConstraint = new SDMXObjectModel.Structure.ContentConstraintType(); ContentConstraint.id = DevInfo.Lib.DI_LibSDMX.Constants.Constraint.Prefix + RegistrationId; ContentConstraint.Name.Add(new TextType(null, DevInfo.Lib.DI_LibSDMX.Constants.Constraint.Name + RegistrationId)); ContentConstraint.agencyID = AgencyId; ContentConstraint.version = DevInfo.Lib.DI_LibSDMX.Constants.Constraint.Version; ContentConstraint.Description.Add(new TextType(null, DevInfo.Lib.DI_LibSDMX.Constants.Constraint.Description)); ContentConstraint.Annotations = null; ContentConstraint.ReleaseCalendar = null; ContentConstraint.ConstraintAttachment = new ContentConstraintAttachmentType(); if (!String.IsNullOrEmpty(FileURL)) { ContentConstraint.ConstraintAttachment.Items = new object[1]; ContentConstraint.ConstraintAttachment.Items[0] = FileURL; ContentConstraint.ConstraintAttachment.ItemsElementName = new ConstraintAttachmentChoiceType[] { ConstraintAttachmentChoiceType.SimpleDataSource }; } DataKeySet = new DataKeySetType(); DataKeySet.isIncluded = true; ContentConstraint.Items.Add(DataKeySet); KeyIndex = 0; foreach (XmlNode SeriesNode in ObjXmlNodeList) { ((DataKeySetType)(ContentConstraint.Items[0])).Key.Add(new DataKeyType()); foreach (XmlAttribute SeriesAttribute in SeriesNode.Attributes) { DataKeyValue = new DataKeyValueType(); DataKeyValue.id = SeriesAttribute.Name; DataKeyValue.Items.Add(new SimpleKeyValueType()); ((SimpleKeyValueType)(DataKeyValue.Items[0])).Value = SeriesAttribute.Value; ((DataKeySetType)(ContentConstraint.Items[0])).Key[KeyIndex].KeyValue.Add(DataKeyValue); } KeyIndex = KeyIndex + 1; } ConstraintStructure.Structures.Constraints.Add(ContentConstraint); SDMXObjectModel.Serializer.SerializeToFile(typeof(SDMXObjectModel.Message.StructureType), ConstraintStructure, ConstraintFileLocation); InsertQuery = "INSERT INTO Artefacts (DBNId, Id, AgencyId, Version, URN, Type, FileLocation)" + " VALUES(" + DbNId + ",'" + ContentConstraint.id + "','" + ContentConstraint.agencyID + "','" + ContentConstraint.version + "','" + string.Empty + "'," + Convert.ToInt32(ArtefactTypes.Constraint).ToString() + ",'" + ConstraintFileLocation + "');"; DIConnection.ExecuteDataTable(InsertQuery); } catch (Exception ex) { Global.CreateExceptionString(ex, null); throw ex; } finally { if (DIConnection != null) { DIConnection.Dispose(); } } }
public override List<ArtefactInfo> Generate_Artefact() { List<ArtefactInfo> RetVal; ArtefactInfo Artefact; SDMXObjectModel.Structure.ContentConstraintType ContentConstraint; SDMXObjectModel.Message.RegistryInterfaceType RegistryInterface; SDMXObjectModel.Registry.RegistrationType Registration; StructureSpecificTimeSeriesDataType StructureSpecificTimeSeriesData; DataKeySetType DataKeySet; DataKeyValueType DataKeyValue; int KeyIndex; string SimpleDataFileUrl = string.Empty; RetVal = null; try { StructureSpecificTimeSeriesData = (SDMXObjectModel.Message.StructureSpecificTimeSeriesDataType)Deserializer.LoadFromXmlDocument(typeof(SDMXObjectModel.Message.StructureSpecificTimeSeriesDataType), this._sdmxMLFileXMLDocument); ContentConstraint = new SDMXObjectModel.Structure.ContentConstraintType(); ContentConstraint.id = Constants.Constraint.Prefix + this._registrationId; ContentConstraint.Name.Add(new TextType(null, Constants.Constraint.Name + this._registrationId)); ContentConstraint.agencyID = this.AgencyId; ContentConstraint.version = Constants.Constraint.Version; ContentConstraint.Description.Add(new TextType(null, Constants.Constraint.Description)); ContentConstraint.Annotations = null; ContentConstraint.ReleaseCalendar = null; ContentConstraint.ConstraintAttachment = new ContentConstraintAttachmentType(); if (!String.IsNullOrEmpty(this._simpleDataSourceUrl)) { ContentConstraint.ConstraintAttachment.Items = new object[1]; ContentConstraint.ConstraintAttachment.Items[0] = this._simpleDataSourceUrl; ContentConstraint.ConstraintAttachment.ItemsElementName = new ConstraintAttachmentChoiceType[] { ConstraintAttachmentChoiceType.SimpleDataSource }; } DataKeySet = new DataKeySetType(); DataKeySet.isIncluded = true; ContentConstraint.Items.Add(DataKeySet); KeyIndex = 0; foreach (SDMXObjectModel.Data.StructureSpecific.SeriesType Series in StructureSpecificTimeSeriesData.DataSet[0].Items) { ((DataKeySetType)(ContentConstraint.Items[0])).Key.Add(new DataKeyType()); foreach (XmlAttribute SeriesAttribute in Series.AnyAttr) { DataKeyValue = new DataKeyValueType(); DataKeyValue.id = SeriesAttribute.Name; DataKeyValue.Items.Add(new SimpleKeyValueType()); ((SimpleKeyValueType)(DataKeyValue.Items[0])).Value = SeriesAttribute.Value; ((DataKeySetType)(ContentConstraint.Items[0])).Key[KeyIndex].KeyValue.Add(DataKeyValue); } KeyIndex = KeyIndex + 1; } // Preparing Artefact and saving Artefact = this.Prepare_ArtefactInfo_From_ConstraintCreation(ContentConstraint, ContentConstraint.id + Constants.XmlExtension); this.Add_ArtefactInfo_To_List(ref RetVal, Artefact); } catch (Exception ex) { throw ex; } finally { } return RetVal; }