public void TestWriteCodedTimeDimensionV20()
        {
            IDimensionMutableObject dimension = new DimensionMutableCore();
            dimension.TimeDimension = true;
            dimension.Id = DimensionObject.TimeDimensionFixedId;
            dimension.ConceptRef = new StructureReferenceImpl("TEST_AGENCY", "TEST_CONCEPTS", "1.0", SdmxStructureEnumType.Concept, "TIME_PERIOD");
            var structureReference = new StructureReferenceImpl("TEST_AGENCY", "CL_TIME_PERIOD", "1.0", SdmxStructureEnumType.CodeList);
            dimension.Representation = new RepresentationMutableCore() { Representation = structureReference };
            var immutable = BuildDataStructureObject(dimension);
            using (var stream = new MemoryStream())
            {
                this._writerManager.WriteStructure(immutable, new HeaderImpl("TEST", "TEST"), new SdmxStructureFormat(StructureOutputFormat.GetFromEnum(StructureOutputFormatEnumType.SdmxV2StructureDocument)), stream);

                stream.Position = 0;
                using (var location = new MemoryReadableLocation(stream.ToArray()))
                {
                    var workspace = _parsingManager.ParseStructures(location);
                    var dsd = workspace.GetStructureObjects(false).DataStructures.First();
                    var timeDimension = dsd.TimeDimension;
                    Assert.IsTrue(timeDimension.HasCodedRepresentation());
                    Assert.AreEqual(timeDimension.Representation.Representation.AgencyId, structureReference.AgencyId);
                    Assert.AreEqual(timeDimension.Representation.Representation.MaintainableId, structureReference.MaintainableId);
                    Assert.AreEqual(timeDimension.Representation.Representation.Version, structureReference.Version);
                }
            }
        }
        public void Test()
        {
            const string Buffer = "123456";

            using (var readable = new MemoryReadableLocation(Encoding.UTF8.GetBytes(Buffer)))
            {
                Assert.IsTrue(readable.InputStream.ReadByte() > 0);
                Assert.AreNotSame(readable.InputStream, readable.InputStream);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Message SubmitStructure(Message request)
        {

            if (!SettingsManager.EnableSubmitStructure)
                return null;

            

            var submitStructureController = new SubmitStructureController();
            var responseBuilder = new SubmitStructureResponseBuilder();
            ISdmxObjects sdmxObjects;



            XTypedElement response;
            try
            {
                // Il documento template che verrà caricato con gli artefatti da importare
                XmlDocument xDomTemp = new XmlDocument();

                // Il documento sorgente passato in input
                XmlDocument xDomSource = SubmitStructureUtil.MessageToXDom(request);

                // Creo gli elementi del file template
                xDomTemp.InnerXml = SubmitStructureConstant.xmlTemplate;

                // Valido il documento e ricavo l'action
                string actionValue = SubmitStructureUtil.ValidateDocument(xDomSource);
                SubmitStructureConstant.ActionType action = Ws.SubmitStructure.SubmitStructureConstant.ActionType.Replace;
                if (actionValue != string.Empty)
                    action = (SubmitStructureConstant.ActionType)Enum.Parse(typeof(SubmitStructureConstant.ActionType), actionValue);

                // Imposto l'Header
                SubmitStructureUtil.SetHeader(xDomTemp, xDomSource);

                // Il nodo root "Structure" del template
                XmlNode xTempStructNode = xDomTemp.SelectSingleNode("//*[local-name()='Structure']");

                // Creo il nodo "Structures" che conterrà gli artefatti
                XmlNode xSourceStructNode = xDomTemp.CreateNode(XmlNodeType.Element, "Structures", "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message");

                // Inserisco nel nodo "Structures" gli artefatti presenti nell' sdmx passato in input
                xSourceStructNode.InnerXml = xDomSource.SelectSingleNode("//*[local-name()='Structures']").InnerXml;

                // Aggiungo al template l'elemento "Structures" con gli artefatti da caricare
                xTempStructNode.AppendChild(xSourceStructNode);

                // Converto il documento in un MemoryReadableLocation
                MemoryReadableLocation mRL = new MemoryReadableLocation(SubmitStructureUtil.ConvertToBytes(xDomTemp));

                // Richiamo del metodo che esegue il SaveStructures e inserisce nel DB
                sdmxObjects = submitStructureController.Submit(mRL, action);

                // Success response
                response = responseBuilder.BuildSuccessResponse(sdmxObjects,
                SdmxSchemaEnumType.VersionTwoPointOne);
            }
            catch (SubmitStructureException e)
            {
                // Error response
                response = responseBuilder.BuildErrorResponse(e,
                e.StructureReference, SdmxSchemaEnumType.VersionTwoPointOne);
            }
            catch (Exception ex)
            {
                response = responseBuilder.BuildErrorResponse(ex,
                new StructureReferenceImpl(), SdmxSchemaEnumType.VersionTwoPointOne);
            }

            var streamController = new StreamController<XmlWriter>(
            (writer, queue) =>
            {
                queue.RunAll(); // This is required to write the soap envelope
                submitStructureController.Write(writer, response); // Write the response
            });

            return new SdmxMessageSoap(
            streamController,
            exception => _messageFaultBuilder.BuildException(exception,
            SoapOperation.SubmitStructure.ToString()),
            SoapOperation.SubmitStructure.GetQueryRootElementV21());

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

        }
示例#5
0
        private ISdmxObjects LoadSDMXRet(XmlDocument xDomSource)
        {
            // Converto il documento in un MemoryReadableLocation
            MemoryReadableLocation mRL = new MemoryReadableLocation(WSUtils.ConvertToBytes(xDomSource));

            IStructureParsingManager _parsingManager = new StructureParsingManager();

            // Parse structures IStructureParsingManager is an instance field.
            IStructureWorkspace structureWorkspace = _parsingManager.ParseStructures(mRL);

            // Get immutable objects from workspace
            return structureWorkspace.GetStructureObjects(false);
        }
示例#6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xDomSource"></param>
        /// <returns></returns>
        private ISdmxObjects LoadSDMXObject(XmlDocument xDomSource)
        {
            // Il documento template che verrà caricato con gli artefatti da importare
            XmlDocument xDomTemp = new XmlDocument();

            // Creo gli elementi del file template
            xDomTemp.InnerXml = WSConstants.xmlTemplate;

            // Il nodo root "Structure" del template
            XmlNode xTempStructNode = xDomTemp.SelectSingleNode("//*[local-name()='Structure']");

            // Creo il nodo "Structures" che conterrà gli artefatti
            XmlNode xSourceStructNode = xDomTemp.CreateNode(XmlNodeType.Element, "Structures", "http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message");

            // Inserisco nel nodo "Structures" gli aertefatti presenti nell' sdmx passato in input
            xSourceStructNode.InnerXml = xDomSource.SelectSingleNode("//*[local-name()='Structures']").InnerXml;

            // Aggiungo al template l'elemento "Structures" con gli artefatti da caricare
            xTempStructNode.AppendChild(xSourceStructNode);

            // Converto il documento in un MemoryReadableLocation
            MemoryReadableLocation mRL = new MemoryReadableLocation(WSUtils.ConvertToBytes(xDomTemp));

            IStructureParsingManager _parsingManager = new StructureParsingManager();

            // Parse structures IStructureParsingManager is an instance field.
            IStructureWorkspace structureWorkspace = _parsingManager.ParseStructures(mRL);

            // Get immutable objects from workspace
            return structureWorkspace.GetStructureObjects(false);
        }