Beispiel #1
0
 private BaseParams BuildAddressParams(Pair <string, string> stateParam, Pair <string, string> cityParam, Pair <string, string> districtParam, Pair <string, string> streetParam, Pair <string, string> numberParam, Pair <string, string> radiusParam, List <string> filters)
 {
     try
     {
         return(new AddressParams
         {
             State = stateParam.Value.ToUpper().RemoveAccents(),
             City = cityParam.Value.ToUpper().RemoveAccents(),
             District = (districtParam.Value ?? "").ToUpper().RemoveAccents(),
             Street = streetParam.Value.ToUpper().RemoveAccents(),
             Number = numberParam.Value,
             Radius = double.Parse(radiusParam.Value, Utility.GetCultureInfoUS()),
             Filters = filters
         });
     }
     catch (FormatException)
     {
         throw new FormatException(FORMAT_INCORRECT);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Gera um objeto que tem latitude, longitude e raio.
 /// </summary>
 /// <param name="latParam">Latitude</param>
 /// <param name="lngParam">Longitude</param>
 /// <param name="radiusParam">Raio</param>
 /// <returns>Retorna objeto que tem latitude, longitude e raio.</returns>
 private BaseParams BuildLatLngParams(Pair <string, string> latParam, Pair <string, string> lngParam, Pair <string, string> radiusParam, List <string> filters)
 {
     try
     {
         return(new LatLngParams
         {
             Latitude = double.Parse(latParam.Value, Utility.GetCultureInfoUS()),
             Longitude = double.Parse(lngParam.Value, Utility.GetCultureInfoUS()),
             Radius = Convert.ToDouble(radiusParam.Value, Utility.GetCultureInfoUS()),
             Filters = filters
         });
     }
     catch (FormatException)
     {
         throw new FormatException(FORMAT_INCORRECT);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Beispiel #3
0
 private BaseParams BuildLatLngNetParams(Pair <string, string> latCustomerParam, Pair <string, string> lngCustomerParam,
                                         Pair <string, string> latNetParam, Pair <string, string> lngNetParam, List <string> filters)
 {
     try
     {
         return(new LatLngNetParams
         {
             LatCustomer = double.Parse(latCustomerParam.Value, Utility.GetCultureInfoUS()),
             LngCustomer = double.Parse(lngCustomerParam.Value, Utility.GetCultureInfoUS()),
             LatNet = double.Parse(latNetParam.Value, Utility.GetCultureInfoUS()),
             LngNet = double.Parse(lngNetParam.Value, Utility.GetCultureInfoUS()),
             Filters = filters
         });
     }
     catch (FormatException)
     {
         throw new FormatException(FORMAT_INCORRECT);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Beispiel #4
0
        private BaseParams CheckParameters()
        {
            var foundParameters = Request.QueryString.AllKeys.Where(x => x != null).Select(x => x.ToLower());

            /* Se não existir parâmetros na url mostre o mapa sem elementos*/
            if (foundParameters.Count() == 0)
            {
                return(null);
            }

            var filterParam      = new Pair <string, string>(FILTER_PARAM, Request.QueryString[FILTER_PARAM]);
            var latParam         = new Pair <string, string>(LAT_PARAM, Request.QueryString[LAT_PARAM]);
            var lngParam         = new Pair <string, string>(LNG_PARAM, Request.QueryString[LNG_PARAM]);
            var radiusParam      = new Pair <string, string>(RADIUS_PARAM, Request.QueryString[RADIUS_PARAM]);
            var radiusCTOParam   = new Pair <string, string>(RADIUS_CTO_PARAM, Request.QueryString[RADIUS_CTO_PARAM]);
            var latCustomerParam = new Pair <string, string>(LAT_CUSTOMER_PARAM, Request.QueryString[LAT_CUSTOMER_PARAM]);
            var lngCustomerParam = new Pair <string, string>(LNG_CUSTOMER_PARAM, Request.QueryString[LNG_CUSTOMER_PARAM]);
            var latNetParam      = new Pair <string, string>(LAT_NET_PARAM, Request.QueryString[LAT_NET_PARAM]);
            var lngNetParam      = new Pair <string, string>(LNG_NET_PARAM, Request.QueryString[LNG_NET_PARAM]);
            var stateParam       = new Pair <string, string>(STATE_PARAM, Request.QueryString[STATE_PARAM]);
            var cityParam        = new Pair <string, string>(CITY_PARAM, Request.QueryString[CITY_PARAM]);
            var districtParam    = new Pair <string, string>(DISTRICT_PARAM, Request.QueryString[DISTRICT_PARAM]);
            var streetParam      = new Pair <string, string>(STREET_PARAM, Request.QueryString[STREET_PARAM]);
            var numberParam      = new Pair <string, string>(NUMBER_PARAM, Request.QueryString[NUMBER_PARAM]);

            var    lstFilters = new List <string>();
            string filters    = "";

            filters = string.IsNullOrEmpty(filterParam.Value) ? "cto,ceo,st" : filterParam.Value.Trim();

            RadiusCTO = radiusCTOParam.Value ?? "0.0";

            if (!erDouble.IsMatch(RadiusCTO))
            {
                throw new FormatException(FORMAT_INCORRECT_RADIUS_CTO);
            }

            foreach (var it in Regex.Split(filters, @"\s*,\s*"))
            {
                switch (it.ToLower())
                {
                case "cto": lstFilters.Add(Constants.ID_CTO); break;

                case "ceo": lstFilters.Add(Constants.ID_CEO); break;

                case "st": lstFilters.Add(Constants.ID_ST); break;

                case "all":
                    lstFilters.Add(Constants.ID_ST);
                    lstFilters.Add(Constants.ID_CEO);
                    lstFilters.Add(Constants.ID_CTO);
                    break;

                case "none": break;

                default: throw new Exception("Valor inválido para filtro. Os valores possíveis são a combinação de: none, cto, ceo, st e all");
                }
            }

            var lstParams = new List <Pair <string, string> >
            {
                filterParam, latParam, lngParam, radiusParam, latCustomerParam, lngCustomerParam,
                latNetParam, lngNetParam, stateParam, cityParam, districtParam, streetParam, numberParam, radiusCTOParam
            };

            var invalidParams = foundParameters.Except(lstParams.Select(x => x.Key.ToLower()));

            /* Se tiver parâmetros na url que não foram previstos é gerado um erro e mostrado na tela */
            if (invalidParams.Count() > 0)
            {
                throw new Exception(string.Format(INVALID_PARAMETERS, string.Join(", ", invalidParams)));
            }

            var sum = lstParams.Select((item, idx) => Convert.ToInt32(Math.Pow(2, idx)) * (item.Value != null ? 1 : 0)).Sum() | 8192 | 1;

            bool latLngOptions             = sum == 8207;
            bool latLngNetCustomersOptions = sum == 8433;
            bool CityStateOptions          = sum == 8961;
            bool AddressOptions            = sum == 15113 || sum == 16137;

            if (latLngOptions)
            {
                return(BuildLatLngParams(latParam, lngParam, radiusParam, lstFilters.Distinct().ToList()));
            }
            else
            if (latLngNetCustomersOptions)
            {
                return(BuildLatLngNetParams(latCustomerParam, lngCustomerParam, latNetParam, lngNetParam, lstFilters.Distinct().ToList()));
            }
            else
            if (CityStateOptions)
            {
                return(BuildCityStateParams(stateParam, cityParam, lstFilters.Distinct().ToList()));
            }
            else
            if (AddressOptions)
            {
                return(BuildAddressParams(stateParam, cityParam, districtParam, streetParam, numberParam, radiusParam, lstFilters.Distinct().ToList()));
            }
            else
            {
                string msgError = new StringBuilder("Parâmetros faltando ou informados incorretamente.<br /><br />")
                                  .Append("Veja alguns exemplos de chamada:<br />")
                                  .Append("<div style=\"font-size:70%\"><ul>")
                                  .Append("<li>http://cm.com.br/mapa/view</li>")
                                  .Append("<li>http://cm.com.br/mapa/view?lat=-18.906300518044&long=-48.2686865991104&raio=150.0&filtro=cto,ceo,st</li>")
                                  .Append("<li>http://cm.com.br/mapa/view?lat_cliente=-18.90630051804&long_cliente=-48.2686865991104&lat_rede=-18.9104572070146&long_rede=-48.2720228619498</li>")
                                  .Append("<li>http://cm.com.br/mapa/view?estado=MG&localidade=UBERLANDIA</li>")
                                  .Append("<li>http://cm.com.br/mapa/view?estado=MG&localidade=UBERLANDIA&bairro=CENTRO</li>")
                                  .Append("<li>http://cm.com.br/mapa/view?estado=MG&localidade=UBERLANDIA&bairro=CENTRO&logradouro=AV+AFONSO+PENA</li>")
                                  .Append("<li>http://cm.com.br/mapa/view?estado=MG&localidade=UBERLANDIA&bairro=CENTRO&logradouro=AV+AFONSO+PENA&numero=20</li>")
                                  .Append("</ul></div>")
                                  .ToString();

                throw new Exception(msgError);
            }
        }