/// <summary> /// This method checks a dsd for compliance with producing Compact Data. /// In detail, it checks that if a TimeDimension is present and at least /// one dimension is frequency dimension. If there is none an error message /// is returned to the caller /// </summary> /// <param name="dsd"> /// The <see cref="Estat.Sdmx.Model.Structure.KeyFamilyBean"/>of the DSD to be checked /// </param> /// <returns> /// The error messages in case of invalid dsd or an empty string in case a valid dsd /// </returns> public static string ValidateForCompact(IDataStructureObject dsd) { string text = string.Empty; bool isFrequency = false; foreach (IDimension dimension in dsd.DimensionList.Dimensions) { if (dimension.FrequencyDimension) { isFrequency = true; break; } } if (dsd.TimeDimension == null) { // text= "Dsd does not have at least one Frequency dimension"; text = "DSD " + dsd.Id + " v" + dsd.Version + " does not have a Time Dimension. Only Cross-Sectional data may be requested."; } else if (!isFrequency) { // normally it should never reach here text = "DSD " + dsd.Id + " v" + dsd.Version + " does not have a Frequency dimension. According SDMX v2.0: Any DSD which uses the Time dimension must also declare a frequency dimension."; } return(text); }
protected void PrepareSqlColumns(IDataStructureObject keyFamily) { // dimensions add them all and to primary key foreach (IDimension comp in keyFamily.DimensionList.Dimensions) { if (!comp.TimeDimension) { this._columns.Add(comp.Id, null); if (comp.MeasureDimension) { this._measureColumn = comp.Id; } } } if (keyFamily.TimeDimension != null) { this._columns.Add(keyFamily.TimeDimension.Id, null); } this._columns.Add(keyFamily.PrimaryMeasure.Id, null); if (this.ParseSdmxAttributes) { foreach (IAttributeObject comp in keyFamily.Attributes) { this._columns.Add(comp.Id, null); } } }
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); }
/// <summary> /// This method checks a dsd for compliance with producing Compact Data. /// In detail, it checks that if a TimeDimension is present and at least /// one dimension is frequency dimension. If there is none an error message /// is returned to the caller /// </summary> /// <param name="dsd"> /// The <see cref="Estat.Sdmx.Model.Structure.KeyFamilyBean"/>of the DSD to be checked /// </param> /// <returns> /// The error messages in case of invalid dsd or an empty string in case a valid dsd /// </returns> public static string ValidateForCompact(IDataStructureObject dsd) { string text = string.Empty; bool isFrequency = false; foreach (IDimension dimension in dsd.DimensionList.Dimensions) { if (dimension.FrequencyDimension) { isFrequency = true; break; } } if (dsd.TimeDimension == null) { // text= "Dsd does not have at least one Frequency dimension"; text = "DSD " + dsd.Id + " v" + dsd.Version + " does not have a Time Dimension. Only Cross-Sectional data may be requested."; } else if (!isFrequency) { // normally it should never reach here text = "DSD " + dsd.Id + " v" + dsd.Version + " does not have a Frequency dimension. According SDMX v2.0: Any DSD which uses the Time dimension must also declare a frequency dimension."; } return text; }
/// <summary> /// Initializes a new instance of the <see cref="DataParseMetadata"/> class. /// </summary> /// <param name="sourceData"> /// The readable data location /// </param> /// <param name="outPutStream"> /// The output stream /// </param> /// <param name="outputSchemaVersion"> /// The output schema version /// </param> /// <param name="keyFamily"> /// The key family /// </param> public DataParseMetadata(IReadableDataLocation sourceData, Stream outPutStream, SdmxSchema outputSchemaVersion, IDataStructureObject keyFamily) { this._sourceData = sourceData; this._outPutStream = outPutStream; this._dataStructure = keyFamily; this._outputSchemaVersion = outputSchemaVersion; }
/// <summary> /// Create a Dataflow Node /// </summary> /// <param name="dataflow"> /// The SDMX Model Dataflow object /// </param> /// <returns> /// The Dataflow Node /// </returns> private JsTreeNode CreateDataflowNode(IDataflowObject dataflow) { var dataflowNode = new JsTreeNode(); // dataflowNode.data.attributes.rel = MakeKey(dataflow); dataflowNode.SetId(Utils.MakeKey(dataflow).Replace('.', '_').Replace('+', '-')); SetupNode(dataflowNode, dataflow); IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, _dataStructure); if (dsd != null && NsiClientHelper.DataflowDsdIsCrossSectional(dsd)) { dataflowNode.SetRel("xs-dataflow"); } else { dataflowNode.SetRel("dataflow"); } dataflowNode.AddClass("dataflow-item"); dataflowNode.SetLeaf(true); // dataflowNode.state = "closed"; dataflowNode.metadata = new JSTreeMetadata { DataflowID = dataflow.Id, DataflowVersion = dataflow.Version, DataflowAgency = dataflow.AgencyId }; // dataflowNode.metadata.dataflow_name = dataflow.PrimaryName; return(dataflowNode); }
/// <summary> /// This method checks a DSD for compliance with producing Compact Data. /// In detail, it checks that if a TimeDimension is present and at least /// one dimension is frequency dimension. If there is none an error message /// is returned to the caller /// </summary> /// <param name="keyFamily"> /// The <see cref="IDataStructureObject"/>of the DSD to be checked /// </param> /// <returns> /// The error messages in case of invalid DSD or an empty string in case a valid DSD /// </returns> public static string ValidateForCompact(IDataStructureObject keyFamily) { string text = string.Empty; bool isFrequency = false; foreach (IDimension dimension in keyFamily.DimensionList.Dimensions) { if (dimension.FrequencyDimension) { isFrequency = true; break; } } if (keyFamily.TimeDimension == null) { text = string.Format( CultureInfo.InvariantCulture, Resources.ErrorNoTimeDimensionFormat2, keyFamily.Id, keyFamily.Version); } else if (!isFrequency) { // normally it should never reach here text = "DSD " + keyFamily.Id + " v" + keyFamily.Version + " does not have a Frequency dimension. According SDMX v2.0: Any DSD which uses the Time dimension must also declare a frequency dimension."; } return text; }
public void SetDsdOrder(IDataStructureObject dsd) { IList <IDimension> dimensions = dsd.GetDimensions(SdmxStructureEnumType.Dimension); ordine = new string[dimensions.Count]; ordineser = new string[dimensions.Count]; }
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(); }
/// <summary> /// Initializes a new instance of the <see cref="DataSetStoreDB"/> class /// </summary> /// <param name="dbInfo"> /// The database information which will used to connect /// </param> /// <param name="cacheTableName"> /// The cache database table name /// </param> /// <param name="keyFamily"> /// The SDMX keyfamily bean /// </param> public DataSetStoreDataView(DBInfo dbInfo, string cacheTableName, IDataStructureObject keyFamily) { if (dbInfo == null) { throw new ArgumentNullException("dbInfo"); } if (string.IsNullOrEmpty(cacheTableName)) { throw new ArgumentNullException("cacheTableName"); } if (keyFamily == null) { throw new ArgumentNullException("keyFamily"); } this._dbInfo = dbInfo; this._cacheTableName = cacheTableName; if (dbInfo.Connection.GetType().Name.Contains("Oracle")) { this._varChar = "varchar2"; } this.CreateSqlTable(dbInfo, keyFamily); }
public List<Entity.Attribute> GetAttributeList(IDataStructureObject attObject, string localization) { List<Entity.Attribute> lAttribute = new List<Entity.Attribute>(); if (attObject.AttributeList == null) return null; foreach (IAttributeObject attribute in attObject.AttributeList.Attributes) { string TextFormat = String.Empty; string CodeList = String.Empty; if (attribute.Representation != null && attribute.Representation.Representation != null) { ICrossReference rep = attribute.Representation.Representation; CodeList = rep.MaintainableId + ","+ rep.AgencyId +","+ rep.Version; if (attribute.Representation.TextFormat != null) TextFormat = attribute.Representation.TextFormat.TextType.EnumType.ToString(); } lAttribute.Add(new Entity.Attribute(attribute.Id, attribute.ConceptRef.MaintainableId + "," + attribute.ConceptRef.AgencyId + "," + attribute.ConceptRef.Version + " - " + attribute.ConceptRef.FullId, CodeList, TextFormat, attribute.AssignmentStatus, attribute.AttachmentLevel.ToString())); } return lAttribute; }
private LayoutObj InitLayout(IDataflowObject df, IDataStructureObject kf) { if (this.DataObj.Layout == null) { return(LayoutWidget.GetDefaultLayout(df, kf)); } return(this.DataObj.Layout); }
/// <summary> /// Obtains a DataReaderEngine that is capable of reading the data which is exposed via the ReadableDataLocation /// </summary> /// <param name="sourceData">The source data, giving access to an InputStream of the data.</param> /// <param name="dsd">The Data Structure Definition, describes the data in terms of the dimensionality.</param> /// <param name="dataflow">The dataflow (optional). Provides further information about the data.</param> /// <returns>The <see cref="IDataReaderEngine"/>; otherwise null if the <paramref name="sourceData"/> cannot be read.</returns> /// <exception cref="ArgumentNullException"><paramref name="sourceData"/> is null -or- <paramref name="dsd"/> is null</exception> public IDataReaderEngine GetDataReaderEngine(IReadableDataLocation sourceData, IDataStructureObject dsd, IDataflowObject dataflow) { _log.Debug("Get DataReader Engine"); if (sourceData == null) { throw new ArgumentNullException("sourceData"); } if (dsd == null) { throw new ArgumentNullException("dsd"); } MessageEnumType messageType; try { messageType = SdmxMessageUtil.GetMessageType(sourceData); } catch (Exception e) { _log.Error("While trying to get the message type.", e); return null; } var dataFormat = this.GetDataFormat(sourceData, messageType); if (dataFormat != null && dataFormat.SdmxDataFormat != null) { switch (dataFormat.SdmxDataFormat.BaseDataFormat.EnumType) { case BaseDataFormatEnumType.Compact: return new CompactDataReaderEngine(sourceData, dataflow, dsd); case BaseDataFormatEnumType.Generic: return new GenericDataReaderEngine(sourceData, dataflow, dsd); case BaseDataFormatEnumType.CrossSectional: var crossDsd = dsd as ICrossSectionalDataStructureObject; if (crossDsd == null) { throw new SdmxNotImplementedException("Not supported. Reading from CrossSectional Data for non cross-sectional dsd."); } return new CrossSectionalDataReaderEngine(sourceData, crossDsd, dataflow); case BaseDataFormatEnumType.Edi: if (this._ediParseManager != null) { return this._ediParseManager.ParseEdiMessage(sourceData).GetDataReader(dsd, dataflow); } break; default: _log.WarnFormat("SdmxDataReaderFactory encountered unsupported SDMX format: {0} ", dataFormat); break; } } return null; }
/// <summary> /// Returns the concepts of all the dimensions and attributes that are not attached at the observation level. /// </summary> /// <param name="dataStructureObject"> /// The data structure object /// </param> /// <returns> /// The concepts of all the dimensions and attributes that are not attached at the observation level. /// </returns> public static IList<string> GetGroupAttribtueConcepts(IDataStructureObject dataStructureObject) { IList<string> keyConcepts = new List<string>(); foreach (IAttributeObject currentBean in dataStructureObject.GroupAttributes) { keyConcepts.Add(currentBean.Id); } return keyConcepts; }
public void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { this._dimensionAtObservation = this.GetDimensionAtObservation(header); _jsonDataWriter.Formatting = Formatting.None; _jsonDataWriter.WritePropertyName("dataSets"); _jsonDataWriter.WriteStartArray(); _jsonDataWriter.WriteStartObject(); _jsonDataWriter.WritePropertyName("actions"); _jsonDataWriter.WriteValue("Information"); }
internal IDataSetStore FindDataCache(IDataflowObject df, IDataStructureObject kf, List <DataCriteria> Criterias, ref Dictionary <string, List <DataChacheObject> > DataCache, bool useAttr, out string DBFileName) { DataChacheObject findCache = null; Dictionary <string, List <string> > Criteri = new Dictionary <string, List <string> >(); Criterias.ForEach(c => Criteri.Add(c.component, c.values)); DBFileName = null; if (DataCache != null) { string DfID = Utils.MakeKey(df); if (DataCache.ContainsKey(DfID)) { List <DataChacheObject> singleDataCache = DataCache[DfID]; findCache = singleDataCache.Find(dc => DictionaryEqual(dc.Criterias, Criteri)); Dictionary <string, List <string> > CriteriDataCache = new Dictionary <string, List <string> >(); if (singleDataCache.Count > 0) { CriteriDataCache = singleDataCache.FirstOrDefault().Criterias; } bool pippo = false; if (CriteriDataCache.Count > 0) { pippo = DictionaryContain(singleDataCache.FirstOrDefault().Criterias, Criteri); } if (pippo) { findCache = singleDataCache.FirstOrDefault(); } } } if (findCache != null) { if (!string.IsNullOrEmpty(findCache.DBFileName) && File.Exists(findCache.DBFileName)) { #region Connessione e Creazione DB SQLLite string ConnectionString = string.Format(CultureInfo.InvariantCulture, Constants.FileDBSettingsFormat, findCache.DBFileName); var info = new DBInfo(ConnectionString); string tempTable = "table_" + Utils.MakeKey(df).Replace("+", "_").Replace(".", ""); IDataSetStore store = new DataSetStoreDB(info, tempTable, kf, false, useAttr); //DBFileName = findCache.DBFileName; store.SetCriteria(Criterias); return(store); #endregion } return(null); } return(null); }
public string GetKeyPosition(IDataStructureObject DsD, string keyDim) { foreach (var Dim in DsD.DimensionList.Dimensions) { if (Dim.Id == keyDim) { return((Dim.Position - 1).ToString()); } } return(null); }
/// <summary> /// This method checks a DSD for compliance with producing Cross-Sectional Data. /// In detail, it checks all Dimensions and all Attributes for having or not having /// cross-sectional attachment group. If there are components with no attachment level, /// it returns a list with them in the message. /// </summary> /// <param name="keyFamily"> /// The <see cref="IDataStructureObject"/>of the DSD to be checked /// </param> /// <returns> /// The error messages in case of invalid DSD or an empty string in case a valid DSD /// </returns> public static string ValidateForCrossSectional(IDataStructureObject keyFamily) { var crossSectionalDataStructure = keyFamily as ICrossSectionalDataStructureObject; if (crossSectionalDataStructure == null) { return "Not a cross-sectional DSD"; } return string.Empty; }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM MUTABLE OBJECTS ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="AttributeListCore"/> class. /// </summary> /// <param name="itemMutableObject"> /// The sdmxObject. /// </param> /// <param name="parent"> /// The parent. /// </param> public AttributeListCore(IAttributeListMutableObject itemMutableObject, IDataStructureObject parent) : base(itemMutableObject, parent) { this.attributes = new List<IAttributeObject>(); if (itemMutableObject.Attributes != null) { foreach (IAttributeMutableObject currentAttribute in itemMutableObject.Attributes) { this.attributes.Add(new AttributeObjectCore(currentAttribute, this)); } } }
private List <string> AllPossibleValues(List <string> dimensions, IDataStructureObject kf, ISet <ICodelistObject> codelists) { if (NewLines.ContainsKey(string.Join("+", dimensions))) { return(NewLines[string.Join("+", dimensions)]); } Dictionary <string, string> allVals = new Dictionary <string, string>(); List <string> BuilderSeries = new List <string>(); foreach (var dim in dimensions) { if (dim == kf.TimeDimension.Id) { return(new List <string>()); } IComponent component = kf.Components.FirstOrDefault(c => c.Id == dim); if (component == null || !component.HasCodedRepresentation() || string.IsNullOrEmpty(component.Representation.Representation.MaintainableReference.MaintainableId)) { return(new List <string>()); } ICodelistObject codelist = codelists.First(c => c.Id == component.Representation.Representation.MaintainableReference.MaintainableId); if (codelist == null) { continue; } List <string> InternalBuilderSeries = new List <string>(); if (BuilderSeries.Count == 0) { foreach (var code in codelist.Items) { InternalBuilderSeries.Add(code.Id); } } else { BuilderSeries.ForEach(bs => { foreach (var code in codelist.Items) { InternalBuilderSeries.Add(bs + "+" + code.Id); } }); } BuilderSeries = InternalBuilderSeries; } NewLines.Add(string.Join("+", dimensions), BuilderSeries); return(BuilderSeries); }
/// <summary> /// Gets a bean with data about the key family for specified dataflow. /// </summary> /// <param name="dataflow"> /// The dataflow /// </param> /// <param name="dataStructures"> /// The data Structures. /// </param> /// <returns> /// a <c>StructureBean</c> instance with requested data; the result is never <c>null</c> or incomplete, instead an exception is throwed away if something goes wrong and not all required data is successfully retrieved /// </returns> /// <remarks> /// The resulted bean will contain exactly one key family, but also will include any concepts and codelists referenced by the key family. /// </remarks> public ISdmxObjects GetStructure(IDataflowObject dataflow, ISet <IDataStructureObject> dataStructures) { Logger.InfoFormat( CultureInfo.InvariantCulture, Resources.InfoGettingStructureFormat3, dataflow.AgencyId, dataflow.Id, dataflow.Version); ISdmxObjects structure = new SdmxObjectsImpl(); try { ISdmxObjects responseConceptScheme = new SdmxObjectsImpl(); ISdmxObjects response = new SdmxObjectsImpl(); IStructureQueryFormat <string> structureQueryFormat = new RestQueryFormat(); IStructureQueryFactory factory = new RestStructureQueryFactory(); IStructureQueryBuilderManager structureQueryBuilderManager = new StructureQueryBuilderManager(factory); IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, dataStructures); structure.AddDataStructure(dsd); NsiClientValidation.CheckifStructureComplete(structure, dataflow); IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First()); foreach (var structureReference in conceptRefs) { IRestStructureQuery structureQuery = new RESTStructureQueryCore(StructureQueryDetail.GetFromEnum(StructureQueryDetailEnumType.Full), StructureReferenceDetail.GetFromEnum(StructureReferenceDetailEnumType.None), null, structureReference, false); string request = structureQueryBuilderManager.BuildStructureQuery(structureQuery, structureQueryFormat); responseConceptScheme = this.SendQueryStructureRequest(request); response.Merge(responseConceptScheme); } structure.Merge(response); NsiClientValidation.CheckConcepts(structure); Logger.Info(Resources.InfoSuccess); } catch (NsiClientException e) { Logger.Error(Resources.ExceptionGettingStructure); Logger.Error(e.Message, e); throw; } catch (Exception e) { Logger.Error(Resources.ExceptionGettingStructure); Logger.Error(e.Message, e); throw new NsiClientException(Resources.ExceptionGettingStructure, e); } return(structure); }
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); } }
/// <summary> /// Reset everything /// </summary> public void Reset() { this._dataflow = null; this._structure = null; this._keyFamily = null; this._dataflowTreeList = null; this._componentIndex.Clear(); this._conceptMap.Clear(); this._criteriaComponentIdx = 0; this._workPageIdx = 0; this.Clear(); this._sessionPrefix = Guid.NewGuid().ToString(); }
internal List <DataCriteria> InitCriteria(IDataStructureObject kf, Dictionary <string, List <string> > Criteria) { List <DataCriteria> criterias = new List <DataCriteria>(); foreach (IComponent comp in kf.Components.Where(c => Criteria.ContainsKey(c.Id))) { criterias.Add(new DataCriteria() { component = comp.Id, values = Criteria[comp.Id] }); } return(criterias); }
/// <summary> /// Obtains a DataReaderEngine that is capable of reading the data which is exposed via the ReadableDataLocation /// </summary> /// <param name="sourceData"> /// SourceData - giving access to an InputStream of the data /// </param> /// <param name="dsd"> /// Describes the data in terms of the dimensionality /// </param> /// <param name="dataflowObject"> /// The data flow object (optional) /// </param> /// <returns> /// The data reader engine /// </returns> /// throws SdmxNotImplementedException if ReadableDataLocation or DataStructureBean is null, also if additioanlInformation is not of the expected type public IDataReaderEngine GetDataReaderEngine(IReadableDataLocation sourceData, IDataStructureObject dsd, IDataflowObject dataflowObject) { foreach (var currentFactory in this._engines) { IDataReaderEngine dre = currentFactory.GetDataReaderEngine(sourceData, dsd, dataflowObject); if (dre != null) { return dre; } } throw new SdmxNotImplementedException("Data format is either not supported, or has an invalid syntax"); }
/// <summary> /// Initializes a new instance of the <see cref="DataSetStoreDataView"/> class. /// </summary> /// <param name="keyFamily"> /// The <see cref="KeyFamilyBean"/> /// </param> public DataSetStoreDataView(IDataStructureObject keyFamily) { this._dataTable = new DataTable("obs") { Locale = CultureInfo.InvariantCulture }; if (keyFamily == null) { throw new ArgumentNullException("keyFamily"); } this.InitTable(keyFamily); this._currentView = new DataView(this._dataTable); }
/// <summary> /// Get the Dimension or TimeDimension that uses the specified concept id inside a KeyFamily /// </summary> /// <param name="keyFamily"> /// The KeyFamily to search /// </param> /// <param name="concept"> /// The concept id e.g. "FREQ" /// </param> /// <returns> /// The Dimension or TimeDimension as ComponentBean if found, else null /// </returns> public static IDimension GetComponentByName(IDataStructureObject keyFamily, string concept) { IDimension component; if (keyFamily.TimeDimension != null && keyFamily.TimeDimension.Id.Equals(concept)) { component = keyFamily.TimeDimension; } else { component = keyFamily.GetDimension(concept); } return(component); }
/////////////////////////////////////////////////////////////////////////////////////////////////// ////////////BUILD FROM MUTABLE OBJECTS ////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////// #region Constructors and Destructors /// <summary> /// Initializes a new instance of the <see cref="DimensionListCore"/> class. /// </summary> /// <param name="itemMutableObject"> /// The agencyScheme. /// </param> /// <param name="parent"> /// The parent. /// </param> public DimensionListCore(IDimensionListMutableObject itemMutableObject, IDataStructureObject parent) : base(itemMutableObject, parent) { this.dimensions = new List<IDimension>(); if (itemMutableObject.Dimensions != null) { int pos = 1; foreach (IDimensionMutableObject currentDimension in itemMutableObject.Dimensions) { this.dimensions.Add(new DimensionCore(currentDimension, pos, this)); pos++; } } }
public IDataQuery Build(IDataStructureObject dsd, IDataflowObject dataflowObject) { IDataQuerySelection dataQuerySelection = new DataQueryDimensionSelectionImpl("FREQ", "M", "A"); IDataQuerySelectionGroup dataQuerySelectionGroup = new DataQuerySelectionGroupImpl(new HashSet<IDataQuerySelection> { dataQuerySelection }, new SdmxDateCore("2000-01"), new SdmxDateCore("2005-03")); return new DataQueryImpl( dataStructure: dsd, lastUpdated: null, dataQueryDetail: DataQueryDetail.GetFromEnum(DataQueryDetailEnumType.Full), firstNObs: null, lastNObs: null, dataProviders: null, dataflow: dataflowObject, dimensionAtObservation: "TIME_PERIOD", selectionGroup: new[] { dataQuerySelectionGroup }); }
/// <summary> /// Gets a bean with data about the key family for specified dataflow. /// </summary> /// <param name="dataflow"> /// The dataflow /// </param> /// <returns> /// a <c>StructureBean</c> instance with requested data; the result is never <c>null</c> or incomplete, instead an exception is throwed away if something goes wrong and not all required data is successfully retrieved /// </returns> /// <remarks> /// The resulted bean will contain exactly one key family, but also will include any concepts and codelists referenced by the key family. /// </remarks> public ISdmxObjects GetStructure(IDataflowObject dataflow, ISet <IDataStructureObject> dataStructures) { Logger.InfoFormat( CultureInfo.InvariantCulture, Resources.InfoGettingStructureFormat3, dataflow.AgencyId, dataflow.Id, dataflow.Version); ISdmxObjects structure = new SdmxObjectsImpl(); try { ISdmxObjects responseConceptScheme = new SdmxObjectsImpl(); ISdmxObjects response = new SdmxObjectsImpl(); IDataStructureObject dsd = NsiClientHelper.GetDsdFromDataflow(dataflow, dataStructures); structure.AddDataStructure(dsd); NsiClientValidation.CheckifStructureComplete(structure, dataflow); IEnumerable <IStructureReference> conceptRefs = NsiClientHelper.BuildConceptSchemeRequest(structure.DataStructures.First()); foreach (var structureReference in conceptRefs) { IRestStructureQuery structureQueryConceptScheme = new RESTStructureQueryCore(structureReference); IBuilder <IComplexStructureQuery, IRestStructureQuery> transformerCategoryScheme = new StructureQuery2ComplexQueryBuilder(); IComplexStructureQuery complexStructureQueryConceptScheme = transformerCategoryScheme.Build(structureQueryConceptScheme); responseConceptScheme = this.SendQueryStructureRequest(complexStructureQueryConceptScheme, SDMXWSFunctionV21.GetConceptScheme); response.Merge(responseConceptScheme); } structure.Merge(response); NsiClientValidation.CheckConcepts(structure); Logger.Info(Resources.InfoSuccess); } catch (NsiClientException e) { Logger.Error(Resources.ExceptionGettingStructure); Logger.Error(e.Message, e); throw; } catch (Exception e) { Logger.Error(Resources.ExceptionGettingStructure); Logger.Error(e.Message, e); throw new NsiClientException(Resources.ExceptionGettingStructure, e); } return(structure); }
/// <summary> /// Initializes a new instance of the <see cref="TestComplexDataQueryToXDoc"/> class. /// </summary> public TestComplexDataQueryToXDoc() { IStructureParsingManager manager = new StructureParsingManager(); this._dataQueryBuilderManager = new ComplexDataQueryBuilderManager(new ComplexDataQueryFactoryV21()); using (var readable = new FileReadableDataLocation("tests/V21/Structure/test-sdmxv2.1-ESTAT+SSTSCONS_PROD_M+2.0.xml")) { var structureWorkspace = manager.ParseStructures(readable); this._dataflowObject = structureWorkspace.GetStructureObjects(false).Dataflows.First(); } using (var readable = new FileReadableDataLocation("tests/V21/Structure/test-sdmxv2.1-ESTAT+STS+2.0.xml")) { var structureWorkspace = manager.ParseStructures(readable); this._dataStructureObject = structureWorkspace.GetStructureObjects(false).DataStructures.First(); } }
private IDataQuery CreateQueryBean(IDataflowObject df, IDataStructureObject kf) { IDataQuery query; if (DataObjConfiguration._TypeEndpoint == EndpointType.REST) { query = new DataQueryFluentBuilder().Initialize(kf, df).Build(); } else { query = new DataQueryFluentBuilder().Initialize(kf, df). WithOrderAsc(true). WithMaxObservations(MaximumObservations).Build(); } return(query); }
public DataStructureObjectBaseCore(IDataStructureObject dataStructure, IList<IDimensionObjectBase> dimensions, IList<IAttributeObjectBase> attributes, IPrimaryMeasureObjectBase primaryMeasure) : base(dataStructure) { this._groups = new List<IGroupObjectBase>(); this._conceptComponentMap = new Dictionary<String, IComponentObjectBase>(); this._conceptCodelistMap = new Dictionary<String, ICodelistObjectBase>(); this._referencedCodelists = new HashSet<ICodelistObjectBase>(); this.keyFamily = dataStructure; this._dimensions = dimensions; this._attributes = attributes; this._primaryMeasure = primaryMeasure; //Create Mapping of Concept Id To Dimension that refers to that concept conceptDimensionMap = new Dictionary<String, IDimensionObjectBase>(); /* foreach */ foreach (IDimensionObjectBase currentDimension in dimensions) { conceptDimensionMap.Add(currentDimension.Id, currentDimension); _conceptComponentMap.Add(currentDimension.Id , currentDimension); if (currentDimension.GetCodelist(true) != null) { _conceptCodelistMap.Add(currentDimension.Id, currentDimension.GetCodelist(true)); _referencedCodelists.Add(currentDimension.GetCodelist(true)); } } if (attributes != null) { /* foreach */ foreach (IAttributeObjectBase attributeObjectBase in attributes) { _conceptComponentMap.Add(attributeObjectBase.Id , attributeObjectBase); if (attributeObjectBase.GetCodelist(true) != null) { _conceptCodelistMap.Add(attributeObjectBase.Id, attributeObjectBase.GetCodelist(true)); _referencedCodelists.Add(attributeObjectBase.GetCodelist(true)); } } } if (primaryMeasure != null) { _conceptComponentMap.Add(primaryMeasure.Id, primaryMeasure); if (primaryMeasure.GetCodelist(true) != null) { _conceptCodelistMap.Add(primaryMeasure.Id, primaryMeasure.GetCodelist(true)); _referencedCodelists.Add(primaryMeasure.GetCodelist(true)); } } /* foreach */ foreach (IGroup currentGroup in dataStructure.Groups) { _groups.Add(new GroupObjectBaseCore(currentGroup, this)); } }
public void WriteSampleData(IDataStructureObject dsd, IDataflowObject dataflow, IDataWriterEngine dwe) { dwe.StartDataset(dataflow, dsd, null); dwe.StartSeries(); dwe.WriteSeriesKeyValue("COUNTRY", "UK"); dwe.WriteSeriesKeyValue("INDICATOR", "E_P"); dwe.WriteObservation("2000", "18,22"); dwe.WriteObservation("2000-02", "17,63"); dwe.StartSeries(); dwe.WriteSeriesKeyValue("COUNTRY", "FR"); dwe.WriteSeriesKeyValue("INDICATOR", "E_P"); dwe.WriteObservation("2000", "22,22"); dwe.WriteObservation("2000-Q3", "15,63"); dwe.Close(); }
/// <summary> /// Build concept scheme requests from the concept scheme references of the specified KeyFamilyBean object /// </summary> /// <param name="kf"> /// The KeyFamily to look for concept Scheme references /// </param> /// <returns> /// A list of concept scheme requests /// </returns> public static IEnumerable <IStructureReference> BuildConceptSchemeRequest(IDataStructureObject kf) { var conceptSchemeSet = new Dictionary <string, object>(); var ret = new List <IStructureReference>(); var crossDsd = kf as ICrossSectionalDataStructureObject; List <IComponent> components = new List <IComponent>(); components.AddRange(kf.GetDimensions()); components.AddRange(kf.Attributes); if (kf.PrimaryMeasure != null) { components.Add(kf.PrimaryMeasure); } if (crossDsd != null) { components.AddRange(crossDsd.CrossSectionalMeasures); } ICollection <IComponent> comps = components; foreach (IComponent comp in comps) { string key = Utils.MakeKey(comp.ConceptRef.MaintainableReference.MaintainableId, comp.ConceptRef.MaintainableReference.Version, comp.ConceptRef.MaintainableReference.AgencyId); if (!conceptSchemeSet.ContainsKey(key)) { // create concept ref var conceptSchemeRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme)) { MaintainableId = comp.ConceptRef.MaintainableReference.MaintainableId, AgencyId = comp.ConceptRef.MaintainableReference.AgencyId, Version = comp.ConceptRef.MaintainableReference.Version }; // add it to request ret.Add(conceptSchemeRef); // added it to set of visited concept schemes conceptSchemeSet.Add(key, null); } } return(ret); }
public StreamResponseAction ExportSDMXQuery() { SessionQuery query = SessionQueryManager.GetSessionQuery(Session); //ControllerSupport CS = new ControllerSupport(); //GetCodemapObject PostDataArrived = CS.GetPostData<GetCodemapObject>(this.Request); //PostDataArrived.Configuration.Locale = System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName; string request = ""; var xdoc = new XmlDocument(); EndpointSettings DataObjConfiguration = new EndpointSettings(); DataObjConfiguration = query._endpointSettings; //IGetSDMX GetSDMXObject = WebServiceSelector.GetSdmxImplementation(DataObjConfiguration); IGetSDMX GetSDMXObject = (query._IGetSDMX == null) ? WebServiceSelector.GetSdmxImplementation(DataObjConfiguration) : query._IGetSDMX; BaseDataObject BDO = new BaseDataObject(DataObjConfiguration, "appo.xml"); ISdmxObjects structure = query.Structure; IDataflowObject df = structure.Dataflows.First(); IDataStructureObject kf = structure.DataStructures.First(); IDataQuery sdmxQuery = BDO.CreateQueryBean(df, kf, query.GetCriteria()); GetSDMXObject.GetSdmxQuery(sdmxQuery, out request); string filename = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", query.Dataflow.Id, "xml"); this.HttpContext.Response.Clear(); this.HttpContext.Response.ContentType = "text/xml"; this.HttpContext.Response.ContentEncoding = Encoding.UTF8; string contentDisposition = string.Format( CultureInfo.InvariantCulture, Constants.AttachmentFilenameFormat, filename); this.HttpContext.Response.AddHeader(Constants.ContentDispositionHttpHeader, contentDisposition); this.HttpContext.Response.AddHeader("content-disposition", contentDisposition); this.HttpContext.Response.Write(request); this.HttpContext.Response.End(); throw new NotImplementedException(); }
/// <summary> /// Build concept scheme requests from the concept scheme references of the specified KeyFamilyBean object /// </summary> /// <param name="kf"> /// The KeyFamily to look for concept Scheme references /// </param> /// <returns> /// A list of concept scheme requests /// </returns> public static IEnumerable<IStructureReference> BuildConceptSchemeRequest(IDataStructureObject kf) { var conceptSchemeSet = new Dictionary<string, object>(); var ret = new List<IStructureReference>(); var crossDsd = kf as ICrossSectionalDataStructureObject; List<IComponent> components = new List<IComponent>(); components.AddRange(kf.GetDimensions()); components.AddRange(kf.Attributes); if (kf.PrimaryMeasure != null) { components.Add(kf.PrimaryMeasure); } if (crossDsd != null) { components.AddRange(crossDsd.CrossSectionalMeasures); } ICollection<IComponent> comps = components; foreach (IComponent comp in comps) { string key = Utils.MakeKey(comp.ConceptRef.MaintainableReference.MaintainableId, comp.ConceptRef.MaintainableReference.Version, comp.ConceptRef.MaintainableReference.AgencyId); if (!conceptSchemeSet.ContainsKey(key)) { // create concept ref var conceptSchemeRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.ConceptScheme)) { MaintainableId = comp.ConceptRef.MaintainableReference.MaintainableId, AgencyId = comp.ConceptRef.MaintainableReference.AgencyId, Version = comp.ConceptRef.MaintainableReference.Version }; // add it to request ret.Add(conceptSchemeRef); // added it to set of visited concept schemes conceptSchemeSet.Add(key, null); } } return ret; }
public void writeSampleData(IDataStructureObject dsd, IDataflowObject dataflow, IDataWriterEngine dwe){ //Step 1. Writing sample data. //1) Start the dataset dwe.StartDataset(dataflow, dsd, null); //2) Start the dataset series dwe.StartSeries(); //3) Write dimensions dwe.WriteSeriesKeyValue("FREQ", "Q"); dwe.WriteSeriesKeyValue("REF_AREA","IT"); dwe.WriteSeriesKeyValue("ADJUSTMENT","W"); dwe.WriteSeriesKeyValue("STS_INDICATOR","E_P"); dwe.WriteSeriesKeyValue("STS_ACTIVITY","NS0020"); dwe.WriteSeriesKeyValue("STS_INSTITUTION","1"); dwe.WriteSeriesKeyValue("STS_BASE_YEAR","2000"); //4) Write Attribute at Series Level dwe.WriteAttributeValue("TIME_FORMAT", "P3M"); //5) Write the observations dwe.WriteObservation("2000-Q1", "18,22"); dwe.WriteObservation("2000-Q2", "17,63"); //6) Write Attribute at Observation Level dwe.WriteAttributeValue("OBS_STATUS", "C"); //7) Repeat the steps from 2 to 6 to create another dataset series dwe.StartSeries(); dwe.WriteSeriesKeyValue("FREQ", "M"); dwe.WriteSeriesKeyValue("REF_AREA", "SP"); dwe.WriteSeriesKeyValue("ADJUSTMENT", "N"); dwe.WriteSeriesKeyValue("STS_INDICATOR", "PROD"); dwe.WriteSeriesKeyValue("STS_ACTIVITY", "NS0030"); dwe.WriteSeriesKeyValue("STS_INSTITUTION", "1"); dwe.WriteSeriesKeyValue("STS_BASE_YEAR", "2001"); dwe.WriteAttributeValue("TIME_FORMAT", "P1M"); dwe.WriteObservation("2000-01", "18,22"); dwe.WriteObservation("2000-02", "17,63"); dwe.WriteAttributeValue("OBS_STATUS", "S"); //8) Close the dataset dwe.Close(); }
/// <summary> /// Checks if a structure is complete according to the requirements of <see cref="GetStructure"/> /// </summary> /// <param name="structure"> /// The StructureBean object to check. /// </param> /// <param name="dataflow"> /// The requested dataflow /// </param> /// <exception cref="NsiClientException"> /// Server response error /// </exception> public static void CheckifStructureComplete(ISdmxObjects structure, IDataflowObject dataflow) { if (structure.DataStructures.Count != 1) { Logger.Error(Resources.ExceptionKeyFamilyCountNot1); throw new NsiClientException(Resources.ExceptionKeyFamilyCountNot1); } IDataStructureObject kf = structure.DataStructures.First(); var keyFamilyRef = dataflow.DataStructureRef; if (kf.Id == null || keyFamilyRef == null || !kf.Id.Equals(keyFamilyRef.MaintainableReference.MaintainableId) || !kf.AgencyId.Equals(keyFamilyRef.MaintainableReference.AgencyId) || !kf.Version.Equals(keyFamilyRef.MaintainableReference.Version)) { Logger.Error(Resources.ExceptionServerResponseInvalidKeyFamily); throw new NsiClientException(Resources.ExceptionServerResponseInvalidKeyFamily); } }
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; }
/// <summary> /// The update references. /// </summary> /// <param name="maintianable"> /// The maintianable. /// </param> /// <param name="updateReferences"> /// The update references. /// </param> /// <param name="newVersionNumber"> /// The new version number. /// </param> /// <returns> /// The <see cref="IDataStructureObject"/>. /// </returns> public IDataStructureObject UpdateReferences(IDataStructureObject maintianable, IDictionary<IStructureReference, IStructureReference> updateReferences, String newVersionNumber) { IDataStructureMutableObject dsd = maintianable.MutableInstance; dsd.Version = newVersionNumber; if (dsd.DimensionList != null && dsd.DimensionList.Dimensions != null) { UpdateComponentReferneces(dsd.DimensionList.Dimensions, updateReferences); } if (dsd.AttributeList != null && dsd.AttributeList.Attributes != null) { UpdateComponentReferneces(dsd.AttributeList.Attributes, updateReferences); } if (dsd.MeasureList != null && dsd.MeasureList.PrimaryMeasure != null) { UpdateComponentReferneces(dsd.MeasureList.PrimaryMeasure, updateReferences); } return dsd.ImmutableInstance; }
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(); }
/// <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> /// Gets a bean with data about the codelist for specified dataflow and component. /// The dataflow can be retrieved from <see cref="RetrieveTree"/> and the component from <see cref="GetStructure"/> /// </summary> /// <param name="dataflow"> /// The dataflow /// </param> /// <param name="component"> /// The component /// </param> /// <param name="criteria"> /// The criteria includes a set of Member and MemberValue(s) for each dimension. The Member has componentRef the dimension conceptRef and the MemberValue(s) specify the selected codes for this dimension. /// </param> /// <returns> /// A <c>CodeListBean</c> with the requested data /// </returns> public ICodelistObject GetCodelist( IDataflowObject dataflow, IDataStructureObject dsd, IComponent component, List <IContentConstraintMutableObject> criterias, bool Constrained) { var codelistRef = new StructureReferenceImpl(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.CodeList)); var dimension = component as IDimension; if (dimension != null && dimension.TimeDimension) { codelistRef.MaintainableId = CustomCodelistConstants.TimePeriodCodeList; codelistRef.AgencyId = CustomCodelistConstants.Agency; codelistRef.Version = CustomCodelistConstants.Version; } else if (dimension != null && dimension.MeasureDimension && dsd is ICrossSectionalDataStructureObject) { var crossDsd = dsd as ICrossSectionalDataStructureObject; codelistRef.MaintainableId = crossDsd.GetCodelistForMeasureDimension(dimension.Id).MaintainableReference.MaintainableId; codelistRef.AgencyId = crossDsd.GetCodelistForMeasureDimension(dimension.Id).MaintainableReference.AgencyId; codelistRef.Version = crossDsd.GetCodelistForMeasureDimension(dimension.Id).MaintainableReference.Version; } else { if (component.HasCodedRepresentation()) { codelistRef.MaintainableId = component.Representation.Representation.MaintainableReference.MaintainableId; codelistRef.AgencyId = component.Representation.Representation.MaintainableReference.AgencyId; codelistRef.Version = component.Representation.Representation.MaintainableReference.Version; } } string info = string.Format( CultureInfo.InvariantCulture, Resources.InfoPartialCodelistFormat3, Utils.MakeKey(dataflow), component.ConceptRef, Utils.MakeKey(codelistRef)); return(this.GetCodelist(dataflow, codelistRef, criterias, info, Constrained)); }
public void StartDataset(string dsdName, IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { string appPath = System.Web.HttpRuntime.AppDomainAppPath; string giorno = System.Web.HttpContext.Current.Timestamp.Day.ToString(); string ora = System.Web.HttpContext.Current.Timestamp.Hour.ToString(); string min = System.Web.HttpContext.Current.Timestamp.Minute.ToString(); string secondi = System.Web.HttpContext.Current.Timestamp.Second.ToString(); string ms = System.Web.HttpContext.Current.Timestamp.Millisecond.ToString(); string namedir = giorno + ora + min + secondi + ms; dirPath = appPath + namedir; DirectoryInfo MyRoot = new DirectoryInfo(@appPath); MyRoot.CreateSubdirectory(namedir); IList<IDimension> dimensions = dsd.GetDimensions(SdmxStructureEnumType.Dimension); string[] ordinamento1 = new string[dimensions.Count]; string[] ordinamento2 = new string[dsd.Components.Count]; ordine = new string[dimensions.Count]; ordineser = new string[dimensions.Count]; int indord = 0; string valoredati = ""; IList<IDimension> dimensions1 = dsd.GetDimensions(SdmxStructureEnumType.Dimension); foreach (IDimension dim in dimensions1) { _CsvZipDataWriter.WriteValue(dim.Id + "_code,"); valoredati += dim.Id + "_code,"; ordine[indord] = dim.Id; indord++; } valoredati += "VALUE,date"; string newLinedati = string.Format("{0}{1}", valoredati, Environment.NewLine); csvdati.Append(newLinedati); }
private string CalculateDominantFrequency(List <DataCriteria> Criterias, IDataStructureObject kf, ISet <ICodelistObject> codelists) { string DominantFreq = null; if (kf.FrequencyDimension.HasCodedRepresentation() && !string.IsNullOrEmpty(kf.FrequencyDimension.Representation.Representation.MaintainableReference.MaintainableId)) { ICodelistObject codes = codelists.FirstOrDefault(c => c.Id == kf.FrequencyDimension.Representation.Representation.MaintainableReference.MaintainableId && c.AgencyId == kf.FrequencyDimension.Representation.Representation.MaintainableReference.AgencyId && c.Version == kf.FrequencyDimension.Representation.Representation.MaintainableReference.Version); if (codes.Items != null && codes.Items.Count > 1) { List <string> allFreq = new List <string>(); codes.Items.ToList().ForEach(c => allFreq.Add(c.Id)); DataCriteria filter = Criterias.Find(cri => cri.component.Id == kf.FrequencyDimension.Id); if (filter != null) { allFreq = filter.values; } if (allFreq.Count > 1) { if (allFreq.Contains("A")) { DominantFreq = "A"; } if (allFreq.Contains("S")) { DominantFreq = "S"; } if (allFreq.Contains("Q")) { DominantFreq = "Q"; } if (allFreq.Contains("M")) { DominantFreq = "M"; } } } } return(DominantFreq); }
/// <summary> /// Check if the specified structure has all referenced concept schemes from the first keyfamily /// </summary> /// <param name="structure"> /// The StructureBean to check /// </param> public static void CheckConcepts(ISdmxObjects structure) { var cshtMap = new Dictionary <string, IConceptSchemeObject>(); IDataStructureObject kf = structure.DataStructures.First(); foreach (IConceptSchemeObject c in structure.ConceptSchemes) { cshtMap.Add(Utils.MakeKey(c), c); } var crossDsd = kf as ICrossSectionalDataStructureObject; List <IComponent> components = new List <IComponent>(); components.AddRange(kf.GetDimensions()); components.AddRange(kf.Attributes); if (kf.PrimaryMeasure != null) { components.Add(kf.PrimaryMeasure); } if (crossDsd != null) { components.AddRange(crossDsd.CrossSectionalMeasures); } var comps = components; foreach (IComponent comp in comps) { string conceptKey = Utils.MakeKey(comp.ConceptRef.MaintainableReference.MaintainableId, comp.ConceptRef.MaintainableReference.AgencyId, comp.ConceptRef.MaintainableReference.Version); if (!cshtMap.ContainsKey(conceptKey)) { string message = string.Format(CultureInfo.InvariantCulture, Resources.ExceptionMissingConceptSchemeFormat1, conceptKey); Logger.Error(message); throw new NsiClientException(message); } } }
/// <summary> /// Initialize the <see cref="_componentIndex"/> and <see cref="_queryComponentIndex"/> fields for the specified KeyFamilyBean /// </summary> /// <param name="kf"> /// The Keyfamily /// </param> public void InitializeComponentList(IDataStructureObject kf) { this._componentIndex.Clear(); this._queryComponentIndex.Clear(); int x = 0; if (kf.DimensionList != null) { foreach (IDimension comp in kf.DimensionList.Dimensions) { this._componentIndex.Add(comp, x); this._queryComponentIndex.Add(null); x++; } } //if (kf.TimeDimension != null) //{ // this._componentIndex.Add(kf.TimeDimension, x); // this._queryComponentIndex.Add(null); //} }
/// <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> /// Initializes a new instance of the <see cref="CompactDataReaderEngine"/> class. /// Initializes a new instance of the <see cref="AbstractSdmxDataReaderEngine"/> class. /// </summary> /// <param name="dataLocation"> /// The data Location. /// </param> /// <param name="objectRetrieval"> /// The SDMX Object Retrieval. giving the ability to retrieve DSDs for the datasets this /// reader engine is reading. This can be null if there is only one relevant DSD - in which case the /// <paramref name="defaultDsd"/> should be provided. /// </param> /// <param name="defaultDataflow"> /// The default Dataflow. (Optional) /// </param> /// <param name="defaultDsd"> /// The default DSD. The default DSD to use if the <paramref name="objectRetrieval"/> is null, or /// if the bean retrieval does not return the DSD for the given dataset. /// </param> /// <exception cref="System.ArgumentException"> /// AbstractDataReaderEngine expects either a ISdmxObjectRetrievalManager or a /// IDataStructureObject to be able to interpret the structures /// </exception> public CompactDataReaderEngine(IReadableDataLocation dataLocation, ISdmxObjectRetrievalManager objectRetrieval, IDataflowObject defaultDataflow, IDataStructureObject defaultDsd) : base(dataLocation, objectRetrieval, defaultDataflow, defaultDsd) { this.Reset(); }
/// <summary> /// Sets the current DSD. /// </summary> /// <param name="currentDsd"> /// The current DSD. /// </param> /// <exception cref="SdmxNotImplementedException"> /// Time series without time dimension /// </exception> protected override void SetCurrentDsd(IDataStructureObject currentDsd) { base.SetCurrentDsd(currentDsd); // reset all maps this._dimensionConcepts = new List<string>(); this._datasetAttributes = new HashSet<string>(StringComparer.Ordinal); this._seriesAttributes = new HashSet<string>(StringComparer.Ordinal); this._observationAttributes = new HashSet<string>(StringComparer.Ordinal); this._groups = new List<string>(); this._groupConcepts = new Dictionary<string, List<string>>(StringComparer.Ordinal); if (this.DatasetHeader.DataStructureReference != null) { this.SetDimensionAtObservation(this.DatasetHeader.DataStructureReference.DimensionAtObservation); } else { this.SetDimensionAtObservation(DimensionObject.TimeDimensionFixedId); } // Roll up any attribute values foreach (var valuePair in this._attributesOnDatasetNode) { var component = currentDsd.GetComponent(valuePair.Key); if (component != null) { this._rolledUpAttributes.Add(valuePair); } } // Create a list of dimension concepts foreach (var dimension in currentDsd.GetDimensions(SdmxStructureEnumType.Dimension, SdmxStructureEnumType.MeasureDimension)) { this._dimensionConcepts.Add(dimension.Id); } // Create a list of dataset attribute concepts foreach (var datasetAttribute in currentDsd.DatasetAttributes) { this._datasetAttributes.Add(datasetAttribute.Id); } // Create a list of dimension group attribute concepts foreach (var dimensionGroupAttribute in currentDsd.DimensionGroupAttributes) { this._seriesAttributes.Add(dimensionGroupAttribute.Id); } // Create a list of observation attribute concepts foreach (var observationAttribute in currentDsd.ObservationAttributes) { this._observationAttributes.Add(observationAttribute.Id); } this._primaryMeasureConcept = currentDsd.PrimaryMeasure.Id; if (currentDsd.TimeDimension == null) { throw new SdmxNotImplementedException(string.Format(CultureInfo.InvariantCulture, "The DSD: {0} has no time dimension. This is unsupported!", currentDsd.Id)); } this._timeConcept = currentDsd.TimeDimension.Id; foreach (var dsdGroup in currentDsd.Groups) { string groupId = dsdGroup.Id; this._groups.Add(groupId); ISet<string> groupAttributes = new HashSet<string>(currentDsd.GetGroupAttributes(groupId, true).Select(o => o.Id), StringComparer.Ordinal); this._groupAttributeConcepts.Add(groupId, groupAttributes); var groups = new List<string>(); PopulateGroupContents(dsdGroup, groups); this._groupConcepts.Add(groupId, groups); } }
/// <summary> /// Starts a dataset with the data conforming to the DSD /// </summary> /// <param name="dataflow">Optional. The dataflow can be provided to give extra information about the dataset.</param> /// <param name="dsd">The data structure is used to know the dimensionality of the data</param> /// <param name="header">Dataset header containing, amongst others, the dataset action, reporting dates, /// dimension at observation if null then the dimension at observation is assumed to be TIME_PERIOD and the dataset action is assumed to be INFORMATION</param> /// <param name="annotations">Any additional annotations that are attached to the dataset, can be null if no annotations exist</param> /// <exception cref="T:System.ArgumentException">if the DSD is null</exception> public void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { this._actions.Enqueue(() => this._dataWriterEngine.StartDataset(dataflow, dsd, header, annotations)); }
/// <summary> /// Initializes a new instance of the <see cref="CompactDataReaderEngine"/> class. /// </summary> /// <param name="dataLocation"> /// The data Location. /// </param> /// <param name="defaultDataflow"> /// The default Dataflow. (Optional) /// </param> /// <param name="defaultDsd"> /// The default DSD. The default DSD to use if the /// <paramref> /// <name>objectRetrieval</name> /// </paramref> /// is null, or /// if the bean retrieval does not return the DSD for the given dataset. /// </param> /// <exception cref="System.ArgumentException"> /// AbstractDataReaderEngine expects either a ISdmxObjectRetrievalManager or a /// IDataStructureObject to be able to interpret the structures /// </exception> public CompactDataReaderEngine(IReadableDataLocation dataLocation, IDataflowObject defaultDataflow, IDataStructureObject defaultDsd) : this(dataLocation, null, defaultDataflow, defaultDsd) { }
/// <summary> /// Gets the measure concept. /// </summary> /// <param name="dataStructureObject"> /// The data structure object. /// </param> /// <returns> /// The measure concept. /// </returns> public static string GetMeasureConcept(IDataStructureObject dataStructureObject) { return dataStructureObject.PrimaryMeasure.Id; }
/// <summary> /// Starts a dataset with the data conforming to the DSD /// </summary> /// <param name="dataflow">Optional. The dataflow can be provided to give extra information about the dataset.</param> /// <param name="dsd">The <see cref="IDataStructureObject" /> for which the dataset will be created</param> /// <param name="header">The <see cref="IHeader" /> of the dataset</param> /// <param name="annotations">Any additional annotations that are attached to the dataset, can be null if no annotations exist</param> /// <exception cref="System.ArgumentNullException">if the <paramref name="dsd" /> is null</exception> public override void StartDataset(IDataflowObject dataflow, IDataStructureObject dsd, IDatasetHeader header, params IAnnotation[] annotations) { base.StartDataset(dataflow, dsd, header, annotations); this._primaryMeasureConcept = this.GetComponentId(dsd.PrimaryMeasure); this._compactNs = this.TargetSchema.EnumType != SdmxSchemaEnumType.VersionTwoPointOne ? this.Namespaces.DataSetStructureSpecific : NamespacePrefixPair.Empty; this._obsConcept = this.IsTwoPointOne ? this.DimensionAtObservation : ConceptRefUtil.GetConceptId(this.KeyFamily.TimeDimension.ConceptRef); if (this.IsTwoPointOne) { this.WriteAnnotations(ElementNameTable.AnnotationType, annotations); } else { this._datasetAnnotations = annotations; } }
/// <summary> /// Returns the group id, along with a list of concepts that belong to the group key. /// </summary> /// <param name="dataStructureObject"> /// The data structure object. /// </param> /// <returns> /// The group id, along with a list of concepts that belong to the group key. /// </returns> public static IDictionary<string, IList<string>> GetGroupConcepts(IDataStructureObject dataStructureObject) { IDictionary<string, IList<string>> returnMap = new Dictionary<string, IList<string>>(); if (dataStructureObject.Groups != null) { foreach (IGroup currentBean in dataStructureObject.Groups) { returnMap.Add(currentBean.Id, currentBean.DimensionRefs); } } return returnMap; }
/// <summary> /// Returns the observation concepts including the measure concept, /// and all the attribute concepts that are attached to the observation. /// The measure concept is always the first concept in the list, the others are added in the order they appear /// in the DataStructureObject. /// </summary> /// <param name="dataStructureObject"> /// The data structure object. /// </param> /// <returns> /// The observation concepts. /// </returns> public static IList<string> GetObservationConcepts(IDataStructureObject dataStructureObject) { IList<string> obsConcepts = new List<string>(); obsConcepts.Add(GetMeasureConcept(dataStructureObject)); if (dataStructureObject.Attributes != null) { foreach (IAttributeObject currentAttribute in dataStructureObject.Attributes) { string conceptId = currentAttribute.Id; if (currentAttribute.AttachmentLevel == AttributeAttachmentLevel.Observation) { if (!obsConcepts.Contains(conceptId)) { obsConcepts.Add(conceptId); } } } } return obsConcepts; }
/// <summary> /// Gets the time concept. /// </summary> /// <param name="dataStructureObject"> /// The data structure object. /// </param> /// <returns> /// The time concept. /// </returns> public static string GetTimeConcept(IDataStructureObject dataStructureObject) { if (dataStructureObject.TimeDimension != null) { return dataStructureObject.TimeDimension.ConceptRef.ChildReference.Id; } return null; }
/// <summary> /// Returns the series key concepts. /// </summary> /// <param name="dataStructureObject"> /// The data structure object. /// </param> /// <returns> /// The series key concepts. /// </returns> public static IList<string> GetSeriesKeyConcepts(IDataStructureObject dataStructureObject) { IList<string> keyConcepts = new List<string>(); foreach (IDimension currentDimension in dataStructureObject.GetDimensions(SdmxStructureEnumType.Dimension, SdmxStructureEnumType.MeasureDimension)) { keyConcepts.Add(currentDimension.Id); } return keyConcepts; }
/// <summary> /// Returns the concept id's belonging to each series attributes in the order they appear in the DataStructureObject, /// followed by the concept id's belonging to each group attributes in the order of the groups, /// and attributes within each group. /// A concept id will not be added to the list twice, so if a concept id appears in a series attribute /// and a group attribute, then the first occurrence will be added to the list, which will be the series /// attribute, the second occurrence will not be added. /// </summary> /// <param name="dataStructureObject"> /// The data structure object. /// </param> /// <returns> /// The concept id's. /// </returns> public static IList<string> GetSeriesAndGroupAttributeConcepts(IDataStructureObject dataStructureObject) { IList<string> attributeConcepts = new List<string>(); if (dataStructureObject.DimensionGroupAttributes != null) { foreach (IAttributeObject currentAttribute in dataStructureObject.DimensionGroupAttributes) { attributeConcepts.Add(currentAttribute.Id); } foreach (IAttributeObject currentAttribute in dataStructureObject.GroupAttributes) { if (!attributeConcepts.Contains(currentAttribute.Id)) { attributeConcepts.Add(currentAttribute.Id); } } } return attributeConcepts; }