Esempio n. 1
0
            public static seriesCatalogTypeSeries CreateSeriesRecord(DataRow row)
            {
                seriesCatalogTypeSeries series = new seriesCatalogTypeSeries();

                CoreTables.SeriesCatalogDataTable scDt = new CoreTables.SeriesCatalogDataTable();
                scDt.ImportRow(row);

                CoreTables.SeriesCatalogRow scRow = (CoreTables.SeriesCatalogRow)scDt.Rows[0];
                //series.variable = variable != null ? variable : CreateVariableDescriptionType();
                //VariableInfoType vdt = new VariableInfoType();
                //variableCode[] var = new variableCode[1];
                //var[0] = new variableCode();
                //vdt.variableCode = var;
                //vdt.units = new units();
                //return vdt;

                // create a VariablesRow, fill it. pass it to row2Variable()
                CoreTables.VariablesDataTable vDt = new CoreTables.VariablesDataTable();
                vDt.ImportRow(row);

                series.variable = CreateVariableRecord(row);


                if (!scRow.IsValueCountNull())
                {
                    series.valueCount       = new seriesCatalogTypeSeriesValueCount();
                    series.valueCount.Value = scRow.ValueCount;
                }



                //set the time interval

                // if (isRealTime)
                if (!scRow.IsRealTimeStationNull() &&
                    scRow.RealTimeStation)
                {
                    TimePeriodRealTimeType rt = new TimePeriodRealTimeType();
                    int timeInterval          = 0;
                    if (!scRow.IsRealTimeAvailabilityInDaysNull())
                    {
                        rt.realTimeDataPeriod = scRow.RealTimeAvailabilityInDays.ToString(); // 31 day Period

                        rt.beginDateTime = DateTime.Today.AddDays((-1) * scRow.RealTimeAvailabilityInDays);
                    }
                    else
                    {
                        rt.realTimeDataPeriod = "31"; // 31 day Period
                        rt.beginDateTime      = DateTime.Today.AddDays(-31);
                    }

                    rt.endDateTime = DateTime.Today;
                    series.variableTimeInterval = rt;
                }
                else
                {
                    if (!scRow.IsBeginDateTimeNull())
                    {
                        TimeIntervalType tm = new TimeIntervalType();

                        tm.beginDateTime = DateTime.Parse(scRow.BeginDateTime);

                        if (!scRow.IsEndDateTimeNull())
                        {
                            tm.endDateTime = DateTime.Parse(scRow.EndDateTime);;
                        }
                        else
                        {
                            tm.endDateTime = tm.beginDateTime;
                        }
                        series.variableTimeInterval = tm;
                    }
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                // if (!String.IsNullOrEmpty(QualityControlLevelTerm))
                if (!scRow.IsQualityControlLevelIDNull() ||
                    !scRow.IsQualityControlLevelTermNull())
                {
                    series.qualityControlLevel = new QualityControlLevelType();
                    // need to have a dataset with an enum so we can
                    // SetEnumFromText(qsds,row,series.QualityControlLevel, typeof(QualityControlLevelEnum));


                    if (!scRow.IsQualityControlLevelTermNull())
                    {
                        series.qualityControlLevel.definition = scRow.QualityControlLevelTerm;

                        // originally defined as an enum, but enums cannot be empty, and we have an id
                        // QualityControlLevelTerm = QualityControlLevelTerm.Replace(" ", "");
                        // if (Enum.IsDefined(typeof(QualityControlLevelEnum), QualityControlLevelTerm))
                        // {
                        //     object aEnum = Enum.Parse(typeof(QualityControlLevelEnum), QualityControlLevelTerm);
                        //     series.QualityControlLevel.Value = (QualityControlLevelEnum)aEnum;
                        // }
                    }
                    else
                    {
                        // hard code conversion to term
                        int qcId = scRow.QualityControlLevelID;
                        switch (qcId)
                        {
                        case 0:
                            series.qualityControlLevel.definition = "Raw data";
                            break;

                        case 1:
                            series.qualityControlLevel.definition = "Quality controlled data";
                            break;

                        case 2:
                            series.qualityControlLevel.definition = "Derived products";
                            break;

                        case 3:
                            series.qualityControlLevel.definition = "Interpreted products";
                            break;

                        case 4:
                            series.qualityControlLevel.definition = "Knowledge products";
                            break;

                        case -9999:
                        default:
                            series.qualityControlLevel.definition = "Unknown";
                            break;
                        }
                    }
                }
                else
                {
                    series.qualityControlLevel            = new QualityControlLevelType();
                    series.qualityControlLevel.definition = "Unknown";
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (!scRow.IsMethodNameNull())
                {
                    MethodType method = new MethodType();
                    if (!String.IsNullOrEmpty(scRow.MethodName))
                    {
                        method.methodDescription = scRow.MethodName;
                    }

                    series.method = method;
                }

                if (!scRow.IsSourceDescriptionNull() ||
                    !scRow.IsOrganizationNull())
                {
                    SourceType source = new SourceType();
                    if (!scRow.IsSourceDescriptionNull())
                    {
                        source.sourceDescription = scRow.SourceDescription;
                    }
                    if (!scRow.IsOrganizationNull())
                    {
                        source.organization = scRow.Organization;
                    }

                    series.source = source;
                }
                return(series);
            }
Esempio n. 2
0
            public static seriesCatalogTypeSeries CreateSeriesRecord(string VariableCode, string VariableName, string VariableUnitName, string VariableUnitAbrreviation, string VariableUnitCode, string sampleMedium, string dataType, string valueType, string generalCategory, W3CDateTime?beginDateTime, W3CDateTime?endDateTime, int?valueCount, bool?valueCountIsEstimated, int?TimeInterval, string TimeIntervalUnits, bool isRealTime, string QualityControlLevelTerm, string methodName, string organization, string sourceDescription, string VariableVocabulary)
            {
                /* don't forget to check the VariableInfoType for the
                 * dataType,ValueType and General Category
                 *
                 */
                /*
                 * logic
                 * create seriesCatalogTypeSeries
                 * if variable != null use it. if null, make an empty variable
                 * if variable != null
                 *    and sampleMedium,dataType,valueType or generalCategory is null
                 *    try to get value from variable
                 * add datTime interface logic
                 *
                 */
                seriesCatalogTypeSeries series = new seriesCatalogTypeSeries();


                //series.variable = variable != null ? variable : CreateVariableDescriptionType();
                //VariableInfoType vdt = new VariableInfoType();
                //variableCode[] var = new variableCode[1];
                //var[0] = new variableCode();
                //vdt.variableCode = var;
                //vdt.units = new units();
                //return vdt;

                // create a VariablesRow, fill it. pass it to row2Variable()
                CoreTables.VariablesDataTable vDs = new CoreTables.VariablesDataTable();
                CoreTables.VariablesRow       row = vDs.NewVariablesRow();
                row.VariableCode              = VariableCode;
                row.VariableName              = VariableName;
                row.VariableUnitsName         = VariableUnitName;
                row.VariableUnitsAbbreviation = VariableUnitAbrreviation;
                row.ValueType          = valueType;
                row.DataType           = dataType;
                row.SampleMedium       = sampleMedium;
                row.GeneralCategory    = generalCategory;
                row.VariableVocabulary = VariableVocabulary;
                vDs.Rows.Add(row);
                vDs.AcceptChanges();

                series.variable = CreateVariableRecord(row);

                if (valueCount.HasValue)
                {
                    series.valueCount       = new seriesCatalogTypeSeriesValueCount();
                    series.valueCount.Value = valueCount.Value;
                }



                //set the time interval

                if (isRealTime)
                {
                    TimePeriodRealTimeType rt = new TimePeriodRealTimeType();
                    rt.realTimeDataPeriod       = TimeInterval.ToString(); // 31 day Period
                    rt.beginDateTime            = DateTime.Today.AddDays(-31);
                    rt.endDateTime              = DateTime.Today;
                    series.variableTimeInterval = rt;
                }
                else
                {
                    if (beginDateTime.HasValue)
                    {
                        TimeIntervalType tm = new TimeIntervalType();

                        tm.beginDateTime = beginDateTime.Value.DateTime;

                        if (endDateTime.HasValue)
                        {
                            tm.endDateTime = endDateTime.Value.DateTime;
                        }
                        else
                        {
                            tm.endDateTime = tm.beginDateTime;
                        }
                        series.variableTimeInterval = tm;
                    }
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (!String.IsNullOrEmpty(QualityControlLevelTerm))
                {
                    series.qualityControlLevel = new QualityControlLevelType();
                    // need to have a dataset with an enum so we can
                    // SetEnumFromText(qsds,row,series.QualityControlLevel, typeof(QualityControlLevelEnum));


                    if (!String.IsNullOrEmpty(QualityControlLevelTerm))
                    {
                        series.qualityControlLevel.definition = QualityControlLevelTerm;

                        // originally defined as an enum, but enums cannot be empty, and we have an id
                        // QualityControlLevelTerm = QualityControlLevelTerm.Replace(" ", "");
                        // if (Enum.IsDefined(typeof(QualityControlLevelEnum), QualityControlLevelTerm))
                        // {
                        //     object aEnum = Enum.Parse(typeof(QualityControlLevelEnum), QualityControlLevelTerm);
                        //     series.QualityControlLevel.Value = (QualityControlLevelEnum)aEnum;
                        // }
                    }
                }

                /* TODO: fully populate
                 * These need to use ID< and fully populat from database
                 */
                if (!String.IsNullOrEmpty(methodName))
                {
                    MethodType method = new MethodType();
                    if (!String.IsNullOrEmpty(methodName))
                    {
                        method.methodDescription = methodName;
                    }

                    series.method = method;
                }
                if (!String.IsNullOrEmpty(sourceDescription) ||
                    !String.IsNullOrEmpty(organization))
                {
                    SourceType source = new SourceType();
                    if (!String.IsNullOrEmpty(sourceDescription) ||
                        !String.IsNullOrEmpty(organization))
                    {
                        source.sourceDescription = sourceDescription;
                        source.organization      = organization;
                    }

                    series.source = source;
                }

                return(series);
            }
Esempio n. 3
0
            /// <summary>
            /// Builds a VariableInfoType which is part of the VariablesResponse;
            /// Columns:
            /// VariableID
            /// VariableCode (R)
            /// VariableVocabulary
            /// VariableName (r) - will display 'not specified'
            /// </summary>
            /// <param name="aRow"></param>
            /// <returns></returns>
            public static VariableInfoType CreateVariableRecord(DataRow aRow)
            {
                CoreTables.VariablesDataTable vDs = new CoreTables.VariablesDataTable();

                vDs.ImportRow(aRow);

                vDs.AcceptChanges();

                VariableInfoType vit = new VariableInfoType();

                if (vDs.Rows.Count > 0)
                {
                    CoreTables.VariablesRow row =
                        (CoreTables.VariablesRow)vDs.Rows[0];
                    {
                        // set attributes
                        if (!row.IsVariableIDNull())
                        {
                            vit.oid = row.VariableID.ToString();
                        }

                        // add a vCode
                        vit.variableCode = new VariableInfoTypeVariableCode[1];
                        VariableInfoTypeVariableCode vCode = new VariableInfoTypeVariableCode();
                        if (!row.IsVariableVocabularyNull())
                        {
                            vCode.vocabulary       = row.VariableVocabulary;
                            vCode.@default         = true;
                            vCode.defaultSpecified = true;
                        }
                        vCode.Value         = row.VariableCode;
                        vit.variableCode[0] = vCode;

                        // add name
                        if (!row.IsVariableNameNull())
                        {
                            vit.variableName = row.VariableName;
                        }
                        else
                        {
                            vit.variableName = "Not Specified.";
                        }

                        // value type
                        if (!row.IsValueTypeNull())
                        {
                            //                           SetEnumFromText(vit, row, "valueType", typeof(valueTypeEnum));

                            vit.valueType = row.ValueType;
                        }
                        //add DataType
                        if (!row.IsDataTypeNull())
                        {
                            //SetEnumFromText(vit, row, "dataType", typeof(dataTypeEnum));
                            vit.dataType = row.DataType;
                        }
                        //add General Categoy
                        //
                        if (!row.IsGeneralCategoryNull())
                        {
                            // SetEnumFromText(vit, row, "generalCategory", typeof(generalCategoryEnum));
                            vit.generalCategory = row.GeneralCategory;
                        }

                        // Units
                        // if just the ID exists... then it's not useful
                        if (!row.IsVariableUnitsNameNull() ||
                            !row.IsVariableUnitsAbbreviationNull())
                        {
                            UnitsType unit = new UnitsType();
                            if (!row.IsVariableUnitsNameNull())
                            {
                                unit.unitName = row.VariableUnitsName;
                            }
                            if (!row.IsVariableUnitsAbbreviationNull())
                            {
                                unit.unitAbbreviation = row.VariableUnitsAbbreviation;
                            }
                            if (!row.IsVariableUnitsIDNull())
                            {
                                unit.unitCode = row.VariableUnitsID.ToString();
                            }
                            vit.unit = unit;
                        }
                    }

                    // add time support
                    if (!row.IsIsRegularNull() && row.IsRegular)
                    {
                        vit.timeScale           = new VariableInfoTypeTimeScale();
                        vit.timeScale.isRegular = row.IsRegular;
                        //vit.timeScale.isRegularSpecified = true;

                        // add time support

                        // check to be sure we've got some vaild stuff
                        if (!row.IsTimeSupportNull())
                        {
                            vit.timeScale.timeSupport = row.TimeSupport;
                        }

                        if (!row.IsTimeUnitsNameNull() ||
                            !row.IsTimeUnitsAbbreviationNull()
                            )
                        {
                            vit.timeScale.unit = new UnitsType();
                            if (!row.IsTimeUnitsNameNull())
                            {
                                vit.timeScale.unit.unitName = row.TimeUnitsName;
                            }
                            if (!row.IsTimeUnitsAbbreviationNull())
                            {
                                vit.timeScale.unit.unitAbbreviation = row.TimeUnitsAbbreviation;
                            }

                            // vit.timeSupport.unit.UnitType = (UnitsTypeEnum)CoreBuilder.GetTextAsEnum("Time", typeof(UnitsTypeEnum));
                            vit.timeScale.unit.unitType = "Time";
                        }
                        else
                        {
                            // try to get info from time unitsID
                            ///@TODO fix this
                            //if (!row.IsTimeUnitsIDNull())
                            //{

                            //    vit.timeSupport.unit = new UnitsType();
                            //    vit.timeSupport.unit.UnitID = 104;
                            //    vit.timeSupport.unit.UnitIDSpecified = true;
                            //    vit.timeSupport.unit.UnitDescription = "day";
                            //    vit.timeSupport.unit.UnitAbbreviation = "d";
                            //    vit.timeSupport.unit.UnitType = (UnitsTypeEnum)CoreBuilder.GetTextAsEnum("Time", typeof(UnitsTypeEnum)); ;

                            //}
                        }
                    }
                }

                return(vit);
            }