/// <summary> /// The main. /// </summary> /// <param name="args"> /// The args. /// </param> public static void Main(string[] args) { // 1. initialize the ISdmxObjectRetrievalManager we will use for retrieving Dataflow and DSD. // Depending on the implementation, they could be retrieved from the registry or mapping store. // but in this example we used a simple implementation which retrieves them from files. IStructureParsingManager parsingManager = new StructureParsingManager(); ISdmxObjects objects = new SdmxObjectsImpl(); using (IReadableDataLocation location = new FileReadableDataLocation("ESTAT+STS+2.0.xml")) { objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false)); } using (IReadableDataLocation location = new FileReadableDataLocation("ESTAT+SSTSCONS_PROD_M+2.0.xml")) { objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false)); } ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects); // 2. initialize the IDataQueryParseManager implementation. IDataQueryParseManager parseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwo); // 3. Create a IReadableDataLocation. Since we work with files we use the FileReadableDataLocation implementation. IList<IDataQuery> buildDataQuery; using (IReadableDataLocation readable = new FileReadableDataLocation("query.xml")) { // 4. we call BuildDataQuery to process the query.xml and get a list of IDataQuery buildDataQuery = parseManager.BuildDataQuery(readable, retrievalManager); } // below we print to console the contents of each IDataQuery foreach (var dataQuery in buildDataQuery) { Console.WriteLine("Dataflow: {0}", dataQuery.Dataflow.Id); Console.WriteLine("DSD: {0}", dataQuery.DataStructure.Id); Console.WriteLine("Maximum number of observations (DefaultLimit): {0}", dataQuery.FirstNObservations); Console.WriteLine("Has selections: {0}", dataQuery.HasSelections()); Console.WriteLine("("); foreach (var selectionGroup in dataQuery.SelectionGroups) { if (selectionGroup.DateFrom != null) { Console.WriteLine("\tPeriod from {0}", selectionGroup.DateFrom); Console.WriteLine(" AND "); } if (selectionGroup.DateTo != null) { Console.WriteLine("\tPeriod to {0}", selectionGroup.DateTo); Console.WriteLine(" AND "); } foreach (var selection in selectionGroup.Selections) { var s = selection.HasMultipleValues ? string.Join(" OR ", selection.Values) : selection.Value; Console.WriteLine("{0} = ( {1} )", selection.ComponentId, s); Console.WriteLine(" AND "); } } } }
public void TestDownload(string dsd, string dataflow, string query) { IStructureParsingManager parsingManager = new StructureParsingManager(); ISdmxObjects objects = new SdmxObjectsImpl(); using (IReadableDataLocation location = new FileReadableDataLocation(dsd)) { objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false)); } using (IReadableDataLocation location = new FileReadableDataLocation(dataflow)) { objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false)); } ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects); IList<IDataQuery> buildDataQuery; IDataQueryParseManager parseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwo); using (IReadableDataLocation readable = new FileReadableDataLocation(query)) { // call BuildDataQuery to process the query.xml and get a list of IDataQuery buildDataQuery = parseManager.BuildDataQuery(readable, retrievalManager); } IList<IDataQuery> buildDataQuery1; foreach (var dataQuery in buildDataQuery) { IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(new DataQueryFactory()); var xdoc = dataQueryBuilderManager.BuildDataQuery(dataQuery, new QueryMessageV2Format()); Assert.IsNotNull(xdoc); MemoryStream xmlStream = new MemoryStream(); xdoc.Save(xmlStream); using (IReadableDataLocation readable = new MemoryReadableLocation(xmlStream.ToArray())) { // call BuildDataQuery to process the xmlStream and get a list of IDataQuery buildDataQuery1 = parseManager.BuildDataQuery(readable, retrievalManager); } Assert.AreEqual(dataQuery.ToString(),buildDataQuery1[0].ToString()); xmlStream.Flush(); } }
/// <summary> /// Gets the data query from stream. /// </summary> /// <param name="input"> /// The input. /// </param> /// <exception cref="Org.Sdmxsource.Sdmx.Api.Exception.SdmxSemmanticException"> /// Operation not accepted /// </exception> /// <returns> /// The <see cref="IDataQuery"/>. /// </returns> protected IDataQuery GetDataQueryFromStream(IReadableDataLocation input) { IDataQueryParseManager dataQueryParseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwo); var dataQuery = dataQueryParseManager.BuildDataQuery(input, this.SdmxRetrievalManager).FirstOrDefault(); if (dataQuery == null) { throw new SdmxSemmanticException(Estat.Sri.Ws.Controllers.Properties.Resources.ErrorOperationNotAccepted); } return dataQuery; }
public void TestRestQueryFormat(string dsd, string dataflow, string query) { IStructureParsingManager parsingManager = new StructureParsingManager(); ISdmxObjects objects = new SdmxObjectsImpl(); using (IReadableDataLocation location = new FileReadableDataLocation(dsd)) { objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false)); } using (IReadableDataLocation location = new FileReadableDataLocation(dataflow)) { objects.Merge(parsingManager.ParseStructures(location).GetStructureObjects(false)); } ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects); IList<IDataQuery> buildDataQuery; IDataQueryParseManager parseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwo); using (IReadableDataLocation readable = new FileReadableDataLocation(query)) { // call BuildDataQuery to process the query.xml and get a list of IDataQuery buildDataQuery = parseManager.BuildDataQuery(readable, retrievalManager); } IDataQueryFormat<string> structureQueryFormat = new RestQueryFormat(); IDataQueryFactory dataQueryFactory = new DataQueryFactory(); foreach (var dataQuery in buildDataQuery) { IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(dataQueryFactory); string request = dataQueryBuilderManager.BuildDataQuery(dataQuery, structureQueryFormat); Assert.IsNotNull(request); } }