public void Resolve(FileInfo codelistsConceptsFile, FileInfo dsdFile) 
        {
		    ISdmxObjectRetrievalManager retManager;
		    using (IReadableDataLocation codelistRdl = this._dataLocationFactory.GetReadableDataLocation(codelistsConceptsFile))
		    {
		        retManager = new InMemoryRetrievalManager(codelistRdl, this._structureParsingManager, null);
		    }

		    Console.WriteLine("In memory objects built!!!");

		    IStructureWorkspace workspace;
		    using (IReadableDataLocation dsdRdl = this._dataLocationFactory.GetReadableDataLocation(dsdFile))
		    {
		        ResolutionSettings settings = new ResolutionSettings(ResolveExternalSetting.Resolve, ResolveCrossReferences.ResolveExcludeAgencies);
		        workspace = this._structureParsingManager.ParseStructures(dsdRdl, settings, retManager);
		    }

		    ISdmxObjects sdmxObjects = workspace.GetStructureObjects(true);
			
			ISet<IMaintainableObject> maintainables =  sdmxObjects.GetAllMaintainables();
			foreach (IMaintainableObject m in maintainables) {
				Console.WriteLine(m.Urn);
				Console.WriteLine("{0} - {1}", m.StructureType.StructureType, m.Name);
				Console.WriteLine(" --- ");
			}
		}
 public void TestSaveStructure()
 {
     IDataflowMutableObject dataflow = new DataflowMutableCore { Id = "TEST_DF", AgencyId = "TEST_AGENCY", DataStructureRef = new StructureReferenceImpl("TEST_AGENCY", "TEST_DSD", "1.0", SdmxStructureEnumType.Dsd) };
     dataflow.AddName("en", "A test DF");
     
     var retrievalManager = new InMemoryRetrievalManager();
     Assert.AreEqual(0, retrievalManager.GetMaintainableObjects<IDataflowObject>().Count);
     retrievalManager.SaveStructure(dataflow.ImmutableInstance);
     Assert.AreEqual(1, retrievalManager.GetMaintainableObjects<IDataflowObject>().Count);
 }
        /// <summary>
        ///     Initializes a new instance of the <see cref="TestWsRetrieverFactory" /> class.
        /// </summary>
        public TestWsRetrieverFactory()
        {
            ISdmxObjects sdmxObjects = new SdmxObjectsImpl();
            using (var stream = GetResource("ESTAT+STS+2.0.xml"))
            {
                Merge(stream, sdmxObjects);
            }

            using (var stream = GetResource("ESTAT+DEMOGRAPHY+2.1.xml"))
            {
                Merge(stream, sdmxObjects);
            }

            var sts = sdmxObjects.GetDataStructures(new MaintainableRefObjectImpl(null, "STS", null)).Select(o => o.AsReference).FirstOrDefault();
            var demo = sdmxObjects.GetDataStructures(new MaintainableRefObjectImpl(null, "DEMOGRAPHY", null)).Select(o => o.AsReference).FirstOrDefault();
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.NoResults, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.ResponseExceedsLimit, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.ResponseTooLarge, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.Semantic, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.TimeSeries, sts));
            sdmxObjects.AddDataflow(BuildDataflow(Dataflows.CrossV20Only, demo));

            InMemoryRetrievalManager retrievalManager = new InMemoryRetrievalManager(sdmxObjects);
            retrievalManager.CrossReferenceRetrievalManager = new CrossReferencedRetrievalManager(retrievalManager);
            this._sdmxObjectRetrievalManager = retrievalManager;
            this._mutableStructureSearchManager = new SampleStructureSearchManager(this._sdmxObjectRetrievalManager);
            this._sampleAdvancedMutableStructureSearchManager = new SampleAdvancedMutableStructureSearchManager(this._mutableStructureSearchManager);
            this._sampleAuthAdvancedStructureSearchManager = new SampleAuthAdvancedStructureSearchManager(this._sampleAdvancedMutableStructureSearchManager);
        }
        public void TestNestedAndInOrV21(string file, string dataflowFile, string dsdFile, int expectedDataSelectionGroup)
        {
            // To be analysed  in SDMXRI-124
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dataflowFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dsdFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }

            var retrievalManager = new InMemoryRetrievalManager(objects);
            using (var fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                var dataQuery = this.dataQueryParseManager.BuildComplexDataQuery(fileReadableDataLocation, retrievalManager);
                Assert.IsNotEmpty(dataQuery);
                Assert.AreEqual(expectedDataSelectionGroup, dataQuery.First().SelectionGroups.Count);
            }
        }
        public void TestDataQueryParserManagerV21(string file,string dataflowFile, string dsdFile)
        {
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dataflowFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }
            using (IReadableDataLocation readableDataLocation = new FileReadableDataLocation(dsdFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(readableDataLocation);
                objects.Merge(structureWorkspace.GetStructureObjects(false));
            }

            var retrievalManager = new InMemoryRetrievalManager(objects);
            using (var fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                var dataQuery = this.dataQueryParseManager.BuildComplexDataQuery(fileReadableDataLocation, retrievalManager);
                Assert.IsNotEmpty(dataQuery);
            }
        }
        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();
            }

        }
        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);
            }

        }
        public void TestResolveReference(string file)
        {
            ICrossReferenceResolverEngine crossReferenceResolverEngine = new CrossReferenceResolverEngineCore();
            ISdmxObjects structureBeans;
            using (IReadableDataLocation fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                IStructureWorkspace structureWorkspace = this.parsingManager.ParseStructures(fileReadableDataLocation);
                Assert.NotNull(structureWorkspace);
                structureBeans = structureWorkspace.GetStructureObjects(false);
            }

            var retrievalManager = new InMemoryRetrievalManager(structureBeans);
            foreach (var maintainableObject in structureBeans.DataStructures)
            {
                ISet<IIdentifiableObject> identifiableObjects = crossReferenceResolverEngine.ResolveReferences(maintainableObject, false, 10, retrievalManager);
                Assert.IsNotEmpty(identifiableObjects);
            }
        }
        private static ISdmxObjectRetrievalManager GetManagerImmutable()
        {
            Estat.Nsi.StructureRetriever.Manager.AuthMutableStructureSearchManager srManager = new Estat.Nsi.StructureRetriever.Manager.AuthMutableStructureSearchManager(SQLConnString_DB);
            List<IStructureReference> query = new List<IStructureReference>();
            IStructureReference sr = new StructureReferenceImpl(new MaintainableRefObjectImpl("", "", ""), Org.Sdmxsource.Sdmx.Api.Constants.SdmxStructureEnumType.Dsd);
            query.Add(sr);

            IMutableObjects retObject = srManager.RetrieveStructures(query, true, false, null);
            ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(retObject.ImmutableObjects);

            return retrievalManager;
        }
        public void TestLikeNSIWCVariousDataWithDsdFile(string file, string dsdFile)
        {
            IDataReaderManager manager = new DataReaderManager();
            ISdmxObjects objects;
            using (var dataLocation = this._factory.GetReadableDataLocation(new FileInfo(dsdFile)))
            {
                IStructureParsingManager parsingManager = new StructureParsingManager();
                objects = parsingManager.ParseStructures(dataLocation).GetStructureObjects(false);
            }
            var retrievalManager = new InMemoryRetrievalManager(objects); 
            IList<IDictionary<string, string>> dataSetStoreList = new List<IDictionary<string, string>>();
            using (var sourceData = this._factory.GetReadableDataLocation(new FileInfo(file)))
            using (var compact = manager.GetDataReaderEngine(sourceData, retrievalManager))
            {
                while (compact.MoveNextKeyable())
                {
                    if (compact.CurrentKey.Series)
                    {
                        IList<IKeyValue> keyValues = compact.CurrentKey.Key;

                        while (compact.MoveNextObservation())
                        {
                            var dataSetStore = new Dictionary<string, string>(StringComparer.Ordinal);
                            foreach (var key in keyValues)
                            {
                                dataSetStore.Add(key.Concept, key.Code);
                            }

                            IObservation currentObservation = compact.CurrentObservation;
                            Assert.IsNotNullOrEmpty(currentObservation.ObservationValue);
                            Assert.IsNotNullOrEmpty(currentObservation.ObsTime);
                            Assert.IsFalse(currentObservation.CrossSection);
                            dataSetStore.Add(DimensionObject.TimeDimensionFixedId, currentObservation.ObsTime);
                            ISdmxDate sdmxDate = new SdmxDateCore(currentObservation.ObsTime);
                            Assert.NotNull(sdmxDate);
                            Assert.AreEqual(sdmxDate.TimeFormatOfDate, currentObservation.ObsTimeFormat);
                            dataSetStore.Add(PrimaryMeasure.FixedId, currentObservation.ObservationValue);
                            if (!currentObservation.ObservationValue.Equals(EdiConstants.MissingVal))
                            {
                                double i;
                                Assert.IsTrue(double.TryParse(currentObservation.ObservationValue, NumberStyles.Any, CultureInfo.InvariantCulture, out i), "Cannot convert to int {0}", currentObservation.ObservationValue);
                            }

                            dataSetStoreList.Add(dataSetStore);
                        }
                    }
                }
            }
        }
        /// <summary>
        ///   The resolve references internal.
        /// </summary>
        /// <param name="sdmxObjects"> The sdmxObjects. </param>
        /// <param name="retrievalManager"> The retrieval manager. </param>
        /// <param name="populateMissingMap"> The populate missing map. </param>
        /// <returns> The <see cref="IIdentifiableObject" /> dictionary. </returns>
        /// <exception cref="CrossReferenceException">Reference error</exception>
        private IDictionaryOfSets<IIdentifiableObject, IIdentifiableObject> ResolveReferencesInternal(
            ISdmxObjects sdmxObjects,
            IIdentifiableRetrievalManager retrievalManager,
            IDictionary<IIdentifiableObject, ISet<ICrossReference>> populateMissingMap)
        {
            _log.Info("Resolve References, bean retrieval manager: " + retrievalManager);

            /* foreach */
            foreach (IAgency currentAgency in sdmxObjects.Agencies)
            {
                this._agencies.Add(currentAgency.FullId, currentAgency);
            }

            // Add all the top level sdmxObjects to the maintainables list
            this.AddObjectsToMap(sdmxObjects);

            // LOOP THROUGH ALL THE BEANS AND RESOLVE ALL THE REFERENCES
            if (this._resolveAgencies)
            {
                /* foreach */
                foreach (IMaintainableObject currentBean in sdmxObjects.GetAllMaintainables())
                {
                    try
                    {
                        this.ResolveAgency(currentBean, retrievalManager);
                    }
                    catch (CrossReferenceException e)
                    {
                        throw new SdmxReferenceException(e,
                            AgencyRef(currentBean.AgencyId));
                    }
                }
            }

            ISet<IMaintainableObject> loopSet = new HashSet<IMaintainableObject>();
            loopSet.AddAll(sdmxObjects.GetAllMaintainables());
            ISdmxObjectRetrievalManager retMan = new InMemoryRetrievalManager(sdmxObjects);

            /* foreach */
            foreach (IMaintainableObject currentMaintainable in loopSet)
            {
                this._log.Debug("Resolving References For : " + currentMaintainable.Urn);
                ISet<ICrossReference> crossReferences0;
                if (_maintainableCrossReferenceRetrieverEngine != null)
                {
                    crossReferences0 = _maintainableCrossReferenceRetrieverEngine.GetCrossReferences(retMan, currentMaintainable);
                }
                else
                {
                    crossReferences0 = currentMaintainable.CrossReferences;
                }
                this._log.Debug("Number of References : " + crossReferences0.Count);
                int i = 0;

                /* foreach */
                foreach (ICrossReference crossReference in crossReferences0)
                {
                    i++;
                    if (this._log.IsDebugEnabled)
                    {
                        this._log.Debug(
                            "Resolving Reference " + i + ": " + crossReference + " - referenced from -"
                            + crossReference.ReferencedFrom.StructureType);
                    }

                    try
                    {
                        this.StoreRef(
                            crossReference.ReferencedFrom, this.ResolveCrossReference(crossReference, retrievalManager));
                    }
                    catch (CrossReferenceException e)
                    {
                        if (populateMissingMap == null)
                        {
                            throw;
                        }
                        
                        HandleMissingReference(e, populateMissingMap);
                        //throw new ReferenceException(e, "Reference from structure '" + currentMaintainable.Urn + "' can not be resolved");
                    }
                }
            }

            return this._crossReferences;
        }
        /// <summary>
        /// Reads the data.
        /// </summary>
        /// <param name="structureFile">The structure file.</param>
        /// <param name="dataFile">The data file.</param>
        private void ReadData(FileInfo structureFile, FileInfo dataFile)
        {
            // Parse Structures into ISdmxObjects and build a SdmxBeanRetrievalManager
            IStructureWorkspace workspace;
            using (IReadableDataLocation rdl = this._rdlFactory.GetReadableDataLocation(structureFile))
            {
                workspace = this._structureParsingManager.ParseStructures(rdl);
            }

            ISdmxObjects beans = workspace.GetStructureObjects(false);
            ISdmxObjectRetrievalManager retreivalManager = new InMemoryRetrievalManager(beans);

            // Get the DataLocation, and from this the DataReaderEngine
            using (IReadableDataLocation dataLocation = this._rdlFactory.GetReadableDataLocation(dataFile))
            using (IDataReaderEngine dre = this._dataReaderManager.GetDataReaderEngine(dataLocation, retreivalManager))
            {
                while (dre.MoveNextDataset())
                {
                    IDataStructureObject dsd = dre.DataStructure;
                    Console.WriteLine(dsd.Name);

                    while (dre.MoveNextKeyable())
                    {
                        IKeyable currentKey = dre.CurrentKey;
                        Console.WriteLine(currentKey);
                        while (dre.MoveNextObservation())
                        {
                            IObservation obs = dre.CurrentObservation;
                            Console.WriteLine(obs);
                        }
                    }
                }
            }
        }
 public void TestGetMissingCrossReferences()
 {
     ICrossReferenceResolverEngine crossReferenceResolverEngine = new CrossReferenceResolverEngineCore();
     InMemoryRetrievalManager retrievalManager = new InMemoryRetrievalManager();
     ISdmxObjects objects = new SdmxObjectsImpl(dataStructureObject);
     IDictionary<IIdentifiableObject, ISet<ICrossReference>> missingCrossRef = crossReferenceResolverEngine.GetMissingCrossReferences(objects, 10, retrievalManager);
     Assert.IsNotEmpty(missingCrossRef);
     Assert.AreEqual(dataStructureObject.DimensionList.Dimensions[0].Urn, missingCrossRef.First().Key.Urn);
     Assert.IsTrue(missingCrossRef.Any(pair => pair.Key.Urn.Equals(this.dataStructureObject.PrimaryMeasure.Urn)));
     Assert.IsTrue(missingCrossRef.Any(pair => pair.Key.Urn.Equals(this.dataStructureObject.TimeDimension.Urn)));
 }
        public void TestResolveCrossReference(string file)
        {

            ICrossReferenceResolverEngine crossReferenceResolverEngine = new CrossReferenceResolverEngineCore();
            ISdmxObjects structureBeans;
            using (IReadableDataLocation fileReadableDataLocation = new FileReadableDataLocation(file))
            {
                IStructureWorkspace structureWorkspace = this.parsingManager.ParseStructures(fileReadableDataLocation);
                Assert.NotNull(structureWorkspace);
                structureBeans = structureWorkspace.GetStructureObjects(false);
            }

            var retrievalManager = new InMemoryRetrievalManager(structureBeans);
            ICodelistObject immutableInstance = CreateSampleCodelist();
            var cross = new CrossReferenceImpl(immutableInstance, "urn:sdmx:org.sdmx.infomodel.datastructure.DataStructure=TFFS:CRED_EXT_DEBT(1.0)");

            int i = 0;

            foreach (IMaintainableObject maintainableObject in this.maintainableObjectSet)
            {
                beanRetrivalManager.Setup(m => m.GetMaintainableObject(It.IsAny<IStructureReference>(), false, false)).Returns(maintainableObject);
                beanRetrivalManager.Setup(m => m.GetIdentifiableObject(It.IsAny<ICrossReference>())).Returns(maintainableObject);
                IIdentifiableObject ret = crossReferenceResolverEngine.ResolveCrossReference(cross, beanRetrivalManager.Object);
                Assert.IsNotNull(ret);
                Assert.AreEqual(maintainableObject.Urn, ret.Urn);
                i++;
            } 
        }
        public void TestBuildComplexDataQuery()
        {
            IStructureParsingManager manager = new StructureParsingManager();
            IDataQueryParseManager queryParseManager = new DataQueryParseManager(SdmxSchemaEnumType.VersionTwoPointOne);
            IComplexDataQueryBuilderManager dataQueryBuilderManager = new ComplexDataQueryBuilderManager(new ComplexDataQueryFactoryV21());
            
            IDataflowObject dataFlow;
            IDataStructureObject dsd;
            using (var readable = new FileReadableDataLocation("tests/V21/Structure/test-sdmxv2.1-ESTAT+SSTSCONS_PROD_M+2.0.xml"))
            {
                var structureWorkspace = manager.ParseStructures(readable);
                dataFlow = structureWorkspace.GetStructureObjects(false).Dataflows.First();
            }

            using (var readable = new FileReadableDataLocation("tests/V21/Structure/test-sdmxv2.1-ESTAT+STS+2.0.xml"))
            {
                var structureWorkspace = manager.ParseStructures(readable);
                dsd = structureWorkspace.GetStructureObjects(false).DataStructures.First();
            }

            ISet<IComplexDataQuerySelection> sections = new HashSet<IComplexDataQuerySelection>();
            var freqCriteria = new ComplexDataQuerySelectionImpl("FREQ", new IComplexComponentValue[] { new ComplexComponentValueImpl("M", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.Equal), SdmxStructureEnumType.Dimension), new ComplexComponentValueImpl("A", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.NotEqual), SdmxStructureEnumType.Dimension), new ComplexComponentValueImpl("B", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.Equal), SdmxStructureEnumType.Dimension) });
            sections.Add(freqCriteria);
            var adjustmentCriteria = new ComplexDataQuerySelectionImpl("ADJUSTMENT", new IComplexComponentValue[] { new ComplexComponentValueImpl("01", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.NotEqual), SdmxStructureEnumType.Dimension),  new ComplexComponentValueImpl("S2", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.NotEqual), SdmxStructureEnumType.Dimension) });
            sections.Add(adjustmentCriteria);
            var titleCriteria = new ComplexDataQuerySelectionImpl(
                "TITLE", 
                new IComplexComponentValue[] { new ComplexComponentValueImpl("PAOKARA", TextSearch.GetFromEnum(TextSearchEnumType.Contains), SdmxStructureEnumType.DataAttribute),  new ComplexComponentValueImpl("ARIS", TextSearch.GetFromEnum(TextSearchEnumType.DoesNotContain), SdmxStructureEnumType.DataAttribute) });
            sections.Add(titleCriteria);
            OrderedOperator equalOperator = OrderedOperator.GetFromEnum(OrderedOperatorEnumType.Equal);
            var dateFrom = new SdmxDateCore("2000-01");
            var dateFromOperator = OrderedOperator.GetFromEnum(OrderedOperatorEnumType.GreaterThanOrEqual);
            var primaryMeasureValue = new ComplexComponentValueImpl("200.20", OrderedOperator.GetFromEnum(OrderedOperatorEnumType.GreaterThan), SdmxStructureEnumType.PrimaryMeasure);
            ICollection<IComplexDataQuerySelectionGroup> collection = new[] { new ComplexDataQuerySelectionGroupImpl(sections, dateFrom, dateFromOperator, null, equalOperator, new HashSet<IComplexComponentValue> { primaryMeasureValue }) };

            var complexDataQueryImpl = new ComplexDataQueryImpl(
                null, 
                null, 
                null, 
                dsd, 
                dataFlow, 
                null, 
                null, 
                0, 
                null, 
                false, 
                null, 
                DimensionAtObservation.GetFromEnum(DimensionAtObservationEnumType.Time).Value, 
                false, 
                DataQueryDetail.GetFromEnum(DataQueryDetailEnumType.Full), 
                collection);

            var buildComplexDataQuery = dataQueryBuilderManager.BuildComplexDataQuery(
                complexDataQueryImpl, new StructSpecificDataFormatV21());

            var fileName = string.Format("test-TestBuildComplexDataQuery.xml");
            buildComplexDataQuery.Save(fileName);

            ISdmxObjects objects = new SdmxObjectsImpl();
            objects.AddDataStructure(dsd);
            objects.AddDataflow(dataFlow);
            ISdmxObjectRetrievalManager beanRetrievalManager = new InMemoryRetrievalManager(objects);

            IComplexDataQuery query;
            using (var readable = new FileReadableDataLocation(fileName))
            {
                XMLParser.ValidateXml(readable, SdmxSchemaEnumType.VersionTwoPointOne);

                query = queryParseManager.BuildComplexDataQuery(readable, beanRetrievalManager).First();
            }

            Assert.AreEqual(1, query.SelectionGroups.Count);
            var selectionGroup = query.SelectionGroups.First();
            Assert.AreEqual(dateFrom, selectionGroup.DateFrom);
            Assert.AreEqual(dateFromOperator, selectionGroup.DateFromOperator);
            Assert.IsNull(selectionGroup.DateTo);
            Assert.AreEqual(1, selectionGroup.PrimaryMeasureValue.Count);
            var primaryValue = selectionGroup.PrimaryMeasureValue.First();
            Assert.AreEqual(primaryMeasureValue.Value, primaryValue.Value);
            Assert.AreEqual(primaryMeasureValue.OrderedOperator, primaryValue.OrderedOperator);
            Assert.AreEqual(3, selectionGroup.Selections.Count);

            var gotFreqCriteria = selectionGroup.GetSelectionsForConcept(freqCriteria.ComponentId);
            Assert.AreEqual(gotFreqCriteria, freqCriteria, "FREQ diff");
            
            var gotAdjustmentCriteria = selectionGroup.GetSelectionsForConcept(adjustmentCriteria.ComponentId);
            Assert.AreEqual(gotAdjustmentCriteria, adjustmentCriteria, "ADJ diff");
            Assert.IsTrue(gotAdjustmentCriteria.Values.All(value => value.OrderedOperator.EnumType == OrderedOperatorEnumType.NotEqual));

            var gotTitleCriteria = selectionGroup.GetSelectionsForConcept(titleCriteria.ComponentId);
            Assert.AreEqual(gotTitleCriteria, titleCriteria, "TITLE diff");
        }
 public void TestGetMaintainablesRest(string structureFilePath, string restQuery)
 {
     ISdmxObjects objects = new FileInfo(structureFilePath).GetSdmxObjects(this._structureParsingManager);
     var retrievalManager = new InMemoryRetrievalManager(objects);
     ISdmxObjects sdmxObjects = retrievalManager.GetMaintainables(new RESTStructureQueryCore(restQuery));
     Assert.NotNull(sdmxObjects);
     Assert.IsNotEmpty(sdmxObjects.GetAllMaintainables());
 }
        /// <summary>
        /// Gets the SDMX object retrieval manager.
        /// </summary>
        /// <param name="dataflowFile">The dataflow file.</param>
        /// <param name="dsdFile">The DSD file.</param>
        /// <returns>The SDMX Object retrieval manager</returns>
        private ISdmxObjectRetrievalManager GetSdmxObjectRetrievalManager(string dataflowFile, string dsdFile)
        {
            ISdmxObjects objects = new SdmxObjectsImpl();
            using (var fileDataFlowReadableDataLocation = new FileReadableDataLocation(dataflowFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(fileDataFlowReadableDataLocation);
                ISdmxObjects structureBeans = structureWorkspace.GetStructureObjects(false);
                objects.Merge(structureBeans);
                Assert.IsNotEmpty(structureBeans.Dataflows);
            }

            using (var fileKeybeanReadableDataLocation = new FileReadableDataLocation(dsdFile))
            {
                var structureWorkspace = this.parsingManager.ParseStructures(fileKeybeanReadableDataLocation);
                ISdmxObjects structureBeans = structureWorkspace.GetStructureObjects(false);
                objects.Merge(structureBeans);
                Assert.IsNotEmpty(structureBeans.DataStructures);
            }
            ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects);
            return retrievalManager;
        }
        public void TestFull(string file, string dsd)
        {
            var retrievalManager = new InMemoryRetrievalManager();
            IDataStructureObject dsdObject;
            using (IReadableDataLocation dataLocation = _factory.GetReadableDataLocation(new FileInfo(dsd)))
            {
                IStructureParsingManager manager = new StructureParsingManager();
                var structureWorkspace = manager.ParseStructures(dataLocation);
                retrievalManager.SaveStructures(structureWorkspace.GetStructureObjects(false));

            }

            IReportedDateEngine reportedDateEngine = new ReportedDateEngine();
            var sdmxDataReaderFactory = new SdmxDataReaderFactory(new DataInformationManager(new FixedConceptEngine(), reportedDateEngine), null);
            using (var sourceData = this._factory.GetReadableDataLocation(new FileInfo(file)))
            using (var dataReaderEngine = sdmxDataReaderFactory.GetDataReaderEngine(sourceData, retrievalManager))
            {
                while (dataReaderEngine.MoveNextDataset())
                {
                    while (dataReaderEngine.MoveNextKeyable())
                    {
                        IKeyable currentKey = dataReaderEngine.CurrentKey;
                        if (currentKey.Series)
                        {
                            while (dataReaderEngine.MoveNextObservation())
                            {
                                
                            }
                        }
                    }
                }
            }
        }
        /// <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 RestService()
        {
            // 1.a To support additional data formats pass additional IDataWriterFactory implementations to the DataWriterManager constructor  
            IDataWriterFactory dataWriterFactory = new DataWriterFactory();
            IDataWriterManager dataWriterManager = new DataWriterManager(dataWriterFactory/*, add your factories here) */);

            // 1.b To support additional data formats pass additional IStructureWriterFactory implementations to the DataWriterManager constructor  
            IStructureWriterManager structureWriterManager = new StructureWriterManager(new SdmxStructureWriterFactory() /*, add your factories here */);

            // a map between the HTTP Accept header value and the IDataFormat
            this._acceptToDataFormats = new Dictionary<string, IDataFormat>(StringComparer.Ordinal) {
                                                { "application/vnd.sdmx.genericdata+xml", this._genericV21Format },
                                                { "application/xml", this._genericV21Format },
                                                { "application/vnd.sdmx.structurespecificdata+xml", this._structureSpecificFormat },
                                                /* 2. add new data formats here */ };

            // a map between the HTTP Accept header value and the IStructureFormat
            this._acceptToStructureFormats = new Dictionary<string, IStructureFormat>(StringComparer.Ordinal)
                                                 {
                                                     { "application/vnd.sdmx.structure+xml", this._structureFormatv21 },
                                                     { "application/xml", this._structureFormatv21 }
                                                    /* 2. add new structure formats here */ };
            
            // load the structures
            ISdmxObjects objects;
            IReadableDataLocationFactory dataLocationFactory = new ReadableDataLocationFactory();
            IStructureParsingManager structureParsingManager = new StructureParsingManager();

            using (IReadableDataLocation structureLocation = dataLocationFactory.GetReadableDataLocation(HttpContext.Current.Server.MapPath("~/App_Data/structures.xml")))
            {
                IStructureWorkspace structureWorkspace = structureParsingManager.ParseStructures(structureLocation);
                objects = structureWorkspace.GetStructureObjects(false);
            }

            ISdmxObjectRetrievalManager retrievalManager = new InMemoryRetrievalManager(objects);

            _dataQueryManager = new RestDataQueryManager(new SampleDataRetrieval(), dataWriterManager, retrievalManager);
            _restStructureQueryManager = new RestStructureQueryManager(structureWriterManager, retrievalManager);
        }