Example #1
0
        protected virtual string ToMarkerColor(BusinessRulesBase rules, JObject autofill)
        {
            var color = ((string)(autofill["markerColor"]));

            if (string.IsNullOrEmpty(color))
            {
                color = "red";
            }
            return(color);
        }
Example #2
0
        protected virtual string ToZoom(BusinessRulesBase rules, JObject autofill)
        {
            var zoom = ((string)(autofill["zoom"]));

            if (string.IsNullOrEmpty(zoom))
            {
                zoom = "16";
            }
            return(zoom);
        }
Example #3
0
        protected virtual string ToMarkerSize(BusinessRulesBase rules, JObject autofill)
        {
            var size = ((string)(autofill["markerSize"]));

            if (string.IsNullOrEmpty(size))
            {
                size = "mid";
            }
            return(size);
        }
Example #4
0
        protected virtual string ToScale(BusinessRulesBase rules, JObject autofill)
        {
            var scale = ((string)(autofill["scale"]));

            if (string.IsNullOrEmpty(scale))
            {
                scale = "1";
            }
            return(scale);
        }
Example #5
0
        protected virtual string ToMapType(BusinessRulesBase rules, JObject autofill)
        {
            var mapType = ((string)(autofill["mapType"]));

            if (string.IsNullOrEmpty(mapType))
            {
                mapType = "roadmap";
            }
            return(mapType);
        }
Example #6
0
        protected virtual string ToMarkerList(BusinessRulesBase rules, JObject autofill)
        {
            // try lat & lng
            var lat = ((string)(autofill["latitude"]));
            var lng = ((string)(autofill["longitude"]));

            if (!(string.IsNullOrEmpty(lat)) && !(string.IsNullOrEmpty(lng)))
            {
                return(string.Format("{0},{1}", lat, lng));
            }
            else
            {
                var mb = new List <string>();
                // address 1
                var addr1 = ((string)(autofill["address1"]));
                if (!(string.IsNullOrEmpty(addr1)))
                {
                    mb.Add(addr1);
                }
                // city
                var city = ((string)(autofill["city"]));
                if (!(string.IsNullOrEmpty(city)))
                {
                    mb.Add(city);
                }
                // region
                var region = ((string)(autofill["region"]));
                if (!(string.IsNullOrEmpty(region)))
                {
                    mb.Add(region);
                }
                // postalcode
                var postalCode = ((string)(autofill["postalcode"]));
                if (string.IsNullOrEmpty(postalCode))
                {
                    postalCode = ((string)(autofill.GetValue("componentpostalcode", StringComparison.OrdinalIgnoreCase)));
                }
                if (!(string.IsNullOrEmpty(postalCode)))
                {
                    mb.Add(postalCode);
                }
                // country
                var country = ((string)(autofill["country"]));
                if (!(string.IsNullOrEmpty(country)))
                {
                    mb.Add(country);
                }
                return(string.Join(",", mb.ToArray()).Replace(" ", "+"));
            }
        }
Example #7
0
        public static void Evaluate(BusinessRulesBase rules)
        {
            var args = rules.Arguments;

            if ((args.CommandName == "AutoFill") && !(string.IsNullOrEmpty(rules.View)))
            {
                var      autofill = JObject.Parse(args.Trigger);
                AutoFill handler  = null;
                if (Handlers.TryGetValue(((string)(autofill["autofill"])), out handler) && handler.Supports(autofill))
                {
                    var result = handler.Process(rules, autofill);
                    rules.Result.Values.Add(new FieldValue("AutoFill", result.ToString()));
                }
            }
        }
Example #8
0
        protected override JToken Process(BusinessRulesBase rules, JObject autofill)
        {
            var requestUrl        = CreateRequestUrl(rules, autofill);
            var outputAddressList = new JArray();

            using (var client = new WebClient())
            {
                client.Headers["Accept-Language"] = Language();
                var addressJson = JObject.Parse(Encoding.UTF8.GetString(client.DownloadData(requestUrl)));
                var addressList = ((JArray)(addressJson["results"]));
                foreach (JToken address in addressList)
                {
                    var componentList     = address["address_components"];
                    var addressComponents = new JObject();
                    foreach (var component in componentList)
                    {
                        var types     = ((string[])(component["types"].ToObject(typeof(string[]))));
                        var shortName = ((string)(component["short_name"]));
                        var longName  = ((string)(component["long_name"]));
                        foreach (var componentType in types)
                        {
                            if (componentType != "political")
                            {
                                addressComponents[componentType]             = shortName;
                                addressComponents[(componentType + "_long")] = longName;
                            }
                        }
                    }
                    var normalizedAddressComponents = new JObject();
                    foreach (var p in addressComponents)
                    {
                        normalizedAddressComponents[p.Key.Replace("_", string.Empty)] = p.Value;
                    }
                    outputAddressList.Add(new JObject(new JProperty("name", address["formatted_address"]), new JProperty("address1", Format("address1", addressComponents)), new JProperty("address2", Format("address2", addressComponents, ((string)(autofill["address2"])))), new JProperty("address3", Format("address3", addressComponents, ((string)(autofill["address3"])))), new JProperty("city", Format("city", addressComponents)), new JProperty("region", Format("region", addressComponents)), new JProperty("postalcode", Format("postalcode", addressComponents)), new JProperty("country", Format("country", addressComponents)), new JProperty("type", address["types"][0]), new JProperty("latitude", address["geometry"]["location"]["lat"]), new JProperty("longitude", address["geometry"]["location"]["lng"]), new JProperty("components", normalizedAddressComponents), new JProperty("rawAddress", address)));
                }
            }
            try
            {
                ConfirmResult(rules, outputAddressList);
            }
            catch (Exception)
            {
                // do nothing
            }
            return(outputAddressList);
        }
Example #9
0
        protected override JToken Process(BusinessRulesBase rules, JObject autofill)
        {
            var requestUrl = CreateRequestUrl(rules, autofill);
            var result     = new JObject();

            using (var client = new WebClient())
            {
                client.Headers["Accept-Language"] = Language();
                var data        = Convert.ToBase64String(client.DownloadData(requestUrl));
                var contentType = client.ResponseHeaders[HttpResponseHeader.ContentType];
                if (contentType.StartsWith("image"))
                {
                    result["image"]       = data;
                    result["contentType"] = contentType;
                }
            }
            return(result);
        }
Example #10
0
 protected virtual void ConfirmResult(BusinessRulesBase rules, JArray addresses)
 {
     foreach (JToken address in addresses)
     {
         if (((string)(address["components"]["country"])) == "US")
         {
             // try enhancing address by verifying it with USPS
             var serialNo = ((string)(ApplicationServicesBase.Settings("server.geocoding.usps.serialNo")));
             var userName = ((string)(ApplicationServicesBase.Settings("server.geocoding.usps.userName")));
             var password = ((string)(ApplicationServicesBase.Settings("server.geocoding.usps.password")));
             var address1 = ((string)(address["address1"]));
             if (!(string.IsNullOrEmpty(userName)) && !(string.IsNullOrEmpty(address1)))
             {
                 var uspsRequest = new StringBuilder("<VERIFYADDRESS><COMMAND>ZIP1</COMMAND>");
                 uspsRequest.AppendFormat("<SERIALNO>{0}</SERIALNO>", serialNo);
                 uspsRequest.AppendFormat("<USER>{0}</USER>", userName);
                 uspsRequest.AppendFormat("<PASSWORD>{0}</PASSWORD>", password);
                 uspsRequest.Append("<ADDRESS0></ADDRESS0>");
                 uspsRequest.AppendFormat("<ADDRESS1>{0}</ADDRESS1>", address1);
                 uspsRequest.AppendFormat("<ADDRESS2>{0}</ADDRESS2>", address["address2"]);
                 uspsRequest.AppendFormat("<ADDRESS3>{0},{1},{2}</ADDRESS3>", address["city"], address["region"], address["postalcode"]);
                 uspsRequest.Append("</VERIFYADDRESS>");
                 using (var client = new WebClient())
                 {
                     var uspsResponseText = client.DownloadString(("http://www.dial-a-zip.com/XML-Dial-A-ZIP/DAZService.asmx/MethodZIPValidate?input=" +
                                                                   "" + HttpUtility.UrlEncode(uspsRequest.ToString())));
                     var uspsResponse = new XPathDocument(new StringReader(uspsResponseText)).CreateNavigator().SelectSingleNode("/Dial-A-ZIP_Response");
                     if (uspsResponse != null)
                     {
                         address["address1"]   = uspsResponse.SelectSingleNode("AddrLine1").Value;
                         address["address2"]   = uspsResponse.SelectSingleNode("AddrLine2").Value;
                         address["city"]       = uspsResponse.SelectSingleNode("City").Value;
                         address["region"]     = uspsResponse.SelectSingleNode("State").Value;
                         address["postalcode"] = (uspsResponse.SelectSingleNode("ZIP5").Value
                                                  + ("-" + uspsResponse.SelectSingleNode("Plus4").Value));
                         address["components"]["postalcode"]       = uspsResponse.SelectSingleNode("ZIP5").Value;
                         address["components"]["postalcodesuffix"] = uspsResponse.SelectSingleNode("Plus4").Value;
                         address["country"] = address["country"].ToString().ToUpper();
                     }
                 }
             }
         }
     }
 }
Example #11
0
        protected override string CreateRequestUrl(BusinessRulesBase rules, JObject autofill)
        {
            var pb = new List <string>();
            // latitude
            var lat = ((string)(autofill["latitude"]));

            if (!(string.IsNullOrEmpty(lat)))
            {
                pb.Add(lat);
            }
            // longitude
            var lng = ((string)(autofill["longitude"]));

            if (!(string.IsNullOrEmpty(lng)))
            {
                pb.Add(lng);
            }
            return(string.Format("https://maps.googleapis.com/maps/api/geocode/json?latlng={0}&key={1}", HttpUtility.UrlEncode(string.Join(",", pb.ToArray()).Replace(" ", "+")), ApplicationServicesBase.Settings("server.geocoding.google.key")));
        }
Example #12
0
        protected virtual string ToSize(BusinessRulesBase rules, JObject autofill)
        {
            var width = 0;

            if (autofill.Property("width") != null)
            {
                width = ((int)(autofill["width"]));
            }
            if (width < 180)
            {
                width = 180;
            }
            var height = 0;

            if (autofill.Property("height") != null)
            {
                height = ((int)(autofill["height"]));
            }
            if (height < 180)
            {
                height = 180;
            }
            return(string.Format("{0}x{1}", width, height));
        }
Example #13
0
        protected virtual string CreateRequestUrl(BusinessRulesBase rules, JObject autofill)
        {
            var components = new List <string>();
            var pb         = new List <string>();
            // address 1
            var addr1 = ((string)(autofill["address1"]));

            if (!(string.IsNullOrEmpty(addr1)))
            {
                pb.Add(addr1);
            }
            // city
            var city = ((string)(autofill["city"]));

            if (!(string.IsNullOrEmpty(city)))
            {
                pb.Add(city);
            }
            // region
            var region = ((string)(autofill["region"]));

            if (!(string.IsNullOrEmpty(region)))
            {
                pb.Add(region);
            }
            // postalcode
            var postalCode = ((string)(autofill["postalcode"]));

            if (string.IsNullOrEmpty(postalCode))
            {
                postalCode = ((string)(autofill.GetValue("componentpostalcode", StringComparison.OrdinalIgnoreCase)));
            }
            if (!(string.IsNullOrEmpty(postalCode)))
            {
                components.Add(("postal_code:" + postalCode));
            }
            // country
            var country = ((string)(autofill["country"]));

            if (!(string.IsNullOrEmpty(country)))
            {
                if ((country.Length > 2) && (!(string.IsNullOrEmpty(postalCode)) || !(string.IsNullOrEmpty(region))))
                {
                    var allCultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
                    foreach (var ci in allCultures)
                    {
                        var ri = new RegionInfo(ci.LCID);
                        if (ri.EnglishName.Equals(country, StringComparison.CurrentCultureIgnoreCase) || ri.NativeName.Equals(country, StringComparison.CurrentCultureIgnoreCase))
                        {
                            country = ri.TwoLetterISORegionName;
                            break;
                        }
                    }
                }
                if (country.Length == 2)
                {
                    components.Add(("country:" + country));
                }
                else
                {
                    pb.Add(country);
                }
            }
            var requestUrl = string.Format("https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}", HttpUtility.UrlEncode(string.Join(",", pb.ToArray()).Replace(" ", "+")), ApplicationServicesBase.Settings("server.geocoding.google.key"));

            if (components.Count > 0)
            {
                requestUrl = string.Format("{0}&components={1}", requestUrl, HttpUtility.UrlEncode(string.Join("|", components.ToArray()).Replace(" ", "+")));
            }
            return(requestUrl);
        }
Example #14
0
 protected virtual string CreateRequestUrl(BusinessRulesBase rules, JObject autofill)
 {
     // size=512x512&maptype=roadma&markers=size:mid|color:red|San Francisco,CA|Oakland,CA|San Jose,CA&key=737dk343kjfld83lkjfdlk
     return(string.Format("https://maps.googleapis.com/maps/api/staticmap?size={0}&scale={1}&maptype={2}&zoo" +
                          "m={3}&markers={4}&key={5}", ToSize(rules, autofill), ToScale(rules, autofill), ToMapType(rules, autofill), ToZoom(rules, autofill), ToMarkers(rules, autofill), ApplicationServicesBase.Settings("server.geocoding.google.key")));
 }
Example #15
0
 protected virtual string ToMarkers(BusinessRulesBase rules, JObject autofill)
 {
     // size:mid|color:red|San Francisco,CA|Oakland,CA|San Jose,CA
     return(HttpUtility.UrlEncode(string.Format("size:{0}|color:{1}|{2}", ToMarkerSize(rules, autofill), ToMarkerColor(rules, autofill), ToMarkerList(rules, autofill))));
 }
Example #16
0
 protected virtual JToken Process(BusinessRulesBase rules, JObject autoFill)
 {
     return(null);
 }