Ejemplo n.º 1
0
        public SessionImplObject GetData(out object DataStream,SessionQuery query)
        {
            try
            {
                // Init session objects
                if (this.SessionObj == null)
                {
                    this.SessionObj = new SessionImplObject();
                    this.SessionObj.SdmxObject = new SdmxObjectsImpl();
                }

                if (BDO == null || GetSDMXObject == null)
                    throw new Exception(Messages.label_error_network + " " + DataObj.Configuration.Title);

                codemapWidget = new CodemapWidget(new GetCodemapObject() {
                    Configuration = this.DataObj.Configuration,
                    Dataflow = this.DataObj.Dataflow,
                    PreviusCostraint=this.DataObj.Criteria },
                    this.SessionObj);
                //ISdmxObjects structure = codemapWidget.GetDsd();
                ISdmxObjects structure = query.Structure;
                IDataflowObject df = structure.Dataflows.FirstOrDefault();
                IDataStructureObject kf = structure.DataStructures.First();
                if (df == null) throw new InvalidOperationException("Dataflow is not set");

                /****************/
                // Get all codelist
                /****************/
                //Dictionary<string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(df, kf, true);
                Dictionary<string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(query, false);
                ComponentCodeDescriptionDictionary codemap = new ComponentCodeDescriptionDictionary();
                foreach (string ConceptId in ConceptCodelists.Keys)
                {
                    ICodelistObject codelist = ConceptCodelists[ConceptId];
                    Dictionary<string, string> codes = new Dictionary<string, string>();
                    foreach (ICode codeItem in codelist.Items)
                        codes.Add(codeItem.Id, TextTypeHelper.GetText(codeItem.Names, this.DataObj.Configuration.Locale));
                    codemap.Add(ConceptId, codes);
                }
                /****************/
                //codemapWidget.GetCodeListCostraint(df,kf,component)

                this.SessionObj.MergeObject(codemapWidget.SessionObj);

                #region Gestione last period
                if (this.DataObj.Criteria.ContainsKey(kf.TimeDimension.Id)
                 && this.DataObj.Criteria[kf.TimeDimension.Id].Count == 1
                 && !this.DataObj.Layout.axis_z.Contains(kf.TimeDimension.Id))
                {
                    int offsetTime = int.Parse(this.DataObj.Criteria[kf.TimeDimension.Id].First());
                    var codMap = codemap;
                    int lengthTime = codMap[kf.TimeDimension.Id].Count;

                    if ((lengthTime - offsetTime) >= 0)
                    {
                        var codes = codMap[kf.TimeDimension.Id].Reverse().Take(offsetTime);
                        List<string> _criteriaTime = (from c in codes select c.Key).ToList<string>();

                        this.DataObj.Criteria[kf.TimeDimension.Id] = new List<string>();
                        this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.Last());
                        this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.First());
                    }
                    else
                    {
                        this.DataObj.Criteria[kf.TimeDimension.Id] = new List<string>();
                        this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].First().Key);
                        this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].Last().Key);
                    }
                }
                #endregion

                LayoutObj layObj = InitLayout(df, kf);
                List<DataCriteria> Criterias = BDO.InitCriteria(kf, this.DataObj.Criteria);
                //query.GetCriteria();

                Dictionary<string, List<DataChacheObject>> DataCache = SessionObj.DataCache;
                List <string> ret = null;
                List<DataCriteria> QueryCriterias=new List<DataCriteria>();

                if (query.Criteria != null)//criteri nulli se proviene da un template
                {
                    if (query._store != null) //.Count == 1)
                    { query.SetCriteriaTime(this.DataObj.Criteria[kf.TimeDimension.Id]); }

                    if (query.Criteria.TryGetValue(kf.TimeDimension.Id, out ret))
                    {
                        if (ret.Count == 1)
                        { query.SetCriteriaTime(this.DataObj.Criteria[kf.TimeDimension.Id]); }
                    }

                    QueryCriterias = query.GetCriteria();
                    /*if (query._store == null) //.Count == 1)
                    { QueryCriterias = Criterias; }
                    else
                    { QueryCriterias = query.GetCriteria(); }*/

                }
                else
                {
                    QueryCriterias = Criterias;
                }

                //aggiunta da fabio
                IDataSetStore store;
                if (query._store != null)
                { store = query._store; }
                else
                {
                    //store = BDO.GetDataset(df, kf, Criterias, ref DataCache, _useAttr);
                    store = BDO.GetDataset(df, kf, QueryCriterias, ref DataCache, _useAttr);
                    query._store = store;
                }
                //fine nuovo

                SessionObj.DataCache = DataCache;

                DataStream = new DataObjectForStreaming()
                {
                    Configuration = this.DataObj.Configuration,
                    store = store,
                    layObj = layObj,
                    Criterias = Criterias,
                    structure = structure,
                    codemap = codemap
                };

                return this.SessionObj;
            }
            catch (Exception ex)
            {
                Logger.Warn(ex.Message, ex);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private static ISTAT.WebClient.WidgetEngine.Model.DataRender.IDataSetModel GetDataSetModel(DataObjectForStreaming dataStream)
        {
            ISTAT.WebClient.WidgetEngine.Model.DataRender.IDataSetModel dataSetModel;

            dataStream.layObj.axis_x.ForEach(axisX => { if (!dataStream.store.ExistsColumn(axisX)) dataStream.layObj.axis_x.Remove(axisX); });
            dataStream.layObj.axis_y.ForEach(axisY => { if (!dataStream.store.ExistsColumn(axisY)) dataStream.layObj.axis_y.Remove(axisY); });
            dataStream.layObj.axis_z.ForEach(axisZ => { if (!dataStream.store.ExistsColumn(axisZ)) dataStream.layObj.axis_z.Remove(axisZ); });

            dataSetModel = new DataSetModelStore(dataStream.structure, dataStream.store);

            dataSetModel.Initialize();
            dataSetModel.UpdateAxis(dataStream.layObj.axis_z, dataStream.layObj.axis_x, dataStream.layObj.axis_y);

            return dataSetModel;
        }
Ejemplo n.º 3
0
 public static void GetDownloadStream(IDataSetRenderer renderer, DataObjectForStreaming dataStream, MemoryStream memoryStream)
 {
     GetModel(renderer, GetDataSetModel(dataStream), memoryStream);
 }
Ejemplo n.º 4
0
 public static void GetDownloadStream(IDataSetRenderer renderer, DataObjectForStreaming dataStream, TextWriter streamResponse)
 {
     GetModel(renderer, GetDataSetModel(dataStream), streamResponse);
 }
Ejemplo n.º 5
0
        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();
        }
        private void InitObject()
        {
            if (Session[_iD] == null || !(Session[_iD] is DataObjectForStreaming))
                throw new Exception("Data not found");

            _maxContent = (long)ISTAT.WebClient.WidgetComplements.Model.Settings.WebClientSettings.Instance.MaxResultHTML;
            _memoryStream = new System.IO.MemoryStream();
            _textWriter = new System.IO.StreamWriter(_memoryStream);
            _useAttr = (ConfigurationManager.AppSettings["ParseSDMXAttributes"].ToString().ToLower() == "true");
            _dataStream = (DataObjectForStreaming)Session[_iD];
        }
        public void GetDataSet(IDataSetRenderer renderer, DataObjectForStreaming dataStream, TextWriter streamResponse, string endPointType)
        {
            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);
                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();
        }