コード例 #1
0
        public static List <GeoReport> getAllGeoReports()
        {
            List <GeoReport> geoReports = new List <GeoReport>();
            GeoReportAccess  access     = new GeoReportAccess();
            DataTable        dtResult   = access.GetGeoReports();

            foreach (DataRow dtr in dtResult.Rows)
            {
                GeoReport item = new GeoReport
                {
                    GEOREPORTCD    = dtr["GEOREPORTCD"].ToString(),
                    DEPTCODE       = dtr["DEPTCODE"].ToString(),
                    SYS_EMPID      = dtr["SYS_EMPID"].ToString(),
                    APPLYDATE      = DateTime.Parse(string.IsNullOrEmpty(dtr["APPLYDATE"].ToString()) ? "1-1-1999" : dtr["APPLYDATE"].ToString()),
                    ISACTIVE       = dtr["ISACTIVE"].ToString(),
                    POSITION       = dtr["POSITION"].ToString(),
                    SKILL          = dtr["SKILL"].ToString(),
                    REMARK         = dtr["REMARK"].ToString(),
                    GEOREPORTLEVEL = dtr["GEOREPORTLEVEL"].ToString(),
                    CREATE_UID     = dtr["CREATE_UID"].ToString(),
                    CREATE_DT      = dtr["CREATE_DT"].ToString(),
                    UPDATE_UID     = dtr["UPDATE_UID"].ToString(),
                    UPDATE_DT      = dtr["UPDATE_DT"].ToString(),
                };
                geoReports.Add(item);
            }
            return(geoReports);
        }
コード例 #2
0
        public static WeatherReport GetWeatherForecast(ref TempDataDictionary data, GeoReport geoReport)
        {
            string   weatherKey = WebConfigurationManager.AppSettings["weatherKey"];
            string   weatherUri;
            DateTime?dateTime = (DateTime?)data["datetime"];

            try
            {
                Location coordinates = geoReport.results.First().geometry.location;
                weatherUri = String.Format("https://api.darksky.net/forecast/{0}/{1},{2}", weatherKey, coordinates.lat, coordinates.lng);
                if (dateTime != null)
                {
                    weatherUri += "," + ((DateTimeOffset)dateTime).ToUnixTimeSeconds();
                }
            }
            catch (Exception ex)
            {
                data["errorMessage"] = "Could not find coordinates for location.";
                return(null);
            }

            // call Weather API
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpResponseMessage response = client.GetAsync(weatherUri).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        string weatherJson = response.Content.ReadAsStringAsync().Result;
                        data["weatherJson"] = weatherJson;
                        WeatherReport weatherReport = JsonConvert.DeserializeObject <WeatherReport>(weatherJson);
                        //data["chart1"] = setChart1(weatherReport);
                        //data["chart2"] = setChart2(weatherReport);
                        //data["chart3"] = setChart3(weatherReport);
                        //data["chart4"] = setChart4(weatherReport);
                        return(weatherReport);
                    }
                    else
                    {
                        throw new HttpRequestException("Bad Request.");
                    }
                }
            }
            catch (HttpRequestException)
            {
                data["errorMessage"] = "Could not find weather data.";
            }
            return(null);
        }
コード例 #3
0
        public static GeoReport GetGeoLocation(ref TempDataDictionary data, string location, string dateTime)
        {
            data["location"] = location;
            try
            {
                data["dateTime"] = String.IsNullOrEmpty(dateTime) ? null : (DateTime?)Convert.ToDateTime(dateTime);
            }
            catch (Exception ex)
            {
                data["errorMessage"] = "Unrecognizable date format.";
                return(null);
            }
            string geoKey = WebConfigurationManager.AppSettings["geoKey"];
            string geoUri = String.Format("https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}", location, geoKey);

            // call Geo API
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpResponseMessage response = client.GetAsync(geoUri).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        string geoJson = response.Content.ReadAsStringAsync().Result;
                        data["geoJson"] = geoJson;
                        GeoReport geoReport = JsonConvert.DeserializeObject <GeoReport>(geoJson);
                        return(geoReport);
                    }
                    throw new HttpRequestException("Bad Request.");
                }
            }
            catch (HttpRequestException)
            {
                data["errorMessage"] = "Could not find location.";
            }
            return(null);
        }