コード例 #1
0
ファイル: InitAckChunk.cs プロジェクト: sgf/SCTP
        public InitAckChunk(CType type, byte flags, int length, ByteBuffer pkt)
            : base(type, flags, length, pkt)
        {
            if (_body.remaining() >= 16)
            {
                _initiateTag    = _body.GetInt();
                _adRecWinCredit = _body.GetUInt();;
                _numOutStreams  = _body.GetUShort();
                _numInStreams   = _body.GetUShort();
                _initialTSN     = _body.GetUInt();
                Logger.Trace("Init Ack" + this.ToString());
                while (_body.hasRemaining())
                {
                    VariableParam v = readVariable();
                    _varList.Add(v);
                }

                foreach (VariableParam v in _varList)
                {
                    // now look for variables we are expecting...
                    Logger.Trace("variable of type: " + v.getName() + " " + v.ToString());
                    if (typeof(StateCookie).IsAssignableFrom(v.GetType()))
                    {
                        _cookie = ((StateCookie)v).getData();
                    }
                    else
                    {
                        Logger.Trace("ignored variable of type: " + v.getName());
                    }
                }
            }
        }
コード例 #2
0
            public override object GetTimeSeries(
                locationParam lp,
                VariableParam vp,
                Nullable <W3CDateTime> startDate,
                Nullable <W3CDateTime> endDate)
            {
                if (lp.isGeometry)
                {
                    throw new WaterOneFlowException("Geometry not supported ");
                }

                TimeSeriesResponseType result = null;

                string[] StationsList = new string[] { lp.SiteCode };

                result = CuahsiBuilder.CreateTimeSeriesObject();

                result.queryInfo.criteria.locationParam = lp.ToString();
                result.queryInfo.criteria.variableParam = vp.ToString();

                result.timeSeries.sourceInfo = DataInfoService.GetSite(lp);

                // not fully correct, but just choose the first one.
                VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp);
                result.timeSeries.variable = vits[0];
                string aURL = InstantaneousData(startDate, endDate,
                                                new string[] { vp.Code }, StationsList, USGSCommon.option2AgencyCode(lp));

                try
                {
                    result.timeSeries.values =
                        CreateWQTimeSeriesObject(vp, aURL);
                }
                catch (WaterOneFlowException e)
                {
                    throw;
                }
                catch (WaterOneFlowSourceException e)
                {
                    throw;
                }
                catch (Exception e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("An External resource failed.", e);
                }

                List <NoteType> notes   = new List <NoteType>();
                NoteType        urlNote = new NoteType();

                urlNote.title = "USGS URL";
                urlNote.Value = aURL;
                notes.Add(urlNote);
                result.queryInfo.note = notes.ToArray();

                return(result);
            }
コード例 #3
0
 public ReConfigChunk(CType type, byte flags, int length, ByteBuffer pkt)
     : base(type, flags, length, pkt)
 {
     Logger.Debug("ReConfig chunk" + this.ToString());
     if (_body.remaining() >= 4)
     {
         while (_body.hasRemaining())
         {
             VariableParam v = this.readVariable();
             _varList.Add(v);
             Logger.Debug("\tParam :" + v.ToString());
         }
     }
 }
コード例 #4
0
 public InitChunk(CType type, byte flags, int length, ByteBuffer pkt)
     : base(type, flags, length, pkt)
 {
     if (_body.remaining() >= 16)
     {
         _initiateTag    = _body.GetInt();
         _adRecWinCredit = _body.GetUInt();
         _numOutStreams  = _body.GetUShort();
         _numInStreams   = _body.GetUShort();
         _initialTSN     = _body.GetUInt();
         Logger.Trace("Init " + this.ToString());
         while (_body.hasRemaining())
         {
             VariableParam v = readVariable();
             _varList.Add(v);
         }
         foreach (VariableParam v in _varList)
         {
             // now look for variables we are expecting...
             Logger.Trace("variable of type: " + v.getName() + " " + v.ToString());
             if (typeof(SupportedExtensions).IsAssignableFrom(v.GetType()))
             {
                 _farSupportedExtensions = ((SupportedExtensions)v).getData();
             }
             else if (typeof(RandomParam).IsAssignableFrom(v.GetType()))
             {
                 _farRandom = ((RandomParam)v).getData();
             }
             else if (typeof(ForwardTSNsupported).IsAssignableFrom(v.GetType()))
             {
                 _farForwardTSNsupported = true;
             }
             else if (typeof(RequestedHMACAlgorithmParameter).IsAssignableFrom(v.GetType()))
             {
                 _farHmacs = ((RequestedHMACAlgorithmParameter)v).getData();
             }
             else if (typeof(ChunkListParam).IsAssignableFrom(v.GetType()))
             {
                 _farChunks = ((ChunkListParam)v).getData();
             }
             else
             {
                 Logger.Trace("unexpected variable of type: " + v.getName());
             }
         }
     }
 }
コード例 #5
0
            public override object GetTimeSeries(
                locationParam lp,
                VariableParam vp,
                Nullable <W3CDateTime> startDate,
                Nullable <W3CDateTime> endDate)
            {
                if (lp.isGeometry)
                {
                    throw new WaterOneFlowException("Geometry not supported ");
                }

                TimeSeriesResponseType result = null;

                //string Network;
                //string SiteCode;
                ////WSUtils.ParseSiteId(siteId, out Network, out SiteCode);
                //try
                //{
                //    locationParam sq = new locationParam(siteNumber);
                //    Network = sq.Network;
                //    SiteCode = sq.SiteCode;
                //    if (sq.isGeometry)
                //    {
                //        throw new WaterOneFlowException("Location by Geometry not accepted: " + siteNumber);
                //    }
                //}
                //catch (WaterOneFlowException we)
                //{
                //    log.Info("Bad SiteID:" + siteNumber);
                //    throw;
                //}
                //catch (Exception e)
                //{
                //    log.Error("Uncaught exception:" + e.Message);
                //    throw new WaterOneFlowException("Sorry. Your submitted site ID for this getSiteInfo request caused an problem that we failed to catch programmatically: " + e.Message);
                //}

                //// string WaterQualityList = "&parameter_cd=" + variable;
                //string[] StationsList = new string[] { SiteCode };
                string[] StationsList = new string[] { lp.SiteCode };

                //VariableParam vp;
                //try
                //{
                //    vp = new VariableParam(variable);

                //}
                //catch (WaterOneFlowException we)
                //{
                //    log.Info("Bad Variable Request '" + variable + "'");
                //    throw;
                //}
                //catch (Exception e)
                //{
                //    log.Error("uncaught exception duing Variable Request '" + variable + "'");
                //    throw new WaterOneFlowException("Sorry. Your variable parameter caused an exception that we failed to catch:" + e.Message);

                //}

                result = CuahsiBuilder.CreateTimeSeriesObject();

                //// all data are provisional
                //List<note> notes = new List<note>();
                //note urlNote = new note();
                //urlNote.title = "USGS Data Provisional";
                //urlNote.href = "http://waterdata.usgs.gov/nwis/help/?provisional";
                //urlNote.Value = "All data are provisional, and subject to revision";
                //notes.Add(urlNote);
                //result.queryInfo.note = notes.ToArray();

                result.queryInfo.criteria.locationParam = lp.ToString();
                result.queryInfo.criteria.variableParam = vp.ToString();


                // result.queryInfo.criteria.timeParam  = CuahsiBuilder.createQueryInfoTimeCriteria(startDate, endDate);

                // look for siteInfoType in cache, and use if it is there

                /* SiteInfoType sit = (SiteInfoType)appCache[sitCache + SiteCode];
                 * if (sit == null)
                 * {
                 *   // just use the values for now.
                 *   ((SiteInfoType)result.timeSeries.sourceInfo).siteCode[0].Value = SiteCode;
                 *   ((SiteInfoType)result.timeSeries.sourceInfo).siteCode[0].network = "NWIS";
                 *
                 * }
                 * else
                 * {
                 *   // in the cache, use it
                 *   result.timeSeries.sourceInfo = sit;
                 * }
                 * */
                result.timeSeries.sourceInfo = DataInfoService.GetSite(lp);


                // vaiable info
                // result.timeSeries.variable = vp.getVariableSchemaType();
                //result.timeSeries.variable = NwisVariableCatalog.getVariable(vp.Code, variableDataSet);
                //result.timeSeries.variable = ODvariables.getVariable(vp.Code, variableDataSet)[0];

                // not fully correct, but just choose the first one.
                VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp);
                result.timeSeries.variable = vits[0];
                string aURL = GroundWater(startDate, endDate,
                                          StationsList, USGSCommon.option2AgencyCode(lp));

                try
                {
                    // refactor too much abstraction
                    //CreateRealTimeSeriesObject(result, RealTime(StationsList));
                    result.timeSeries.values =
                        CreateGWTimeSeriesObject(vp, aURL);
                }
                catch (WaterOneFlowException e)
                {
                    //log.Error(e.Message + e.StackTrace);
                    throw;
                }
                catch (WaterOneFlowSourceException e)
                {
                    //log.Error(e.Message + e.StackTrace);
                    throw;
                }
                catch (WebException e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("Connecting to External resource failed.", e);
                }
                catch (Exception e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("An External resource failed.", e);
                }

                result.timeSeries.sourceInfo = DataInfoService.GetSite(lp);

                List <NoteType> notes   = new List <NoteType>();
                NoteType        urlNote = new NoteType();

                urlNote.title = "USGS URL";
                urlNote.Value = aURL;
                notes.Add(urlNote);
                result.queryInfo.note = notes.ToArray();

                return(result);
            }
コード例 #6
0
            public override object GetTimeSeries(
                locationParam Location,
                VariableParam Variable,
                W3CDateTime?BeginDateTime, W3CDateTime?EndDateTime)
            {
                string siteNum;

                string parameterCode;
                string statisticCode;
                string agencyCode;
                string startDateTime = null;
                string endDateTime   = null;

                if (Location.isGeometry)
                {
                    throw new WaterOneFlowException("Geometry not supported ");
                }

                if (Location != null)
                {
                    siteNum = Location.SiteCode;
                }
                else
                {
                    throw new WaterOneFlowException("Missing SiteCode ");
                }

                if (Variable != null)
                {
                    parameterCode = Variable.Code;
                    statisticCode = option2UsgsStatCode(Variable);
                    agencyCode    = option2AgencyCode(Variable);
                }
                else
                {
                    throw new WaterOneFlowException("Missing Parameter ");
                }

                if (BeginDateTime.HasValue)
                {
                    startDateTime = BeginDateTime.Value.DateTime.ToString("yyyy-MM-dd");
                }
                else
                {
                    startDateTime = DateTime.Now.AddDays(-29).ToString("yyyy-MM-dd");
                }



                if (EndDateTime.HasValue)
                {
                    endDateTime = EndDateTime.Value.DateTime.ToString("yyyy-MM-dd");
                }
                else
                {
                    endDateTime = DateTime.Now.ToString("yyyy-MM-dd");
                }
                String dailyValues = null;

                try
                {
                    //dailyValues = svc.getDV(siteNum,
                    //                              parameterCode, statisticCode,
                    //                              startDateTime, endDateTime,
                    //                              agencyCode);
                    //NWISWS.TimeSeriesResponseType response
                    //    = svc.GetValuesObject(siteNum,
                    //                parameterCode,
                    //                startDateTime, endDateTime,
                    //                "*****@*****.**");
                    NWISWS.TimeSeriesResponseType response
                        = svc.GetValuesObject(Location.ToString(),
                                              Variable.ToString(),
                                              startDateTime, endDateTime,
                                              "*****@*****.**");
                    return(response);
                }
                catch (SoapHeaderException she)
                {
                    log.Info("USGS " + she.Message);
                    throw new WaterOneFlowSourceException("Error connecting to USGS;" + she.Message);
                }
                catch (Exception ex)
                {
                    log.Info("USGS DailyValue Connection Error " + ex.Message);
                    throw new WaterOneFlowSourceException("Error connecting to USGS");
                }
            }
コード例 #7
0
            public override object GetTimeSeries(
                locationParam Location,
                VariableParam Variable,
                W3CDateTime?BeginDateTime, W3CDateTime?EndDateTime)
            {
                string siteNum;

                string      parameterCode;
                string      statisticCode;
                string      agencyCode = "USGS";
                W3CDateTime startDateTime;
                W3CDateTime endDateTime;

                if (Location.isGeometry)
                {
                    throw new WaterOneFlowException("Geometry not supported ");
                }

                if (Location != null)
                {
                    siteNum    = Location.SiteCode;
                    agencyCode = option2AgencyCode(Location);
                }
                else
                {
                    throw new WaterOneFlowException("Missing SiteCode ");
                }

                if (Variable != null)
                {
                    parameterCode = Variable.Code;
                    statisticCode = option2UsgsStatCode(Variable);
                    //agencyCode = option2AgencyCode(Variable);
                }
                else
                {
                    throw new WaterOneFlowException("Missing Parameter ");
                }

                W3CDateTime startMinDate = W3CDateTime.Now.AddDays(-maxRequestDays);

                startDateTime = startMinDate;
                if (BeginDateTime.HasValue)
                {
                    startDateTime = BeginDateTime.Value;
                    if (startDateTime <= startMinDate)
                    {
                        startDateTime = startMinDate;
                    }
                }



                W3CDateTime endDateMax = W3CDateTime.Now;

                endDateTime = endDateMax;
                if (EndDateTime.HasValue)
                {
                    endDateTime = EndDateTime.Value;

                    if (endDateTime >= endDateMax)
                    {
                        endDateTime = endDateMax;
                    }
                }
                if (endDateTime < W3CDateTime.Now.AddDays(-maxRequestDays))
                {
                    throw new WaterOneFlowException("Only Properties.Settings.Default.UVDaysAvailable days back is supported in the NWIS UV service");
                }
                if (endDateTime < startDateTime)
                {
                    endDateTime = W3CDateTime.Now;
                }

                //TimeSpan span = endDateTime - startDateTime;
                //if (span.Days > 31 )
                //{
                //    span = new TimeSpan(31, 0, 0);
                //}
                //http://waterservices.usgs.gov/WOF/InstantaneousValues?location=06869950&variable=00065&period=P1D
                //string urlFormat = "http://{0}/{1}?location={2}&variable={3}&period=P{4}D";
                //string url = string.Format(urlFormat, "waterservices.usgs.gov",
                //                           "WOF/InstantaneousValues",
                //                           siteNum,
                //                           parameterCode,
                //                           span.Days);
                //   string urlFormat = "{0}?location={1}&variable={2}&startDate={3}&endDate={4}";

                /*  he site number may be optionally prefixed by the agency code followed by a colon, which ensures the site is unique. Examples: ?site=06306300 or ?sites=USGS:06306300. There is no default if this parameter is used. For real-time streamflow sites, the site number is normally 8 characters. Site numbers range from 8 to 15 character.
                 */
                string urlFormat = "{0}?sites={1}&parameterCd={2}&startDT={3}&endDT={4}";
                string url       = string.Format(urlFormat, USGSUVBaseUrl,
                                                 locationToUvRest(Location),
                                                 parameterCode,
                                                 startDateTime.ToString("W"), // startDateTime.ToString("yyyy-MM-dd"),
                                                 endDateTime.ToString("W")    //  endDateTime.ToString("yyyy-MM-dd")


                                                 );

                try
                {
                    Uri uri = new Uri(url);
                    using (WebClient web = new WebClient())
                    {
                        TimeSeriesResponseType response;


                        using (XmlReader reader = new XmlTextReader(web.OpenRead(url)))
                        {
                            XmlWriter    writer       = null;
                            MemoryStream memoryStream = new MemoryStream();
                            try
                            {
                                writer = XmlWriter.Create(memoryStream);
                                // Create the XsltArgumentList.
                                XsltArgumentList argList = new XsltArgumentList();

                                argList.AddParam("network", "", Location.Network);
                                argList.AddParam("vocabulary", "", Variable.Vocabulary);
                                argList.AddParam("location", "", Location.ToString());
                                argList.AddParam("variable", "", Variable.ToString());
                                argList.AddParam("starttime", "", startDateTime.ToString("W"));
                                argList.AddParam("endtime", "", endDateTime.ToString("W"));


                                xslt.Transform(reader, argList, writer);
                                memoryStream.Position = 0;
                                using (var reader2 = XmlReader.Create(memoryStream))
                                {
                                    response
                                        = (TimeSeriesResponseType)serializer.Deserialize(reader2);
                                }
                            }
                            finally
                            {
                                memoryStream.Close();
                            }
                        }


                        //TimeSeriesResponseType response
                        //    = new Passthrough(web.OpenRead(url));
                        return(response);
                    }
                }


                catch (WebException ex)
                {
                    if (ex.Response is HttpWebResponse)
                    {
                        switch (((HttpWebResponse)ex.Response).StatusCode)
                        {
                        case HttpStatusCode.NotFound:
                            log.Info("USGS  Not Found" + ex.Message);
                            throw new WaterOneFlowSourceException("USGS Site/Variable combination Not Found");
                            break;

                        case HttpStatusCode.ServiceUnavailable:
                            log.Info("USGS  Service Not Available " + ex.Message);
                            throw new WaterOneFlowSourceException("USGS Service Not Available. Please try later");
                            break;

                        default:
                            log.Info("USGS  Connection Error " + ex.Message);
                            throw new WaterOneFlowSourceException("Error connecting to USGS");
                        }
                    }
                    log.Info("USGS  Connection Error " + ex.Message);
                    throw new WaterOneFlowSourceException("Error connecting to USGS: WebException: " + url);
                }
                catch (XmlException ex)
                {
                    log.Info("Error in communication with USGS " + ex.Message);
                    throw new WaterOneFlowSourceException("Error in communication with USGS: XmlExpcetion ");
                }
                catch (XsltException ex)
                {
                    log.Info("Error in communication with USGS " + ex.Message);
                    throw new WaterOneFlowSourceException("Error in communication with USGS: XsltException ");
                }
                catch (Exception ex)
                {
                    log.Info("Error in communication with USGS " + ex.Message);
                    throw new WaterOneFlowSourceException("Error in communication with USGS: Unknown Exception ");
                }
            }
コード例 #8
0
            /*
             * public  TimeSeriesResponseType GetValues(
             *  locationParam Location,
             *   VariableParam Variable,
             *   W3CDateTime? BeginDateTime, W3CDateTime? EndDateTime)
             */



            public override WaterOneFlow.Service.Response.v1_1.TimeSeriesResponseType GetTimeSeries(
                locationParam lp,
                VariableParam vp,
                Nullable <W3CDateTime> startDate,
                Nullable <W3CDateTime> endDate)
            {
                // put the date check up front.
                // a start date can be older than 31 days, as long as the endDate is not older than 31 days.

                if (endDate.HasValue && endDate.Value.DateTime < DateTime.Today.AddDays(-31))
                {
                    throw new WaterOneFlowException("No Data. EndDate must be less than that 31 days from present.");
                }

                TimeSeriesResponseType result = null;

                string[] StationsList = new string[] { lp.SiteCode };

                result = CuahsiBuilder.CreateTimeSeriesObject();


                result.queryInfo.criteria.locationParam = lp.ToString();
                result.queryInfo.criteria.variableParam = vp.ToString();

                // not fully correct, but just choose the first one.
                VariableInfoType[] vits = DataInfoService.GetVariableInfoObject(vp);
                result.timeSeries.variable = vits[0];

                string aUrl = UnitValues(startDate, endDate,
                                         new string[] { vp.Code }, StationsList);

                try
                {
                    // refactor too much abstraction
                    //CreateRealTimeSeriesObject(result, RealTime(StationsList));
                    result.timeSeries.values    = new TsValuesSingleVariableType[1];
                    result.timeSeries.values[0] =
                        USGSCommon.CreateTimeSeriesValuesElement(vp,
                                                                 aUrl,
                                                                 true // add provisional flag
                                                                 );
                }
                catch (Exception e)
                {
                    log.Error(e.Message + e.StackTrace);
                    throw new WaterOneFlowException("An External resource failed.", e);
                }


                // all data are provisional
                List <NoteType> notes = new List <NoteType>();
                NoteType        pNote = new NoteType();

                pNote.title = "USGS Data Provisional";
                pNote.href  = "http://waterdata.usgs.gov/nwis/help/?provisional";
                pNote.Value = "All data are provisional, and subject to revision";
                notes.Add(pNote);

                NoteType urlNote = new NoteType();

                urlNote.title = "USGS URL";
                urlNote.Value = aUrl;
                notes.Add(urlNote);

                result.queryInfo.note = notes.ToArray();

                return(new WaterOneFlow.Service.v1_1.xsd.TimeSeriesResponse(result));
            }
コード例 #9
0
            public override object GetTimeSeries(
                locationParam Location,
                VariableParam Variable,
                W3CDateTime?BeginDateTime, W3CDateTime?EndDateTime)
            {
                string siteNum;

                string parameterCode;
                string statisticCode;
                string agencyCode    = "USGS";
                string startDateTime = "";
                string endDateTime   = "";

                if (Location.isGeometry)
                {
                    throw new WaterOneFlowException("Geometry not supported ");
                }

                if (Location != null)
                {
                    siteNum = Location.SiteCode;
                    if (Location.options.ContainsKey("agency"))
                    {
                        agencyCode = Location.options["agency"].Trim();
                    }
                }
                else
                {
                    throw new WaterOneFlowException("Missing SiteCode ");
                }

                if (Variable != null)
                {
                    parameterCode = Variable.Code;
                    statisticCode = option2UsgsStatCode(Variable);
                    //  agencyCode = option2AgencyCode(Variable);
                }
                else
                {
                    throw new WaterOneFlowException("Missing Parameter ");
                }
                if (BeginDateTime.HasValue)
                {
                    startDateTime = BeginDateTime.Value.DateTime.ToString("yyyy-MM-dd");
                }
                if (EndDateTime.HasValue)
                {
                    endDateTime = EndDateTime.Value.DateTime.ToString("yyyy-MM-dd");
                }

                //http://waterservices.usgs.gov/WOF/InstantaneousValues?location=06869950&variable=00065&period=P1D
                //string urlFormat = "http://{0}/{1}?location={2}&variable={3}&period=P{4}D";
                //string url = string.Format(urlFormat, "waterservices.usgs.gov",
                //                           "WOF/InstantaneousValues",
                //                           siteNum,
                //                           parameterCode,
                //                           span.Days);
                //   string urlFormat = "{0}?location={1}&variable={2}&startDate={3}&endDate={4}";
                string urlFormat = "{0}?SiteNum={1}&ParameterCode={2}&StartDate={3}&EndDate={4}&StatisticCode={5}&AgencyCode={6}";

                string url = string.Format(urlFormat, USGSUVBaseUrl,
                                           locationParam.SiteCodeRemoveOption(siteNum),
                                           parameterCode,
                                           startDateTime,
                                           endDateTime,
                                           statisticCode,
                                           agencyCode);


                try
                {
                    Uri uri = new Uri(url);
                    using (WebClient web = new WebClient())
                    {
                        TimeSeriesResponseType response;


                        using (XmlReader reader = new XmlTextReader(web.OpenRead(url)))
                        {
                            XmlWriter    writer       = null;
                            MemoryStream memoryStream = new MemoryStream();
                            try
                            {
                                writer = XmlWriter.Create(memoryStream);
                                // Create the XsltArgumentList.
                                XsltArgumentList argList = new XsltArgumentList();

                                argList.AddParam("network", "", Location.Network);
                                argList.AddParam("vocabulary", "", Variable.Vocabulary);
                                argList.AddParam("location", "", Location.ToString());
                                argList.AddParam("variable", "", Variable.ToString());
                                argList.AddParam("starttime", "", startDateTime);
                                argList.AddParam("endtime", "", endDateTime);
                                ;


                                xslt.Transform(reader, argList, writer);
                                memoryStream.Position = 0;
                                using (var reader2 = XmlReader.Create(memoryStream))
                                {
                                    response
                                        = (TimeSeriesResponseType)serializer.Deserialize(reader2);
                                }
                            }
                            finally
                            {
                                memoryStream.Close();
                            }
                        }
                        return(response);
                    }
                }
                catch (WebException ex)
                {
                    if (ex.Response is HttpWebResponse)
                    {
                        switch (((HttpWebResponse)ex.Response).StatusCode)
                        {
                        case HttpStatusCode.NotFound:
                            log.Info("USGS  Not Found" + ex.Message);
                            throw new WaterOneFlowSourceException("USGS Site/Variable combination Not Found");
                            break;

                        case HttpStatusCode.ServiceUnavailable:
                            log.Info("USGS  Service Not Available " + ex.Message);
                            throw new WaterOneFlowSourceException("USGS Service Not Available. Please try later");
                            break;

                        default:
                            log.Info("USGS  Connection Error " + ex.Message);
                            throw new WaterOneFlowSourceException("Error connecting to USGS");
                        }
                    }
                    log.Info("USGS  Connection Error " + ex.Message);
                    throw new WaterOneFlowSourceException("Error connecting to USGS: WebException: " + url);
                }
                catch (XmlException ex)
                {
                    log.Info("Error in communication with USGS " + ex.Message);
                    throw new WaterOneFlowSourceException("Error in communication with USGS: XmlExpcetion ");
                }
                catch (XsltException ex)
                {
                    log.Info("Error in communication with USGS " + ex.Message);
                    throw new WaterOneFlowSourceException("Error in communication with USGS: XsltException ");
                }
                catch (Exception ex)
                {
                    log.Info("Error in communication with USGS " + ex.Message);
                    throw new WaterOneFlowSourceException("Error in communication with USGS: Unknown Exception ");
                }
            }
コード例 #10
0
        public override TimeSeriesResponseType GetTimeSeries(
            locationParam Location,
            VariableParam Variable,
            W3CDateTime?BeginDateTime, W3CDateTime?EndDateTime)
        {
            string siteNum;
            string parameterCode;
            string statisticCode;
            string agencyCode;
            string startDateTime = null;
            string endDateTime   = null;

            if (Location != null)
            {
                siteNum = Location.SiteCode;
            }
            else
            {
                throw new WaterOneFlowException("Missing SiteCode ");
            }

            if (Variable != null)
            {
                parameterCode = Variable.Code;
            }
            else
            {
                throw new WaterOneFlowException("Missing Parameter ");
            }

            if (BeginDateTime.HasValue)
            {
                startDateTime = BeginDateTime.Value.DateTime.ToString("yyyy-MM-dd");
            }
            if (EndDateTime.HasValue)
            {
                endDateTime = EndDateTime.Value.DateTime.ToString("yyyy-MM-dd");
            }
            edu.sdsc.river.TimeSeriesResponseType valuesResponse = null;
            try
            {
                valuesResponse = svc.GetValuesObject(Location.ToString(),

                                                     Variable.ToString(),
                                                     startDateTime, endDateTime,
                                                     null
                                                     );
            }
            catch
            {
                log.Info("DailyValue Connection Error ");
                throw new WaterOneFlowSourceException("Error connecting to Values Service");
            }

            Stream xStream = new MemoryStream();

            serializer.Serialize(xStream, valuesResponse);
            TimeSeriesResponseType res = (TimeSeriesResponseType)serializer.Deserialize(xStream);

            // this was for string responses
            //TimeSeriesResponseType res = reserializeResponse(WebServiceSerializer.Serialize(valuesResponse));

            List <note> notes;

            if (res.queryInfo.note != null)
            {
                notes = new List <note>(res.queryInfo.note);
            }
            else
            {
                notes = new List <note>();
            }
            note urlNote = new note();

            urlNote.title = "CUAHSI Data Source";
            urlNote.href  = svc.Url;
            urlNote.Value = "Retrieved from WaterML Soap Interface";
            notes.Add(urlNote);
            res.queryInfo.note = notes.ToArray();


            return(res);
        }