Пример #1
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);
        }