Esempio n. 1
0
        internal void SettingValues(List <DataMessageObject> dmo, SdmxJsonBaseDataWriter dataWriterEngine)
        {
            try
            {
                bool AddedDatasetAttribute = false;

                foreach (DataMessageObject seriesKey in dmo.FindAll(dim => OnlySeriesKey(dim)))
                {
                    dataWriterEngine.AddSerie(seriesKey.ColImpl.ConceptObjectCode, seriesKey.Val.ToString(), dataWriterEngine.GetKeyPosition(dataWriterEngine._dsd, seriesKey.ColImpl.ConceptObjectCode), true);
                }

                foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlySeriesAttribute(att)))
                {
                    dataWriterEngine.AddAttribute(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString(), "Serie");
                }


                DataMessageObject val = dmo.Find(dimV => dimV.ColImpl.ConceptType == ConceptTypeEnum.Attribute && ((IAttributeConcept)dimV.ColImpl).IsValueAttribute);

                DataMessageObject ObsVal = null;

                if (string.IsNullOrEmpty(DimensionAtObservation))
                {
                    DimensionAtObservation = "TIME_PERIOD";
                }

                ObsVal = dmo.Find(dimT => dimT.ColImpl.Id.Trim().ToUpper() == DimensionAtObservation.Trim().ToUpper());
                dataWriterEngine.AddObsValue(ObsVal.Val.ToString());

                if (dataWriterEngine.JsonStruct.Observation.ID == null)
                {
                    dataWriterEngine.JsonStruct.Observation.Role = "time";
                    dataWriterEngine.JsonStruct.Observation.ID   = ObsVal.ColImpl.Id;
                }

                if (!AddedDatasetAttribute)
                {
                    foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyDatasetAttribute(att)))
                    {
                        dataWriterEngine.AddAttribute(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString(), "DataSet");
                    }
                    AddedDatasetAttribute = true;
                }

                foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyObservationAttribute(att)))
                {
                    dataWriterEngine.AddAttribute(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString(), "Observation");
                }
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteTimeSeriesData, ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Write a TimeSeries Data
        /// </summary>
        /// <param name="dataWriterEngine">input structure contains data</param>
        private void WriteTimeSeriesData(IDataWriterEngine dataWriterEngine)
        {
            //TODO: MAX - FORSE E' QUESTA LA PARTE DA MODIFICARE!!

            try
            {
                bool AddedDatasetAttribute   = false;
                List <DataMessageObject> dmo = _tableResponse.GetNext();
                do
                {
                    if (dmo == null)
                    {
                        break;
                    }

                    //Aggiungo gli Attributi di Dataset
                    if (!AddedDatasetAttribute)
                    {
                        foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyDatasetAttribute(att)))
                        {
                            dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                        }
                        AddedDatasetAttribute = true;
                    }


                    //SERIE
                    if (CheckChanged(dmo))
                    {
                        dataWriterEngine.StartSeries();

                        foreach (DataMessageObject seriesKey in dmo.FindAll(dim => OnlySeriesKey(dim)))
                        {
                            dataWriterEngine.WriteSeriesKeyValue(seriesKey.ColImpl.ConceptObjectCode, seriesKey.Val.ToString());
                        }

                        foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlySeriesAttribute(att)))
                        {
                            dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                        }
                    }

                    //OBSERVATION
                    DataMessageObject val = dmo.Find(dimV => dimV.ColImpl.ConceptType == ConceptTypeEnum.Attribute && ((IAttributeConcept)dimV.ColImpl).IsValueAttribute);

                    DataMessageObject ObsVal = null;
                    if (string.IsNullOrEmpty(DimensionAtObservation) || new List <string> {
                        "TIME_PERIOD", "ALLDIMENSIONS"
                    }.Contains(DimensionAtObservation.Trim().ToUpper()))
                    {
                        ObsVal = dmo.Find(dimT => dimT.ColImpl.ConceptType == ConceptTypeEnum.Dimension && ((IDimensionConcept)dimT.ColImpl).DimensionType == DimensionTypeEnum.Time);
                        dataWriterEngine.WriteObservation(ObsVal.Val.ToString(), val.Val.ToString());
                    }
                    else
                    {
                        ObsVal = dmo.Find(dimT => dimT.ColImpl.Id.Trim().ToUpper() == DimensionAtObservation.Trim().ToUpper());
                        dataWriterEngine.WriteObservation(ObsVal.ColImpl.Id, ObsVal.Val.ToString(), val.Val.ToString());
                    }

                    foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyObservationAttribute(att)))
                    {
                        if (seriesAttribute.Val.ToString() != String.Empty)
                        {
                            dataWriterEngine.WriteAttributeValue(seriesAttribute.ColImpl.ConceptObjectCode, seriesAttribute.Val.ToString());
                        }
                    }

                    dmo = _tableResponse.GetNext();
                } while (dmo != null);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteTimeSeriesData, ex);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Write a TimeSeries Data
        /// </summary>
        /// <param name="dataWriterEngine">input structure contains data</param>
        private void WriteTimeSeriesData(SdmxJsonBaseDataWriter dataWriterEngine)
        {
            try
            {
                bool AddedDatasetAttribute   = false;
                List <DataMessageObject> dmo = _tableResponse.GetNext();
                do
                {
                    if (dmo == null)
                    {
                        break;
                    }

                    SettingValues(dmo, dataWriterEngine);

                    if (!AddedDatasetAttribute)
                    {
                        dataWriterEngine.StartElement("attributes", false);
                        foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyDatasetAttribute(att)))
                        {
                            dataWriterEngine.WriteAttributes(seriesAttribute);
                        }

                        AddedDatasetAttribute = true;
                        dataWriterEngine.CloseArray();
                        dataWriterEngine.StartSeries();
                    }
                    //SERIE
                    if (CheckChanged(dmo))
                    {
                        if (dataWriterEngine.StartedObservations)
                        {
                            dataWriterEngine.CloseObject();
                            dataWriterEngine.CloseObject();
                            dataWriterEngine._startedObservations = false;
                        }

                        dataWriterEngine.WriteSeriesKey(dmo);

                        // write series attributes
                        dataWriterEngine.StartElement("attributes", false);
                        foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlySeriesAttribute(att)))
                        {
                            dataWriterEngine.WriteAttributes(seriesAttribute);
                        }
                        dataWriterEngine.CloseArray();


                        if (!dataWriterEngine._startedObservations)
                        {
                            dataWriterEngine.StartElement("observations", true);
                            dataWriterEngine._startedObservations = true;
                        }
                    }
                    ////OBSERVATION
                    DataMessageObject val = dmo.Find(dimV => dimV.ColImpl.ConceptType == ConceptTypeEnum.Attribute && ((IAttributeConcept)dimV.ColImpl).IsValueAttribute);

                    DataMessageObject ObsVal = null;

                    ObsVal = dmo.Find(dimT => dimT.ColImpl.Id.Trim().ToUpper() == DimensionAtObservation.Trim().ToUpper());
                    dataWriterEngine.WriteObservation(dataWriterEngine.GetObsValPosition(ObsVal.Val.ToString()), val.Val.ToString());
                    //Write Observation Attributes
                    foreach (DataMessageObject seriesAttribute in dmo.FindAll(att => OnlyObservationAttribute(att)))
                    {
                        dataWriterEngine.WriteAttributes(seriesAttribute);
                    }

                    dataWriterEngine.CloseArray();


                    dmo = _tableResponse.GetNext();
                } while (dmo != null);
            }
            catch (SdmxException) { throw; }
            catch (Exception ex)
            {
                throw new SdmxException(this, FlyExceptionObject.FlyExceptionTypeEnum.ErrorWriteTimeSeriesData, ex);
            }
        }