public List <DirectionStep> GetDirections(string origin, string destination)
        {
            string  strcurpath = Directory.GetCurrentDirectory() + '\\' + "umass.ini";
            Inifile configfile = new Inifile(strcurpath);

            if (!configfile.ExistINIFile())
            {
                Console.WriteLine("Configure file does not exist.");
                return(null);
            }
            else
            {
                string requestUrl = configfile.IniReadValue("WebService", "WS_URL_DIR");
                var    URL        = string.Format(requestUrl, origin, destination);
                try
                {
                    var client = new WebClient();
                    var result = client.DownloadString(URL);
                    return(ParseDirectionResults(result));
                }
                catch (Exception ex)
                {
                    RecordLog("client.DownloadString", ex.Message);
                    return(null);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string  strcurpath = Directory.GetCurrentDirectory() + '\\' + "umass.ini";
            Inifile configfile = new Inifile(strcurpath);

            if (!configfile.ExistINIFile())
            {
                Console.WriteLine("Configure file does not exist.");
            }

            string conStr_UMS = configfile.IniReadValue("ConnectStrings", "DBconnect");

            SqlCommand    command;
            SqlDataReader reader;


            //----------------------------------------------------
            //Get Postal Address which request to get GEO code
            //call SP [usp_List_PostalAddressGEOCode]
            //----------------------------------------------------
            SqlConnection Conn_UMS = new SqlConnection(conStr_UMS);

            command             = new SqlCommand("[ElkhornDataAccess].[usp_List_PostalAddressGEOCode]", Conn_UMS);
            command.CommandType = CommandType.StoredProcedure;
            reader = null;

            Int32  ContactMechanismID = 0;
            string Latitude           = string.Empty;
            string Longitude          = string.Empty;
            string AddressLine1       = string.Empty;
            string AddressLine2       = string.Empty;
            string AddressLine3       = string.Empty;

            try
            {
                if (Conn_UMS.State == ConnectionState.Closed)
                {
                    Conn_UMS.Open();
                }

                reader = command.ExecuteReader();
                do
                {
                    while (reader.Read())
                    {
                        ContactMechanismID = Convert.ToInt32(reader["ContactMechanismID"].ToString());
                        AddressLine1       = reader["AddressLine1"].ToString();
                        AddressLine2       = reader["AddressLine2"].ToString();
                        AddressLine3       = reader["AddressLine3"].ToString();

                        //Call webservice to get two places distance.
                        DistanceCalc       distanceCalc = new DistanceCalc();
                        List <GEOCodeStep> addrs        = new List <GEOCodeStep>();
                        addrs = distanceCalc.GetGEOCode(AddressLine1);
                        foreach (GEOCodeStep addr in addrs)
                        {
                            Latitude  = addr.lat;
                            Longitude = addr.lng;
                        }

                        //Use address2 or address3 to get GEO code the address1 returns ZERO_RESULTS
                        if (Latitude == "ZERO_RESULTS")
                        {
                            addrs = distanceCalc.GetGEOCode(AddressLine2);
                            foreach (GEOCodeStep addr in addrs)
                            {
                                Latitude  = addr.lat;
                                Longitude = addr.lng;
                            }

                            if (Latitude == "ZERO_RESULTS")
                            {
                                addrs = distanceCalc.GetGEOCode(AddressLine3);
                                foreach (GEOCodeStep addr in addrs)
                                {
                                    Latitude  = addr.lat;
                                    Longitude = addr.lng;
                                }
                            }
                        }

                        CallSP_usp_Update_PostalAddress
                        (
                            conStr_UMS,
                            ContactMechanismID,
                            Latitude,
                            Longitude
                        );

                        //Reset variable
                        ContactMechanismID = 0;
                        Latitude           = string.Empty;
                        Longitude          = string.Empty;
                        AddressLine1       = string.Empty;
                        AddressLine2       = string.Empty;
                        AddressLine3       = string.Empty;
                    }
                }while (reader.NextResult());

                if (reader != null)
                {
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                RecordLog(" Failed to call SP usp_List_PostalAddressGEOCode", ex.Message);
            }
            finally
            {
                if (Conn_UMS != null && Conn_UMS.State == ConnectionState.Open)
                {
                    Conn_UMS.Close();
                }
            }
        }