/// <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); }
/// <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); }