Exemple #1
0
        /// <summary>
        /// createSiteInfoResponse populates a SiteInfoResponseType.
        /// It is used the webmethod getSiteInfo.
        /// designed for multiple site codes
        /// This method will be slow if the information has never been cached.
        /// </summary>
        /// <param name="LocationParams"></param>
        private SiteInfoResponseType CreateSitesResponse(locationParam[] LocationParams)
        {
            /* for each site code, add a siteInfo type with a period of record
            // for each site
             *     createSitInfoType
             *     add to response
             *     createPeriodOfRecord
             *     add to response
             * return response
             * */
            SiteInfoResponseType response;

            SiteInfoType[] sites = ODSiteInfo.GetSitesByLocationParameters(LocationParams);
            if (sites.Length == 0)
            {
                throw new WaterOneFlowException("No Sites found");
            }
            response = CuahsiBuilder.CreateASetOfSiteResponses(sites.Length, 1);
                for (int i = 0; i < sites.Length; i++)
            {
                response.site[i].siteInfo = sites[i];
                String aSiteID = response.site[i].siteInfo.siteCode[0].siteID;

                // no period of record
            }

            return response;
        }
Exemple #2
0
        public SiteInfoResponseType GetSites(string[] locationParameters)
        {
            XmlDocument XMLResponse = new XmlDocument();

            locationParameters = WSUtils.removeEmptyStrings(locationParameters);
            //string[] siteCodes = Array.ConvertAll(locationParameters, new Converter<string, string>(locationParam.getSiteCode));
            List<locationParam> siteCodes = new List<locationParam>(locationParameters.Length);
             foreach(String s in locationParameters)
             {
                 locationParam lp = new locationParam(s);
                 siteCodes.Add(lp);
             }

             SiteInfoResponseType result = CreateSitesResponse(siteCodes.ToArray());

            return result;
        }
        public SiteInfoResponseType GetSiteInfo(locationParam locationParameter)
        {
            string Network;
            string SiteCode;

            SiteInfoResponseType result = createSiteInfoResponse(new locationParam[] { locationParameter });
            // put a no result check here
            result.queryInfo.criteria.locationParam = locationParameter.ToString(); // to string returns orignal string
            if (result.site[0].siteInfo != null)
            {
                result.site[0].siteInfo.siteCode[0].network =
                    System.Configuration.ConfigurationManager.AppSettings["network"];
            }
            else
            {
                // we only have one site... so throw the exception
                throw new WaterOneFlowException("Site '" + locationParameter.ToString() + "' Not Found");

            }
            return result;
        }
        // create period of record
        private seriesCatalogType[] CreateSeriesCatalogRecord(locationParam LocationParameter, int? siteID)
        {
            // need the siteID for the DB sites, and the siteCode for retrival from the service

            if (siteID.HasValue)
            {
                seriesCatalogDataSet seriesDataset = ODSeriesCatalog.GetSeriesCatalogDataSet(siteID.Value);
                if (seriesDataset != null && seriesDataset.SeriesCatalog.Rows.Count > 0)
                    if (seriesDataset.SeriesCatalog.Rows.Count > 0)
                    {
                        seriesCatalogType[] seriesFromDB =
                            ODSeriesCatalog.dataSet2SeriesCatalog(seriesDataset, variablesDs);
                        if (seriesFromDB != null && seriesFromDB.Length > 0)
                        {
                            return seriesFromDB;
                        }
                    }
            }

            // send back empty catalog
            List<seriesCatalogType> seriesList = new List<seriesCatalogType>();
            seriesList.Add(new seriesCatalogType());
            return seriesList.ToArray();
        }
        public SiteInfoResponseType GetSiteInfo(string locationParameter)
        {
            Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();

            queryLog2.LogStart(Logging.Methods.GetSiteInfo, locationParameter,
                appContext.Request.UserHostName);
            locationParam lp = null;
            try
            {
                lp = new locationParam(locationParameter);
                if (lp.isGeometry)
                {
                    String error = "Location by Geometry not accepted: " + locationParameter;
                    log.Debug(error);
                    throw new WaterOneFlowException(error);
                }
            }
            catch (WaterOneFlowException we)
            {
                //waterLog.WriteEntry("Bad SiteID:" + siteId, EventLogEntryType.Information);
                log.Error(we.Message);
                throw;
            }
            catch (Exception e)
            {
                // waterLog.WriteEntry("Uncaught exception:" + e.Message, EventLogEntryType.Error);
                String error =
                    "Sorry. Your submitted site ID for this getSiteInfo request caused an problem that we failed to catch programmatically: " +
                    e.Message;
                log.Error(error);
                throw new WaterOneFlowException(error);
            }
            GetSiteInfoOD getSiteInfo = new GetSiteInfoOD();

            SiteInfoResponseType resp = getSiteInfo.GetSiteInfo(lp);

            // add service location using the app context
            // for ODM, we one only seriesCatalog
            // String serviceName = (String) appContext.Session["serviceName"];
            // String serviceUrl = (String) appContext.Session["serviceUrl"];
            if (resp.site[0].seriesCatalog.Length > 0)
            {
                resp.site[0].seriesCatalog[0].menuGroupName = serviceName;
                resp.site[0].seriesCatalog[0].serviceWsdl = serviceUrl;
            }
            queryLog2.LogEnd(Logging.Methods.GetSiteInfo,
                locationParameter,
                timer.ElapsedMilliseconds.ToString(),
                resp.site.Length.ToString(),
                    appContext.Request.UserHostName);

            return resp;
        }
        private SiteInfoResponseType createSiteInfoResponse(locationParam[] LocationParameters)
        {
            /* for each site code, add a siteInfo type with a period of record
              * for each site
               *     createSitInfoType
               *     add to response
               *     createPeriodOfRecord
               *     add to response
               * return response
               * */
            SiteInfoResponseType response = CuahsiBuilder.CreateASetOfSiteResponses(LocationParameters.Length, 1);

            for (int i = 0; i < LocationParameters.Length; i++)
            {
                if (LocationParameters[i] == null) continue;

                response.site[i].siteInfo = getSiteInfoType(LocationParameters[i]);
                if (response.site[i].siteInfo != null)
                {
                    String aSiteID = null;

                    Nullable<int> siteIDint = null;
                    try
                    {
                        aSiteID = response.site[i].siteInfo.siteCode[0].siteID;
                    }
                    catch (NullReferenceException e)
                    {
                        String error = " no site code returned for sitecode" + LocationParameters[i];
                        log.Warn(error);
                        response.site[i].seriesCatalog = CreateSeriesCatalogRecord(LocationParameters[i], null);
                    }

                    try
                    {
                        siteIDint = Convert.ToInt32(aSiteID);
                        response.site[i].seriesCatalog = CreateSeriesCatalogRecord(LocationParameters[i], siteIDint);
                    }
                    catch (InvalidCastException e)
                    {
                        String error = " siteID was not an integer" + LocationParameters[i];
                        log.Warn(error);
                        response.site[i].seriesCatalog = CreateSeriesCatalogRecord(LocationParameters[i], null);
                    }

                }
                else
                {
                    String error = " no site code returned for sitecode" + LocationParameters[i];
                    log.Warn(error);

                }
            }

            return response;
        }
        private SiteInfoType getSiteInfoType(locationParam LocationParameter)
        {
            SiteInfoType sit;

            //   look in memory
            //           sit = (SiteInfoType)appCache[sitCache + siteCode];
            //         if (sit != null) return sit;

            //ok, try the database
            SiteInfoType[] sites = ODSiteInfo.GetSitesByLocationParameters(new locationParam[] { LocationParameter });
            if (sites == null || sites.Length == 0)
            {
                return null;
            }
            else

                if (sites != null && sites.Length == 1)
                {
                    return sites[0];
                }
                else
                {
                    // had better be only one
                    String error = "More than one site with SiteCode '" + LocationParameter + "'";
                    log.Error(error);
                    throw new WaterOneFlowException(error);
                }

            return sit;
        }
Exemple #8
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;
        }
Exemple #9
0
        public static siteInfoDataSet GetSiteInfoDataSet(locationParam[] LocationParameters)
        {
            siteInfoDataSet ds = new siteInfoDataSet();

            SpatialReferencesTableAdapter spatialTableAdapter =
                 new SpatialReferencesTableAdapter();
            sitesTableAdapter sitesTableAdapter = new sitesTableAdapter();
            spatialTableAdapter.Connection.ConnectionString = Config.ODDB();
            sitesTableAdapter.Connection.ConnectionString = Config.ODDB();

            try
            {
                spatialTableAdapter.Fill(ds.SpatialReferences);
            }
            catch (Exception e)
            {
                log.Fatal("Cannot connect to database " + e.Message); //+ spatialTableAdapter.Connection.DataSource
                throw new WaterOneFlowServerException(e.Message);
            }
            if (LocationParameters[0].isGeometry)
            {
                if (LocationParameters[0].Geometry.GetType().Equals(typeof(box)))
                {
                    box queryBox = (box)LocationParameters[0].Geometry;
                    sitesTableAdapter.FillByBox(ds.sites,
                        queryBox.South, queryBox.North, queryBox.West, queryBox.East);
                }
            }
            else
            {
                siteInfoDataSet.sitesDataTable aSitetable = new siteInfoDataSet.sitesDataTable();

                foreach (locationParam s in LocationParameters)
                {
                    try
                    {
                        if (s.IsId)
                        {
                            int siteID = int.Parse(s.SiteCode);
                            sitesTableAdapter.FillBySiteID(aSitetable, siteID);
                        }
                        else
                        {
                            sitesTableAdapter.FillBySiteCode(aSitetable, s.SiteCode);
                        }
                        ds.sites.Merge(aSitetable);
                    }
                    catch (Exception e)
                    {
                        log.Fatal("Cannot connect to database " + e.Message); //+ sitesTableAdapter.Connection.DataSource
                        throw new WaterOneFlowServerException(e.Message);
                    }
                }
            }

            return ds;
        }
Exemple #10
0
 public static siteInfoDataSet GetSiteInfoDataSet(locationParam LocationParam)
 {
     return GetSiteInfoDataSet(new locationParam[] { LocationParam });
 }
Exemple #11
0
        public static SiteInfoType[] GetSitesByLocationParameters(locationParam[] locationParameters)
        {
            siteInfoDataSet sDS;
            if (locationParameters.Length > 0)
            {
                sDS = GetSiteInfoDataSet(locationParameters);

            }
            else
            {
                sDS = GetSiteInfoDataSet();
            }
            List<SiteInfoType> sites = new List<SiteInfoType>(locationParameters.Length);

            foreach (siteInfoDataSet.sitesRow s in sDS.sites)
            {
                SiteInfoType sit = row2SiteInfoElement(s, sDS);
                sites.Add(sit);
            }

            return sites.ToArray();
        }