public static void GetDataSetStream(IDataSetRenderer renderer, DataObjectForStreaming dataStream, TextWriter streamResponse)
        {
            EndpointSettings DataObjConfiguration = dataStream.Configuration;

            IDataStructureObject kf = dataStream.structure.DataStructures.First();

            //DataObjectForStreaming
            SDMXWSFunction op = SDMXWSFunction.GetCompactData;
            //DataObjConfiguration

            bool cross = (DataObjConfiguration._TypeEndpoint == EndpointType.V21 || DataObjConfiguration._TypeEndpoint == EndpointType.REST)
                          ? NsiClientHelper.DataflowDsdIsCrossSectional(kf) : !Utils.IsTimeSeries(kf);

            if (cross)
            {
                op = SDMXWSFunction.GetCrossSectionalData;
            }
            var ser = new JavaScriptSerializer();

            ser.MaxJsonLength = int.MaxValue;
            try
            {
                IGetSDMX       GetSDMXObject = WebServiceSelector.GetSdmxImplementation(DataObjConfiguration);
                BaseDataObject BDO           = new BaseDataObject(DataObjConfiguration, @"c:\pippo.txt");


                //GetSDMXObject.ExecuteQuery(BDO.CreateQueryBean(_  df, kf, Criterias), op, FileTmpData);
                //GetSDMXObject.ExecuteQuery(BDO.CreateQueryBean(, kf, Criterias), op, FileTmpData);
            }
            catch (Exception ex)
            {
            }
            //throw new NotImplementedException();
        }
Example #2
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="observationLimit">
        /// The maximum number of observations to return
        /// </param>
        /// <param name="tempFileName">
        /// The temporary fila name
        /// </param>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, int observationLimit, string tempFileName)
        {
            query = new DataQueryFluentBuilder().Initialize(query.DataStructure, query.Dataflow)
                    .WithDataQuerySelectionGroup(query.SelectionGroups).Build();

            this.ExecuteQuery(query, operationName, tempFileName);
        }
Example #3
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <exception cref="NsiClientException">Failute to execute query</exception>
        /// <returns>
        /// The SDMX-ML data as a stream.
        /// </returns>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            try
            {
                this.SendSdmxQuery(query, operationName, tempFileName);
            }

            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
            }
        }
        /// <summary>
        /// Sends the SDMX Query Request
        /// </summary>
        /// <param name="query">
        /// The SDMX Query
        /// </param>
        /// <param name="operation">
        /// The Web Service function
        /// </param>
        /// <param name="tempFileName">
        /// The temp file name
        /// </param>
        private void SendSdmxQuery(IDataQuery query, SDMXWSFunction operation, string tempFileName)
        {
            IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(new DataQueryFactory());
            var xdoc = dataQueryBuilderManager.BuildDataQuery(query, new QueryMessageV2Format());
            var doc  = new XmlDocument();

            doc.LoadXml(xdoc.ToString());
            this.SendRequest(doc, operation, tempFileName);
        }
Example #5
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="observationLimit">
        /// The maximum number of observations to return
        /// </param>
        /// <returns>
        /// The SDMX-ML data as a stream.
        /// </returns>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, int observationLimit, string tempFileName)
        {
            query = new DataQueryFluentBuilder().Initialize(query.DataStructure, query.Dataflow)
                    .WithOrderAsc(true)
                    .WithDataQuerySelectionGroup(query.SelectionGroups).WithMaxObservations(observationLimit).
                    WithDataProviders(query.DataProvider).WithDataQueryDetail(query.DataQueryDetail).
                    WithDimensionAtObservation(query.DimensionAtObservation).Build();

            this.ExecuteQuery(query, operationName, tempFileName);
        }
Example #6
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="tempFileName">
        /// The temporary file name
        /// </param>
        /// <exception cref="NsiClientException">
        /// Failute to execute query
        /// </exception>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            try
            {
                switch (operationName)
                {
                case SDMXWSFunction.GetCompactData:
                {
                    this.SendSdmxQuery(query, tempFileName);
                    break;
                }

                case SDMXWSFunction.GetCrossSectionalData:
                {
                    this._nsiClientWs.ExecuteQuery(query, operationName, tempFileName);
                    break;
                }

                default:
                {
                    Logger.Error(Resources.ExceptionExecuteQuery);
                    throw new NsiClientException(Resources.ExceptionExecuteQuery);
                }
                }
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
            }
        }
Example #7
0
        public void GetDataSet(IDataSetRenderer renderer, DataObjectForStreaming dataStream, TextWriter streamResponse, string endPointType, SessionQuery sessionQuery)
        {
            EndpointSettings DataObjConfiguration = dataStream.Configuration;

            IDataStructureObject kf = dataStream.structure.DataStructures.First();

            //DataObjectForStreaming
            SDMXWSFunction op = SDMXWSFunction.GetCompactData;
            //DataObjConfiguration

            bool cross = (DataObjConfiguration._TypeEndpoint == ISTAT.WebClient.WidgetComplements.Model.Enum.EndpointType.V21 || DataObjConfiguration._TypeEndpoint == ISTAT.WebClient.WidgetComplements.Model.Enum.EndpointType.REST)
                          ? NsiClientHelper.DataflowDsdIsCrossSectional(kf) : !Utils.IsTimeSeries(kf);

            if (cross)
            {
                op = SDMXWSFunction.GetCrossSectionalData;
            }
            var ser = new JavaScriptSerializer();

            ser.MaxJsonLength = int.MaxValue;
            try
            {
                //IGetSDMX GetSDMXObject = WebServiceSelector.GetSdmxImplementation(DataObjConfiguration);
                IGetSDMX       GetSDMXObject = (sessionQuery._IGetSDMX == null) ? WebServiceSelector.GetSdmxImplementation(DataObjConfiguration) : sessionQuery._IGetSDMX;
                BaseDataObject BDO           = new BaseDataObject(DataObjConfiguration, "tem.txt");

                string fullPath = Utils.App_Data_Path + @"\Download\" + GetFileName(_iD, "xml");

                IDataQuery query = BDO.CreateQueryBean(dataStream.structure.Dataflows.First(), kf, dataStream.Criterias);
                GetSDMXObject.ExecuteQuery(query, op, fullPath);

                //if (endPointType == "V21")
                //{
                //    SendAttachment(ConvertTo21(fullPath),GetFileName(_iD, "xml")) ;
                //    return;
                //}
                SendAttachmentFile(fullPath);
            }
            catch (Exception ex)
            {
            }
            //throw new NotImplementedException();
        }
Example #8
0
        /// <summary>
        /// Gets a reader based on the specified <paramref name="operation"/>
        /// </summary>
        /// <param name="operation">
        /// The operation
        /// </param>
        /// <param name="keyFamily">
        /// The SDMX-ML dataset KeyFamily (i.e. DSD)
        /// </param>
        /// <param name="store">
        /// The <see cref="IDataSetStore"/> in which the dataset will be stored
        /// </param>
        /// <param name="dataflow">
        /// The <see cref="IDataflowObject"/> the dataflow
        /// </param>
        /// <param name="dataLocation">
        /// The <see cref="IReadableDataLocation"/> the data location
        /// </param>
        public static void GetReader(SDMXWSFunction operation, IDataStructureObject keyFamily, IDataSetStore store,
                                     IDataflowObject dataflow, IReadableDataLocation dataLocation)
        {
            switch (operation)
            {
            case SDMXWSFunction.GetCompactData:
                var compact       = new CompactDataReaderEngine(dataLocation, dataflow, keyFamily);
                var readerCompact = new SdmxDataReader(keyFamily, store);
                readerCompact.ReadData(compact);
                break;

            case SDMXWSFunction.GetCrossSectionalData:
                var dsdCrossSectional = (ICrossSectionalDataStructureObject)keyFamily;
                var crossSectional    = new CrossSectionalDataReaderEngine(dataLocation, dsdCrossSectional, dataflow);
                var reader            = new SdmxDataReader(keyFamily, store);
                reader.ReadData(crossSectional);
                break;

            default:
                throw new ArgumentException(Resources.ExceptionUnsupported_operation + operation.ToString(), "operation");
            }
        }
        /// <summary>
        /// Constructs a SOAP envelope request, with a body that includes the operation as element and the W3C Document and saves the SDMX Part of the response to the specified ouput
        /// The W3C Document contains either a SDMX-ML Query or a SDMX-ML Registry Interface
        /// </summary>
        /// <param name="request">
        /// The W3C Document representation of a SDMX-ML Query or QueryStructureRequest
        /// </param>
        /// <param name="webServiceOperation">
        /// The Web Service function
        /// </param>
        /// <param name="tempFileName">
        /// The temporary file name
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// request is null
        /// </exception>
        /// <exception cref="NsiClientException">
        /// Error in server response or communication
        /// </exception>
        private void SendRequest(XmlDocument request, SDMXWSFunction webServiceOperation, string tempFileName)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            NsiClientHelper.LogSdmx(_config, request);
            var sb = new StringBuilder();
            sb.AppendFormat(SoapConstants.SoapRequest, this._config.Prefix, this._wsdlConfig.GetTargetNamespace());
            var doc = new XmlDocument();
            doc.LoadXml(sb.ToString());
            string operationName = webServiceOperation.ToString();
            XmlNodeList nodes = doc.GetElementsByTagName(SoapConstants.Body, SoapConstants.Soap11Ns);
            XmlElement operation = doc.CreateElement(
                this._config.Prefix, operationName, this._wsdlConfig.GetTargetNamespace());

            XmlElement queryParent = operation;
            string parameterName = this._wsdlConfig.GetParameterName(operationName);
            if (!string.IsNullOrEmpty(parameterName))
            {
                queryParent = doc.CreateElement(
                    this._config.Prefix, parameterName, this._wsdlConfig.GetTargetNamespace());
                operation.AppendChild(queryParent);
            }

            if (request.DocumentElement != null)
            {
                XmlNode sdmxQueryNode = doc.ImportNode(request.DocumentElement, true);
                queryParent.AppendChild(sdmxQueryNode);
            }

            nodes[0].AppendChild(operation);

            var endpointUri = new Uri(this._config.EndPoint);
            var webRequest = (HttpWebRequest)WebRequest.Create(endpointUri);
            webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
            webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;

            string soapAction = this._wsdlConfig.GetSoapAction(operationName);
            if (soapAction != null)
            {
                webRequest.Headers.Add(SoapConstants.SoapAction, soapAction);
            }

            webRequest.ContentType = HttpConstants.Content;

            // webRequest.Accept = "text/xml";
            webRequest.Method = HttpConstants.Post;
            webRequest.Timeout = 1800*1000;
            // webRequest.CookieContainer = new CookieContainer();
            this._config.SetupWebRequestAuth(webRequest);

            using (Stream stream = webRequest.GetRequestStream())
            {
                doc.Save(stream);
            }

            try
            {
                using (WebResponse response = webRequest.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            var settings = new XmlWriterSettings();
                            settings.Indent = true;
                            using (XmlWriter writer = XmlWriter.Create(tempFileName, settings))
                            {
                                SoapUtils.ExtractSdmxMessage(stream, writer);
                            }
                            NsiClientHelper.LogSdmx(_config, tempFileName, Resources.InfoSoapResponse);
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                NsiClientHelper.HandleSoapFault(ex);
            }
        }
Example #10
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="tempFileName">
        /// The temporary file name
        /// </param>
        /// <exception cref="NsiClientException">Failute to execute query</exception>
        /// <returns>
        /// The SDMX-ML data as a stream.
        /// </returns>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            try
            {
                switch (operationName)
                {
                case SDMXWSFunction.GetCompactData:
                {
                    this.SendSdmxQuery(query, SDMXWSFunctionV21.GetStructureSpecificData, tempFileName);

                    using (var dataLocation = new FileReadableDataLocation(tempFileName))
                    {
                        var sdmxFooterMessage = SdmxMessageUtilExt.ParseSdmxFooterMessage(dataLocation);
                        if (sdmxFooterMessage != null && (sdmxFooterMessage.Code.Equals("510") || sdmxFooterMessage.Code.Equals("130")))
                        {
                            var sb = new StringBuilder();
                            foreach (var footerText in sdmxFooterMessage.FooterText)
                            {
                                sb.Append(footerText.Value + " ");
                            }
                            string info = string.Format(CultureInfo.InvariantCulture, Resources.SdmxFooterMessage, sb, sdmxFooterMessage.Code, sdmxFooterMessage.Severity);
                            Logger.ErrorFormat(CultureInfo.InvariantCulture, Resources.MaxObservations, info);
                            throw new FooterMessageException(Resources.EnterMoreCriteria);
                        }
                    }
                    break;
                }

                case  SDMXWSFunction.GetCrossSectionalData:
                {
                    _nsiClientWs.ExecuteQuery(query, operationName, tempFileName);
                    break;
                }

                default:
                {
                    Logger.Error(Resources.ExceptionExecuteQuery);
                    throw new NsiClientException(Resources.ExceptionExecuteQuery);
                }
                }
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (FooterMessageException e)
            {
                NsiClientHelper.TryToDelete(tempFileName);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
            }
        }
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="observationLimit">
        /// The maximum number of observations to return
        /// </param>
        /// <param name="tempFileName">
        /// The temporary fila name
        /// </param>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, int observationLimit, string tempFileName)
        {
            query = new DataQueryFluentBuilder().Initialize(query.DataStructure, query.Dataflow)
                .WithDataQuerySelectionGroup(query.SelectionGroups).Build();

             this.ExecuteQuery(query, operationName, tempFileName);
        }
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="tempFileName">
        /// The temporary file name
        /// </param>
        /// <exception cref="NsiClientException">
        /// Failute to execute query
        /// </exception>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            try
            {
                switch (operationName)
                {
                    case SDMXWSFunction.GetCompactData:
                        {
                            this.SendSdmxQuery(query, tempFileName);
                            using (var dataLocation = new FileReadableDataLocation(tempFileName))
                            {
                                var sdmxFooterMessage = SdmxMessageUtilExt.ParseSdmxFooterMessage(dataLocation);
                                if (sdmxFooterMessage!=null && (sdmxFooterMessage.Code.Equals("510") || sdmxFooterMessage.Code.Equals("130")))
                                {
                                    var sb = new StringBuilder();
                                    foreach (var footerText in sdmxFooterMessage.FooterText)
                                    {
                                        sb.Append(footerText.Value + " ");
                                    }
                                    string info = string.Format(CultureInfo.InvariantCulture, Resources.SdmxFooterMessage, sb, sdmxFooterMessage.Code, sdmxFooterMessage.Severity);
                                    Logger.ErrorFormat(CultureInfo.InvariantCulture, Resources.MaxObservations, info);
                                    throw new FooterMessageException(Resources.EnterMoreCriteria);
                                }
                            }
                            break;
                        }

                    case SDMXWSFunction.GetCrossSectionalData:
                        {
                            this._nsiClientWs.ExecuteQuery(query, operationName, tempFileName);
                            break;
                        }

                    default:
                        {
                            Logger.Error(Resources.ExceptionExecuteQuery);
                            throw new NsiClientException(Resources.ExceptionExecuteQuery);
                        }
                }
            }
            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (FooterMessageException e)
            {
                NsiClientHelper.TryToDelete(tempFileName);
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
            }
        }
        internal IDataSetStore GetDataset(IDataflowObject df, IDataStructureObject kf, List <DataCriteria> Criterias, ref Dictionary <string, List <DataChacheObject> > DataCache, bool useAttr, SessionQuery query)
        {
            // if it is not time series then assume it is cross
            SDMXWSFunction op    = SDMXWSFunction.GetCompactData;
            bool           cross = (DataObjConfiguration._TypeEndpoint == EndpointType.V21 || DataObjConfiguration._TypeEndpoint == EndpointType.REST)
                          ? NsiClientHelper.DataflowDsdIsCrossSectional(kf) : !Utils.IsTimeSeries(kf);

            if (cross)
            {
                op = SDMXWSFunction.GetCrossSectionalData;
            }

            var ser = new JavaScriptSerializer();

            ser.MaxJsonLength = int.MaxValue;
            try
            {
                #region Connessione e Creazione DB SQLLite FABIO se nullo lo istanzio
                string   table         = null;
                IGetSDMX GetSDMXObject = (query._IGetSDMX == null) ? WebServiceSelector.GetSdmxImplementation(DataObjConfiguration) : query._IGetSDMX;
                GetSDMXObject.ExecuteQuery(CreateQueryBean(df, kf, Criterias), op, FileTmpData);

                #region Connessione e Creazione DB SQLLite
                table = Path.Combine(Utils.GetAppPath(), string.Format(CultureInfo.InvariantCulture, "{0}-{1}.sqlite", Utils.MakeKey(df).Replace("+", "_").Replace(".", ""), Guid.NewGuid()));
                string        ConnectionString = string.Format(CultureInfo.InvariantCulture, Constants.FileDBSettingsFormat, table);
                var           info             = new DBInfo(ConnectionString);
                string        tempTable        = "table_" + Utils.MakeKey(df).Replace("+", "_").Replace(".", "");
                IDataSetStore store            = new DataSetStoreDB(info, tempTable, kf, true, useAttr);
                #endregion

                using (var dataLocation = new FileReadableDataLocation(FileTmpData))
                {
                    switch (op)
                    {
                    case SDMXWSFunction.GetCompactData:
                        var compact       = new CompactDataReaderEngine(dataLocation, df, kf);
                        var readerCompact = new SdmxDataReader(kf, store);
                        readerCompact.ReadData(compact);
                        break;

                    case SDMXWSFunction.GetCrossSectionalData:
                        var dsdCrossSectional = (ICrossSectionalDataStructureObject)kf;
                        var crossSectional    = new CrossSectionalDataReaderEngine(dataLocation, dsdCrossSectional, df);
                        var reader            = new SdmxDataReader(kf, store);
                        reader.ReadData(crossSectional);
                        break;

                    default:
                        throw new ArgumentException(Resources.ExceptionUnsupported_operation + op.ToString(), "operation");
                    }
                }

                #endregion FABIO



                return(store);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw ex;
            }
            finally
            {
                //delete the temporary file
                if (File.Exists(FileTmpData))
                {
                    File.Delete(FileTmpData);
                }
            }
        }
        internal IDataSetStore GetDataset(IDataflowObject df, IDataStructureObject kf, List <DataCriteria> Criterias, ref Dictionary <string, List <DataChacheObject> > DataCache, bool useAttr)
        {
            // if it is not time series then assume it is cross
            SDMXWSFunction op    = SDMXWSFunction.GetCompactData;
            bool           cross = (DataObjConfiguration._TypeEndpoint == EndpointType.V21 || DataObjConfiguration._TypeEndpoint == EndpointType.REST)
                          ? NsiClientHelper.DataflowDsdIsCrossSectional(kf) : !Utils.IsTimeSeries(kf);

            if (cross)
            {
                op = SDMXWSFunction.GetCrossSectionalData;
            }

            var ser = new JavaScriptSerializer();

            ser.MaxJsonLength = int.MaxValue;
            try
            {
                //commentato vecchio codice
                //IGetSDMX GetSDMXObject = WebServiceSelector.GetSdmxImplementation(DataObjConfiguration);
                //GetSDMXObject.ExecuteQuery(CreateQueryBean(df, kf, Criterias), op, FileTmpData);

                /*
                 #region Connessione e Creazione DB SQLLite
                 * string table = Path.Combine(Utils.GetAppPath(), string.Format(CultureInfo.InvariantCulture, "{0}-{1}.sqlite", Utils.MakeKey(df).Replace("+", "_").Replace(".", ""), Guid.NewGuid()));
                 * string ConnectionString = string.Format(CultureInfo.InvariantCulture, Constants.FileDBSettingsFormat, table);
                 * var info = new DBInfo(ConnectionString);
                 * string tempTable = "table_" + Utils.MakeKey(df).Replace("+", "_").Replace(".", "");
                 * IDataSetStore store = new DataSetStoreDB(info, tempTable, kf, true, useAttr);
                 #endregion
                 * fine vecchio codice*/

                //Salvo in Session

                /*
                 * if (DataCache == null)
                 *  DataCache = new Dictionary<string, List<DataChacheObject>>();
                 * if (!DataCache.ContainsKey(Utils.MakeKey(df)))
                 *  DataCache[Utils.MakeKey(df)] = new List<DataChacheObject>();
                 */
                //string table=null;
                //FABIO NEW
                //IDataSetStore store = FindDataCacheChart(df, kf, Criterias, ref DataCache, useAttr,out table);

                //if (store == null) store = GetDataset(df, kf, Criterias, ref DataCache, useAttr);
                #region Connessione e Creazione DB SQLLite FABIO se nullo lo istanzio
//                if (store == null)
//                {
                string   table         = null;
                IGetSDMX GetSDMXObject = WebServiceSelector.GetSdmxImplementation(DataObjConfiguration);
                GetSDMXObject.ExecuteQuery(CreateQueryBean(df, kf, Criterias), op, FileTmpData);

                #region Connessione e Creazione DB SQLLite
                table = Path.Combine(Utils.GetAppPath(), string.Format(CultureInfo.InvariantCulture, "{0}-{1}.sqlite", Utils.MakeKey(df).Replace("+", "_").Replace(".", ""), Guid.NewGuid()));
                string        ConnectionString = string.Format(CultureInfo.InvariantCulture, Constants.FileDBSettingsFormat, table);
                var           info             = new DBInfo(ConnectionString);
                string        tempTable        = "table_" + Utils.MakeKey(df).Replace("+", "_").Replace(".", "");
                IDataSetStore store            = new DataSetStoreDB(info, tempTable, kf, true, useAttr);
                #endregion

                using (var dataLocation = new FileReadableDataLocation(FileTmpData))
                {
                    switch (op)
                    {
                    case SDMXWSFunction.GetCompactData:
                        var compact       = new CompactDataReaderEngine(dataLocation, df, kf);
                        var readerCompact = new SdmxDataReader(kf, store);
                        readerCompact.ReadData(compact);
                        break;

                    case SDMXWSFunction.GetCrossSectionalData:
                        var dsdCrossSectional = (ICrossSectionalDataStructureObject)kf;
                        var crossSectional    = new CrossSectionalDataReaderEngine(dataLocation, dsdCrossSectional, df);
                        var reader            = new SdmxDataReader(kf, store);
                        reader.ReadData(crossSectional);
                        break;

                    default:
                        throw new ArgumentException(Resources.ExceptionUnsupported_operation + op.ToString(), "operation");
                    }
                }

//                }
                #endregion FABIO



                //using (var dataLocation = new FileReadableDataLocation(FileTmpData))
                //{
                //    switch (op)
                //    {
                //        case SDMXWSFunction.GetCompactData:
                //            var compact = new CompactDataReaderEngine(dataLocation, df, kf);
                //            var readerCompact = new SdmxDataReader(kf, store);
                //            readerCompact.ReadData(compact);
                //            break;

                //        case SDMXWSFunction.GetCrossSectionalData:
                //            var dsdCrossSectional = (ICrossSectionalDataStructureObject)kf;
                //            var crossSectional = new CrossSectionalDataReaderEngine(dataLocation, dsdCrossSectional, df);
                //            var reader = new SdmxDataReader(kf, store);
                //            reader.ReadData(crossSectional);
                //            break;

                //        default:
                //            throw new ArgumentException(Resources.ExceptionUnsupported_operation + op.ToString(), "operation");
                //    }
                //}



                /*
                 * Dictionary<string, List<string>> Criteri = new Dictionary<string, List<string>>();
                 * Criterias.ForEach(c => Criteri.Add(c.component, c.values));
                 * DataChacheObject dco = new DataChacheObject()
                 * {
                 *  Criterias = Criteri,
                 *  DBFileName = table,
                 * };
                 *
                 * //aggiunta da fabio
                 * DataCache[Utils.MakeKey(df)].Clear();
                 * //fine aggiunta fabio
                 * DataCache[Utils.MakeKey(df)].Add(dco);
                 */
                return(store);
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw ex;
            }
            finally
            {
                //delete the temporary file
                if (File.Exists(FileTmpData))
                {
                    File.Delete(FileTmpData);
                }
            }
        }
        /// <summary>
        /// Gets a reader based on the specified <paramref name="operation"/>
        /// </summary>
        /// <param name="operation">
        /// The operation
        /// </param>
        /// <param name="keyFamily">
        /// The SDMX-ML dataset KeyFamily (i.e. DSD) 
        /// </param>
        /// <param name="store">
        /// The <see cref="IDataSetStore"/> in which the dataset will be stored
        /// </param>
        /// <param name="dataflow">
        /// The <see cref="IDataflowObject"/> the dataflow
        /// </param>
        /// <param name="dataLocation">
        /// The <see cref="IReadableDataLocation"/> the data location 
        /// </param>
        public static void GetReader(SDMXWSFunction operation, IDataStructureObject keyFamily, IDataSetStore store,
          IDataflowObject dataflow, IReadableDataLocation dataLocation)
        {
            switch (operation)
            {
                case SDMXWSFunction.GetCompactData:
                    var compact = new CompactDataReaderEngine(dataLocation, dataflow, keyFamily);
                    var readerCompact = new SdmxDataReader(keyFamily, store);
                    readerCompact.ReadData(compact);
                    break;

                case SDMXWSFunction.GetCrossSectionalData:
                    var dsdCrossSectional = (ICrossSectionalDataStructureObject)keyFamily;
                    var crossSectional = new CrossSectionalDataReaderEngine(dataLocation, dsdCrossSectional, dataflow);
                    var reader = new SdmxDataReader(keyFamily, store);
                    reader.ReadData(crossSectional);
                    break;

                default:
                    throw new ArgumentException(Resources.ExceptionUnsupported_operation + operation.ToString(), "operation");
            }
        }
 /// <summary>
 /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
 /// </summary>
 /// <param name="query">
 /// The SDMX Query to execute
 /// </param>
 /// <param name="operationName">
 /// The type of operation, GetCompactData or GetCrossSectionalData
 /// </param>
 /// <param name="tempFileName">
 /// The temporary file name
 /// </param>
 /// <exception cref="NsiClientException">Failute to execute query</exception>
 /// <returns>
 /// The SDMX-ML data as a stream.
 /// </returns>
 public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
 {
     if (query == null)
     {
         throw new ArgumentNullException("query");
     }
     try
     {
         switch (operationName)
         {
             case SDMXWSFunction.GetCompactData:
                 {
                     this.SendSdmxQuery(query, SDMXWSFunctionV21.GetStructureSpecificData, tempFileName);
                     break;
                 }
             case SDMXWSFunction.GetCrossSectionalData:
                 {
                     _nsiClientWs.ExecuteQuery(query, operationName, tempFileName);
                     break;
                 }
             default:
                 {
                     Logger.Error(Resources.ExceptionExecuteQuery);
                     throw new NsiClientException(Resources.ExceptionExecuteQuery);
                 }
         }
     }
     catch (NsiClientException e)
     {
         Logger.Error(Resources.ExceptionExecuteQuery);
         NsiClientHelper.TryToDelete(tempFileName);
         Logger.Error(e.Message, e);
         throw;
     }
     catch (DataflowException e)
     {
         throw;
     }
     catch (Exception e)
     {
         Logger.Error(Resources.ExceptionExecuteQuery);
         NsiClientHelper.TryToDelete(tempFileName);
         throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
     }
 }
Example #17
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <param name="observationLimit">
        /// The maximum number of observations to return
        /// </param>
        /// <returns>
        /// The SDMX-ML data as a stream.
        /// </returns>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, int observationLimit, string tempFileName)
        {
            query = new DataQueryFluentBuilder().Initialize(query.DataStructure, query.Dataflow)
                .WithOrderAsc(true)
                .WithDataQuerySelectionGroup(query.SelectionGroups).WithMaxObservations(observationLimit).
                WithDataProviders(query.DataProvider).WithDataQueryDetail(query.DataQueryDetail).
                WithDimensionAtObservation(query.DimensionAtObservation).Build();

               this.ExecuteQuery(query, operationName, tempFileName);
        }
Example #18
0
        /// <summary>
        /// Execute SDMX Query against the NSI WS to retrieve SDMX-ML Data as a Stream
        /// </summary>
        /// <param name="query">
        /// The SDMX Query to execute
        /// </param>
        /// <param name="operationName">
        /// The type of operation, GetCompactData or GetCrossSectionalData
        /// </param>
        /// <exception cref="NsiClientException">Failute to execute query</exception>
        /// <returns>
        /// The SDMX-ML data as a stream.
        /// </returns>
        public void ExecuteQuery(IDataQuery query, SDMXWSFunction operationName, string tempFileName)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            try
            {
                this.SendSdmxQuery(query, operationName, tempFileName);
            }

            catch (NsiClientException e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                Logger.Error(e.Message, e);
                throw;
            }
            catch (DataflowException e)
            {
                throw;
            }
            catch (Exception e)
            {
                Logger.Error(Resources.ExceptionExecuteQuery);
                NsiClientHelper.TryToDelete(tempFileName);
                throw new NsiClientException(Resources.ExceptionExecuteQuery, e);
            }
        }
Example #19
0
        /// <summary>
        /// Constructs a SOAP envelope request, with a body that includes the operation as element and the W3C Document and saves the SDMX Part of the response to the specified ouput
        /// The W3C Document contains either a SDMX-ML Query or a SDMX-ML Registry Interface
        /// </summary>
        /// <param name="request">
        /// The W3C Document representation of a SDMX-ML Query or QueryStructureRequest
        /// </param>
        /// <param name="webServiceOperation">
        /// The Web Service function
        /// </param>
        /// <param name="tempFileName">
        /// The temporary file name
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// request is null
        /// </exception>
        /// <exception cref="NsiClientException">
        /// Error in server response or communication
        /// </exception>
        private void SendRequest(
            XmlDocument request,
            SDMXWSFunction webServiceOperation,
            string tempFileName)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            NsiClientHelper.LogSdmx(request);
            var sb = new StringBuilder();

            sb.AppendFormat(SoapConstants.SoapRequest, this._config.Prefix, this._wsdlConfig.GetTargetNamespace());
            var doc = new XmlDocument();

            doc.LoadXml(sb.ToString());
            string      operationName = webServiceOperation.ToString();
            XmlNodeList nodes         = doc.GetElementsByTagName(SoapConstants.Body, SoapConstants.Soap11Ns);
            XmlElement  operation     = doc.CreateElement(
                this._config.Prefix, operationName, this._wsdlConfig.GetTargetNamespace());

            XmlElement queryParent   = operation;
            string     parameterName = this._wsdlConfig.GetParameterName(operationName);

            if (!string.IsNullOrEmpty(parameterName))
            {
                queryParent = doc.CreateElement(
                    this._config.Prefix, parameterName, this._wsdlConfig.GetTargetNamespace());
                operation.AppendChild(queryParent);
            }

            if (request.DocumentElement != null)
            {
                XmlNode sdmxQueryNode = doc.ImportNode(request.DocumentElement, true);
                queryParent.AppendChild(sdmxQueryNode);
            }

            nodes[0].AppendChild(operation);

            var endpointUri = new Uri(this._config.EndPoint);
            var webRequest  = (HttpWebRequest)WebRequest.Create(endpointUri);

            webRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
            webRequest.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;

            string soapAction = this._wsdlConfig.GetSoapAction(operationName);

            //if (soapAction != null && soapAction != "")
            if (soapAction != null)
            {
                webRequest.Headers.Add(SoapConstants.SoapAction, soapAction);
            }

            webRequest.ContentType = HttpConstants.Content;

            // webRequest.Accept = "text/xml";
            webRequest.Method  = HttpConstants.Post;
            webRequest.Timeout = 1800 * 1000;
            this.SetupWebRequestAuth(webRequest);

            using (Stream stream = webRequest.GetRequestStream())
            {
                doc.Save(stream);
            }

            try
            {
                using (WebResponse response = webRequest.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            var settings = new XmlWriterSettings();
                            settings.Indent = true;
                            using (XmlWriter writer = XmlWriter.Create(tempFileName, settings))
                            {
                                SoapUtils.ExtractSdmxMessage(stream, writer);
                            }
                            NsiClientHelper.LogSdmx(tempFileName, Resources.InfoSoapResponse);
                        }
                    }
                }
            }
            catch (WebException ex)
            {
                NsiClientHelper.HandleSoapFault(ex);
            }
        }
Example #20
0
 /// <summary>
 /// Sends the SDMX Query Request
 /// </summary>
 /// <param name="query">
 /// The SDMX Query
 /// </param>
 /// <param name="operation">
 /// The Web Service function
 /// </param>
 /// <param name="tempFileName">
 /// The temp file name
 /// </param>
 private void SendSdmxQuery(IDataQuery query, SDMXWSFunction operation, string tempFileName)
 {
     IDataQueryBuilderManager dataQueryBuilderManager = new DataQueryBuilderManager(new DataQueryFactory());
     var xdoc = dataQueryBuilderManager.BuildDataQuery(query, new QueryMessageV2Format());
     var doc = new XmlDocument();
     doc.LoadXml(xdoc.ToString());
     this.SendRequest(doc, operation, tempFileName);
 }