コード例 #1
0
            /// <summary>
            /// Builds a VariableInfoType from a dataset row
            /// the dataSet is stored in the NWISService variableDataSet.
            /// Find the rwo you want with the command:
            ///
            /// and convert.
            /// </summary>
            /// <param name="row"></param>
            /// <returns></returns>
            public static VariableInfoType rowToVariableInfoType(VariablesDataset.VariablesRow row, VariablesDataset ds)
            {
                UnitsType aUnit = null;


                aUnit = getUnitsElement(row.VariableUnitsID, ds);


                String vCode = row.VariableCode;

                int vid = row.VariableID;

                String vocab   = System.Configuration.ConfigurationManager.AppSettings["vocabulary"];
                String varName = row.VariableName;

                VariableInfoType vt = CuahsiBuilder.CreateVariableInfoType(
                    vid,
                    vocab,
                    vCode,
                    varName,
                    null, //variable description
                    aUnit
                    );

                // add time support
                vt.timeScale = new VariableInfoTypeTimeScale();


                vt.timeScale.isRegular = row.IsRegular;

                vt.timeScale.timeSupport          = Convert.ToInt32(row.TimeSupport);
                vt.timeScale.timeSupportSpecified = true;

                // future, when ODM reports spacing
                //if (row.["timeSpacing"] != null)
                //{
                //    vt.timeScale.timeSpacing = Convert.ToInt32(row["timeSpacing"]);
                //    vt.timeScale.timeSpacingSpecified = true;
                //}


                UnitsType tUnit = getUnitsElement(row.TimeUnitsID, ds);

                if (tUnit != null)
                {
                    vt.timeScale.unit = tUnit;
                }

                vt.valueType    = String.IsNullOrEmpty(row.ValueType) ? null : row.ValueType;
                vt.sampleMedium = String.IsNullOrEmpty(row.SampleMedium) ? null : row.SampleMedium;
                vt.dataType     = String.IsNullOrEmpty(row.DataType) ? null : row.DataType;
                if (vt.dataType.Equals("Categorical", StringComparison.InvariantCultureIgnoreCase))
                {
                    IEnumerable <VariableInfoTypeCategory> categories = getCategoryElement(vid, ds);
                    vt.categories = new List <VariableInfoTypeCategory>(categories).ToArray();
                }
                vt.generalCategory = String.IsNullOrEmpty(row.GeneralCategory) ? null : row.GeneralCategory;

                // zero is default value for datatype... so don't add it if it is the default value
                if (!row.NoDataValue.Equals(0))
                {
                    vt.noDataValue          = row.NoDataValue;
                    vt.noDataValueSpecified = true;
                }

                vt.speciation = String.IsNullOrEmpty(row.Speciation) ? null : row.Speciation;


                return(vt);
            }
コード例 #2
0
        private VariableInfoType RowToVariable(UsgsDbDailyValues.VariablesRow vRow)
        {
            VariableInfoType vit;
            String           vCode = vRow.IsVariableCodeNull() ? null : vRow.VariableCode;
            String           vName = vRow.IsVariableNameNull() ? null : vRow.VariableName;
            //String vDescr =
            String uName   = vRow.IsUnitsNull() ? null : vRow.Units;
            String uAbbrev = vRow.IsUnitAbbreviationNull() ? null : vRow.UnitAbbreviation;
            String uType   = vRow.IsUnitTypeNull() ? null : vRow.UnitType;
            String uCode   = null; // ID is code

            if (!vRow.IsVariableUnitsIDNull())
            {
                uCode = vRow.VariableUnitsID.ToString();
            }

            UnitsTypeEnum uTypeEnum = (UnitsTypeEnum)CoreBuilder.GetTextAsEnum(uType, typeof(UnitsTypeEnum));

            units vUnit = CuahsiBuilder.CreateUnitsElement(
                uTypeEnum,
                uCode, uAbbrev, uName);

            /* this needs to be fixed to accept value type and data type
             *  and time options
             */
            vit = CuahsiBuilder.CreateVariableInfoType(
                null,   // don't want variable ID exposed in the NWIS service
                "NWIS",
                vRow.VariableCode,
                vRow.VariableName,
                null,
                vUnit // units
                );

            CoreBuilder.SetEnumFromText(vit, vRow, "valueType", typeof(valueTypeEnum));
            CoreBuilder.SetEnumFromText(vit, vRow, "dataType", typeof(dataTypeEnum));

            // add usgs statistic code options
            if (!vRow.Isstat_cdNull())
            {
                List <option> opts = new List <option>(1);
                option        opt  = new option();
                opt.name       = "statistic";
                opt.optionCode = vRow.stat_cd;
                opts.Add(opt);
                vit.options = opts.ToArray();
            }

            if (!vRow.IsisRegularNull() && vRow.isRegular)
            {
                vit.timeSupport                    = new VariableInfoTypeTimeSupport();
                vit.timeSupport.isRegular          = vRow.isRegular;
                vit.timeSupport.isRegularSpecified = true;

                // add time support

                // check to be sure we've got some vaild stuff
                if (!vRow.IsTimeSupportNull())
                {
                    int timeInterval;
                    if (Int32.TryParse(vRow.TimeSupport, out timeInterval))
                    {
                        vit.timeSupport.timeInterval          = timeInterval;
                        vit.timeSupport.timeIntervalSpecified = true;
                    }
                }
                if (!vRow.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);
        }
コード例 #3
0
        /// <summary>
        /// Builds a VariableInfoType from a dataset row
        /// the dataSet is stored in the NWISService variableDataSet.
        /// Find the rwo you want with the command:
        ///
        /// and convert.
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static VariableInfoType rowToVariableInfoType(VariablesDataset.VariablesRow row, VariablesDataset ds)
        {
            units aUnit = null;

            aUnit = getUnitsElement(row.VariableUnitsID, ds);


            String vCode = !String.IsNullOrEmpty(row.VariableCode) ? row.VariableCode : null;

            int vid = row.VariableID;
            // appSetting['vocabulary']

            String vocab   = System.Configuration.ConfigurationManager.AppSettings["vocabulary"];
            String varName = !String.IsNullOrEmpty(row.VariableName) ? row.VariableName : null;

            VariableInfoType vt = CuahsiBuilder.CreateVariableInfoType(
                vid.ToString(),
                vocab,
                vCode,
                varName,
                null, //variable description
                aUnit
                );

            // add time support
            vt.timeSupport = new VariableInfoTypeTimeSupport();
            if (row.IsRegular)
            {
                vt.timeSupport.isRegular             = true;
                vt.timeSupport.isRegularSpecified    = true;
                vt.timeSupport.timeInterval          = Convert.ToInt32(row.TimeSupport);
                vt.timeSupport.timeIntervalSpecified = true;
                // this is different that the other "units", so populate by code
                units tUnit = getUnitsElement(row.TimeUnitsID, ds);
                if (tUnit != null)
                {
                    vt.timeSupport.unit                  = new UnitsType();
                    vt.timeSupport.unit.UnitID           = int.Parse(tUnit.unitsCode);
                    vt.timeSupport.unit.UnitIDSpecified  = true;
                    vt.timeSupport.unit.UnitDescription  = tUnit.Value;
                    vt.timeSupport.unit.UnitAbbreviation = tUnit.unitsAbbreviation;
                    if (tUnit.unitsTypeSpecified)
                    {
                        // if it's specified in the units, then it's a valid enum
                        vt.timeSupport.unit.UnitType          = tUnit.unitsType;
                        vt.timeSupport.unit.UnitTypeSpecified = true;
                    }
                }
            }
            else
            {
                vt.timeSupport.isRegular          = false;
                vt.timeSupport.isRegularSpecified = true;
            }
            CuahsiBuilder.SetEnumFromText(vt, row, "valueType", typeof(valueTypeEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "sampleMedium", typeof(SampleMediumEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "dataType", typeof(dataTypeEnum));
            CuahsiBuilder.SetEnumFromText(vt, row, "generalCategory", typeof(generalCategoryEnum));
            // if (!String.IsNullOrEmpty(row.NoDataValue)) {
            vt.NoDataValue = row.NoDataValue.ToString();
            // }
            return(vt);
        }