Пример #1
0
            public static List <QualityControlLevelType> DatasetQCLevels(ValuesDataSet ds, string valuesWhereClause)
            {
                /* generate a list
                 * create a distinct DataSet
                 * - new data view
                 * - set filter (no nulls)
                 * - use toTable with unique to get unique list
                 * foreach to generate qualifiers
                 * */
                string COLUMN    = "QualityControlLevelID";
                string TABLENAME = "QualityControlLevels";
                List <QualityControlLevelType> list = new List <QualityControlLevelType>();

                try
                {
                    DataView view = new DataView(ds.DataValues);
                    view.RowFilter = valuesWhereClause;

                    DataTable ids = view.ToTable(TABLENAME, true, new string[] { COLUMN });

                    foreach (DataRow r in ids.Rows)
                    {
                        try
                        {
                            // Object aId = r[COLUMN];

                            if (r[COLUMN] == DBNull.Value)
                            {
                                continue;
                            }
                            int?aId = Convert.ToInt32(r[COLUMN]);
                            // edit here
                            ValuesDataSet.QualityControlLevelsRow qcLevels =
                                ds.QualityControlLevels.FindByQualityControlLevelID((int)aId.Value);
                            if (qcLevels != null)
                            {
                                QualityControlLevelType t = new QualityControlLevelType();
                                t.qualityControlLevelID          = qcLevels.QualityControlLevelID;
                                t.qualityControlLevelIDSpecified = true;
                                t.qualityControlLevelCode        = qcLevels.QualityControlLevelCode;
                                t.definition  = qcLevels.Definition;
                                t.explanation = qcLevels.Explanation;


                                list.Add(t);
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error generating a QualityControlLevels " + r.ToString() + e.Message);
                        }
                    }
                    return(list);
                }

                catch (Exception e)
                {
                    log.Error("Error generating a QualityControlLevels " + e.Message);
                    // non fatal exceptions
                    return(null);
                }
            }
Пример #2
0
        /// <summary>
        /// DataValue creation. Converts a ValuesDataSet to the XML schema ValueSingleVariable
        /// If variable is null, it will return all
        /// If variable has extra options (variable:code/Value=Key/Value=Key)
        ///
        /// </summary>
        /// <param name="ds">Dataset that you want converted</param>
        /// <param name="variable">Variable that you want to use to place limits on the returned data</param>
        /// <returns></returns>
        public static List <ValueSingleVariable> dataset2ValuesList(ValuesDataSet ds, VariableParam variable)
        {
            List <ValueSingleVariable> tsTypeList = new List <ValueSingleVariable>();


            /* logic
             * if there is a variable that has options, then get a set of datarows
             * using a select clause
             * use an enumerator, since it is generic
             * */
            IEnumerator dataValuesEnumerator;

            ValuesDataSet.DataValuesRow[] dvRows; // if we find options, we need to use this.

            String select = OdValuesCommon.CreateValuesWhereClause(variable, null);

            if (select.Length > 0)
            {
                dvRows = (ValuesDataSet.DataValuesRow[])ds.DataValues.Select(select.ToString());

                dataValuesEnumerator = dvRows.GetEnumerator();
            }
            else
            {
                dataValuesEnumerator = ds.DataValues.GetEnumerator();
            }

            //  foreach (ValuesDataSet.DataValuesRow aRow in ds.DataValues){
            while (dataValuesEnumerator.MoveNext())
            {
                ValuesDataSet.DataValuesRow aRow = (ValuesDataSet.DataValuesRow)dataValuesEnumerator.Current;
                try
                {
                    ValueSingleVariable tsTypeValue = new ValueSingleVariable();

                    #region DateTime Standard
                    tsTypeValue.dateTime = Convert.ToDateTime(aRow.DateTime);
                    //tsTypeValue.dateTimeSpecified = true;
                    DateTime temprealdate;



                    //<add key="returnUndefinedUTCorLocal" value="Undefined"/>
                    if (ConfigurationManager.AppSettings["returnUndefinedUTCorLocal"].Equals("Undefined"))
                    {
                        temprealdate = Convert.ToDateTime(aRow.DateTime); // not time zone shift
                    }
                    else if (ConfigurationManager.AppSettings["returnUndefinedUTCorLocal"].Equals("Local"))
                    {
                        TimeSpan zone   = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
                        Double   offset = Convert.ToDouble(aRow.UTCOffset);

                        if (zone.TotalHours.Equals(offset))
                        {
                            // zone is the same as server. Shift
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime), DateTimeKind.Local);
                        }
                        else
                        {
                            //// zone is not the same. Output in UTC.
                            //temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime), DateTimeKind.Utc);
                            //// correct time with shift.
                            //temprealdate = temprealdate.AddHours(offset);

                            // just use the DateTime UTC
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTimeUTC), DateTimeKind.Utc);
                        }
                    }
                    else if (ConfigurationManager.AppSettings["returnUndefinedUTCorLocal"].Equals("UTC"))
                    {
                        temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTimeUTC), DateTimeKind.Utc);
                    }
                    else
                    {
                        temprealdate = Convert.ToDateTime(aRow.DateTime); // not time zone shift
                    }

                    temprealdate = Convert.ToDateTime(aRow.DateTime); // not time zone shift
                    #endregion
                    #region DateTimeOffset Failed
                    /// using XML overrides
                    // Attemp to use DateTimeOffset in xml Schema
                    //TimeSpan zone = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
                    //Double offset = Convert.ToDouble(aRow.UTCOffset);

                    //DateTimeOffset temprealdate;
                    //temprealdate = new DateTimeOffset(Convert.ToDateTime(aRow.DateTime),
                    //    new TimeSpan(Convert.ToInt32(offset),0,0));
                    //DateTimeOffset temprealdate;
                    //temprealdate = new DateTimeOffset(Convert.ToDateTime(aRow.DateTime),
                    //    new TimeSpan(Convert.ToInt32(offset), 0, 0));

                    //tsTypeValue.dateTime = temprealdate;
                    //tsTypeValue.dateTimeSpecified = true;
                    #endregion

                    //tsTypeValue.censored = string.Empty;
                    if (string.IsNullOrEmpty(aRow.Value.ToString()))
                    {
                        continue;
                    }
                    else
                    {
                        tsTypeValue.Value = Convert.ToDecimal(aRow.Value);
                    }

                    try
                    {
                        tsTypeValue.censorCode          = (CensorCodeEnum)Enum.Parse(typeof(CensorCodeEnum), aRow.CensorCode, true);
                        tsTypeValue.censorCodeSpecified = true;

                        if (!aRow.IsOffsetTypeIDNull())
                        {
                            tsTypeValue.offsetTypeID          = aRow.OffsetTypeID;
                            tsTypeValue.offsetTypeIDSpecified = true;

                            // enabled to fix issue with hydroobjects
                            ValuesDataSet.OffsetTypesRow off = ds.OffsetTypes.FindByOffsetTypeID(aRow.OffsetTypeID);


                            ValuesDataSet.UnitsRow offUnit = ds.Units.FindByUnitsID(off.OffsetUnitsID);
                            tsTypeValue.offsetUnitsCode         = offUnit.UnitsID.ToString();
                            tsTypeValue.offsetUnitsAbbreviation = offUnit.UnitsAbbreviation;
                        }

                        // offset value may be separate from the units... anticpating changes for USGS
                        if (!aRow.IsOffsetValueNull())
                        {
                            tsTypeValue.offsetValue          = aRow.OffsetValue;
                            tsTypeValue.offsetValueSpecified = true;
                        }


                        ValuesDataSet.MethodsRow meth = ds.Methods.FindByMethodID(aRow.MethodID);
                        tsTypeValue.methodID          = aRow.MethodID;
                        tsTypeValue.methodIDSpecified = true;


                        if (!aRow.IsQualifierIDNull())
                        {
                            ValuesDataSet.QualifiersRow qual = ds.Qualifiers.FindByQualifierID(aRow.QualifierID);
                            if (qual != null)
                            {
                                tsTypeValue.qualifiers = qual.QualifierCode;
                            }
                        }


                        ValuesDataSet.QualityControlLevelsRow qcl =
                            ds.QualityControlLevels.FindByQualityControlLevelID(aRow.QualityControlLevelID);
                        string qlName = qcl.Definition.Replace(" ", "");

                        if (Enum.IsDefined(typeof(QualityControlLevelEnum), qlName))
                        {
                            tsTypeValue.qualityControlLevel = (QualityControlLevelEnum)
                                                              Enum.Parse(
                                typeof(QualityControlLevelEnum), qlName, true);
                            if (tsTypeValue.qualityControlLevel != QualityControlLevelEnum.Unknown)
                            {
                                tsTypeValue.qualityControlLevelSpecified = true;
                            }
                        }
                        //}
                        tsTypeValue.sourceID          = aRow.SourceID;
                        tsTypeValue.sourceIDSpecified = true;

                        if (!aRow.IsSampleIDNull())
                        {
                            tsTypeValue.sampleID          = aRow.SampleID;
                            tsTypeValue.sampleIDSpecified = true;
                        }
                    }
                    catch (Exception e)
                    {
                        log.Debug("Error generating a value " + e.Message);
                        // non fatal exceptions
                    }

                    tsTypeList.Add(tsTypeValue);
                }
                catch (Exception e)
                {
                    //  ignore any value errors
                }
            }
            return(tsTypeList);
        }
Пример #3
0
            public static IEnumerable <ValueSingleVariable> dataset2ValuesList(ValuesDataSet ds, VariableParam variable, int?VariableId, VariablesDataset variablesDs)
            {
                Boolean          variableIsCategorical = false;
                VariableInfoType variableInfoType      = ODvariables.GetVariableByID(VariableId, variablesDs);

                if (variableInfoType != null && variableInfoType.dataType.Equals("Categorical"))
                {
                    variableIsCategorical = true;
                }

                /* logic
                 * if there is a variable that has options, then get a set of datarows
                 * using a select clause
                 * use an enumerator, since it is generic
                 * */

                IEnumerator dataValuesEnumerator;     // = ds.DataValues.GetEnumerator();

                ValuesDataSet.DataValuesRow[] dvRows; // if we find options, we need to use this.

                String select = OdValuesCommon.CreateValuesWhereClause(variable, VariableId);

                if (select.Length > 0)
                {
                    dvRows = (ValuesDataSet.DataValuesRow[])ds.DataValues.Select(select.ToString());

                    dataValuesEnumerator = dvRows.GetEnumerator();
                }
                else
                {
                    dataValuesEnumerator = ds.DataValues.GetEnumerator();
                }

                while (dataValuesEnumerator.MoveNext())
                {
                    ValuesDataSet.DataValuesRow aRow        = (ValuesDataSet.DataValuesRow)dataValuesEnumerator.Current;
                    ValueSingleVariable         tsTypeValue = new ValueSingleVariable();
                    Boolean goodValue = false;
                    try
                    {
                        tsTypeValue.dateTime = Convert.ToDateTime(aRow.DateTime);

                        DateTime temprealdate;

                        TimeSpan zone   = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
                        Double   offset = Convert.ToDouble(aRow.UTCOffset);
                        if (zone.TotalHours.Equals(offset))
                        {
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime),
                                                                DateTimeKind.Local);
                        }
                        else
                        {
                            temprealdate = DateTime.SpecifyKind(Convert.ToDateTime(aRow.DateTime), DateTimeKind.Utc);

                            temprealdate = temprealdate.AddHours(offset);
                        }
                        temprealdate         = Convert.ToDateTime(aRow.DateTime);
                        tsTypeValue.dateTime = temprealdate;


                        tsTypeValue.dateTimeUTC          = aRow.DateTimeUTC;
                        tsTypeValue.dateTimeUTCSpecified = true;
                        tsTypeValue.timeOffset           = OffsetDoubleToHoursMinutesString(aRow.UTCOffset);

                        //tsTypeValue.dateTime = new DateTimeOffset(temprealdate);
                        //tsTypeValue.dateTimeSpecified = true;


                        if (string.IsNullOrEmpty(aRow.Value.ToString()))
                        {
                            continue;
                        }
                        else
                        {
                            tsTypeValue.Value = Convert.ToDecimal(aRow.Value);
                        }

                        try
                        {
                            tsTypeValue.censorCode =
                                aRow.CensorCode;
                            if (!aRow.IsOffsetTypeIDNull())
                            {
                                //tsTypeValue.offsetTypeID = aRow.OffsetTypeID.ToString();
                                tsTypeValue.offsetTypeCode = aRow.OffsetTypeID.ToString();

                                // HIS-97 moved to OffsetUnitsType
                                //      ValuesDataSet.OffsetTypesRow off =
                                //        ds.OffsetTypes.FindByOffsetTypeID(aRow.OffsetTypeID);
                                //    ValuesDataSet.UnitsRow offUnit = ds.Units.FindByUnitsID(off.OffsetUnitsID);
                                //    tsTypeValue.offsetUnitsCode = offUnit.UnitsID.ToString();
                                //    tsTypeValue.offsetUnitsAbbreviation = offUnit.UnitsAbbreviation;
                            }

                            // offset value may be separate from the units... anticpating changes for USGS
                            if (!aRow.IsOffsetValueNull())
                            {
                                tsTypeValue.offsetValue          = aRow.OffsetValue;
                                tsTypeValue.offsetValueSpecified = true;
                            }

                            ValuesDataSet.MethodsRow meth = ds.Methods.FindByMethodID(aRow.MethodID);
                            // tsTypeValue.methodID = aRow.MethodID.ToString();
                            tsTypeValue.methodCode = aRow.MethodID.ToString();

                            // qualifiers
                            if (!aRow.IsQualifierIDNull())
                            {
                                ValuesDataSet.QualifiersRow qual = ds.Qualifiers.FindByQualifierID(aRow.QualifierID);
                                if (qual != null)
                                {
                                    tsTypeValue.qualifiers = qual.QualifierCode;
                                }
                            }

                            //  quality control level

                            ValuesDataSet.QualityControlLevelsRow qcl =
                                ds.QualityControlLevels.FindByQualityControlLevelID(aRow.QualityControlLevelID);
                            string qlName = qcl.Definition.Replace(" ", "");
                            tsTypeValue.qualityControlLevelCode = qcl.QualityControlLevelCode;
                            //if (!String.IsNullOrEmpty(qlName))
                            //{
                            //    tsTypeValue.qualityControlLevel = qlName;
                            //}


                            // tsTypeValue.sourceID = aRow.SourceID.ToString();
                            tsTypeValue.sourceCode = aRow.SourceID.ToString();

                            if (!aRow.IsSampleIDNull())
                            {
                                //tsTypeValue.sampleID = aRow.SampleID.ToString();
                                ValuesDataSet.SamplesRow lsc = ds.Samples.FindBySampleID(aRow.SampleID);
                                tsTypeValue.labSampleCode = lsc.LabSampleCode;
                            }

                            // categorical
                            if (variableIsCategorical && VariableId.HasValue)
                            {
                                tsTypeValue.codedVocabularyTerm = ODvariables.GetCategoryTerm(VariableId.Value, tsTypeValue.Value, variablesDs);
                                if (!String.IsNullOrEmpty(tsTypeValue.codedVocabularyTerm))
                                {
                                    tsTypeValue.codedVocabulary = true;
                                }
                                tsTypeValue.codedVocabularySpecified = true;
                            }
                        }
                        catch (Exception e)
                        {
                            log.Debug("Error generating a value " + e.Message);
                            // non fatal exceptions
                        }
                        goodValue = true;
                    }
                    catch (Exception e)
                    {
                        goodValue = false;
                        // If there is an error, we do not add it.
                    }

                    if (goodValue)
                    {
                        yield return(tsTypeValue);
                    }
                }
            }