/// <summary> /// Initializes a new instance of the <see cref="DataSetModelStore"/> class. /// Initialize a new instance of the <see cref="DataSetModelStore"/> /// </summary> /// <param name="structure"> /// The SDMX structure file /// </param> /// <param name="store"> /// The <see cref="IDataSetStore"/> /// </param> public DataSetModelStore(ISdmxObjects structure, IDataSetStore store) : base(structure, store) { if (store == null) { throw new ArgumentNullException("store"); } }
/// <summary> /// The set data store. /// </summary> /// <param name="store"> /// The store. /// </param> internal void SetDataStore(IDataSetStore store) { if (this._store != null) { this._store.Dispose(); } this._store = store; }
public DataRender(IDataSetStore store, List <DataCriteria> Criterias, LayoutObj layObj, ISdmxObjects structure, ComponentCodeDescriptionDictionary codemap, bool useAttr, CultureInfo cFrom, CultureInfo cTo) { this.store = store; this.Criterias = Criterias; this.layObj = layObj; this.Structure = structure; this.codemap = codemap; this._useAttr = useAttr; this.cFrom = cFrom; this.cTo = cTo; }
public DataRender(IDataSetStore store, List<DataCriteria> Criterias, LayoutObj layObj, ISdmxObjects structure, ComponentCodeDescriptionDictionary codemap, bool useAttr, CultureInfo cFrom, CultureInfo cTo) { this.store = store; this.Criterias = Criterias; this.layObj = layObj; this.Structure = structure; this.codemap = codemap; this._useAttr=useAttr; this.cFrom=cFrom; this.cTo=cTo; }
/// <summary> /// Clear data /// </summary> public void ClearData() { this.CloseSdmxMLDataSet(); this._dataSetModel = null; string fileName = ""; if (this._store != null) { fileName = (((ISTAT.WebClient.WidgetEngine.Model.DBData.DataSetStoreDB)(this._store))._dbInfo.Connection).DataSource; this._store.Dispose(); this._store = null; } for (int i = 0, j = this._dataDisposeList.Count; i < j; i++) { this._dataDisposeList[i].Dispose(); } this._dataDisposeList.Clear(); try { // close any files //FileInfo[] files = this._cacheFolder.GetFiles(this._sessionPrefix + "*.*"); FileInfo[] files = this._cacheFolder.GetFiles(fileName + ".sqlite"); foreach (FileInfo file in files) { file.Delete(); } } catch (IOException e) { Logger.Warn(e.Message, e); } catch (SecurityException e) { Logger.Warn(e.Message, e); } catch (UnauthorizedAccessException e) { Logger.Warn(e.Message, e); } }
/// <summary> /// Initializes a new instance of the <see cref="AbstractDataSetModel"/> class. /// </summary> /// <param name="structure"> /// The SDMX-ML structure /// </param> /// <param name="store"> /// The <see cref="IDataSetStore"/> containing the dataset data /// </param> protected AbstractDataSetModel(ISdmxObjects structure, IDataSetStore store) { if (structure == null) { throw new ArgumentNullException("structure"); } this._store = store; this._structure = structure; // The structure must define exactly one key family... if ((this._structure.DataStructures == null) || (this._structure.DataStructures.Count != 1)) { throw new Exception( "Invalid structure bean, it does not contain the definition for exactly one key family!"); } this._dataFlow = this._structure.Dataflows.First(); this._keyFamily = this._structure.DataStructures.First(); }
/// <summary> /// Clear data /// </summary> public void ClearData() { this.CloseSdmxMLDataSet(); this._dataSetModel = null; if (this._store != null) { this._store.Dispose(); this._store = null; } for (int i = 0, j = this._dataDisposeList.Count; i < j; i++) { this._dataDisposeList[i].Dispose(); } this._dataDisposeList.Clear(); try { // close any files /*DA FARE FABIO NUOVO * _cacheFolder = new DirectoryInfo(Utils.GetAppPath()); * FileInfo[] files = this._cacheFolder.GetFiles(this._sessionPrefix + "*.*"); * foreach (FileInfo file in files) * { * file.Delete(); * }*/ } catch (IOException e) { Logger.Warn(e.Message, e); } catch (SecurityException e) { Logger.Warn(e.Message, e); } catch (UnauthorizedAccessException e) { Logger.Warn(e.Message, e); } }
/// <summary> /// Clear data /// </summary> public void ClearData() { this.CloseSdmxMLDataSet(); this._dataSetModel = null; if (this._store != null) { this._store.Dispose(); this._store = null; } for (int i = 0, j = this._dataDisposeList.Count; i < j; i++) { this._dataDisposeList[i].Dispose(); } this._dataDisposeList.Clear(); try { // close any files FileInfo[] files = this._cacheFolder.GetFiles(this._sessionPrefix + "*.*"); foreach (FileInfo file in files) { file.Delete(); } } catch (IOException e) { Logger.Warn(e.Message, e); } catch (SecurityException e) { Logger.Warn(e.Message, e); } catch (UnauthorizedAccessException e) { Logger.Warn(e.Message, e); } }
private List <serieType> BuildChart( IDataSetStore store, IDataStructureObject kf, Dictionary <string, ICodelistObject> codelists) { List <string> sort = new List <string>(); foreach (string col in store.GetAllColumns()) { if (col != kf.TimeDimension.Id && col != kf.PrimaryMeasure.Id) { sort.Add(col); } } store.SetSort(sort); // Dimensione sull'asse X string XConcept = (!string.IsNullOrEmpty(ChartObj.DimensionAxe)) ? ChartObj.DimensionAxe : kf.TimeDimension.Id; // Codici sull'asse X Dictionary <string, int> XPosition = new Dictionary <string, int>(); if (codelists.ContainsKey(XConcept)) { ICodelistObject CCodes = codelists[XConcept]; for (int i = 0; i < CCodes.Items.Count; i++) { XPosition.Add(CCodes.Items[i].Id, i); } } #region Dimensione usata per la descrizione string DescConcept = string.Empty; bool single_serie = true; foreach (var obj in ChartObj.Criteria) { if (//obj.Key != kf.TimeDimension.Id && obj.Key != kf.FrequencyDimension.Id) { DescConcept = obj.Key; if (obj.Value.Count > 1 && obj.Key != XConcept) { single_serie = false; DescConcept = obj.Key; break; } } } bool inLegend = !single_serie; inLegend = inLegend || (single_serie && ChartObj.ObsValue.Count > 1); #endregion List <serieType> series = new List <serieType>(); List <serieType> series_s = new List <serieType>(); var v = new Dictionary <string, decimal>(); //IDataReader datareader = store.CreateDataReader(true); IDataReader datareader = store.CreateDataReader(false); while (datareader.Read()) { decimal obs = 0; object vt = null; object vc = null; var obs_val = datareader[kf.PrimaryMeasure.Id]; var xcode = (string)datareader[XConcept]; var xCodeName = (string)TextTypeHelper.GetText(codelists[XConcept].GetCodeById(xcode).Names, this.ChartObj.Configuration.Locale); //fabio 12/08/2015 //string customKeyCode = (ChartObj.CustomKey != null) ? datareader[ChartObj.CustomKey].ToString() : string.Empty; string customKeyCode = (ChartObj.CustomKey != null && ChartObj.CustomKey != "") ? datareader[ChartObj.CustomKey].ToString() : string.Empty; var customSerie = (ChartObj.CustomChartType != null) ? (!string.IsNullOrEmpty(customKeyCode)) ? (from c in ChartObj.CustomChartType where c.code == customKeyCode select c).FirstOrDefault() : null : null; string serieKey = string.Empty; string serieName = string.Empty; bool is_obs_value = false; try { obs = Convert.ToDecimal(obs_val.ToString(), cFrom); is_obs_value = true; obs_val = Math.Round(obs, 1); } catch { //fabio 12/08/2015 aggiunta obs_val = null; is_obs_value = true; //fabio 12/08/2015 eliminata //is_obs_value = false; } // if not time serie no varation if (XConcept == kf.TimeDimension.Id) { #region Calcolo variazioni if (is_obs_value) { var time_p = xcode; int anno = 0; int period = 0; bool _errTimePeriod = false; bool _annual = !((string)time_p).Contains("-"); bool _quater = false; bool _seme = false; #region ESTRAGGO ANNO E PERIOD if (_annual) { _errTimePeriod = !(int.TryParse(((string)time_p), out anno)); } else { _errTimePeriod = !(int.TryParse(((string)time_p).Split('-')[0], out anno)); string _p = ((string)time_p).Split('-')[1]; if (_quater = _p.StartsWith("Q")) { _p = _p.Substring(1); } if (_seme = _p.StartsWith("S")) { _p = _p.Substring(1); } _errTimePeriod = !(int.TryParse(_p, out period)); } #endregion if (!_errTimePeriod) { string serieKeyStr = string.Empty; string _sep = string.Empty; foreach (var dim in kf.DimensionList.Dimensions) { serieKeyStr += ((dim.Id != XConcept) ? _sep + datareader[dim.Id] : string.Empty); _sep = "+"; if (dim.Id == DescConcept) { serieName = TextTypeHelper.GetText( codelists[DescConcept].GetCodeById(datareader[dim.Id].ToString()).Names, this.ChartObj.Configuration.Locale); } } serieKey = serieKeyStr; string vi_k = string.Empty; string vf_k = string.Empty; // Calcolo variazione congiunturale vf_k = serieKeyStr + anno + "_" + (period); if (!_annual) { if (period == 1) { if (_seme) { vi_k = serieKeyStr + (anno - 1) + "_2"; } else if (_quater) { vi_k = serieKeyStr + (anno - 1) + "_4"; } else { vi_k = serieKeyStr + (anno - 1) + "_12"; } } else { vi_k = serieKeyStr + anno + "_" + (period - 1); } } else { vi_k = serieKeyStr + (anno - 1) + "_" + (period); } var vi = (v.ContainsKey(vi_k.ToString())) ? (object)v[vi_k] : null; try { decimal _vi; // non specificare il cFrom nella conversione // poichè vi è il valore gia convertito _vi = Convert.ToDecimal(vi.ToString()); //_vi = Convert.ToDecimal(vi.ToString(), cFrom); if (_vi == 0) { vc = null; } else { vc = Math.Round((((obs - _vi) / _vi) * 100), 1); } } catch { vc = null; } // Calcolo variazione tendenziale vi_k = serieKeyStr + (anno - 1) + "_" + (period); vf_k = serieKeyStr + anno + "_" + (period); vi = (v.ContainsKey(vi_k.ToString())) ? (object)v[vi_k] : null; try { decimal _vi; _vi = Convert.ToDecimal(vi.ToString()); //_vi = Convert.ToDecimal(vi.ToString(), cFrom); if (_vi == 0) { vc = null; } else { vt = Math.Round((((obs - _vi) / _vi) * 100), 1); } } catch { vt = null; } v.Add(vf_k, obs); } } #endregion } else { // Retrive unique key and label serie string serieKeyStr = string.Empty; string _sep = string.Empty; foreach (var dim in kf.DimensionList.Dimensions) { serieKeyStr += ((dim.Id != XConcept) ? _sep + datareader[dim.Id] : string.Empty); _sep = "+"; if (dim.Id == DescConcept) { serieName = TextTypeHelper.GetText( codelists[DescConcept].GetCodeById(datareader[dim.Id].ToString()).Names, this.ChartObj.Configuration.Locale); } } serieKey = serieKeyStr; } #region Primary Serie object primary_obs = (ChartObj.ObsValue[0] == "v") ? (is_obs_value) ? obs_val : null : (ChartObj.ObsValue[0] == "vt") ? vt : (ChartObj.ObsValue[0] == "vc") ? vc : null; bool isNew = false; serieType newSerie = null; newSerie = series.Find(s => s.serieKey == ChartObj.ObsValue[0] + "_" + serieKey);//SerieName); if (newSerie == null) { string _type = (customSerie != null) ? customSerie.chartType.ToString() : ChartObj.ChartType; string _name = (ChartObj.ObsValue[0] == "vt") ? Messages.label_varTrend + "% " : (ChartObj.ObsValue[0] == "vc") ? Messages.label_varCyclical + "% " : (single_serie)? Messages.label_varValue: string.Empty; if (!single_serie) { _name += ((customSerie != null) ? customSerie.title.ToString() : serieName); } isNew = true; newSerie = new serieType() { name = _name, serieKey = ChartObj.ObsValue[0] + "_" + serieKey, showInLegend = inLegend, type = _type, dataPoints = new List <dataPointType>(), axisYType = "primary", lineThickness = 1f, markerType = "circle", //"circle", "square", "cross", "none" markerSize = (_type == "bubble" || _type == "scatter") ? 10f : 1f, }; } newSerie.dataPoints.Add(new dataPointType() { label = xCodeName, legendText = xCodeName, y = primary_obs, x = XPosition[xcode] }); if (isNew) { series.Add(newSerie); } #endregion // if not time serie no secondary if (XConcept == kf.TimeDimension.Id) { #region Seconday serie if (ChartObj.ObsValue.Count > 1) { string _type = (customSerie != null) ? customSerie.chartType.ToString() : ChartObj.ChartType; string _name = (ChartObj.ObsValue[1] == "vt") ? Messages.label_varTrend + "% " : (ChartObj.ObsValue[1] == "vc") ? Messages.label_varCyclical + "% " : Messages.label_varValue + " "; if (!single_serie) { _name += ((customSerie != null) ? customSerie.title.ToString() : serieName); } object secondary_obs = (ChartObj.ObsValue[1] == "v") ? (is_obs_value) ? obs_val : null : (ChartObj.ObsValue[1] == "vt") ? vt : (ChartObj.ObsValue[1] == "vc") ? vc : null; bool isNew_s = false; serieType newSerie_s = null; newSerie_s = series_s.Find(s => s.serieKey == ChartObj.ObsValue[1] + "_" + serieKey);//SerieName); if (newSerie_s == null) { isNew_s = true; newSerie_s = new serieType() { name = _name, serieKey = ChartObj.ObsValue[1] + "_" + serieKey, showInLegend = inLegend, type = _type, dataPoints = new List <dataPointType>(), axisYType = "secondary", lineThickness = 1f, markerType = "circle", //"circle", "square", "cross", "none" markerSize = (_type == "bubble" || _type == "scatter") ? 10f : 1f, }; } newSerie_s.dataPoints.Add(new dataPointType() { label = xCodeName, legendText = xCodeName, y = secondary_obs, x = XPosition[xcode] }); if (isNew_s) { series_s.Add(newSerie_s); } } #endregion } } series.AddRange(series_s); #region Series foreach (var serie in series) { var sortedCodes = serie.dataPoints.OrderBy <dataPointType, int>(o => int.Parse(o.x.ToString())).ToArray(); serie.dataPoints.Clear(); serie.dataPoints.AddRange(sortedCodes); for (int i = 0; i < serie.dataPoints.Count; i++) { serie.dataPoints[i].x = i; } } #endregion return(series); }
/// <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"); } }
public DatasetJsonObj ParseAllData(IDataSetStore store, List <DataCriteria> Criterias, LayoutObj layObj, IDataStructureObject kf, ISet <ICodelistObject> codelists) { if (PageNumber > 0) { return(ParseAllDataPage(1)); } string DominantFreq = CalculateDominantFrequency(Criterias, kf, codelists); CurrentPageIndex = 1; int NObservationForPage = WebClientSettings.Instance.NObservationForPage; DatasetJsonObj dataset = new DatasetJsonObj() { series = new Dictionary <string, Dictionary <string, string> >() }; List <string> sort = new List <string>(); sort.AddRange(layObj.axis_y); sort.AddRange(layObj.axis_x); store.SetSort(sort); store.SetCriteria(Criterias); IDataReader datareader = store.CreateDataReader(false); try { int ActualRecordRegistred = 0; PageNumber = 0; JavaScriptSerializer ser = new JavaScriptSerializer(); ser.MaxJsonLength = int.MaxValue; while (datareader.Read()) { List <string> Colonne = new List <string>(); layObj.axis_x.ForEach(axisX => Colonne.Add(GetFromReader(datareader, axisX, DominantFreq, kf.TimeDimension.Id))); List <string> Righe = new List <string>(); layObj.axis_y.ForEach(axisY => Righe.Add(GetFromReader(datareader, axisY, DominantFreq, kf.TimeDimension.Id))); string OBSVal = (string)datareader[kf.PrimaryMeasure.Id]; string serieString = string.Join("+", Righe); if (!dataset.series.ContainsKey(serieString)) { if (ActualRecordRegistred >= NObservationForPage) { //NormalizeDataset(dataset, layObj.axis_x, kf, codelists); FileInfo fi = new FileInfo(Path.Combine(PagingFileDirectory.FullName, string.Format(FilePageFormat, PagingFileDirectory.Name, PageNumber + 1))); File.WriteAllText(fi.FullName, ser.Serialize(dataset)); ActualRecordRegistred = 0; PageNumber++; dataset = null; dataset = new DatasetJsonObj() { series = new Dictionary <string, Dictionary <string, string> >() }; } //dataset.series[serieString] = AllPossibleValues(layObj.axis_x, kf, codelists); dataset.series[serieString] = new Dictionary <string, string>(); } dataset.series[serieString][string.Join("+", Colonne)] = OBSVal; ActualRecordRegistred++; } FileInfo fiLastPage = new FileInfo(Path.Combine(PagingFileDirectory.FullName, string.Format(FilePageFormat, PagingFileDirectory.Name, PageNumber + 1))); File.WriteAllText(fiLastPage.FullName, ser.Serialize(dataset)); PageNumber++; if (PageNumber == 1) { return(dataset); } return(ParseAllDataPage(1)); } catch (Exception) { throw; } finally { store.Commit(); } }
/// <summary> /// Initializes a new instance of the <see cref="SdmxDataReader"/> class. /// Initialize a new instance of the <see cref="SdmxDataReader"/> /// </summary> /// <param name="keyFamily"> /// The key family of the SDMX-ML dataset /// </param> /// <param name="store"> /// The <see cref="IDataSetStore"/> in which the SDMX-ML dataset will be stored /// </param> public SdmxDataReader(IDataStructureObject keyFamily, IDataSetStore store) : base(keyFamily, store) { }
/// <summary> /// Initializes a new instance of the <see cref="DataSetReader"/> class. /// Initialize a new instance of the <see cref="DataSetReader"/> /// </summary> /// <param name="keyFamily"> /// The key family of the SDMX-ML dataset /// </param> /// <param name="store"> /// The <see cref="IDataSetStore"/> in which the SDMX-ML dataset will be stored /// </param> protected DataSetReader(IDataStructureObject keyFamily, IDataSetStore store) { this._dataSetStore = store; this._keyFamily = keyFamily; }
public DatasetJsonObj ParseAllData(IDataSetStore store, List<DataCriteria> Criterias, LayoutObj layObj, IDataStructureObject kf, ISet<ICodelistObject> codelists) { if (PageNumber > 0) return ParseAllDataPage(1); string DominantFreq = CalculateDominantFrequency(Criterias, kf, codelists); CurrentPageIndex = 1; int NObservationForPage = WebClientSettings.Instance.NObservationForPage; DatasetJsonObj dataset = new DatasetJsonObj() { series = new Dictionary<string, Dictionary<string, string>>() }; List<string> sort = new List<string>(); sort.AddRange(layObj.axis_y); sort.AddRange(layObj.axis_x); store.SetSort(sort); store.SetCriteria(Criterias); IDataReader datareader = store.CreateDataReader(false); try { int ActualRecordRegistred = 0; PageNumber = 0; JavaScriptSerializer ser = new JavaScriptSerializer(); ser.MaxJsonLength = int.MaxValue; while (datareader.Read()) { List<string> Colonne = new List<string>(); layObj.axis_x.ForEach(axisX => Colonne.Add(GetFromReader(datareader, axisX, DominantFreq, kf.TimeDimension.Id))); List<string> Righe = new List<string>(); layObj.axis_y.ForEach(axisY => Righe.Add(GetFromReader(datareader, axisY, DominantFreq, kf.TimeDimension.Id))); string OBSVal = (string)datareader[kf.PrimaryMeasure.Id]; string serieString = string.Join("+", Righe); if (!dataset.series.ContainsKey(serieString)) { if (ActualRecordRegistred >= NObservationForPage) { //NormalizeDataset(dataset, layObj.axis_x, kf, codelists); FileInfo fi = new FileInfo(Path.Combine(PagingFileDirectory.FullName, string.Format(FilePageFormat, PagingFileDirectory.Name, PageNumber + 1))); File.WriteAllText(fi.FullName, ser.Serialize(dataset)); ActualRecordRegistred = 0; PageNumber++; dataset = null; dataset = new DatasetJsonObj() { series = new Dictionary<string, Dictionary<string, string>>() }; } //dataset.series[serieString] = AllPossibleValues(layObj.axis_x, kf, codelists); dataset.series[serieString] = new Dictionary<string, string>(); } dataset.series[serieString][string.Join("+", Colonne)] = OBSVal; ActualRecordRegistred++; } FileInfo fiLastPage = new FileInfo(Path.Combine(PagingFileDirectory.FullName, string.Format(FilePageFormat, PagingFileDirectory.Name, PageNumber + 1))); File.WriteAllText(fiLastPage.FullName, ser.Serialize(dataset)); PageNumber++; if (PageNumber == 1) return dataset; return ParseAllDataPage(1); } catch (Exception) { throw; } finally { store.Commit(); } }
public SessionImplObject GetDataChart(SessionQuery sessionQuery) { try { // Init session objects if (this.SessionObj == null) { this.SessionObj = new SessionImplObject(); this.SessionObj.SdmxObject = new SdmxObjectsImpl(); } JavaScriptSerializer ser = new JavaScriptSerializer(); ser.MaxJsonLength = int.MaxValue; #region +++ Caching +++ ConnectionStringSettings connectionStringSetting; CacheWidget cache = null; bool UseWidgetCache = (WebClientSettings.Instance != null) ? WebClientSettings.Instance.UseWidgetCache : false; if (UseWidgetCache) { connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"]; cache = new CacheWidget(connectionStringSetting.ConnectionString); } if (ChartObj.WidgetId > 0 && UseWidgetCache) { SavedWidget widget = cache.GetWidget(ChartObj.WidgetId, ChartObj.Configuration.Locale); if (widget != null && !String.IsNullOrEmpty(widget.widgetData)) { this.SessionObj.SavedChart = widget.widgetData; return(this.SessionObj); } } #endregion if (BDO == null || GetSDMXObject == null) { throw new Exception(Messages.label_error_network); } codemapWidget = new CodemapWidget( new GetCodemapObject() { PreviusCostraint = this.ChartObj.Criteria, Configuration = this.ChartObj.Configuration, Dataflow = this.ChartObj.Dataflow }, this.SessionObj, sessionQuery); //ISdmxObjects structure = codemapWidget.GetDsd(); //IDataflowObject df = structure.Dataflows.FirstOrDefault(); //IDataStructureObject kf = structure.DataStructures.First(); ISdmxObjects structure = sessionQuery.Structure; //IDataflowObject df = structure.Dataflows.First(); IDataflowObject df = sessionQuery.Dataflow; //IDataStructureObject kf = structure.DataStructures.First(); IDataStructureObject kf = sessionQuery.KeyFamily; if (kf == null) { throw new InvalidOperationException("DSD is not set"); } if (df == null) { throw new InvalidOperationException("Dataflow is not set"); } Dictionary <string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(df, kf, 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.ChartObj.Configuration.Locale)); } codemap.Add(ConceptId, codes); //var useFix20 = (ConfigurationManager.AppSettings["UseFix20Criteria"].ToString().ToLower() == "true"); //fabio prova var useFix20 = (ConfigurationManager.AppSettings["UseFix20Criteria"].ToString().ToLower() == "false"); if (useFix20) { if (!(codelist.Items.Count > 1)) { this.ChartObj.Criteria.Remove(ConceptId); } } } this.SessionObj.MergeObject(codemapWidget.SessionObj); #region Gestione last period int num1; if (this.ChartObj.Criteria.ContainsKey(kf.TimeDimension.Id) && this.ChartObj.Criteria[kf.TimeDimension.Id].Count == 1 && int.TryParse(this.ChartObj.Criteria[kf.TimeDimension.Id].First(), out num1) ) { int offsetTime = int.Parse(this.ChartObj.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.ChartObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.Last()); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.First()); } else { this.ChartObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].First().Key); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].Last().Key); } } #endregion List <DataCriteria> Criterias = BDO.InitCriteria(kf, this.ChartObj.Criteria); //List<DataCriteria> Criterias = sessionQuery.GetCriteria(); Dictionary <string, List <DataChacheObject> > DataCache = SessionObj.DataCache; //aggiunta da fabio //IDataSetStore store = BDO.GetDataset(df, kf, Criterias, ref DataCache, false, sessionQuery); IDataSetStore store = sessionQuery._store; store.SetCriteria(Criterias); /* * IDataSetStore store; * if (sessionQuery._store != null) * { store = sessionQuery._store; } * else * { * //store = BDO.GetDataset(df, kf, Criterias, ref DataCache, _useAttr); * store = BDO.GetDataset(df, kf, Criterias, ref DataCache, false, sessionQuery); * sessionQuery._store = store; * } */ //fine nuovo //string DBFileName = null; //IDataSetStore store = BDO.FindDataCache(df, kf, Criterias, ref DataCache, false, out DBFileName); //if (store == null) store = BDO.GetDataset(df, kf, Criterias, ref DataCache); //if (store == null) store = BDO.GetDataset(df, kf, Criterias, ref DataCache, false); //da vedere se eliminare aggiunta fabio per svuotare datacache SessionObj.DataCache = null; SessionObj.DataCache = DataCache; DataObjectForStreaming DataStream = new DataObjectForStreaming() { store = store, Criterias = Criterias, structure = structure, codemap = codemap }; ChartResponseObject ChartResponse = new ChartResponseObject(); ChartResponse.series_title = TextTypeHelper.GetText(df.Names, this.ChartObj.Configuration.Locale); ChartResponse.series = BuildChart(store, kf, ConceptCodelists); ChartResponse.primary_name = (this.ChartObj.ObsValue[0] == "v") ? Messages.label_varValue : (this.ChartObj.ObsValue[0] == "vt") ? Messages.label_varTrend : (this.ChartObj.ObsValue[0] == "vc") ? Messages.label_varCyclical : string.Empty; ChartResponse.secondary_name = (this.ChartObj.ObsValue.Count > 1) ? (this.ChartObj.ObsValue[1] == "v") ? Messages.label_varValue : (this.ChartObj.ObsValue[1] == "vt") ? Messages.label_varTrend : (this.ChartObj.ObsValue[1] == "vc") ? Messages.label_varCyclical : string.Empty : string.Empty; ChartResponse.x_name = (!string.IsNullOrEmpty(ChartObj.DimensionAxe)) ? ChartObj.DimensionAxe : kf.TimeDimension.Id;; // 23/07/2015 // calcolo massimo e minimo decimal?primary_max = null; decimal?primary_min = null; decimal?secondary_max = null; decimal?secondary_min = null; decimal costantemax = 1.1m; decimal costantemin = 0.9m; foreach (serieType serie in ChartResponse.series) { if (serie.axisYType == "secondary") { //fabio 12/08/2015 //decimal max = (decimal)serie.dataPoints.Where(m => m.y != null).Max(d => d.y); decimal max = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Max(d => d.y)); if (secondary_max == null || max > secondary_max) { secondary_max = max; } //fabio 12/08/2015 //decimal min = (decimal)serie.dataPoints.Where(m => m.y != null).Min(d => d.y); decimal min = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Min(d => d.y)); if (secondary_min == null || min < secondary_min) { secondary_min = min; } //fabio 12/08/2015 if (secondary_min == secondary_max) { secondary_min = secondary_min * costantemin; secondary_max = secondary_max * costantemax; } } else { //fabio 12/08/2015 //decimal max = (decimal)serie.dataPoints.Where(m => m.y != null).Max(d => d.y); decimal max = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Max(d => d.y)); if (primary_max == null || max > primary_max) { primary_max = max; } //fabio 12/08/2015 //decimal min = (decimal)serie.dataPoints.Where(m => m.y != null).Min(d => d.y); decimal min = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Min(d => d.y)); if (primary_min == null || min < primary_min) { primary_min = min; } //fabio 12/08/2015 if (primary_min == primary_max) { primary_min = primary_min * costantemin; primary_max = primary_max * costantemax; } } } if (primary_max != null && primary_min != null) { //decimal delta = (decimal)primary_max - (decimal)primary_min; //ChartResponse.primary_max = (decimal)primary_max; //ChartResponse.primary_min = (decimal)primary_min; if (primary_max > 0) { ChartResponse.primary_max = (decimal)(primary_max * 1.1m); } else if (primary_max == 0) { ChartResponse.primary_max = (decimal) - 1.1m; } else { ChartResponse.primary_max = (decimal)(primary_max * 0.9m); } if (primary_min > 0) { ChartResponse.primary_min = (decimal)(primary_min * 0.9m); } else if (primary_min == 0) { ChartResponse.primary_min = (decimal) - 1.1m; } else { ChartResponse.primary_min = (decimal)(primary_min * 1.1m); } } if (secondary_max != null && secondary_min != null) { //ChartResponse.secondary_max = (decimal)secondary_max; //ChartResponse.secondary_min = (decimal)secondary_min; if (secondary_max > 0) { ChartResponse.secondary_max = (decimal)(secondary_max * 1.1m); } else if (secondary_max == 0) { ChartResponse.secondary_max = (decimal) - 1.1m; } else { ChartResponse.secondary_max = (decimal)(secondary_max * 0.9m); } if (secondary_min > 0) { ChartResponse.secondary_min = (decimal)(secondary_min * 0.9m); } else if (secondary_min == 0) { ChartResponse.secondary_min = (decimal) - 1.1m; } else { ChartResponse.secondary_min = (decimal)(secondary_min * 1.1m); } } this.SessionObj.SavedChart = ser.Serialize(ChartResponse); // +++ Caching +++ if (ChartObj.WidgetId > 0 && UseWidgetCache) { cache.InsertWidget(ChartObj.WidgetId, this.SessionObj.SavedChart, ChartObj.Configuration.Locale); } return(this.SessionObj); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw ex; } }