public static void UspGetUSGSDataBySite(SqlInt32 site) { ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://waterservices.usgs.gov/nwis/iv/?format=waterml,2.0&indent=on&sites=" + site + "&siteStatus=all"); request.Method = "GET"; request.ContentLength = 0; request.ContentType = "application/xml"; request.Accept = "application/xml"; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream receiveStream = response.GetResponseStream()) { using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) { string strContent = readStream.ReadToEnd(); XmlDocument xdoc = new XmlDocument(); xdoc.LoadXml(strContent); SqlDataRecord record = new SqlDataRecord(new SqlMetaData("USGS_XML", SqlDbType.Xml)); record.SetSqlXml(0, new SqlXml(new XmlNodeReader(xdoc))); SqlContext.Pipe.Send(record); } } } }
internal static void PushSingleRecordResult(object result, System.Data.SqlDbType sqlDBType) { //SqlContext.Pipe.Send("Response output:\n"); //SqlContext.Pipe.Send(result.ToString()); SqlDataRecord record = null; switch (sqlDBType) { case System.Data.SqlDbType.NVarChar: case System.Data.SqlDbType.VarChar: record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("Result", sqlDBType, -1) }); record.SetString(0, result.ToString()); break; case System.Data.SqlDbType.Xml: record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("Result", sqlDBType) }); SqlXml xml; using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(new System.IO.StringReader(result.ToString()))) { xml = new SqlXml(reader); } record.SetSqlXml(0, xml); break; case System.Data.SqlDbType.Int: record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("Result", sqlDBType) }); record.SetInt32(0, (Int32)result); break; default: throw new ArgumentException("SqlDbType " + sqlDBType.ToString() + " is not supported by PushSingleRecordResult."); } SqlContext.Pipe.SendResultsStart(record); SqlContext.Pipe.SendResultsRow(record); SqlContext.Pipe.SendResultsEnd(); }
public static void ListQueuesProc( SqlString accountName, SqlString sharedKey, SqlBoolean useHTTPS, SqlString prefix, SqlBoolean IncludeMetadata, SqlInt32 timeoutSeconds, SqlGuid xmsclientrequestId) { ITPCfSQL.Azure.AzureQueueService aqs = new AzureQueueService(accountName.Value, sharedKey.Value, useHTTPS.Value); //SqlContext.Pipe.Send("Created " + aqs); List <ITPCfSQL.Azure.Queue> lQueues = aqs.ListQueues( prefix != null ? prefix.Value : null, IncludeMetadata.Value, timeoutSeconds.Value, xmsclientrequestId.IsNull ? (Guid?)null : xmsclientrequestId.Value); for (int i = 0; i < lQueues.Count; i++) { SqlDataRecord record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("Name", System.Data.SqlDbType.NVarChar, 4000), new SqlMetaData("Url", System.Data.SqlDbType.NVarChar, 4000), new SqlMetaData("Metadata", System.Data.SqlDbType.Xml) }); record.SetString(0, lQueues[i].Name); record.SetString(1, lQueues[i].Url.ToString()); if (IncludeMetadata) { System.IO.MemoryStream ms = new System.IO.MemoryStream(); using (System.Xml.XmlWriter wr = System.Xml.XmlWriter.Create(ms)) { wr.WriteStartElement("MetadataList"); foreach (string s in lQueues[i].Metadata.Keys) { wr.WriteStartElement(s); wr.WriteString(lQueues[i].Metadata[s]); wr.WriteEndElement(); } wr.WriteEndElement(); wr.Flush(); wr.Close(); } ms.Seek(0, System.IO.SeekOrigin.Begin); record.SetSqlXml(2, new SqlXml(ms)); } if (i == 0) { SqlContext.Pipe.SendResultsStart(record); } SqlContext.Pipe.SendResultsRow(record); if ((i + 1) >= lQueues.Count) { SqlContext.Pipe.SendResultsEnd(); } } }