public static LayoutObj GetDefaultLayout(IDataflowObject df, IDataStructureObject kf) { LayoutObj lay = FindInConfigFile(df, kf); if (lay != null) { return(lay); } lay = new LayoutObj(); foreach (var item in kf.DimensionList.Dimensions) { if (item.TimeDimension) { lay.axis_y.Add(item.Id); } else if (item.FrequencyDimension) { lay.axis_z.Add(item.Id); } else { lay.axis_x.Add(item.Id); } } return(lay); }
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 SessionImplObject GetLayout(SessionQuery query) { try { //ISdmxObjects structure = GetKeyFamily(); //IDataflowObject df = structure.Dataflows.First(); //IDataStructureObject kf = structure.DataStructures.First(); ISdmxObjects structure = query.Structure; IDataflowObject df = query.Dataflow; IDataStructureObject kf = query.KeyFamily; if (kf == null || df == null) { throw new InvalidOperationException("DataStructure is not set"); } if (this.SessionObj.DafaultLayout == null) { this.SessionObj.DafaultLayout = new Dictionary <string, LayoutObj>(); } if (!this.SessionObj.DafaultLayout.ContainsKey(Utils.MakeKey(df))) { LayoutObj deflay = GetDefaultLayout(df, kf); this.SessionObj.DafaultLayout[Utils.MakeKey(df)] = deflay; } DefaultLayoutResponseObject defaultLayoutResponseObject = new DefaultLayoutResponseObject(); defaultLayoutResponseObject.DefaultLayout = this.SessionObj.DafaultLayout[Utils.MakeKey(df)]; this.SessionObj.SavedDefaultLayout = new JavaScriptSerializer().Serialize(defaultLayoutResponseObject); return(this.SessionObj); } catch (InvalidOperationException ex) { Logger.Warn(Resources.ErrorMaxJsonLength); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (ArgumentException ex) { Logger.Warn(Resources.ErrorRecursionLimit); Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } }
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, query); //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); int num1; #region Gestione last period if (this.DataObj.Criteria.ContainsKey(kf.TimeDimension.Id) && this.DataObj.Criteria[kf.TimeDimension.Id].Count == 1 && int.TryParse(this.DataObj.Criteria[kf.TimeDimension.Id].First(), out num1) && !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); 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; } }
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(); } }