Ejemplo n.º 1
0
 public void TestCompactDataReader(string file)
 {
     IDataStructureObject dsd = BuildDsd();
     using (var sourceData = this._factory.GetReadableDataLocation(new FileInfo(file)))
     {
         var dataReaderEngine = new CompactDataReaderEngine(sourceData, null, dsd);
         Assert.NotNull(dataReaderEngine.Header);
         Assert.IsTrue(dataReaderEngine.MoveNextDataset());
         Assert.IsTrue(dataReaderEngine.MoveNextKeyable());
         Assert.AreEqual("Q", dataReaderEngine.CurrentKey.GetKeyValue("FREQ"));
         Assert.AreEqual("N", dataReaderEngine.CurrentKey.GetKeyValue("ADJUSTMENT"));
         Assert.AreEqual("A", dataReaderEngine.CurrentKey.GetKeyValue("STS_ACTIVITY"));
         Assert.IsTrue(dataReaderEngine.MoveNextObservation());
         Assert.AreEqual("2005-Q1", dataReaderEngine.CurrentObservation.ObsTime);
     }
 }
Ejemplo n.º 2
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");
            }
        }
Ejemplo n.º 3
0
        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);

            }
        }