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); }
/// <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 variableCode[1]; variableCode vCode = new variableCode(); 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)); } //add DataType if (!row.IsDataTypeNull()) { SetEnumFromText(vit, row, "dataType", typeof(dataTypeEnum)); } //add General Categoy // if (!row.IsGeneralCategoryNull()) { SetEnumFromText(vit, row, "generalCategory", typeof(generalCategoryEnum)); } if (!row.IsSampleMediumNull()) { SetEnumFromText(vit, row, "sampleMedium", typeof(SampleMediumEnum)); } // Units // if just the ID exists... then it's not useful if (!row.IsVariableUnitsNameNull() || !row.IsVariableUnitsAbbreviationNull()) { units unit = new units(); if (!row.IsVariableUnitsNameNull()) { unit.Value = row.VariableUnitsName; } if (!row.IsVariableUnitsAbbreviationNull()) { unit.unitsAbbreviation = row.VariableUnitsAbbreviation; } if (!row.IsVariableUnitsIDNull()) { unit.unitsCode = row.VariableUnitsID.ToString(); } vit.units = unit; } } // add time support if (!row.IsIsRegularNull() && row.IsRegular) { vit.timeSupport = new VariableInfoTypeTimeSupport(); vit.timeSupport.isRegular = row.IsRegular; vit.timeSupport.isRegularSpecified = true; // add time support // check to be sure we've got some vaild stuff if (!row.IsTimeSupportNull()) { vit.timeSupport.timeInterval = row.TimeSupport; vit.timeSupport.timeIntervalSpecified = true; } if (!row.IsTimeUnitsNameNull() || !row.IsTimeUnitsAbbreviationNull() ) { vit.timeSupport.unit = new UnitsType(); if (!row.IsTimeUnitsNameNull()) { vit.timeSupport.unit.UnitName = row.TimeUnitsName; } if (!row.IsTimeUnitsAbbreviationNull()) { vit.timeSupport.unit.UnitAbbreviation = row.TimeUnitsAbbreviation; } if (!row.IsTimeUnitsIDNull()) { vit.timeSupport.unit.UnitID = row.TimeUnitsID; vit.timeSupport.unit.UnitIDSpecified = true; } vit.timeSupport.unit.UnitType = (UnitsTypeEnum)CoreBuilder.GetTextAsEnum("Time", typeof(UnitsTypeEnum)); } 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); }