/// <summary>
        /// Creates the HTTP SOAP web request for GetValues method
        /// </summary>
        /// <param name="dataCart">The series data cart containing the GetValues parameters</param>
        /// <returns>Returns the fully initialized web request object</returns>
        public static HttpWebRequest CreatePostRequest(SeriesDataCart dataCart)
        {
            string url = dataCart.ServURL;
            string fullSiteCode = dataCart.SiteCode;
            string fullVariableCode = dataCart.VariableCode;
            DateTime startDate = dataCart.BeginDate;
            DateTime endDate = dataCart.EndDate;

            url = url.Trim().ToLower();
            //for http request, we need to remove the ?WSDL part from the url
            if (url.EndsWith("?wsdl"))
            {
                url = url.Replace("?wsdl", "");
            }

            //get the valid SOAP namespace
            string soapNamespace = GetCuahsiSoapNamespace(url);

            //create the SOAP Envelope
            string soapEnvelope = CreateSoapEnvelope(soapNamespace, fullSiteCode, fullVariableCode, startDate, endDate);

            //send the SOAP envelope to the service as a xml document
            XmlDocument doc = new XmlDocument();
            doc.Load(new StringReader(soapEnvelope));

            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

            //this is the valid SoapAction header for GetValues web method
            string soapAction = soapNamespace + "GetValuesObject";

            req.Headers.Add("SOAPAction", soapAction);

            req.ContentType = "text/xml;charset=\"utf-8\"";
            req.Accept = "text/xml";
            req.Method = "POST";
            Stream stm = req.GetRequestStream();
            doc.Save(stm);
            stm.Close();

            return req;
        }
 /// <summary>
 /// Gets the name of the data cart
 /// </summary>
 /// <param name="cart">the series data cart object</param>
 /// <returns>the unique name of the series data cart</returns>
 public static string GetDataCartName(SeriesDataCart cart)
 {
     string str = String.Format("{0}-{1}", cart.SiteCode, cart.VariableCode);
     string str2 = str.Replace("/", "_");
     string str3 = str2.Replace(@"\", "_");
     string str4 = str3.Replace(":", "_");
     return str4;
 }
 /// <summary>
 /// Given a Series Data cart, creates a GetValues web request
 /// </summary>
 /// <param name="dc">the series data cart containing information about the site, variable, begin data and end date</param>
 /// <returns>the web request for getting the values</returns>
 public static HttpWebRequest CreateGetValuesRequest(SeriesDataCart dc)
 {
     return CreateGetValuesRequest(dc.ServURL, dc.SiteCode, dc.VariableCode, dc.BeginDate, dc.EndDate);
 }
Example #4
0
        /// <summary>
        /// Read the list of series from the XML that is returned by HIS Central
        /// </summary>
        /// <param name="reader">the xml reader</param>
        /// <returns>the list of intermediate 'SeriesDataCart' objects</returns>
        private SeriesDataCart ReadSeriesFromHISCentral(XmlReader reader)
        {
            var series = new SeriesDataCart();
            while (reader.Read())
            {
                var nodeName = reader.Name.ToLower();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (nodeName)
                    {
                        case "servcode":
                            reader.Read();
                            series.ServCode = reader.Value;
                            break;
                        case "servurl":
                            reader.Read();
                            series.ServURL = reader.Value;
                            break;
                        case "location":
                            reader.Read();
                            series.SiteCode = reader.Value;
                            break;
                        case "varcode":
                            reader.Read();
                            series.VariableCode = reader.Value;
                            break;
                        case "varname":
                            reader.Read();
                            series.VariableName = reader.Value;
                            break;
                        case "begindate":
                            reader.Read();
                            if (!String.IsNullOrWhiteSpace(reader.Value))
                                series.BeginDate = Convert.ToDateTime(reader.Value, _invariantCulture);
                            else
                                return null;
                            break;
                        case "enddate":
                            reader.Read();
                            if (!String.IsNullOrWhiteSpace(reader.Value))
                                series.EndDate = Convert.ToDateTime(reader.Value, _invariantCulture);
                            else
                                return null;
                            break;
                        case "valuecount":
                            reader.Read();
                            if (!String.IsNullOrWhiteSpace(reader.Value))
                                series.ValueCount = Convert.ToInt32(reader.Value);
                            else
                                return null;
                            break;
                        case "sitename":
                            reader.Read();
                            series.SiteName = reader.Value;
                            break;
                        case "latitude":
                            reader.Read();
                            if (!String.IsNullOrWhiteSpace(reader.Value))
                                series.Latitude = Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture);
                            else
                                return null;
                            break;
                        case "longitude":
                            reader.Read();
                            if (!String.IsNullOrWhiteSpace(reader.Value))
                                series.Longitude = Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture);
                            else
                                return null;
                            break;
                        case "datatype":
                            reader.Read();
                            series.DataType = reader.Value;
                            break;
                        case "valuetype":
                            reader.Read();
                            series.ValueType = reader.Value;
                            break;
                        case "samplemedium":
                            reader.Read();
                            series.SampleMedium = reader.Value;
                            break;
                        case "timeunits":
                            reader.Read();
                            series.TimeUnit = reader.Value;
                            break;
                        case "conceptkeyword":
                            reader.Read();
                            series.ConceptKeyword = reader.Value;
                            break;
                        case "gencategory":
                            reader.Read();
                            series.GeneralCategory = reader.Value;
                            break;
                        case "timesupport":
                            reader.Read();
                            if (!String.IsNullOrWhiteSpace(reader.Value))
                                series.TimeSupport = Convert.ToDouble(reader.Value, CultureInfo.InvariantCulture);
                            break;
                        case "isregular":
                            reader.Read();
                            if (!String.IsNullOrWhiteSpace(reader.Value))
                                series.IsRegular = Convert.ToBoolean(reader.Value);
                            break;
                        case "variableunits":
                            reader.Read();
                            series.VariableUnits = reader.Value;
                            break;
                    }
                }
                else if (reader.NodeType == XmlNodeType.EndElement && nodeName == "seriesrecord")
                {
                    return series;
                }
            }

            return null;
        }
Example #5
0
 private static void PopulateDataRow(SeriesDataCart series, DataRow row)
 {
     row["DataSource"] = series.ServCode;
     row["SiteName"] = series.SiteName;
     row["VarName"] = series.VariableName;
     row["SiteCode"] = series.SiteCode;
     row["VarCode"] = series.VariableCode;
     row["Keyword"] = series.ConceptKeyword;
     row["ValueCount"] = series.ValueCount;
     row["StartDate"] = series.BeginDate.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
     row["EndDate"] = series.EndDate.ToString("yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
     row["ServiceURL"] = series.ServURL;
     row["ServiceCode"] = series.ServCode;
     row["DataType"] = series.DataType;
     row["ValueType"] = series.ValueType;
     row["SampleMed"] = series.SampleMedium;
     row["TimeUnits"] = series.TimeUnit;
     row["TimeSupport"] = series.TimeSupport;
     row["Latitude"] = series.Latitude;
     row["Longitude"] = series.Longitude;
     row["IsRegular"] = series.IsRegular;
     row["Units"] = series.VariableUnits;
 }
Example #6
0
        /// <summary>
        /// Adds series to an existing feature set
        /// </summary>
        /// <param name="series">Series</param>
        /// <param name="fs">Feature set</param>
        private static void AddToFeatureSet(SeriesDataCart series, IFeatureSet fs)
        {
            double lat = series.Latitude;
            double lon = series.Longitude;
            var coord = new Coordinate(lon, lat);

            var f = new Feature(FeatureType.Point, new[] {coord});
            fs.Features.Add(f);

            var row = f.DataRow;
            PopulateDataRow(series, row);
        }
Example #7
0
        /// <summary>
        /// Updates  BeginDate/EndDate/ValueCount in the SeriesDataCart to the user-specified range
        /// </summary>
        /// <param name="series">Series to update</param>
        /// <param name="startDate">User-specified startDate</param>
        /// <param name="endDate">User-specified endDate</param>
        public static void UpdateDataCartToDateInterval(SeriesDataCart series, DateTime startDate, DateTime endDate)
        {
            // Update BeginDate/EndDate/ValueCount to the user-specified range
            var seriesStartDate = series.BeginDate < startDate ? startDate : series.BeginDate;
            // Fix http://hydrodesktop.codeplex.com/workitem/8468
            // HIS Central sometimes doesn't contains actual end dates for datasets,
            // so always set end date of series to user-specified endDate.
            var seriesEndDate = endDate; //var seriesEndDate = series.EndDate > endDate ? endDate : series.EndDate;

            var serverDateRange = series.EndDate.Subtract(series.BeginDate);
            var userDateRange = seriesEndDate.Subtract(seriesStartDate);

            var userFromServerPercentage = serverDateRange.TotalDays > 0
                                               ? userDateRange.TotalDays / serverDateRange.TotalDays
                                               : 1.0;
            if (userFromServerPercentage > 1.0)
                userFromServerPercentage = 1.0;
            var esimatedValueCount = (int)(series.ValueCount * userFromServerPercentage);

            series.ValueCount = esimatedValueCount;
            series.BeginDate = seriesStartDate;
            series.EndDate = seriesEndDate;
        }