Example #1
0
        public static TimeSeriesResponseType getValues(ValuesDataSet ValuesDs, VariableParam variable)
        {
            TimeSeriesResponseType response = CuahsiBuilder.CreateTimeSeriesObjectSingleValue();

            // get siteInfo

            // get variable Info

            // get Values
            // reformats values dataset into a TimeSeriesResponseType
            List <ValueSingleVariable> valueList = ODValues.dataset2ValuesList(ValuesDs, variable);

            response.timeSeries.values.value = valueList.ToArray();
            response.timeSeries.values.count = valueList.Count.ToString();

            // add qualifiers
            List <qualifier> qualifers = ODValues.datasetQualifiers(ValuesDs);

            if (qualifers != null && qualifers.Count > 0)
            {
                response.timeSeries.values.qualifier = qualifers.ToArray();
            }
            // add methods
            List <MethodType> methods = ODValues.datasetMethods(ValuesDs);

            if (methods != null && methods.Count > 0)
            {
                response.timeSeries.values.method = methods.ToArray();
            }
            List <SourceType> sources = ODValues.datasetSources(ValuesDs);

            if (sources != null && sources.Count > 0)
            {
                response.timeSeries.values.source = sources.ToArray();
            }
            List <OffsetType> offsets = ODValues.datasetOffsetTypes(ValuesDs);

            if (offsets != null && offsets.Count > 0)
            {
                response.timeSeries.values.offset = offsets.ToArray();
            }
            return(response);
        }
Example #2
0
            public static ValuesDataSet GetValuesDataSet(int?siteID, int?VariableID, W3CDateTime BeginDateTime,
                                                         W3CDateTime EndDateTime)
            {
                ValuesDataSet         ds          = basicValuesDataSet();
                SitesTableAdapter     siteAdapter = new SitesTableAdapter();
                VariablesTableAdapter vAdapter    = new VariablesTableAdapter();

                siteAdapter.Connection.ConnectionString = odws.Config.ODDB();
                vAdapter.Connection.ConnectionString    = odws.Config.ODDB();
                //if (!siteID.HasValue || !VariableID.HasValue) return ds;
                //DataValuesTableAdapter valuesTableAdapter = new DataValuesTableAdapter();
                //valuesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();
                //valuesTableAdapter.FillBySiteIdVariableIDBetweenDates(ds.DataValues, siteID.Value, VariableID.Value, BeginDateTime.DateTime, EndDateTime.DateTime);
                //return ds;

                siteAdapter.FillBySiteID(ds.Sites, siteID.Value);
                vAdapter.FillByVariableID(ds.Variables, VariableID.Value);
                return(getDataValues(ds, BeginDateTime.DateTime, EndDateTime.DateTime));
            }
Example #3
0
            /* private static ValuesDataSet getDataValues(ValuesDataSet ds, DateTime startDate, DateTime endDate)
             * {
             *   SeriesCatalogTableAdapter scAdapater = new SeriesCatalogTableAdapter();
             *   scAdapater.Connection.ConnectionString = odws.Config.ODDB();
             *   seriesCatalogDataSet sc = new seriesCatalogDataSet();
             *   scAdapater.FillBySiteVariable(sc.SeriesCatalog, ds.Sites[0].SiteID, ds.Variables[0].VariableID);
             *
             *   string requestData = "";
             *   try
             *   {
             *       Thread thread = new Thread (delegate(){
             *       requestData = generateURL(URLSiteName(ds.Sites), URLVariableCode(ds.Variables, ds.Sites), selectStartDate(startDate, sc.SeriesCatalog[0].SeriesID), selectEndDate(endDate, sc.SeriesCatalog[0].SeriesID));
             *       });
             *       thread.Start();
             *       while (thread.IsAlive )
             *       {
             *           Thread.Sleep(150);
             *       }
             *       return newTable(ds.Variables[0].VariableID.ToString(), sc.SeriesCatalog[0].SeriesID, requestData);
             *   }
             *   catch (Exception ex)
             *   {
             *       return new ValuesDataSet();
             *   }
             * }*/


            /* newTable
             * creates the Data Table required by rest of program to create the XML form
             * use this if no variable or datetime information is provided
             */
            //private static ValuesDataSet newTable(int siteID)
            //{
            //    ValuesDataSet ds = basicValuesDataSet();
            //    DataTable variableTable = ds.Tables[0];
            //    int ValueID = 0;
            //    DataRow[] rows = oDS.Tables[0].Select();

            //    foreach (DataRow row in rows)
            //    {
            //        for (int i = 1; i < oDS.Tables["Variables"].Columns.Count; i++)//(string column in oDS.Tables["Variables"].Columns)
            //        {
            //            //SqlCommand cmd = new SqlCommand("SELECT MethodID, SourceID, QualityControllevelID, TimeZone, VariableID FROM dbo.SeriesCatalog INNER JOIN dbo.Sites ON dbo.SeriesCatalog.SiteID=dbo.Sites.SiteID WHERE dbo.SeriesCatalog.SiteID = '" + siteID + "' AND dbo.SeriesCatalog.VariableCode= '" + oDS.Tables["Variables"].Columns[i].ColumnName + "'", SnotelConnection);
            //            //SqlDataReader objReader = cmd.ExecuteReader();

            //            object[] Values = new object[5];
            //           // objReader.Read();
            //            //objReader.GetValues(Values);
            //            //variableTable.Rows.Add(ValueID, siteID, Values[4], "nc", 0, Values[0], Values[1], 0, 0, Values[2], row[0] == "" ? -9999 : row[Convert.ToInt32(Values[4])], 0, convertDate(row[0].ToString(), 0), convertDate(row[0].ToString(), Convert.ToInt32(Values[3])), Convert.ToInt32(Values[3]));
            //            ValueID++;

            //        }
            //    }


            //    return ds;
            //}


            #region odm 1 series based

            public static ValuesDataSet GetValueDataSet(int?siteID, int?VariableID, int?MethodID, int?SourceID,
                                                        int?QualityControlLevelID, W3CDateTime BeginDateTime,
                                                        W3CDateTime EndDateTime)
            {
                ValuesDataSet ds = basicValuesDataSet();

                if (!siteID.HasValue || !VariableID.HasValue)
                {
                    return(ds);
                }
                DataValuesTableAdapter valuesTableAdapter = new DataValuesTableAdapter();

                valuesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                valuesTableAdapter.FillBySiteIdVariableIDBetweenDates(ds.DataValues, siteID.Value, VariableID.Value,
                                                                      BeginDateTime.DateTime, EndDateTime.DateTime);

                return(ds);
            }
Example #4
0
            public static ValuesDataSet GetValuesDataSet(int?siteID, int?VariableID)
            {
                ValuesDataSet         ds          = basicValuesDataSet();
                SitesTableAdapter     siteAdapter = new SitesTableAdapter();
                VariablesTableAdapter vAdapter    = new VariablesTableAdapter();

                siteAdapter.Connection.ConnectionString = odws.Config.ODDB();
                vAdapter.Connection.ConnectionString    = odws.Config.ODDB();
                //if (!siteID.HasValue || !VariableID.HasValue) return ds;
                //DataValuesTableAdapter valuesTableAdapter = new DataValuesTableAdapter();
                //valuesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();
                //valuesTableAdapter.FillBySiteIDVariableID(ds.DataValues, siteID.Value, VariableID.Value);
                //return ds;

                siteAdapter.FillBySiteID(ds.Sites, siteID.Value);
                vAdapter.FillBySiteID(ds.Variables, VariableID.Value);

                return(getDataValues(ds, new DateTime(1900, 01, 01), DateTime.Now));
            }
Example #5
0
        public ValuesDataSet getDataValues(ValuesDataSet ds, DateTime startDate, DateTime endDate)
        {
            SeriesCatalogTableAdapter scAdapater = new SeriesCatalogTableAdapter();

            scAdapater.Connection.ConnectionString = odws.Config.ODDB();
            seriesCatalogDataSet sc = new seriesCatalogDataSet();

            scAdapater.FillBySiteVariable(sc.SeriesCatalog, ds.Sites[0].SiteID, ds.Variables[0].VariableID);

            string requestData = "";

            try
            {
                requestData = generateURL(URLSiteName(ds.Sites), URLVariableCode(ds.Variables, ds.Sites), selectStartDate(startDate, sc.SeriesCatalog[0].SeriesID), selectEndDate(endDate, sc.SeriesCatalog[0].SeriesID));
                return(newTable(ds.Variables[0].VariableID.ToString(), sc.SeriesCatalog[0].SeriesID, requestData));
            }
            catch (Exception ex)
            {
                return(new ValuesDataSet());
            }
        }
Example #6
0
        public static ValuesDataSet GetValuesDataSet(int?siteID, int?VariableID, W3CDateTime BeginDateTime, W3CDateTime EndDateTime)
        {
            ValuesDataSet ds = basicValuesDataSet();

            //if (!siteID.HasValue || !VariableID.HasValue) return ds;
            //ValuesDataSetTableAdapters.DataValuesTableAdapter valuesTableAdapter = new DataValuesTableAdapter();
            //valuesTableAdapter.Connection.ConnectionString = Config.ODDB();

            //valuesTableAdapter.FillBySiteIdVariableIDBetweenDates(ds.DataValues, siteID.Value, VariableID.Value, BeginDateTime.DateTime, EndDateTime.DateTime);

            //return ds;


            //style 2
            // return getDataValues(db.getSiteCode(siteID.Value), db.getVariableCode(VariableID.Value), BeginDateTime.DateTime, EndDateTime.DateTime);


            siteAdapter.FillBySiteID(ds.Sites, siteID.Value);
            vAdapter.FillBySiteID(ds.Variables, ds.Sites[0].SiteID);
            return(getDataValues(ds, new DateTime(1900, 01, 01), DateTime.Now));
        }
            public static ValuesDataSet GetValuesDataSet(int siteID)
            {
                ValuesDataSet ds = basicValuesDataSet();

                DataValuesTableAdapter valuesTableAdapter = new DataValuesTableAdapter();

                valuesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                try
                {
                    valuesTableAdapter.FillBySiteID(ds.DataValues, siteID);
                }
                catch (Exception e)
                {
                    log.Fatal("Cannot retrieve information from database: " + e.Message);
                    //+ valuesTableAdapter.Connection.DataSource
                }


                return(ds);
            }
Example #8
0
        /*
         * newTable
         * creates the Data Table required by rest of program to create the XML form
         */
        private ValuesDataSet newTable(seriesCatalogDataSet.SeriesCatalogDataTable series, ref DataSet oDS)
        {
            ValuesDataSet     ds            = basicValuesDataSet();
            DataTable         variableTable = ds.DataValues;
            SitesTableAdapter sitesAdapter  = new SitesTableAdapter();
            siteInfoDataSet   sites         = new siteInfoDataSet();

            sitesAdapter.Connection.ConnectionString = odws.Config.ODDB();
            sitesAdapter.FillBySiteID(sites.sites, series[0].SiteID);
            int ValueID = 0;

            DataRow[] rows = oDS.Tables["Variables"].Select();
            //DataRow siteTable = sites.sites[0];
            foreach (DataRow row in rows)
            {
                ValueID++;
                int timezone = sites.sites[0].TimeZone;
                variableTable.Rows.Add(ValueID, series[0].SiteID, series[0].VariableID, DBNull.Value, DBNull.Value, "nc", 0, series[0].MethodID, series[0].SourceID, 0, 0, series[0].QualityControlLevelID, (row[0] == "") ? (-9999) : row[series[0].VariableCode.ToLower()], 0, convertDate(row[0].ToString(), 0), convertDate(row[0].ToString(), timezone), timezone);
                //"ValueID","SiteID","VariableID",""OffsetValue", "OffsetTypeID","CensorCode","QualifierID","MethodID","SourceID","SampleID","DerivedFromID","QualityControlLevelID", "Value",                                   "AccuracyStdDev","DateTime",                        "DateTimeUTC",                                               "UTCOffset"*/
            }
            return(ds);
        }
Example #9
0
            private static ValuesDataSet getDataValues(ValuesDataSet ds, DateTime sdateTime, DateTime edateTime)
            {
                ValuesDataSet requestData = basicValuesDataSet();

                try
                {
                    Thread thread = new Thread(delegate()
                    {
                        WebserviceCall wc = new WebserviceCall();
                        requestData       = wc.getDataValues(ds, sdateTime, edateTime);
                    });
                    thread.Start();
                    while (thread.IsAlive)
                    {
                        Thread.Sleep(150);
                    }
                    return(requestData);
                }
                catch (Exception ex)
                {
                    return(new ValuesDataSet());
                }
            }
Example #10
0
            private static ValuesDataSet getDataValues(int siteID, int variableID, DateTime sdateTime, DateTime edateTime)
            {
                ValuesDataSet requestData = basicValuesDataSet();

                try
                {
                    Thread thread = new Thread(delegate()
                    {
                        CallSnotel cs = new CallSnotel();
                        requestData   = cs.getDataValues(siteID, variableID, sdateTime, edateTime);
                    });
                    thread.Start();
                    while (thread.IsAlive)
                    {
                        Thread.Sleep(150);
                    }
                    return(requestData);
                }
                catch
                {
                    return(new ValuesDataSet());
                }
            }
Example #11
0
        /*
         * newTable
         * creates the Data Table required by rest of program to create the XML form
         */
        private static ValuesDataSet newTable(string variable, int SID, string Data)
        {
            ValuesDataSet ds            = basicValuesDataSet();
            DataTable     variableTable = ds.Tables[0];
            int           ValueID       = 0;


            foreach (string entry in Data.Split('\n'))
            {
                string[] row = entry.Split(',');
                if (row[0] != "" && row[0] != null)
                {
                    ValueID++;
                    seriesCatalogDataSet scTable = new seriesCatalogDataSet();
                    scAdapater.FillBySeriesID(scTable.SeriesCatalog, SID);
                    seriesCatalogDataSet.SeriesCatalogRow sc = scTable.SeriesCatalog[0];
                    TimeSpan utcOffset = sc.BeginDateTime.Subtract(sc.BeginDateTimeUTC);
                    variableTable.Rows.Add(ValueID, sc.SiteID, sc.VariableID, 0, 0, "nc", 0, sc.MethodID, sc.SourceID, 0, 0, sc.QualityControlLevelID, (row[0] == string.Empty) || row[1] == string.Empty ? -999999 : Convert.ToDouble(row[1]), 0, Convert.ToDateTime(row[0]), Convert.ToDateTime(row[0]).ToUniversalTime(), utcOffset.Hours);
                    /*"ValueID","SiteID","VariableID",offsetvalue, offset type id, "CensorCode","QualifierID","MethodID","SourceID","SampleID","DerivedFromID","QualityControlLevelID", "Value", "AccuracyStdDev", "DateTime","DateTimeUTC", "UTCOffset"*/
                }
            }

            return(ds);
        }
 public virtual int Update(ValuesDataSet dataSet) {
     return this.Adapter.Update(dataSet, "Qualifiers");
 }
 public virtual int Update(ValuesDataSet.QualityControlLevelsDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
 public virtual int Update(ValuesDataSet dataSet) {
     return this.Adapter.Update(dataSet, "Methods");
 }
 public virtual int Update(ValuesDataSet dataSet) {
     return this.Adapter.Update(dataSet, "OffsetTypes");
 }
 public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs) {
     global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType();
     global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence();
     ValuesDataSet ds = new ValuesDataSet();
     global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
     any1.Namespace = "http://www.w3.org/2001/XMLSchema";
     any1.MinOccurs = new decimal(0);
     any1.MaxOccurs = decimal.MaxValue;
     any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any1);
     global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
     any2.Namespace = "urn:schemas-microsoft-com:xml-diffgram-v1";
     any2.MinOccurs = new decimal(1);
     any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
     sequence.Items.Add(any2);
     global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
     attribute1.Name = "namespace";
     attribute1.FixedValue = ds.Namespace;
     type.Attributes.Add(attribute1);
     global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
     attribute2.Name = "tableTypeName";
     attribute2.FixedValue = "QualityControlLevelsDataTable";
     type.Attributes.Add(attribute2);
     type.Particle = sequence;
     global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
     if (xs.Contains(dsSchema.TargetNamespace)) {
         global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
         global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
         try {
             global::System.Xml.Schema.XmlSchema schema = null;
             dsSchema.Write(s1);
             for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) {
                 schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                 s2.SetLength(0);
                 schema.Write(s2);
                 if ((s1.Length == s2.Length)) {
                     s1.Position = 0;
                     s2.Position = 0;
                     for (; ((s1.Position != s1.Length) 
                                 && (s1.ReadByte() == s2.ReadByte())); ) {
                         ;
                     }
                     if ((s1.Position == s1.Length)) {
                         return type;
                     }
                 }
             }
         }
         finally {
             if ((s1 != null)) {
                 s1.Close();
             }
             if ((s2 != null)) {
                 s2.Close();
             }
         }
     }
     xs.Add(dsSchema);
     return type;
 }
 public virtual int FillBySiteIDVariableID(ValuesDataSet.DataValuesDataTable dataTable, int SiteID, int VariableID) {
     this.Adapter.SelectCommand = this.CommandCollection[2];
     this.Adapter.SelectCommand.Parameters[0].Value = ((int)(SiteID));
     this.Adapter.SelectCommand.Parameters[1].Value = ((int)(VariableID));
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
 public virtual int Update(ValuesDataSet.CensorCodeCVDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
Example #19
0
            public static List<SampleType> datasetSamples(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 = "SampleID";
                string TABLENAME = "Sample";
                List<SampleType> list = new List<SampleType>();
                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.SamplesRow samples = ds.Samples.FindBySampleID((int) aId.Value);
                            if (samples != null)
                            {
                                SampleType t = new SampleType();
                                t.sampleID = samples.SampleID;
                                t.sampleIDSpecified = true;
                                t.labSampleCode = samples.LabSampleCode;
                                if (!String.IsNullOrEmpty(samples.SampleType)) t.sampleType = samples.SampleType;

                                LabMethodType labMethod = new LabMethodType();

                                labMethod.labMethodName = samples.LabMethodName;
                                labMethod.labName = samples.LabName;
                                labMethod.labOrganization = samples.LabOrganization;
                                labMethod.labCode = samples.LabSampleCode;
                                labMethod.labMethodDescription = samples.LabMethodDescription;
                                if (!samples.IsLabMethodLinkNull())
                                {
                                    labMethod.labMethodLink = samples.LabMethodLink;
                                }

                                t.labMethod = labMethod;

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

                catch (Exception e)
                {
                    log.Error("Error generating a Samples " + e.Message);
                    // non fatal exceptions
                    return null;
                }
            }
 public virtual int Update(ValuesDataSet dataSet) {
     return this.Adapter.Update(dataSet, "CensorCodeCV");
 }
Example #21
0
            public static TsValuesSingleVariableType[] getValues(ValuesDataSet ValuesDs, VariableParam variableParam, int? variableId)
            {
                // TimeSeriesResponseType response = CuahsiBuilder.CreateTimeSeriesObjectSingleValue(1);

                TsValuesSingleVariableType[] valuesList = new TsValuesSingleVariableType[1];

                TsValuesSingleVariableType values = new TsValuesSingleVariableType();

                valuesList[0] = values;

                // get siteInfo
                // get variable Info
                // get Values

                string valuesWhereClause = OdValuesCommon.CreateValuesWhereClause(variableParam, variableId);

                // reformats values dataset into a TimeSeriesResponseType
                IEnumerable<ValueSingleVariable> valueE = ODValues.dataset2ValuesList(ValuesDs, variableParam, variableId, variableDs);

                // do this by keeping a list of ID's then generating in after the values list is done
                values.value = new List<ValueSingleVariable>(valueE).ToArray();
                //values.count = values.value.Length;

                if (values.value.Length > 0)
                {
                    // add qualifiers
                    List<QualifierType> qualifers = ODValues.datasetQualifiers(ValuesDs, valuesWhereClause);
                    if (qualifers != null && qualifers.Count > 0)
                    {
                        values.qualifier = qualifers.ToArray();
                    }
                    // add methods
                    List<MethodType> methods = ODValues.datasetMethods(ValuesDs, valuesWhereClause);
                    if (methods != null && methods.Count > 0)
                    {
                        values.method = methods.ToArray();
                    }
                    List<SourceType> sources = ODValues.datasetSources(ValuesDs, valuesWhereClause);
                    if (sources != null && sources.Count > 0)
                    {
                        values.source = sources.ToArray();
                    }
                    List<OffsetType> offsets = ODValues.datasetOffsetTypes(ValuesDs, valuesWhereClause);
                    if (offsets != null && offsets.Count > 0)
                    {
                        values.offset = offsets.ToArray();
                    }

                    List<QualityControlLevelType> qcLevels = ODValues.DatasetQCLevels(ValuesDs, valuesWhereClause);
                    if (qcLevels != null && qcLevels.Count > 0)
                    {
                        values.qualityControlLevel = qcLevels.ToArray();
                    }
                    List<SampleType> samples = ODValues.datasetSamples(ValuesDs, valuesWhereClause);
                    if (samples != null && samples.Count > 0)
                    {
                        values.sample = samples.ToArray();
                    }

                    IEnumerable<CensorCodeType> codeTypes = ODValues.datasetCensorCodes(ValuesDs, valuesWhereClause);
                    values.censorCode = new List<CensorCodeType>(codeTypes).ToArray();
                }

                return valuesList;
            }
Example #22
0
        public TimeSeriesResponseType getValues(string SiteNumber, string Variable, string StartDate, string EndDate)
        {
            // convert dates
            // get site info
            // get site ID
            // return value dataset

            TimeSeriesResponseType response;
            W3CDateTime?           BeginDateTime;
            W3CDateTime?           EndDateTime;
            int?variableId = null;
            int?siteID;

            VariableInfoType varInfoType = null;
            SiteInfoType     siteType    = null;

            if (!String.IsNullOrEmpty(StartDate))
            {
                try
                {
                    BeginDateTime = W3CDateTime.Parse(StartDate);
                }
                catch
                {
                    throw new WaterOneFlowException("Improper BeginDate '" +
                                                    StartDate + "' Must be YYYY-MM-DD");
                }
            }
            else
            {
                BeginDateTime = null;
            }

            if (!String.IsNullOrEmpty(EndDate))
            {
                try
                {
                    EndDateTime = W3CDateTime.Parse(EndDate);
                }
                catch
                {
                    throw new WaterOneFlowException("Improper EndDate '" +
                                                    EndDate + "' Must be YYYY-MM-DD");
                }
            }
            else
            {
                EndDateTime = null;
            }
            VariableParam vp;

            if (Variable != null)
            {
                vp = new VariableParam(Variable);
                VariableInfoType[] v = ODvariables.getVariable(vp, variableDs);
                if (v != null && v.Length > 0)
                {
                    variableId  = Convert.ToInt16(v[0].variableCode[0].variableID);
                    varInfoType = v[0];
                }
                else
                {
                    throw new WaterOneFlowException("Variable parameter not found: " + Variable);
                }
            }
            else
            {
                throw new WaterOneFlowException("Variable parameter is required ");
            }
            locationParam sq;

            sq = new locationParam(SiteNumber);

            if (sq.isGeometry)
            {
                throw new WaterOneFlowException("Location by Geometry not accepted: " + SiteNumber);
            }

            siteInfoDataSet sitDs = ODSiteInfo.GetSiteInfoDataSet(sq);

            if (sitDs != null && sitDs.sites.Count > 0)
            {
                siteID = sitDs.sites[0].SiteID;
                ValuesDataSet valuesDs = getValuesDataset(siteID, variableId, BeginDateTime, EndDateTime, vp);

                response = getValues(valuesDs, vp);

                // above is the values, add the site, and variables
                response.timeSeries.variable = varInfoType;

                if (varInfoType != null)
                {
                    if (varInfoType.units != null)
                    {
                        response.timeSeries.values.unitsAbbreviation = varInfoType.units.unitsAbbreviation;
                        response.timeSeries.values.unitsCode         = varInfoType.units.unitsCode;

                        if (varInfoType.units.unitsType != null)
                        {
                            response.timeSeries.values.unitsType          = varInfoType.units.unitsType;
                            response.timeSeries.values.unitsTypeSpecified = true;
                        }
                        response.timeSeries.values.unitsAreConverted = false;
                    }
                }

                response.timeSeries.sourceInfo = ODSiteInfo.row2SiteInfoElement(sitDs.sites[0], sitDs);
            }
            else
            {
                response = CuahsiBuilder.CreateTimeSeriesObject();
            }
            // add query info
            response.queryInfo.creationTime = DateTime.UtcNow;
            //response.queryInfo.creationTime = DateTimeOffset.UtcNow;
            response.queryInfo.creationTimeSpecified  = true;
            response.queryInfo.criteria.locationParam = SiteNumber;
            response.queryInfo.criteria.variableParam = Variable;
            response.queryInfo.criteria.timeParam     = CuahsiBuilder.createQueryInfoTimeCriteria(StartDate, EndDate);
            NoteType sourceNote = CuahsiBuilder.createNote("OD Web Service");

            response.queryInfo.note = CuahsiBuilder.addNote(response.queryInfo.note,
                                                            sourceNote);


            return(response);
        }
Example #23
0
        /// <summary>
        /// Method to generate a list of Sources in a ValuesDataSet
        /// This is done as a separate method since Values can could contain other VariableValue Types
        ///
        /// </summary>
        /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
        /// <returns></returns>
        public static List <SourceType> datasetSources(ValuesDataSet ds)
        {
            /* 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    = "SourceID";
            string            TABLENAME = "sources";
            List <SourceType> list      = new List <SourceType>();

            try
            {
                DataView view = new DataView(ds.DataValues);
                view.RowFilter = COLUMN + " is not Null";
                DataTable ids = view.ToTable(TABLENAME, true, new string[] { COLUMN });

                foreach (DataRow r in ids.Rows)
                {
                    try
                    {
                        Object aId = r[COLUMN];
                        // edit here
                        ValuesDataSet.SourcesRow source = ds.Sources.FindBySourceID((int)aId);
                        if (source != null)
                        {
                            SourceType t = new SourceType();
                            t.sourceID          = source.SourceID;
                            t.sourceIDSpecified = true;
                            if (!String.IsNullOrEmpty(source.Organization))
                            {
                                t.Organization = source.Organization;
                            }
                            t.SourceDescription = source.SourceDescription;
                            if (!source.IsSourceLinkNull())
                            {
                                t.SourceLink = source.SourceLink;
                            }
                            // create a contact
                            // only one for now

                            ContactInformationType contact = new ContactInformationType();
                            contact.TypeOfContact = "main";
                            if (!String.IsNullOrEmpty(source.ContactName))
                            {
                                contact.ContactName = source.ContactName;
                            }
                            if (!String.IsNullOrEmpty(source.Email))
                            {
                                contact.Email = source.Email;
                            }
                            if (!String.IsNullOrEmpty(source.Phone))
                            {
                                contact.Phone = source.Phone;
                            }
                            StringBuilder address = new StringBuilder();

                            if (!String.IsNullOrEmpty(source.Address))
                            {
                                address.Append(source.Address + System.Environment.NewLine);
                            }
                            if (!String.IsNullOrEmpty(source.City) &&
                                !String.IsNullOrEmpty(source.State) &&
                                !String.IsNullOrEmpty(source.ZipCode))
                            {
                                address.AppendFormat(",{0}, {1} {2}", source.City, source.State, source.ZipCode);
                            }


                            contact.Address = address.ToString();

                            //ContactInformationType[] contacts = new ContactInformationType[1];
                            // contacts[0] = contact;
                            // t.ContactInformation = contacts;
                            t.ContactInformation = contact;
                            list.Add(t);
                        }
                    }
                    catch (Exception e)
                    {
                        log.Error("Error generating a qualifier " + r.ToString() + e.Message);
                    }
                }
                return(list);
            }

            catch (Exception e)
            {
                log.Error("Error generating a qualifiers " + e.Message);
                // non fatal exceptions
                return(null);
            }
        }
Example #24
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);
                    }
                }
            }
Example #25
0
            /// <summary>
            /// Method to generate a list of offset (from OD OffsetTypes table) in a ValuesDataSet
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <returns></returns>
            public static List<OffsetType> datasetOffsetTypes(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 = "OffsetTypeID";
                string TABLENAME = "offsetTypes";
                List<OffsetType> list = new List<OffsetType>();
                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.OffsetTypesRow offset = ds.OffsetTypes.FindByOffsetTypeID((int) aId.Value);
                            if (offset != null)
                            {
                                OffsetType t = new OffsetType();
                                t.offsetTypeID = offset.OffsetTypeID;
                                t.offsetTypeIDSpecified = true;

                                t.offsetTypeCode = t.offsetTypeID.ToString();

                                if (!String.IsNullOrEmpty(offset.OffsetDescription))
                                    t.offsetDescription = offset.OffsetDescription;

                                ValuesDataSet.UnitsRow offUnit = ds.Units.FindByUnitsID(offset.OffsetUnitsID);
                                string offUnitsCode;

                                string offUnitsName = null;
                                string offUnitsAbbreviation = null;
                                if (!String.IsNullOrEmpty(offUnit.UnitsAbbreviation))
                                    offUnitsAbbreviation = offUnit.UnitsAbbreviation;
                                if (!String.IsNullOrEmpty(offUnit.UnitsName)) offUnitsName = offUnit.UnitsName;
                                if (offUnit != null)
                                    t.unit = CuahsiBuilder.CreateUnitsElement(
                                        offUnit.UnitsType, offUnit.UnitsID.ToString(), offUnitsAbbreviation,
                                        offUnitsName);

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

                catch (Exception e)
                {
                    log.Error("Error generating a offsetTypes " + e.Message);
                    // non fatal exceptions
                    return null;
                }
            }
Example #26
0
            /// <summary>
            /// Method to generate a list of qualifiers in a ValuesDataSet
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <param name="valuesWhereClause"></param>
            /// <returns></returns>
            public static List <QualifierType> datasetQualifiers(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
                 * */

                List <QualifierType> qualifiers = new List <QualifierType>();

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

                    DataTable qids = qview.ToTable("Qualifiers", true, new string[] { "QualifierID" });

                    foreach (DataRow q in qids.Rows)
                    {
                        try
                        {
                            if (q["QualifierID"] == DBNull.Value)
                            {
                                continue;
                            }
                            int?qid = Convert.ToInt32(q["QualifierID"]);
                            ValuesDataSet.QualifiersRow qual = ds.Qualifiers.FindByQualifierID((int)qid.Value);
                            if (qual != null)
                            {
                                QualifierType qt = new QualifierType();
                                qt.qualifierID = qual.QualifierID;
                                if (!qual.IsQualifierCodeNull())
                                {
                                    qt.qualifierCode = qual.QualifierCode;
                                }
                                else
                                {
                                    qt.qualifierCode = qual.QualifierID.ToString();
                                }
                                if (!String.IsNullOrEmpty(qual.QualifierDescription))
                                {
                                    qt.qualifierDescription = qual.QualifierDescription;
                                }
                                qualifiers.Add(qt);
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error generating a qualifier " + q.ToString() + e.Message);
                        }
                    }
                    return(qualifiers);
                }

                catch (Exception e)
                {
                    log.Error("Error generating a qualifiers " + e.Message);
                    // non fatal exceptions
                    return(null);
                }
            }
Example #27
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;
                }
            }
Example #28
0
            /// <summary>
            /// Method to generate a list of qualifiers in a ValuesDataSet
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <param name="valuesWhereClause"></param>
            /// <returns></returns>
            public static List <MethodType> datasetMethods(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    = "MethodID";
                string            TABLENAME = "methods";
                List <MethodType> list      = new List <MethodType>();

                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.MethodsRow method = ds.Methods.FindByMethodID((int)aId.Value);
                            if (method != null)
                            {
                                MethodType t = new MethodType();
                                t.methodID          = method.MethodID;
                                t.methodIDSpecified = true;

                                t.methodCode = method.MethodID.ToString();

                                if (!String.IsNullOrEmpty(method.MethodDescription))
                                {
                                    t.methodDescription = method.MethodDescription;
                                }
                                if (!method.IsMethodLinkNull())
                                {
                                    t.methodLink = method.MethodLink;
                                }
                                list.Add(t);
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error generating a qualifier " + r.ToString() + e.Message);
                        }
                    }
                    return(list);
                }

                catch (Exception e)
                {
                    log.Error("Error generating a qualifiers " + e.Message);
                    // non fatal exceptions
                    return(null);
                }
            }
Example #29
0
        // fills dataset with basic tables
        private static ValuesDataSet basicValuesDataSet()
        {
            ValuesDataSet ds = new ValuesDataSet();

            UnitsTableAdapter unitsTableAdapter =
                new UnitsTableAdapter();

            unitsTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

            OffsetTypesTableAdapter offsetTypesTableAdapter =
                new OffsetTypesTableAdapter();

            offsetTypesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

            QualityControlLevelsTableAdapter qualityControlLevelsTableAdapter =
                new QualityControlLevelsTableAdapter();

            qualityControlLevelsTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

            MethodsTableAdapter methodsTableAdapter =
                new MethodsTableAdapter();

            methodsTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

            SamplesTableAdapter samplesTableAdapter =
                new SamplesTableAdapter();

            samplesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();


            SourcesTableAdapter sourcesTableAdapter =
                new SourcesTableAdapter();

            sourcesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

            QualifiersTableAdapter qualifiersTableAdapter =
                new QualifiersTableAdapter();

            qualifiersTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

            CensorCodeCVTableAdapter censorCodeCvTableAdapter =
                new CensorCodeCVTableAdapter();

            censorCodeCvTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

            ISOMetadataTableAdapter IsoMetadataTableAdapter =
                new ISOMetadataTableAdapter();

            IsoMetadataTableAdapter.Connection.ConnectionString = odws.Config.ODDB();


            unitsTableAdapter.Fill(ds.Units);
            offsetTypesTableAdapter.Fill(ds.OffsetTypes);
            qualityControlLevelsTableAdapter.Fill(ds.QualityControlLevels);
            methodsTableAdapter.Fill(ds.Methods);
            samplesTableAdapter.Fill(ds.Samples);
            sourcesTableAdapter.Fill(ds.Sources);
            qualifiersTableAdapter.Fill(ds.Qualifiers);
            censorCodeCvTableAdapter.Fill(ds.CensorCodeCV);
            IsoMetadataTableAdapter.Fill(ds.ISOMetadata);

            return(ds);
        }
Example #30
0
            /// <summary>
            /// Method to generate a list of Sources in a ValuesDataSet
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <returns></returns>
            public static List <SourceType> datasetSources(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    = "SourceID";
                string            TABLENAME = "sources";
                List <SourceType> list      = new List <SourceType>();

                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]);
                            ValuesDataSet.SourcesRow source = ds.Sources.FindBySourceID((int)aId.Value);
                            if (source != null)
                            {
                                SourceType t = new SourceType();
                                t.sourceID          = source.SourceID;
                                t.sourceIDSpecified = true;

                                t.sourceCode = source.SourceID.ToString();

                                if (!String.IsNullOrEmpty(source.Organization))
                                {
                                    t.organization = source.Organization;
                                }
                                t.sourceDescription = source.SourceDescription;
                                if (!source.IsSourceLinkNull())
                                {
                                    t.sourceLink = new string[] { source.SourceLink };
                                }

                                // create a contact
                                // only one for now
                                ContactInformationType contact = new ContactInformationType();
                                contact.typeOfContact = "main";
                                if (!String.IsNullOrEmpty(source.ContactName))
                                {
                                    contact.contactName = source.ContactName;
                                }
                                if (!String.IsNullOrEmpty(source.Email))
                                {
                                    contact.email = new string[] { source.Email };
                                }
                                if (!String.IsNullOrEmpty(source.Phone))
                                {
                                    contact.phone = new string[] { source.Phone };
                                }
                                StringBuilder address = new StringBuilder();

                                if (!String.IsNullOrEmpty(source.Address))
                                {
                                    address.Append(source.Address + System.Environment.NewLine);
                                }
                                if (!String.IsNullOrEmpty(source.City) &&
                                    !String.IsNullOrEmpty(source.State) &&
                                    !String.IsNullOrEmpty(source.ZipCode))
                                {
                                    address.AppendFormat(",{0}, {1} {2}", source.City, source.State, source.ZipCode);
                                }


                                contact.address      = new string[] { address.ToString() };
                                t.contactInformation = new ContactInformationType[] { contact };

                                if (!String.IsNullOrEmpty(source.Citation))
                                {
                                    t.citation = source.Citation;
                                }

                                if (source.MetadataID != 0 && source.ISOMetadataRow != null)
                                {
                                    MetaDataType m = new MetaDataType();
                                    m.topicCategory  = source.ISOMetadataRow.TopicCategory;
                                    m.title          = source.ISOMetadataRow.Title;
                                    m.@abstract      = source.ISOMetadataRow.Abstract;
                                    m.profileVersion = source.ISOMetadataRow.ProfileVersion;
                                    if (!source.ISOMetadataRow.IsMetadataLinkNull())
                                    {
                                        m.metadataLink = source.ISOMetadataRow.MetadataLink;
                                    }
                                    t.metadata = m;
                                }
                                list.Add(t);
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error generating a qualifier " + r.ToString() + e.Message);
                        }
                    }
                    return(list);
                }

                catch (Exception e)
                {
                    log.Error("Error generating a qualifiers " + e.Message);
                    // non fatal exceptions
                    return(null);
                }
            }
 public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) {
     ValuesDataSet ds = new ValuesDataSet();
     global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType();
     global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence();
     global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny();
     any.Namespace = ds.Namespace;
     sequence.Items.Add(any);
     type.Particle = sequence;
     global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
     if (xs.Contains(dsSchema.TargetNamespace)) {
         global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
         global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
         try {
             global::System.Xml.Schema.XmlSchema schema = null;
             dsSchema.Write(s1);
             for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext(); ) {
                 schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                 s2.SetLength(0);
                 schema.Write(s2);
                 if ((s1.Length == s2.Length)) {
                     s1.Position = 0;
                     s2.Position = 0;
                     for (; ((s1.Position != s1.Length) 
                                 && (s1.ReadByte() == s2.ReadByte())); ) {
                         ;
                     }
                     if ((s1.Position == s1.Length)) {
                         return type;
                     }
                 }
             }
         }
         finally {
             if ((s1 != null)) {
                 s1.Close();
             }
             if ((s2 != null)) {
                 s2.Close();
             }
         }
     }
     xs.Add(dsSchema);
     return type;
 }
Example #32
0
            public static List <SampleType> datasetSamples(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    = "SampleID";
                string            TABLENAME = "Sample";
                List <SampleType> list      = new List <SampleType>();

                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.SamplesRow samples = ds.Samples.FindBySampleID((int)aId.Value);
                            if (samples != null)
                            {
                                SampleType t = new SampleType();
                                t.sampleID          = samples.SampleID;
                                t.sampleIDSpecified = true;
                                t.labSampleCode     = samples.LabSampleCode;
                                if (!String.IsNullOrEmpty(samples.SampleType))
                                {
                                    t.sampleType = samples.SampleType;
                                }

                                LabMethodType labMethod = new LabMethodType();

                                labMethod.labMethodName        = samples.LabMethodName;
                                labMethod.labName              = samples.LabName;
                                labMethod.labOrganization      = samples.LabOrganization;
                                labMethod.labCode              = samples.LabSampleCode;
                                labMethod.labMethodDescription = samples.LabMethodDescription;
                                if (!samples.IsLabMethodLinkNull())
                                {
                                    labMethod.labMethodLink = samples.LabMethodLink;
                                }

                                t.labMethod = labMethod;


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

                catch (Exception e)
                {
                    log.Error("Error generating a Samples " + e.Message);
                    // non fatal exceptions
                    return(null);
                }
            }
 public virtual int FillBySiteIdVariableIDBetweenDates(ValuesDataSet.DataValuesDataTable dataTable, int SiteID, int VariableID, System.DateTime BeingDate, System.DateTime EndDate) {
     this.Adapter.SelectCommand = this.CommandCollection[3];
     this.Adapter.SelectCommand.Parameters[0].Value = ((int)(SiteID));
     this.Adapter.SelectCommand.Parameters[1].Value = ((int)(VariableID));
     this.Adapter.SelectCommand.Parameters[2].Value = ((System.DateTime)(BeingDate));
     this.Adapter.SelectCommand.Parameters[3].Value = ((System.DateTime)(EndDate));
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
Example #34
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);
                }
            }
 public virtual int Update(ValuesDataSet.OffsetTypesDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
Example #36
0
            public static TsValuesSingleVariableType[] getValues(ValuesDataSet ValuesDs, VariableParam variableParam, int?variableId)
            {
                // TimeSeriesResponseType response = CuahsiBuilder.CreateTimeSeriesObjectSingleValue(1);

                TsValuesSingleVariableType[] valuesList = new TsValuesSingleVariableType[1];

                TsValuesSingleVariableType values = new TsValuesSingleVariableType();

                valuesList[0] = values;

                // get siteInfo
                // get variable Info
                // get Values

                string valuesWhereClause = OdValuesCommon.CreateValuesWhereClause(variableParam, variableId);

                // reformats values dataset into a TimeSeriesResponseType
                IEnumerable <ValueSingleVariable> valueE = ODValues.dataset2ValuesList(ValuesDs, variableParam, variableId, variableDs);


                // do this by keeping a list of ID's then generating in after the values list is done
                values.value = new List <ValueSingleVariable>(valueE).ToArray();
                //values.count = values.value.Length;

                if (values.value.Length > 0)
                {
                    // add qualifiers
                    List <QualifierType> qualifers = ODValues.datasetQualifiers(ValuesDs, valuesWhereClause);
                    if (qualifers != null && qualifers.Count > 0)
                    {
                        values.qualifier = qualifers.ToArray();
                    }
                    // add methods
                    List <MethodType> methods = ODValues.datasetMethods(ValuesDs, valuesWhereClause);
                    if (methods != null && methods.Count > 0)
                    {
                        values.method = methods.ToArray();
                    }
                    List <SourceType> sources = ODValues.datasetSources(ValuesDs, valuesWhereClause);
                    if (sources != null && sources.Count > 0)
                    {
                        values.source = sources.ToArray();
                    }
                    List <OffsetType> offsets = ODValues.datasetOffsetTypes(ValuesDs, valuesWhereClause);
                    if (offsets != null && offsets.Count > 0)
                    {
                        values.offset = offsets.ToArray();
                    }

                    List <QualityControlLevelType> qcLevels = ODValues.DatasetQCLevels(ValuesDs, valuesWhereClause);
                    if (qcLevels != null && qcLevels.Count > 0)
                    {
                        values.qualityControlLevel = qcLevels.ToArray();
                    }
                    List <SampleType> samples = ODValues.datasetSamples(ValuesDs, valuesWhereClause);
                    if (samples != null && samples.Count > 0)
                    {
                        values.sample = samples.ToArray();
                    }

                    IEnumerable <CensorCodeType> codeTypes = ODValues.datasetCensorCodes(ValuesDs, valuesWhereClause);
                    values.censorCode = new List <CensorCodeType>(codeTypes).ToArray();
                }

                return(valuesList);
            }
 public virtual int Update(ValuesDataSet.QualifiersDataTable dataTable) {
     return this.Adapter.Update(dataTable);
 }
Example #38
0
            //public static ValuesDataSet GetValueDataSet(int? siteID, int? VariableID, int? MethodID, int? SourceID, int? QualityControlLevelID)
            //{
            //    ValuesDataSet ds = basicValuesDataSet();
            //    if (!siteID.HasValue || !VariableID.HasValue) return ds;
            //    ValuesDataSetTableAdapters.DataValuesTableAdapter valuesTableAdapter = new DataValuesTableAdapter();
            //    valuesTableAdapter.FillBySiteIdVariableIDBetweenDates(ds.DataValues, siteID.Value, VariableID.Value, BeginDateTime.DateTime, EndDateTime.DateTime);
            //    return ds;
            //}

            #endregion odm 1 series based

            // fills dataset with basic tables
            private static ValuesDataSet basicValuesDataSet()
            {
                ValuesDataSet ds = new ValuesDataSet();

                UnitsTableAdapter unitsTableAdapter =
                    new UnitsTableAdapter();
                unitsTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                OffsetTypesTableAdapter offsetTypesTableAdapter =
                    new OffsetTypesTableAdapter();
                offsetTypesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                QualityControlLevelsTableAdapter qualityControlLevelsTableAdapter =
                    new QualityControlLevelsTableAdapter();
                qualityControlLevelsTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                MethodsTableAdapter methodsTableAdapter =
                    new MethodsTableAdapter();
                methodsTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                SamplesTableAdapter samplesTableAdapter =
                    new SamplesTableAdapter();
                samplesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                SourcesTableAdapter sourcesTableAdapter =
                    new SourcesTableAdapter();
                sourcesTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                QualifiersTableAdapter qualifiersTableAdapter =
                    new QualifiersTableAdapter();
                qualifiersTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                CensorCodeCVTableAdapter censorCodeCvTableAdapter =
                    new CensorCodeCVTableAdapter();
                censorCodeCvTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                ISOMetadataTableAdapter IsoMetadataTableAdapter =
                 new ISOMetadataTableAdapter();
                IsoMetadataTableAdapter.Connection.ConnectionString = odws.Config.ODDB();

                unitsTableAdapter.Fill(ds.Units);
                offsetTypesTableAdapter.Fill(ds.OffsetTypes);
                qualityControlLevelsTableAdapter.Fill(ds.QualityControlLevels);
                methodsTableAdapter.Fill(ds.Methods);
                samplesTableAdapter.Fill(ds.Samples);
                sourcesTableAdapter.Fill(ds.Sources);
                qualifiersTableAdapter.Fill(ds.Qualifiers);
                censorCodeCvTableAdapter.Fill(ds.CensorCodeCV);
                IsoMetadataTableAdapter.Fill(ds.ISOMetadata);

                return ds;
            }
 public virtual int Fill(ValuesDataSet.QualityControlLevelsDataTable dataTable) {
     this.Adapter.SelectCommand = this.CommandCollection[0];
     if ((this.ClearBeforeFill == true)) {
         dataTable.Clear();
     }
     int returnValue = this.Adapter.Fill(dataTable);
     return returnValue;
 }
Example #40
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;
                    }
                }
            }
 public virtual int Update(ValuesDataSet dataSet) {
     return this.Adapter.Update(dataSet, "QualityControlLevels");
 }
Example #42
0
            /// <summary>
            /// Method to generate a list of qualifiers in a ValuesDataSet
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <param name="valuesWhereClause"></param>
            /// <returns></returns>
            public static List<QualifierType> datasetQualifiers(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
                 * */

                List<QualifierType> qualifiers = new List<QualifierType>();
                try
                {
                    DataView qview = new DataView(ds.DataValues);
                    qview.RowFilter = valuesWhereClause;

                    DataTable qids = qview.ToTable("Qualifiers", true, new string[] {"QualifierID"});

                    foreach (DataRow q in qids.Rows)
                    {
                        try
                        {

                            if (q["QualifierID"]==DBNull.Value)
                            {
                                continue;
                            }
                            int? qid = Convert.ToInt32(q["QualifierID"]);
                            ValuesDataSet.QualifiersRow qual = ds.Qualifiers.FindByQualifierID((int) qid.Value);
                            if (qual != null)
                            {
                                QualifierType qt = new QualifierType();
                                qt.qualifierID = qual.QualifierID;
                                if (!qual.IsQualifierCodeNull())
                                {
                                    qt.qualifierCode = qual.QualifierCode;
                                } else
                                {
                                    qt.qualifierCode = qual.QualifierID.ToString();
                                }
                                if (!String.IsNullOrEmpty(qual.QualifierDescription))
                                    qt.qualifierDescription = qual.QualifierDescription;
                                qualifiers.Add(qt);
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error generating a qualifier " + q.ToString() + e.Message);
                        }
                    }
                    return qualifiers;
                }

                catch (Exception e)
                {
                    log.Error("Error generating a qualifiers " + e.Message);
                    // non fatal exceptions
                    return null;
                }
            }
Example #43
0
 public reqData(ValuesDataSet ds, DateTime startDate, DateTime endDate)
 {
     this.ds        = ds;
     this.startDate = startDate;
     this.endDate   = endDate;
 }
Example #44
0
            /// <summary>
            /// Method to generate a list of qualifiers in a ValuesDataSet
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <param name="valuesWhereClause"></param>
            /// <returns></returns>
            public static List<MethodType> datasetMethods(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 = "MethodID";
                string TABLENAME = "methods";
                List<MethodType> list = new List<MethodType>();
                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.MethodsRow method = ds.Methods.FindByMethodID((int) aId.Value);
                            if (method != null)
                            {
                                MethodType t = new MethodType();
                                t.methodID = method.MethodID;
                                t.methodIDSpecified = true;

                                t.methodCode = method.MethodID.ToString();

                                if (!String.IsNullOrEmpty(method.MethodDescription))
                                    t.methodDescription = method.MethodDescription;
                                if (!method.IsMethodLinkNull()) t.methodLink = method.MethodLink;
                                list.Add(t);
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("Error generating a qualifier " + r.ToString() + e.Message);
                        }
                    }
                    return list;
                }

                catch (Exception e)
                {
                    log.Error("Error generating a qualifiers " + e.Message);
                    // non fatal exceptions
                    return null;
                }
            }
Example #45
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);
        }
Example #46
0
            /// <summary>
            ///  generate a list of CensorCodes 
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <param name="valuesWhereClause"></param>
            /// <returns></returns>
            public static IEnumerable<CensorCodeType> datasetCensorCodes(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 = "CensorCode";
                string TABLENAME = "CensorCodeCV";
                DataView view = new DataView(ds.DataValues);
                view.RowFilter = valuesWhereClause;

                DataTable ids = view.ToTable(TABLENAME, true, new string[] { COLUMN });
                foreach (DataRow r in ids.Rows)
                {
                          //Object aId = r[COLUMN];

                        if (r[COLUMN] == DBNull.Value)
                        {
                            continue;
                        }
                        string aId = (string)r[COLUMN];
                        // edit here
                        ValuesDataSet.CensorCodeCVRow codeCvRow = ds.CensorCodeCV.FindByTerm(aId);
                        if (codeCvRow != null)
                        {
                            CensorCodeType t = new CensorCodeType();
                            t.censorCode = codeCvRow.Term;

                            if (!codeCvRow.IsDefinitionNull() && !String.IsNullOrEmpty(codeCvRow.Definition))
                            {
                                t.censorCodeDescription = codeCvRow.Definition;
                            }

                            yield return t;
                        }
                   }
                //foreach (ValuesDataSet.CensorCodeCVRow r in ds.CensorCodeCV.Rows)
                //{
                //    CensorCodeType t = new CensorCodeType();
                //    t.censorCode = r.Term;

                //    if (!r.IsDefinitionNull() && !String.IsNullOrEmpty(r.Definition))
                //    {
                //          t.censorCodeDescription = r.Definition;
                //    }

                //   yield return t;
                //}
            }
Example #47
0
        /// <summary>
        /// Method to generate a list of offset (from OD OffsetTypes table) in a ValuesDataSet
        /// This is done as a separate method since Values can could contain other VariableValue Types
        ///
        /// </summary>
        /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
        /// <returns></returns>
        public static List <OffsetType> datasetOffsetTypes(ValuesDataSet ds)
        {
            /* 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    = "OffsetTypeID";
            string            TABLENAME = "offsetTypes";
            List <OffsetType> list      = new List <OffsetType>();

            try
            {
                DataView view = new DataView(ds.DataValues);
                view.RowFilter = COLUMN + " is not Null";
                DataTable ids = view.ToTable(TABLENAME, true, new string[] { COLUMN });

                foreach (DataRow r in ids.Rows)
                {
                    try
                    {
                        Object aId = r[COLUMN];
                        // edit here
                        ValuesDataSet.OffsetTypesRow offset = ds.OffsetTypes.FindByOffsetTypeID((int)aId);
                        if (offset != null)
                        {
                            OffsetType t = new OffsetType();
                            t.offsetTypeID          = offset.OffsetTypeID;
                            t.offsetTypeIDSpecified = true;

                            if (!String.IsNullOrEmpty(offset.OffsetDescription))
                            {
                                t.offsetDescription = offset.OffsetDescription;
                            }

                            ValuesDataSet.UnitsRow offUnit = ds.Units.FindByUnitsID(offset.OffsetUnitsID);
                            string offUnitsCode;
                            string offUnitsName         = null;
                            string offUnitsAbbreviation = null;
                            if (!String.IsNullOrEmpty(offUnit.UnitsAbbreviation))
                            {
                                offUnitsAbbreviation = offUnit.UnitsAbbreviation;
                            }
                            if (!String.IsNullOrEmpty(offUnit.UnitsName))
                            {
                                offUnitsName = offUnit.UnitsName;
                            }
                            if (offUnit != null)
                            {
                                t.units = CuahsiBuilder.CreateUnitsElement(
                                    null, offUnit.UnitsID.ToString(), offUnitsAbbreviation, offUnitsName);
                            }

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

            catch (Exception e)
            {
                log.Error("Error generating a qualifiers " + e.Message);
                // non fatal exceptions
                return(null);
            }
        }
Example #48
0
            /// <summary>
            /// Method to generate a list of Sources in a ValuesDataSet
            /// This is done as a separate method since Values can could contain other VariableValue Types
            ///
            /// </summary>
            /// <param name="ds">ValuesDataSet with the values used in the timeSeries</param>
            /// <returns></returns>
            public static List<SourceType> datasetSources(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 = "SourceID";
                string TABLENAME = "sources";
                List<SourceType> list = new List<SourceType>();
                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]);
                            ValuesDataSet.SourcesRow source = ds.Sources.FindBySourceID((int) aId.Value);
                            if (source != null)
                            {
                                SourceType t = new SourceType();
                                t.sourceID = source.SourceID;
                                t.sourceIDSpecified = true;

                                t.sourceCode = source.SourceID.ToString();

                                if (!String.IsNullOrEmpty(source.Organization)) t.organization = source.Organization;
                                t.sourceDescription = source.SourceDescription;
                                if (!source.IsSourceLinkNull())
                                {
                                    t.sourceLink = new string[] {source.SourceLink};
                                }

                                // create a contact
                                // only one for now
                                ContactInformationType contact = new ContactInformationType();
                                contact.typeOfContact = "main";
                                if (!String.IsNullOrEmpty(source.ContactName)) contact.contactName = source.ContactName;
                                if (!String.IsNullOrEmpty(source.Email))
                                {
                                    contact.email = new string[] {source.Email};
                                }
                                if (!String.IsNullOrEmpty(source.Phone))
                                {
                                    contact.phone = new string[] {source.Phone};
                                }
                                StringBuilder address = new StringBuilder();

                                if (!String.IsNullOrEmpty(source.Address))
                                    address.Append(source.Address + System.Environment.NewLine);
                                if (!String.IsNullOrEmpty(source.City)
                                    && !String.IsNullOrEmpty(source.State)
                                    && !String.IsNullOrEmpty(source.ZipCode))
                                    address.AppendFormat(",{0}, {1} {2}", source.City, source.State, source.ZipCode);

                                contact.address = new string[] {address.ToString()};
                                t.contactInformation = new ContactInformationType[] {contact};

                                if (!String.IsNullOrEmpty(source.Citation))
                                {
                                    t.citation = source.Citation;
                                }

                                if (source.MetadataID != 0 && source.ISOMetadataRow != null)
                                {
                                    MetaDataType m= new MetaDataType();
                                    m.topicCategory = source.ISOMetadataRow.TopicCategory;
                                    m.title = source.ISOMetadataRow.Title;
                                    m.@abstract = source.ISOMetadataRow.Abstract;
                                    m.profileVersion = source.ISOMetadataRow.ProfileVersion;
                                    if (!source.ISOMetadataRow.IsMetadataLinkNull())
                                    {
                                        m.metadataLink = source.ISOMetadataRow.MetadataLink;

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

                catch (Exception e)
                {
                    log.Error("Error generating a qualifiers " + e.Message);
                    // non fatal exceptions
                    return null;
                }
            }